swagger-api / swagger-api/swagger-codegen
oneOf in generated spring server return empty JSON
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Q&A (please complete the following information)
- OS: RHEL 7 (docker)
- Browser: yandex broser
- Version: latest container (swagger ui)
- Method of installation: docker
- Swagger/OpenAPI version: 3.0.2
Content & configuration
Example Swagger/OpenAPI definition:
Path is:
/choiceTest:
post:
operationId: "ChoiceTest"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/typicalRequest"
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/checkChoice"
ComponentSchema is:
checkChoice:
type: "object"
oneOf:
- properties:
integerValue:
format: "int32"
type: "integer"
- properties:
longValue:
format: "int64"
type: "integer"
- properties:
stringValue:
type: "string"
- properties:
doubleValue:
format: "double"
type: "number"
Describe the bug you're encountering
if you define oneOF and generate a server. Then even if the value taken from the swagger ui is inserted correctly, an empty json will be returned
To reproduce...
Use swagger ui.
Steps to reproduce the behavior:
- Define any type with one of.
- Generate a spring server.
- In controller define correct value
Expected behavior
Json with a valid value in response. (Actually it return {})
Screenshots


Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the supplied OpenAPI 3.0.2 schema in Swagger UI and a generated Spring server. Inspect how the generated oneOf response is serialized, then compare it with a response using a non-oneOf schema; done means the valid selected value is returned as JSON instead of {}.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100