OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Spring] Default interfaces do not contain response mediatypes except application/json
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
Sample openapi doc causing the issue.
issue_missingmediatypes.txt
Description
The default interface does not contain the mediatypes (empty) except for mediatype application/json.
I provided a yaml with mediatypes application/hal+json and text/plain to reproduce the issue.
This leads to a http status 500 if the stub is executed and api called with Postman.
Spring throws exception:
org.springframework.util.InvalidMimeTypeException: Invalid mime type "": 'mimeType' must not be empty
because the code (is)
mediaType.isCompatibleWith(MediaType.valueOf("")))
contains an empty string instead of (should)
mediaType.isCompatibleWith(MediaType.valueOf("application/hal+json")))
openapi-generator version
6.0.0
OpenAPI declaration file content or url
File uploaded as issue_missingmediatypes.txt, please rename to issue_missingmediatypes.yaml.
Generation Details
java -jar openapi-generator-cli-6.0.0.jar generate -i issue_missingmediatypes.yaml -g spring
Steps to reproduce
Generate stub for generator "spring" and execute "mvn spring-boot:run".
Request API with Postman or
curl --location --request GET 'http://localhost:8080/api/v3/books'
--header 'Accept: application/hal+json'
Related issues/PRs
None.
Suggest a fix
I made a test method to check that and provided a fix for the mustache file:
methodBody.mustache
Line 9 and 11 were changed.
I wrote a test here:
https://github.com/networkinss/openapi-generator/blob/fix_issue_11731/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
New test method is:
doGenerateMediatypes
Fix is ready for PR, if there are no objections.
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 modules/openapi-generator/src/main/resources/JavaSpring/methodBody.mustache and the SpringCodegenTest.java test containing doGenerateMediatypes. Reproduce the Spring generator command with issue_missingmediatypes.yaml, then verify the generated interface handles application/hal+json and text/plain without an empty media type and that the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100