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
When a discriminator is defined in a spec in an allOf inline object, it is ignored. This prevents the inheritance in the generated code from being generated correctly.
I have been studying the open api spec and swagger-codegen projects for the constraints on allOf:
It appears that swagger-codegen (language is java) only recognizes the last inline element of an allOf: array. I have not found a statement in the open api spec or code in swagger-codegen that specifies this constraint.
How are inline objects supposed to be handled when there are multiple inline objects defined within an allOf array?
Adding the following to DefaultCodeGen seems to fix the issue for me. However, this assumes that allOf: can have no more than one inline element that contains a discriminator. (My experience also shows that allOf: understands no more than one inline elements. If more than one exists, only last one is recognized).
@@ -1240,6 +1251,12 @@ public class DefaultCodegen {
allProperties = new LinkedHashMap<String, Property>();
allRequired = new ArrayList<String>();
m.allVars = new ArrayList<CodegenProperty>();
+ for (Model innerModel: composed.getAllOf()) {
+ if (innerModel instanceof ModelImpl) {
+ m.discriminator = ((ModelImpl) innerModel).getDiscriminator();
+ break; // only one discriminator allowed at the moment.
+ }
+ }
} else {
allProperties = null;
allRequired = null;
Description
When a discriminator is defined in a spec in an allOf inline object, it is ignored. This prevents the inheritance in the generated code from being generated correctly.
I have been studying the open api spec and swagger-codegen projects for the constraints on allOf:
It appears that swagger-codegen (language is java) only recognizes the last inline element of an allOf: array. I have not found a statement in the open api spec or code in swagger-codegen that specifies this constraint.
How are inline objects supposed to be handled when there are multiple inline objects defined within an allOf array?
How are discriminators inside the objects from Adds the missing install-ivy build script #1 supposed to be represented in the generated code (java in this case)?
Currently, it appears that only the last inline object is recognized.
FYI: This came up in trying to define a discriminator for the inline object.
Swagger-codegen version
2.2.2-SNAPSHOT + pr 4085
Swagger declaration file content or url
Command line used for generation
Maven
Related issues
#2449
#4085
OAI/OpenAPI-Specification#848
Suggest a Fix
Adding the following to DefaultCodeGen seems to fix the issue for me. However, this assumes that allOf: can have no more than one inline element that contains a discriminator. (My experience also shows that allOf: understands no more than one inline elements. If more than one exists, only last one is recognized).