Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11731
Closed
Open
Issue created Feb 26, 2022 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking