Quite impressed with the toolset you created here.
I was curious about inheritance support so I tried it out with a minimal example:
openapi: 3.0.2info:
title: edit meversion: 1.0.0paths:
/nothing:
description: dummyget:
responses:
'200':
description: emptycontent:
'application/json':
schema:
$ref: '#/components/schemas/ChildSchema'components:
schemas:
ParentSchema:
type: objectproperties:
parentAttr:
type: stringChildSchema:
allOf:
- $ref: '#/components/schemas/ParentSchema'
- type: objectproperties:
childAttr:
type: string
This yields a ChildSchema.java consisting of everything from the parent and child model:
publicclassChildSchema {
@JsonProperty("parentAttr")
privateStringparentAttr;
@JsonProperty("childAttr")
privateStringchildAttr;
publicStringgetParentAttr() {
returnparentAttr;
}
publicvoidsetParentAttr(StringparentAttr) {
this.parentAttr = parentAttr;
}
publicStringgetChildAttr() {
returnchildAttr;
}
publicvoidsetChildAttr(StringchildAttr) {
this.childAttr = childAttr;
}
}Now specifying a discriminator results in inheritance in the generated code (at least for the openapi-generator project):
openapi: 3.0.2info:
title: edit meversion: 1.0.0paths:
/nothing:
description: dummyget:
responses:
'200':
description: emptycontent:
'application/json':
schema:
$ref: '#/components/schemas/ChildSchema'components:
schemas:
ParentSchema:
type: objectdiscriminator:
propertyName: classNameproperties:
parentAttr:
type: stringChildSchema:
allOf:
- $ref: '#/components/schemas/ParentSchema'
- type: objectproperties:
childAttr:
type: string
For this a special propertyName of className is used. If I run that in your playground with spring 2021.5 it complains about the property name which is not wrong strictly speaking:
The discriminator 'className' is not a property of this schema (code: 134)
If I run this locally with 2023.1.2 then this does not error but does not generate two classes with one inheriting from each other:
publicclassChildSchema {
@JsonProperty("parentAttr")
privateStringparentAttr;
@JsonProperty("childAttr")
privateStringchildAttr;
publicStringgetParentAttr() {
returnparentAttr;
}
publicvoidsetParentAttr(StringparentAttr) {
this.parentAttr = parentAttr;
}
publicStringgetChildAttr() {
returnchildAttr;
}
publicvoidsetChildAttr(StringchildAttr) {
this.childAttr = childAttr;
}
}Expected result would have been:
publicclassParentSchema {
@JsonProperty("parentAttr")
privateStringparentAttr;
publicStringgetParentAttr() {
returnparentAttr;
}
publicvoidsetParentAttr(StringparentAttr) {
this.parentAttr = parentAttr;
}
}
publicclassChildSchemaextendsParentSchema {
@JsonProperty("childAttr")
privateStringchildAttr;
publicStringgetChildAttr() {
returnchildAttr;
}
publicvoidsetChildAttr(StringchildAttr) {
this.childAttr = childAttr;
}
}Now this expectation could of course be wrong. My question now would be if this inheritance use case is supported and/or if I would have to do something differently to get the desired result. Thanks.
Quite impressed with the toolset you created here.
I was curious about inheritance support so I tried it out with a minimal example:
This yields a
ChildSchema.javaconsisting of everything from the parent and child model:Now specifying a
discriminatorresults in inheritance in the generated code (at least for the openapi-generator project):For this a special
propertyNameofclassNameis used. If I run that in your playground with spring 2021.5 it complains about the property name which is not wrong strictly speaking:The discriminator 'className' is not a property of this schema (code: 134)If I run this locally with 2023.1.2 then this does not error but does not generate two classes with one inheriting from each other:
Expected result would have been:
Now this expectation could of course be wrong. My question now would be if this inheritance use case is supported and/or if I would have to do something differently to get the desired result. Thanks.