[BUG] [Spring] Default interfaces do not contain response mediatypes except application/json
Created by: networkinss
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.