You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the 7.0.1 java generator, the above schema will generate this Title model:
publicclassTitle {
publicenumTypeEnum {
TITLE("title"),
SUBTITLE("subtitle"),
PARAGRAPH("paragraph");
// ...publicstaticTypeEnumfromValue(Stringvalue) {
for (TypeEnumb : TypeEnum.values()) {
if (b.value.equals(value)) {
returnb;
}
}
thrownewIllegalArgumentException("Unexpected value '" + value + "'");
}
}
This indicates that the 7.0.1 java generator generates model code in which the first entry in the oneOf will match all the other entries. In the above case, the generated Title class matches with the typeEnum of title, subtitle and paragraph. This will cause the model to never be able to deserialize properly, as there are multiple options to deserialize json with type: 'subtitle' (because both Title and Subtitle classes match will it).
This did work properly in openapi-generator 6.6.0.
openapi-generator version
Issue observed in 7.0.1. It worked properly in 6.6.0.
See the generated code for Title in build/generate-resources/main/src/main/java/com/example/api/model/Title.java. Its 'TypeEnum' matches with all the type values of the other components. The code for the other components (for instance in build/generate-resources/main/src/main/java/com/example/api/model/Subtitle.java) show that they only match for their specific type value.
Run the project's Main class in src/main/java to see what problem this causes: Jackson is not able to deserialize a Subtitle, because both Title and Subtitle classes match.
Change the version of openapi-generator in build.gradle.kts to 6.6.0, run ./gradlew clean and run steps 2-4 again. The Title class will contain the correct TypeEnum values.
Suggest a fix
There's probably a bug somewhere in the java generator, introduced since 7.0.1.
The text was updated successfully, but these errors were encountered:
@wing328 this bug was introduced in this commit: 1561c33 .
The issue seems to be originating from the mergeProperties method introduced in this commit. I'm not entirely sure what's going on.. maybe the problem is that this new method is applied to all oneOf situations, where it should only apply to oneOf's inside included.array.items?
Bug Report Checklist
Description
Given an OpenAPI schema containing a component with several oneOf's, in which each oneOf entry has a unique 'type' value. Here's a partial example:
Using the 7.0.1 java generator, the above schema will generate this Title model:
This indicates that the 7.0.1 java generator generates model code in which the first entry in the oneOf will match all the other entries. In the above case, the generated
Title
class matches with the typeEnum oftitle
,subtitle
andparagraph
. This will cause the model to never be able to deserialize properly, as there are multiple options to deserialize json withtype: 'subtitle'
(because both Title and Subtitle classes match will it).This did work properly in openapi-generator 6.6.0.
openapi-generator version
Issue observed in 7.0.1. It worked properly in 6.6.0.
OpenAPI declaration file content or url
See https://github.com/skwakman/openapi-generator-java-issue/blob/main/src/main/resources/example-schema.json .
Generation Details
See https://github.com/skwakman/openapi-generator-java-issue/blob/main/build.gradle.kts
Steps to reproduce
I've made an example project illustrating the issue.
./gradlew openApiGenerate
Title
inbuild/generate-resources/main/src/main/java/com/example/api/model/Title.java
. Its 'TypeEnum' matches with all the type values of the other components. The code for the other components (for instance in build/generate-resources/main/src/main/java/com/example/api/model/Subtitle.java) show that they only match for their specific type value.src/main/java
to see what problem this causes: Jackson is not able to deserialize a Subtitle, because both Title and Subtitle classes match.Change the version of openapi-generator in
build.gradle.kts
to 6.6.0, run./gradlew clean
and run steps 2-4 again. TheTitle
class will contain the correct TypeEnum values.Suggest a fix
There's probably a bug somewhere in the java generator, introduced since 7.0.1.
The text was updated successfully, but these errors were encountered: