-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[BUG] [Spring] Default interfaces do not contain response mediatypes except application/json #11731
Comments
My fix is not correct yet. |
@networkinss @MelleD @tamershahin I'll take a look on all of this issues/requests |
I think that in general mustache is not enough to render this correctly. in the data it has to render there is only one I did some play around with the mustache file and the Kotlin-spring generator like this: openapi
api.mustache
returnValue.mustache
service.mustache :
the generate controller now has 2 methods, as the service interface. but only one returnType specified. e.g.:
|
@tamershahin change seems to be correct but would be better to do this with additional configuration property so that users has a chance to disable this |
it's partially correct: I would expect that auto generated controller, interfaces, etc would report the right return object. e.g.:
if my requests has a header "Accept": "text/plain" the controller should work with maybe first we should try to replicate the spring boot setup we see more useful and possible to generate.. don't know |
@networkinss I have fixed issue with custom content-type - #12460 Regarding multiple response types - still in progress |
Any progress on this? |
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.
The text was updated successfully, but these errors were encountered: