Skip to content

[BUG][JAVA][SPRING] Endpoints don't support different schema per content-type #6708

Open
@bonii-xx

Description

@bonii-xx

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

We want to support multiple schema for a single endpoint, depending on content-types. According to https://swagger.io/docs/specification/describing-request-body/ this is exactly what the OpenAPI spec should support:

The requestBody is more flexible in that it lets you consume different media types, such as JSON, XML, form data, plain text, and others, and use different schemas for different media types.

However the generator always combines the different content-types into a single endpoint, only using the first content-type, with the following output:

[INFO] --- openapi-generator-maven-plugin:4.3.1:generate (testEndpoint) @ pac-service ---
[INFO] OpenAPI Generator: spring (server)
[INFO] Generator 'spring' is considered stable.
[WARNING] Multiple schemas found in the OAS 'content' section, returning only the first one (application/x.foo+json)
Multiple schemas found in the OAS 'content' section, returning only the first one (application/x.foo+json)
openapi-generator version

openapi-generator-maven-plugin 4.3.1

OpenAPI declaration file content or url

https://gist.github.com/bonii-xx/1d48dd6d8e624aa3689cbb062ac2a7d2

Command line used for generation

Via openapi-generator-maven-plugin.

Steps to reproduce

Paste file above into https://editor.swagger.io/
Click on Generate Server -> spring
Check code of generated FoobarApi
Expect 2 endpoints with different RequestBodies, but only one is present handling both. The second request body schema for the second content type is not accepted.

Related issues/PRs

#144
#3990
#3991

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions