[BUG][JAVA][SPRING] Endpoints don't support different schema per content-type
See original GitHub issueBug 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
https://github.com/OpenAPITools/openapi-generator/issues/144 https://github.com/OpenAPITools/openapi-generator/issues/3990 https://github.com/OpenAPITools/openapi-generator/pull/3991
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:8 (3 by maintainers)
Top GitHub Comments
I’d like to push this 🙂
For python-experimental I am using #10973 in this PR: https://github.com/OpenAPITools/openapi-generator/pull/8325 to allow users to send request bodies with different body content types supported. One can see it working here: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/add_pet.py#L78
Java and other generators could do something similar