-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
multipart/form-data with mixed @RequestParts fails to provide correct Content-Type in HTTP request #396
Comments
It should work without any extra configuration. You just need to remove @RequestPart(value = "configuration"). @RequestMapping(
method = PUT,
consumes = {MediaType.MULTIPART_FORM_DATA_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE}
)
public ResponseEntity<?> put(
@PathVariable("config") final String config,
final Configuration configuration,
@RequestPart(value = "file") final MultipartFile aFile) {
// -> Configuration is any data object that will be uploaded as JSON
} |
Hi @bnasslahsen tlrd; removing the You are telling me to change my program code in order to make swagger work? Well .. removing the spring-web annotation
Your solution would work for a API like this: public ResponseEntity<?> put(@PathVariable("config") final String config,
final String configuration,
@RequestPart(value = "file") final MultipartFile aFile) { But that is not what is intended. Somehow swagger must be able to handle a multipart request with each request-part having a defined I do not see any way to make spring handle a (broken?) http multipart request that fails to declare a content-type for each request part. Looking at swagger config, the only way I can make swagger-ui work is to use two file-upload buttons and upload a .json file for the first part (see my comment above). But then: I don't know how produce such a swagger config using swagger-annotations - which would be a good way to solve the issue ... :-( (-> swagger-api/swagger-core#3433) Best, |
If you add on the top of your class Is it working from the swagger-ui in your case? |
Hi @bnasslahsen thanks for the fast responses from your side - very helpful! Adding the
So part of the problem seems solved. BUT... This now has a side effect! Assume we have a second service: @RequestMapping(
method = PUT,
value = {"/configurations/{config}/test"},
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE}
)
public ResponseEntity<Void> put2(@PathVariable("config") final String config,
@RequestBody final Configuration configuration) {...} Now all the occurences of
(The service still works in swagger-ui! But as default model/schema only Also Using a
does not overwrite the values for this service. Looks like the Any idea here? I think it would be appropriate, if each service can be independently declared as needed. Best, |
It really depends if this annotation is valid for all the services or not. I think it will be more convenient to allow I guess the following syntax, will be more convinient in the case, you don't want add the public ResponseEntity<?> put(
@PathVariable("config") final String config,
@RequestPart(value = "configuration") @Parameter(name = "configuration", schema = @Schema(name ="configuration", type = "string", format = "binary")) final Configuration configuration,
@RequestPart(value = "file") final MultipartFile aFile) I can add this enhancement for the next release. |
The I also thought it would be possible to define the complete swagger configuration for the request-body using the
But somehow there is no way to add the "properties". Do you have any idea why there is no |
As @stefan-huettemann mentioned. The above solution has two downsides:
Is there already a solution for those two points? |
Hi. Great work with springdoc-openapi!
PROBLEM
With sprindoc 1.2.29 and spring-boot 2.2.4 I run into a problem with a rest controller:
spring-doc produces the following swagger config:
which results in a HTTP multipart request of the form:
This fails with spring boot
415: HttpMediaTypeNotSupportedException: Content type 'application/octet-stream'
The correct HTTP request would be to have a
Content-Type: application/json
declaration for the first part:Questions:
Content-Type: application/json
for the first part@RequestBody
annotation...Working Solution in swagger config
The following swagger config would provide a possible solution
This result in a swagger-ui with two file-upload buttons. Using a file-upload button the content-type of the mutlipart-request gets set (if the user uploads a .JSON file for parameter "configuration").
BUT: as said above - I fail to produce any such swagger configuration using swagger annotations.
Well ... any idea how to resolve this?
Best,
-Stefan
The text was updated successfully, but these errors were encountered: