Skip to content

Commit 38df7e9

Browse files
committed
Merge branch 'Mattias-Sehlstedt-complex-request-part'
2 parents d9e34c5 + cc22112 commit 38df7e9

File tree

4 files changed

+105
-28
lines changed

4 files changed

+105
-28
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/ParameterInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class ParameterInfo {
8585
private String paramType;
8686

8787
/**
88-
* if the paramater type is RequestPart
88+
* if the parameter type is RequestPart
8989
*/
9090
private boolean requestPart;
9191

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ public boolean isParamToIgnore(MethodParameter parameter) {
471471
return false;
472472
if (isRequestBodyWithMapType(parameter))
473473
return false;
474+
if (isRequestPartWithMapType(parameter))
475+
return false;
474476
return isRequestTypeToIgnore(parameter.getParameterType());
475477
}
476478

@@ -510,6 +512,23 @@ private boolean isRequestBodyWithMapType(MethodParameter parameter) {
510512
return Map.class.isAssignableFrom(parameterType);
511513
}
512514

515+
/**
516+
* Is request part with map type
517+
*
518+
* @param parameter the parameter
519+
* @return the boolean
520+
*/
521+
private boolean isRequestPartWithMapType(MethodParameter parameter) {
522+
// Check for @RequestPart annotation
523+
org.springframework.web.bind.annotation.RequestPart requestPart = parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestPart.class);
524+
if (requestPart == null) {
525+
return false;
526+
}
527+
// Check if the parameter type is assignable to Map
528+
Class<?> parameterType = parameter.getParameterType();
529+
return Map.class.isAssignableFrom(parameterType);
530+
}
531+
513532
/**
514533
* Sets params.
515534
*

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app52/HelloController.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,52 @@
2424

2525
package test.org.springdoc.api.v30.app52;
2626

27-
import java.util.List;
28-
2927
import org.springframework.http.MediaType;
30-
import org.springframework.web.bind.annotation.PathVariable;
31-
import org.springframework.web.bind.annotation.PostMapping;
32-
import org.springframework.web.bind.annotation.RequestHeader;
33-
import org.springframework.web.bind.annotation.RequestPart;
34-
import org.springframework.web.bind.annotation.RestController;
28+
import org.springframework.web.bind.annotation.*;
3529
import org.springframework.web.multipart.MultipartFile;
3630

31+
import java.util.List;
32+
import java.util.Map;
33+
3734
@RestController
3835
public class HelloController {
3936

40-
@PostMapping(value = "/test1/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
41-
public String createTest1(@PathVariable String username, @RequestPart("test") MyTestDto test,
42-
@RequestPart("image") MultipartFile imageFile) {
43-
return null;
44-
}
37+
@PostMapping(value = "/test1/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
38+
public String createTest1(
39+
@PathVariable String username,
40+
@RequestPart("test") MyTestDto test,
41+
@RequestPart("image") MultipartFile imageFile) {
42+
return null;
43+
}
44+
45+
@PostMapping(value = "/test2/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
46+
public String createTest2(
47+
@PathVariable String username,
48+
@RequestPart("image") MultipartFile imageFile,
49+
@RequestPart("test") MyTestDto test,
50+
@RequestHeader("My-Header") String workspaceId) {
51+
return null;
52+
}
4553

46-
@PostMapping(value = "/test2/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
47-
public String createTest2(@PathVariable String username, @RequestPart("image") MultipartFile imageFile,
48-
@RequestPart("test") MyTestDto test, @RequestHeader("My-Header") String workspaceId) {
49-
return null;
50-
}
54+
@PostMapping(value = "/test3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
55+
public String createTest3(
56+
@RequestPart("test") MyTestDto test,
57+
@RequestPart("doc") List<MultipartFile> multipartFiles) {
58+
return null;
59+
}
5160

52-
@PostMapping(value = "/test3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
53-
public String createTest3(@RequestPart("test") MyTestDto test,
54-
@RequestPart("doc") List<MultipartFile> multipartFiles) {
55-
return null;
56-
}
61+
@PostMapping(value = "/test4", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
62+
public String createTest4(
63+
@RequestPart List<MultipartFile> multipartFiles,
64+
@RequestPart Map<String, String> map) {
65+
return null;
66+
}
5767

58-
class MyTestDto {
59-
public String object1;
68+
class MyTestDto {
69+
public String object1;
6070

61-
public String object2;
71+
public String object2;
6272

63-
public String object3;
64-
}
73+
public String object3;
74+
}
6575
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app52.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,54 @@
1111
}
1212
],
1313
"paths": {
14+
"/test4": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "createTest4",
20+
"requestBody": {
21+
"content": {
22+
"multipart/form-data": {
23+
"schema": {
24+
"required": [
25+
"map",
26+
"multipartFiles"
27+
],
28+
"type": "object",
29+
"properties": {
30+
"multipartFiles": {
31+
"type": "array",
32+
"items": {
33+
"type": "string",
34+
"format": "binary"
35+
}
36+
},
37+
"map": {
38+
"type": "object",
39+
"additionalProperties" : {
40+
"type": "string"
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
},
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"type": "string"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
},
1462
"/test3": {
1563
"post": {
1664
"tags": [

0 commit comments

Comments
 (0)