OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] oneOf inception provides wrong output in toJson
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
to json functions gives the wrong output
openapi-generator version
7.5.0 -> no library defined
OpenAPI declaration file content or url
The following Yaml
pt:
type: object
additionalProperties:
nullable: true
oneOf:
- $ref: "#/components/schemas/mv"
- $ref: "#/components/schemas/pi"
- type: array
items:
oneOf:
- $ref: "#/components/schemas/mv"
- $ref: "#/components/schemas/pi"
mv:
oneOf:
- $ref: "#/components/schemas/sv"
- type: array
items:
$ref: "#/components/schemas/sv"
sv:
oneOf:
- type: number
format: double
- type: string
pi:
type: object
properties:
value:
$ref: "#/components/schemas/mv"
additionalProperties:
$ref: "#/components/schemas/pt"
With the following Java
Pi pi = new Pi().value(new Mv(new Sv(1d)));
pi.putAdditionalProperty("key", new Pi().value(new Mv(new Sv(0d))));
pi.toJson();
log.debug("{}", pi.toJson());
gives:
{"value":{"instance":1.0,"isNullable":false,"schemaType":"oneOf"},"key":{"value":{"instance":0.0,"isNullable":false,"schemaType":"oneOf"}}}
Where i would expect
{"value": 1.0,"key":{"value": 0.0}}
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
Reproduce the report by generating the Java models from the supplied OpenAPI YAML with openapi-generator 7.5.0, then inspect the generated Pi, Mv, and Sv classes and their toJson behavior. Compare the serialized output with the expected JSON for the nested oneOf values; done means the generated output omits the internal oneOf metadata and represents the numeric values correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100