-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content-type for POST endpoints with multipart/form-data does not wor…
…k since v2.4.0. Fixes #2621
- Loading branch information
1 parent
6c24eb6
commit cf12547
Showing
6 changed files
with
188 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...c-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app221/HomeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.org.springdoc.api.v30.app221; | ||
|
||
import java.io.IOException; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import test.org.springdoc.api.v30.app221.HomeController.HelloDto; | ||
import test.org.springdoc.api.v30.app221.HomeController.HelloUploadDto; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; | ||
|
||
@Tag(name = "Hello World Api", description = "This is a test api") | ||
@RequestMapping("api/hello") | ||
public interface HomeApi { | ||
|
||
@Operation(summary = "Upload new content", description = "Upload test content") | ||
@PostMapping(produces = APPLICATION_JSON_VALUE, consumes = MULTIPART_FORM_DATA_VALUE) | ||
HelloDto uploadContent(HelloUploadDto contentUploadDto) throws IOException; | ||
} |
24 changes: 24 additions & 0 deletions
24
...pi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app221/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package test.org.springdoc.api.v30.app221; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
public class HomeController implements HomeApi { | ||
|
||
@Override | ||
public HelloDto uploadContent(@Valid HelloUploadDto uploadDto) | ||
throws IOException { | ||
var fileBytes = uploadDto.file.getBytes(); | ||
return new HelloDto(uploadDto.title, fileBytes); | ||
} | ||
|
||
public record HelloDto(String title, byte[] file) {} | ||
|
||
public record HelloUploadDto(@NotNull String title, MultipartFile file) {} | ||
} |
35 changes: 35 additions & 0 deletions
35
...arter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app221/SpringDocApp221Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * * * Copyright 2019-2022 the original author or authors. | ||
* * * * * | ||
* * * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * * you may not use this file except in compliance with the License. | ||
* * * * * You may obtain a copy of the License at | ||
* * * * * | ||
* * * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * * | ||
* * * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * * See the License for the specific language governing permissions and | ||
* * * * * limitations under the License. | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v30.app221; | ||
|
||
import test.org.springdoc.api.v30.AbstractSpringDocV30Test; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
public class SpringDocApp221Test extends AbstractSpringDocV30Test { | ||
|
||
@SpringBootApplication | ||
static class SpringDocTestApp {} | ||
} |
83 changes: 83 additions & 0 deletions
83
springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app221.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "OpenAPI definition", | ||
"version": "v0" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"name": "Hello World Api", | ||
"description": "This is a test api" | ||
} | ||
], | ||
"paths": { | ||
"/api/hello": { | ||
"post": { | ||
"tags": [ | ||
"Hello World Api" | ||
], | ||
"summary": "Upload new content", | ||
"description": "Upload test content", | ||
"operationId": "uploadContent", | ||
"requestBody": { | ||
"content": { | ||
"multipart/form-data": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HelloUploadDto" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HelloDto" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"HelloUploadDto": { | ||
"required": [ | ||
"title" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"file": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
}, | ||
"HelloDto": { | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"file": { | ||
"type": "string", | ||
"format": "byte" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |