-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model not generated with the right type (allOf) #582
Comments
@JFCote I had a similar issue with |
@macjohnny Yeah I had this too. It's all fixed with 3.1.X but this is something else. I'm using 3.1.1-SNAPSHOT and still got this. I think it's a different use case. |
Related issues/PRs: #340 (but not directly) |
I am also affected by this bug. The problem comes from the a897fee commit in the #360 pull request. More precisely, from this change a897fee#diff-7cb46fa53f89a458a7b7cb201d2214a8R1527. Before this commit, when these properties where not un-aliased, a Now, with this un-aliasing, instead of a public String getSchemaType(Schema schema) {
if (schema instanceof ComposedSchema) {
ComposedSchema cs = (ComposedSchema)schema;
if (cs.getAllOf() != null) {
Iterator var3 = cs.getAllOf().iterator();
while(var3.hasNext()) {
Schema s = (Schema)var3.next();
if (s != null) {
schema = s;
break;
}
}
}
}
... Though the #360 pull request fixed the issues #255 and #191, it originated this #582 issue. @wing328, do you think it would be possible to keep the fixes brought by #360 and at the same time have a proper generation of composed schemas? Maybe something like this: public static Schema unaliasSchema(Map<String, Schema> allSchemas, Schema schema) {
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
Schema ref = allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref()));
if (ref == null) {
LOGGER.warn("{} is not defined", schema.get$ref());
return schema;
} else if (isObjectSchema(ref)) { // model
return schema;
} else if (isStringSchema(ref) && (ref.getEnum() != null && !ref.getEnum().isEmpty())) {
// top-level enum class
return schema;
} else if (isMapSchema(ref) || isArraySchema(ref) || isComposedSchema(ref)) { // map/array def should be created as models
return schema;
} else {
return unaliasSchema(allSchemas, allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())));
}
}
return schema;
} You can notice I added |
This change looks good to me! Please create a PR for it. |
…type is a composed (allOf) schema. Before this fix, the data type name of the generated property was that of the first model participating in the allOf clause. After this fix the property data type is again as expected: the one of the composed schema and not one of its parents.
Just created the #704 pull request in order to get this issue fixed. |
…OpenAPITools#582 issue (references to composed schemas should not get unaliased for them to get a proper data type name in the generation of model properties).
…d (allOf) schema (#704) * #582 Fixed the generation of model properties whose data type is a composed (allOf) schema. Before this fix, the data type name of the generated property was that of the first model participating in the allOf clause. After this fix the property data type is again as expected: the one of the composed schema and not one of its parents. * Added unit test in order to have regression testing in the fix for the #582 issue (references to composed schemas should not get unaliased for them to get a proper data type name in the generation of model properties). * Run ./bin/utils/ensure-up-to-date to re-generate samples run in the CI. * Removed tabs from ModelUtilsTest.java
Fixed by #704 |
…d (allOf) schema (OpenAPITools#704) * OpenAPITools#582 Fixed the generation of model properties whose data type is a composed (allOf) schema. Before this fix, the data type name of the generated property was that of the first model participating in the allOf clause. After this fix the property data type is again as expected: the one of the composed schema and not one of its parents. * Added unit test in order to have regression testing in the fix for the OpenAPITools#582 issue (references to composed schemas should not get unaliased for them to get a proper data type name in the generation of model properties). * Run ./bin/utils/ensure-up-to-date to re-generate samples run in the CI. * Removed tabs from ModelUtilsTest.java
Description
A member of a model is not using the model type requested by the spec. Please check the example for a better explanation
openapi-generator version
Master (3.1.1-SNAPSHOT)
OpenAPI declaration file content or url
This is a self contained file that reproduce the issue
As you can see
returnSoftwareStatus
is supposed to be of typeDeviceLifecycleStatus
. If you look in the generated code, you will see that it is of typeDeviceLifecycleStatusCore
instead:Command line used for generation
java -jar openapi-generator-cli.jar generate -i ./swagger.yaml --generator-name java-play-framework -o generatedServer -DhideGenerationTimestamp=true,booleanGetterPrefix=is
Steps to reproduce
Just run the command above
Related issues/PRs
None
Suggest a fix/enhancement
?
The text was updated successfully, but these errors were encountered: