Skip to content

Commit bc185f4

Browse files
committed
A HTTP header in multipart/form-data is handled as form item instead of header. fixes #1842
1 parent 0adc7e2 commit bc185f4

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
335335
while (it.hasNext()) {
336336
Entry<ParameterId, Parameter> entry = it.next();
337337
Parameter parameter = entry.getValue();
338-
if (!ParameterIn.PATH.toString().equals(parameter.getIn())) {
338+
if (!ParameterIn.PATH.toString().equals(parameter.getIn()) && !ParameterIn.HEADER.toString().equals(parameter.getIn() )
339+
&& !ParameterIn.COOKIE.toString().equals(parameter.getIn())) {
339340
io.swagger.v3.oas.models.media.Schema<?> itemSchema = new io.swagger.v3.oas.models.media.Schema<>();
340341
itemSchema.setName(entry.getKey().getpName());
341342
itemSchema.setDescription(parameter.getDescription());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.http.MediaType;
2828
import org.springframework.web.bind.annotation.PathVariable;
2929
import org.springframework.web.bind.annotation.PostMapping;
30+
import org.springframework.web.bind.annotation.RequestHeader;
3031
import org.springframework.web.bind.annotation.RequestPart;
3132
import org.springframework.web.bind.annotation.RestController;
3233
import org.springframework.web.multipart.MultipartFile;
@@ -42,7 +43,7 @@ public String createTest1(@PathVariable String username, @RequestPart("test") My
4243

4344
@PostMapping(value = "/test2/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
4445
public String createTest2(@PathVariable String username, @RequestPart("image") MultipartFile imageFile,
45-
@RequestPart("test") MyTestDto test) {
46+
@RequestPart("test") MyTestDto test, @RequestHeader("My-Header") String workspaceId) {
4647
return null;
4748
}
4849

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,31 @@
1111
}
1212
],
1313
"paths": {
14-
"/test1/{username}": {
14+
"/test3": {
1515
"post": {
1616
"tags": [
1717
"hello-controller"
1818
],
19-
"operationId": "createTest1",
20-
"parameters": [
21-
{
22-
"name": "username",
23-
"in": "path",
24-
"required": true,
25-
"schema": {
26-
"type": "string"
27-
}
28-
}
29-
],
19+
"operationId": "createTest3",
3020
"requestBody": {
3121
"content": {
3222
"multipart/form-data": {
3323
"schema": {
3424
"required": [
35-
"image",
25+
"doc",
3626
"test"
3727
],
3828
"type": "object",
3929
"properties": {
40-
"image": {
41-
"type": "string",
42-
"format": "binary"
43-
},
4430
"test": {
4531
"$ref": "#/components/schemas/MyTestDto"
32+
},
33+
"doc": {
34+
"type": "array",
35+
"items": {
36+
"type": "string",
37+
"format": "binary"
38+
}
4639
}
4740
}
4841
}
@@ -77,6 +70,14 @@
7770
"schema": {
7871
"type": "string"
7972
}
73+
},
74+
{
75+
"name": "My-Header",
76+
"in": "header",
77+
"required": true,
78+
"schema": {
79+
"type": "string"
80+
}
8081
}
8182
],
8283
"requestBody": {
@@ -115,31 +116,38 @@
115116
}
116117
}
117118
},
118-
"/test3": {
119+
"/test1/{username}": {
119120
"post": {
120121
"tags": [
121122
"hello-controller"
122123
],
123-
"operationId": "createTest3",
124+
"operationId": "createTest1",
125+
"parameters": [
126+
{
127+
"name": "username",
128+
"in": "path",
129+
"required": true,
130+
"schema": {
131+
"type": "string"
132+
}
133+
}
134+
],
124135
"requestBody": {
125136
"content": {
126137
"multipart/form-data": {
127138
"schema": {
128139
"required": [
129-
"doc",
140+
"image",
130141
"test"
131142
],
132143
"type": "object",
133144
"properties": {
134-
"doc": {
135-
"type": "array",
136-
"items": {
137-
"type": "string",
138-
"format": "binary"
139-
}
140-
},
141145
"test": {
142146
"$ref": "#/components/schemas/MyTestDto"
147+
},
148+
"image": {
149+
"type": "string",
150+
"format": "binary"
143151
}
144152
}
145153
}

0 commit comments

Comments
 (0)