Skip to content

Commit eb9536a

Browse files
author
bnasslahsen
committed
Merge branch 'patrykpacewicz-bugfix/531-encoding-section-in-multipart-request'
2 parents ca3ef4d + c4cc869 commit eb9536a

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ private void buildContent(RequestBody requestBody, MethodAttributes methodAttrib
148148
if (content.get(value) != null) {
149149
mediaTypeObject.setExample(content.get(value).getExample());
150150
mediaTypeObject.setExamples(content.get(value).getExamples());
151+
mediaTypeObject.setEncoding(content.get(value).getEncoding());
151152
}
152153
content.addMediaType(value, mediaTypeObject);
153154
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.app104;
2+
3+
public class ExampleBody {
4+
private String stringParam;
5+
6+
private int intParam;
7+
8+
public String getStringParam() {
9+
return stringParam;
10+
}
11+
12+
public void setStringParam(String stringParam) {
13+
this.stringParam = stringParam;
14+
}
15+
16+
public int getIntParam() {
17+
return intParam;
18+
}
19+
20+
public void setIntParam(int intParam) {
21+
this.intParam = intParam;
22+
}
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.app104;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import io.swagger.v3.oas.annotations.media.Content;
23+
import io.swagger.v3.oas.annotations.media.Encoding;
24+
import io.swagger.v3.oas.annotations.parameters.RequestBody;
25+
26+
import org.springframework.http.MediaType;
27+
import org.springframework.web.bind.annotation.PostMapping;
28+
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.RequestPart;
30+
import org.springframework.web.bind.annotation.RestController;
31+
import org.springframework.web.multipart.MultipartFile;
32+
33+
@RestController
34+
public class HelloController {
35+
36+
@PostMapping(value = "/test/103", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
37+
@Operation(
38+
requestBody = @RequestBody(
39+
content = @Content(
40+
encoding = @Encoding(name = "body", contentType = "application/json")
41+
)
42+
)
43+
)
44+
public String postMyRequestBody(
45+
@RequestPart("body") ExampleBody body,
46+
@RequestParam("file") MultipartFile file
47+
) {
48+
return null;
49+
}
50+
51+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test.org.springdoc.api.app104;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
public class SpringDocApp104Test extends AbstractSpringDocTest {
8+
@SpringBootApplication
9+
static class SpringDocTestApp {}
10+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
"/test/103": {
15+
"post": {
16+
"tags": [ "hello-controller" ],
17+
"operationId": "postMyRequestBody",
18+
"requestBody": {
19+
"content": {
20+
"multipart/form-data":{
21+
"schema":{
22+
"type":"object",
23+
"properties":{
24+
"body":{"$ref":"#/components/schemas/ExampleBody"},
25+
"file":{"type":"string","format":"binary"}
26+
}
27+
},
28+
"encoding":{
29+
"body":{
30+
"contentType":"application/json"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"responses": {
37+
"200": {
38+
"description": "default response",
39+
"content": {
40+
"*/*": {
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
},
51+
"components": {
52+
"schemas":{
53+
"ExampleBody":{
54+
"type":"object",
55+
"properties":{
56+
"stringParam":{ "type":"string" },
57+
"intParam":{ "type":"integer", "format":"int32" }
58+
}
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)