Endpoints with multiple consuming media types not supported
See original GitHub issueI have a webflux controller like this:
@RestController
@RequestMapping("/foo")
public class FooController {
@PostMapping(path = "/bar/baz", consumes = "application/x.a+json", produces = MediaType.TEXT_PLAIN_VALUE)
public String process1(@RequestBody A a) {
return a.toString();
}
@PostMapping(path = "/bar/baz", consumes = "application/x.b+json", produces = MediaType.TEXT_PLAIN_VALUE)
public String process2(@RequestBody B b) {
return b.toString();
}
}
Note that both java methods are bound to the same path - /foo/bar/baz
and same HTTP method - POST
. The only difference is in the consumed media type.
Spring Boot 2.1.7 supports this and can call the appropriate method based on the content type sent by the client.
However in case of springdoc only one of the methods are exposed. I think the Swagger UI would support multiple different media types because it has a drop down for it but currently it only has one element instead of 2.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Spring 5 consume multiple MediaType - Stack Overflow
RELEASE I have an endpoint and would like to consume multiple MediaType. In particular application/x-www-form-urlencoded and application/json ...
Read more >415 Unsupported MediaType in Spring Application - Baeldung
The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is in...
Read more >415 Unsupported Media Type - HTTP - MDN Web Docs
The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload ......
Read more >Using @Consumes and @Produces to Customize Requests ...
If a resource is unable to consume the MIME type of a client request, the Jersey runtime sends back an HTTP “415 Unsupported...
Read more >OpenAPI Specification - Version 3.0.3 - Swagger
Media type definitions are spread across several resources. ... Primitive data types in the OAS are based on the types supported by the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have an endpoint where content can be submitted either as multipart/form-data or as raw JSON in the request body.
The same endpoint, overloaded with two different Accept headers.
This feature is not a priority and the importance should be proven before being addressed. It’s not the natural choice, to create two methods for the same API resource. I will encourage you to refactor and review the design of the APIs instead.
For example, if you have swagger annotation @operation with a description of both, which one will be chosen? The same question for all the fields. summary, operationId.
You will need to clearly define the expected OpenAPI Description as well, using the swagger annotations on both methods.