question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endpoints with multiple consuming media types not supported

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ndtrevivcommented, Aug 26, 2020

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.

6reactions
springdoccommented, Sep 3, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found