Description
When the schema contains a oneOf-field, the vars field of CodegenModel only contains the fields of two of the subschemas. This is not visible with every generator, since some generate models that use inheritance, but for generators that generate a single object with all possible fields, this results in incorrect models being generated.
I noticed this bug in a downstream library, which uses the CodegenModel directly (see quarkiverse/quarkus-openapi-generator#1275 ), but you can also reproduce it using e.g. the java-vertx generator.
Example:
- Schema Mouse:
- Schema Cat:
- Schema Dog:
- Schema Animal:
Results in:
- Model Animal:
- species
- catId
- dogId
- missing: mouseId
openapi-generator version
The downstream project uses 7.14, but I could reproduce it using the latest JAR cli build (openapi-generator-cli-8.0.0-20240727.184357-6.jar).
OpenAPI declaration file content or url
See https://github.com/fkellner/quarkus-openapi-generator/blob/bugreport/one-of-three/client/deployment/src/test/resources/openapi/one-of-three.yaml
Generation Details
For reproducing with the java-vertx client:
java -jar openapi-generator-cli-8.0.0-20240727.184357-6.jar generate -i one-of-three.yaml -g java-vertx -o out/java-vertx
Then look at the generated model RandomAnimalsResponseAnimalsInner.
Steps to reproduce
Related issues/PRs
I did not find any.
Issue in the downstream project:
quarkiverse/quarkus-openapi-generator#1275
Suggest a fix
Problem seems to be somewhere in the DefaultGenerator, in the generateModels step (schema looks okay).
The CodegenModel class I keep mentioning is this one: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java
I could not find the unit tests for the DefaultGenerator yet, but if I have more time or somebody points me in the right direction, I might be able to provide a unit test demonstrating the problem or even a pull request.
Description
When the schema contains a
oneOf-field, thevarsfield ofCodegenModelonly contains the fields of two of the subschemas. This is not visible with every generator, since some generate models that use inheritance, but for generators that generate a single object with all possible fields, this results in incorrect models being generated.I noticed this bug in a downstream library, which uses the
CodegenModeldirectly (see quarkiverse/quarkus-openapi-generator#1275 ), but you can also reproduce it using e.g. thejava-vertxgenerator.Example:
Results in:
openapi-generator version
The downstream project uses 7.14, but I could reproduce it using the latest JAR cli build (openapi-generator-cli-8.0.0-20240727.184357-6.jar).
OpenAPI declaration file content or url
See https://github.com/fkellner/quarkus-openapi-generator/blob/bugreport/one-of-three/client/deployment/src/test/resources/openapi/one-of-three.yaml
Generation Details
For reproducing with the
java-vertxclient:Then look at the generated model
RandomAnimalsResponseAnimalsInner.Steps to reproduce
java -jar openapi-generator-cli-8.0.0-20240727.184357-6.jar generate -i one-of-three.yaml -g java-vertx -o out/java-vertxRandomAnimalsResponseAnimalsInnerRelated issues/PRs
I did not find any.
Issue in the downstream project:
quarkiverse/quarkus-openapi-generator#1275
Suggest a fix
Problem seems to be somewhere in the DefaultGenerator, in the
generateModelsstep (schema looks okay).The
CodegenModelclass I keep mentioning is this one: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.javaI could not find the unit tests for the DefaultGenerator yet, but if I have more time or somebody points me in the right direction, I might be able to provide a unit test demonstrating the problem or even a pull request.