Skip to content

Commit 24a5840

Browse files
committed
create better "consumes" mapping
1 parent f5c214b commit 24a5840

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main/kotlin/io/openapiprocessor/spring/writer/java/MappingAnnotationWriter.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ class MappingAnnotationWriter: CoreMappingAnnotationWriter {
3737
mapping += "("
3838
mapping += "path = " + quote(endpoint.path)
3939

40-
if (endpoint.requestBodies.isNotEmpty()) {
40+
val consumes = endpoint.getConsumesContentTypes()
41+
if (consumes.isNotEmpty()) {
4142
mapping += ", "
42-
mapping += "consumes = {" + quote(endpoint.getRequestBody().contentType) + "}"
43+
mapping += "consumes = {"
44+
mapping += consumes.map {
45+
quote(it)
46+
}.joinToString(", ")
47+
mapping += '}'
4348
}
4449

4550
val contentTypes = endpointResponse.contentTypes

src/testInt/resources/tests/params-request-body-multipart-mapping/generated/api/Api.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515

1616
public interface Api {
1717

18-
@PostMapping(path = "/multipart/single-file")
18+
@PostMapping(
19+
path = "/multipart/single-file",
20+
consumes = {"multipart/form-data"})
1921
ResponseEntity<Void> postMultipartSingleFile(
2022
@RequestParam(name = "file") MultipartFile file,
2123
@RequestParam(name = "other") String other);
2224

23-
@PostMapping(path = "/multipart/multiple-files")
25+
@PostMapping(
26+
path = "/multipart/multiple-files",
27+
consumes = {"multipart/form-data"})
2428
ResponseEntity<Void> postMultipartMultipleFiles(
2529
@RequestParam(name = "files") MultipartFile[] files,
2630
@RequestParam(name = "other") String other);

0 commit comments

Comments
 (0)