From c4f7c07fa33e0935b6c7438ed33d1056cd2a27ce Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Fri, 15 Dec 2023 16:37:30 +0200 Subject: [PATCH] Swagger description for image type and key --- .../server/controller/ImageController.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/ImageController.java b/application/src/main/java/org/thingsboard/server/controller/ImageController.java index c66af2c754..f4923a6c26 100644 --- a/application/src/main/java/org/thingsboard/server/controller/ImageController.java +++ b/application/src/main/java/org/thingsboard/server/controller/ImageController.java @@ -89,6 +89,10 @@ public class ImageController extends BaseController { private static final String SYSTEM_IMAGE = "system"; private static final String TENANT_IMAGE = "tenant"; + private static final String IMAGE_TYPE_PARAM_DESCRIPTION = "Type of the image: tenant or system"; + private static final String IMAGE_TYPE_PARAM_ALLOWABLE_VALUES = "tenant, system"; + private static final String IMAGE_KEY_PARAM_DESCRIPTION = "Image resource key, for example thermostats_dashboard_background.jpeg"; + @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PostMapping("/api/image") public TbResourceInfo uploadImage(@RequestPart MultipartFile file, @@ -117,7 +121,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PutMapping(IMAGE_URL) - public TbResourceInfo updateImage(@PathVariable String type, + public TbResourceInfo updateImage(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @RequestPart MultipartFile file) throws Exception { TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE); @@ -135,7 +141,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PutMapping(IMAGE_URL + "/info") - public TbResourceInfo updateImageInfo(@PathVariable String type, + public TbResourceInfo updateImageInfo(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @RequestBody TbResourceInfo newImageInfo) throws ThingsboardException { TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE); @@ -145,7 +153,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @PutMapping(IMAGE_URL + "/public/{isPublic}") - public TbResourceInfo updateImagePublicStatus(@PathVariable String type, + public TbResourceInfo updateImagePublicStatus(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @PathVariable boolean isPublic) throws ThingsboardException { TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE); @@ -155,7 +165,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @GetMapping(value = IMAGE_URL, produces = "image/*") - public ResponseEntity downloadImage(@PathVariable String type, + public ResponseEntity downloadImage(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @RequestHeader(name = HttpHeaders.IF_NONE_MATCH, required = false) String etag) throws Exception { return downloadIfChanged(type, key, etag, false); @@ -170,7 +182,10 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @GetMapping(value = IMAGE_URL + "/export") - public ImageExportData exportImage(@PathVariable String type, @PathVariable String key) throws Exception { + public ImageExportData exportImage(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) + @PathVariable String key) throws Exception { TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.READ); ImageDescriptor descriptor = imageInfo.getDescriptor(ImageDescriptor.class); byte[] data = imageService.getImageData(imageInfo.getTenantId(), imageInfo.getId()); @@ -212,7 +227,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @GetMapping(value = IMAGE_URL + "/preview", produces = "image/png") - public ResponseEntity downloadImagePreview(@PathVariable String type, + public ResponseEntity downloadImagePreview(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @RequestHeader(name = HttpHeaders.IF_NONE_MATCH, required = false) String etag) throws Exception { return downloadIfChanged(type, key, etag, true); @@ -220,7 +237,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @GetMapping(IMAGE_URL + "/info") - public TbResourceInfo getImageInfo(@PathVariable String type, + public TbResourceInfo getImageInfo(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key) throws ThingsboardException { return checkImageInfo(type, key, Operation.READ); } @@ -251,7 +270,9 @@ public class ImageController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @DeleteMapping(IMAGE_URL) - public ResponseEntity deleteImage(@PathVariable String type, + public ResponseEntity deleteImage(@ApiParam(value = IMAGE_TYPE_PARAM_DESCRIPTION, allowableValues = IMAGE_TYPE_PARAM_ALLOWABLE_VALUES, required = true) + @PathVariable String type, + @ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true) @PathVariable String key, @RequestParam(name = "force", required = false) boolean force) throws ThingsboardException { TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.DELETE);