OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Multiple response media types causing wrong @RequestMapping(produces=example)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have an openapi specification that contains an endpoint with 2 possible responses (201 and 4xx). Each one has a media type different. When it is generated the api code it is generated something like this:
https://gist.github.com/jgarciasm/5853cf0dac2a2eb597981db065574f60
That code generates the following error when trying to run/debug:
´´´
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invalid mapping on handler class [package.EntityApiController]: public org.springframework.http.ResponseEntity package.EntityApiController.postEntity()
´´´
openapi-generator version
OpenAPI declaration file content or url
https://gist.github.com/jgarciasm/c9e7a3723678d14ab044cadddcaa522d
Generation Details
It is generated an api with @RequestMapping.value with the 2 media types sepparated by ",". That is an error, should be separated by ";".
Steps to reproduce
Using ´´´org.openapitools.codegen.languages.SpringCodegen´´´.
Within any spec place 2 possible responses, both with different media types (as in the example).
Suggest a fix
The problem is being cause because of the "," to separate the 2 media types, it should be ",".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.openapitools.codegen.languages.SpringCodegen and the supplied OpenAPI declaration and generated-code gist. Reproduce an endpoint with 201 and 4xx responses using different media types, then inspect the generated @RequestMapping annotation. Done means Spring accepts the generated mapping without a BeanCreationException and the media types are separated correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100