Skip to content

Commit bae53c3

Browse files
committed
multpart/form-data single paramter cannot resolve in ui. Fixes #1185.
1 parent 9541311 commit bae53c3

File tree

6 files changed

+171
-1
lines changed

6 files changed

+171
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private Schema calculateRequestBodySchema(Components components, ParameterInfo p
336336
requestBodyInfo.getMergedSchema().addProperties(paramName, schemaN);
337337
schemaN = requestBodyInfo.getMergedSchema();
338338
}
339-
else if (schemaN instanceof FileSchema || schemaN instanceof ArraySchema && ((ArraySchema) schemaN).getItems() instanceof FileSchema) {
339+
else if (parameterInfo.isRequestPart() || schemaN instanceof FileSchema || schemaN instanceof ArraySchema && ((ArraySchema) schemaN).getItems() instanceof FileSchema) {
340340
schemaN = new ObjectSchema().addProperties(paramName, schemaN);
341341
requestBodyInfo.setMergedSchema(schemaN);
342342
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public class ParameterInfo {
7171
*/
7272
private String paramType;
7373

74+
/**
75+
* if the paramater type is RequestPart
76+
*/
77+
private boolean requestPart;
78+
7479
private static final Logger LOGGER = LoggerFactory.getLogger(ParameterInfo.class);
7580

7681

@@ -280,4 +285,22 @@ private void calculateParams(RequestHeader requestHeader) {
280285
this.defaultValue = requestHeader.defaultValue();
281286
this.paramType = ParameterIn.HEADER.toString();
282287
}
288+
289+
/**
290+
* Is request part boolean.
291+
*
292+
* @return the boolean
293+
*/
294+
public boolean isRequestPart() {
295+
return requestPart;
296+
}
297+
298+
/**
299+
* Sets request part.
300+
*
301+
* @param requestPart the request part
302+
*/
303+
public void setRequestPart(boolean requestPart) {
304+
this.requestPart = requestPart;
305+
}
283306
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public void calculateRequestBodyInfo(Components components, MethodAttributes met
240240
if (requestPart != null){
241241
paramName = StringUtils.defaultIfEmpty(requestPart.value(), requestPart.name());
242242
parameterInfo.setRequired(requestPart.required());
243+
parameterInfo.setRequestPart(true);
243244
}
244245
paramName = StringUtils.defaultIfEmpty(paramName, parameterInfo.getpName());
245246
parameterInfo.setpName(paramName);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app161;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import io.swagger.v3.oas.annotations.Parameter;
23+
24+
import org.springframework.http.MediaType;
25+
import org.springframework.http.ResponseEntity;
26+
import org.springframework.web.bind.annotation.PostMapping;
27+
import org.springframework.web.bind.annotation.RequestPart;
28+
import org.springframework.web.bind.annotation.RestController;
29+
30+
@RestController
31+
public class HelloController {
32+
33+
34+
@Operation(summary = "add")
35+
@PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
36+
public ResponseEntity<Void> add(@Parameter(description = "content") @RequestPart(value = "content") String content) throws Exception {
37+
return null;
38+
}
39+
40+
41+
@Operation(summary = "add2")
42+
@PostMapping(value = "/add2", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
43+
public ResponseEntity<Void> add2(
44+
@Parameter(description = "content") @RequestPart(value = "content") String content,
45+
@RequestPart(value = "type") String type
46+
) {
47+
return null;
48+
}
49+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test.org.springdoc.api.app161;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
public class SpringDocApp161Test extends AbstractSpringDocTest {
8+
9+
@SpringBootApplication
10+
static class SpringDocTestApp {}
11+
12+
13+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/add": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"summary": "add",
20+
"operationId": "add",
21+
"requestBody": {
22+
"content": {
23+
"multipart/form-data": {
24+
"schema": {
25+
"required": [
26+
"content"
27+
],
28+
"type": "object",
29+
"properties": {
30+
"content": {
31+
"type": "string",
32+
"description": "content"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"responses": {
40+
"200": {
41+
"description": "OK"
42+
}
43+
}
44+
}
45+
},
46+
"/add2": {
47+
"post": {
48+
"tags": [
49+
"hello-controller"
50+
],
51+
"summary": "add2",
52+
"operationId": "add2",
53+
"requestBody": {
54+
"content": {
55+
"multipart/form-data": {
56+
"schema": {
57+
"required": [
58+
"content",
59+
"type"
60+
],
61+
"type": "object",
62+
"properties": {
63+
"content": {
64+
"type": "string",
65+
"description": "content"
66+
},
67+
"type": {
68+
"type": "string"
69+
}
70+
}
71+
}
72+
}
73+
}
74+
},
75+
"responses": {
76+
"200": {
77+
"description": "OK"
78+
}
79+
}
80+
}
81+
}
82+
},
83+
"components": {}
84+
}

0 commit comments

Comments
 (0)