diff --git a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/ParameterInfo.java b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/ParameterInfo.java index 11e7acc0f..93098ce6d 100644 --- a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/ParameterInfo.java +++ b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/ParameterInfo.java @@ -85,7 +85,7 @@ public class ParameterInfo { private String paramType; /** - * if the paramater type is RequestPart + * if the parameter type is RequestPart */ private boolean requestPart; diff --git a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java index 681a61570..401be359e 100644 --- a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java +++ b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java @@ -471,6 +471,8 @@ public boolean isParamToIgnore(MethodParameter parameter) { return false; if (isRequestBodyWithMapType(parameter)) return false; + if (isRequestPartWithMapType(parameter)) + return false; return isRequestTypeToIgnore(parameter.getParameterType()); } @@ -510,6 +512,23 @@ private boolean isRequestBodyWithMapType(MethodParameter parameter) { return Map.class.isAssignableFrom(parameterType); } + /** + * Is request part with map type + * + * @param parameter the parameter + * @return the boolean + */ + private boolean isRequestPartWithMapType(MethodParameter parameter) { + // Check for @RequestPart annotation + org.springframework.web.bind.annotation.RequestPart requestPart = parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestPart.class); + if (requestPart == null) { + return false; + } + // Check if the parameter type is assignable to Map + Class parameterType = parameter.getParameterType(); + return Map.class.isAssignableFrom(parameterType); + } + /** * Sets params. * diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app52/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app52/HelloController.java index 550b17a97..bbdb8e549 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app52/HelloController.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app52/HelloController.java @@ -24,42 +24,52 @@ package test.org.springdoc.api.v30.app52; -import java.util.List; - import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.List; +import java.util.Map; + @RestController public class HelloController { - @PostMapping(value = "/test1/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public String createTest1(@PathVariable String username, @RequestPart("test") MyTestDto test, - @RequestPart("image") MultipartFile imageFile) { - return null; - } + @PostMapping(value = "/test1/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String createTest1( + @PathVariable String username, + @RequestPart("test") MyTestDto test, + @RequestPart("image") MultipartFile imageFile) { + return null; + } + + @PostMapping(value = "/test2/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String createTest2( + @PathVariable String username, + @RequestPart("image") MultipartFile imageFile, + @RequestPart("test") MyTestDto test, + @RequestHeader("My-Header") String workspaceId) { + return null; + } - @PostMapping(value = "/test2/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public String createTest2(@PathVariable String username, @RequestPart("image") MultipartFile imageFile, - @RequestPart("test") MyTestDto test, @RequestHeader("My-Header") String workspaceId) { - return null; - } + @PostMapping(value = "/test3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String createTest3( + @RequestPart("test") MyTestDto test, + @RequestPart("doc") List multipartFiles) { + return null; + } - @PostMapping(value = "/test3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public String createTest3(@RequestPart("test") MyTestDto test, - @RequestPart("doc") List multipartFiles) { - return null; - } + @PostMapping(value = "/test4", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String createTest4( + @RequestPart List multipartFiles, + @RequestPart Map map) { + return null; + } - class MyTestDto { - public String object1; + class MyTestDto { + public String object1; - public String object2; + public String object2; - public String object3; - } + public String object3; + } } \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app52.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app52.json index 351bef514..09f4f2d88 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app52.json +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app52.json @@ -11,6 +11,54 @@ } ], "paths": { + "/test4": { + "post": { + "tags": [ + "hello-controller" + ], + "operationId": "createTest4", + "requestBody": { + "content": { + "multipart/form-data": { + "schema": { + "required": [ + "map", + "multipartFiles" + ], + "type": "object", + "properties": { + "multipartFiles": { + "type": "array", + "items": { + "type": "string", + "format": "binary" + } + }, + "map": { + "type": "object", + "additionalProperties" : { + "type": "string" + } + } + } + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, "/test3": { "post": { "tags": [