[BUG] [Java] "allOf" does not support inheritance
See original GitHub issueDescription
I am trying to generate Java classes from an openapi schema that contains
OrganizationPage:
type: object
allOf:
- $ref: '#/components/schemas/BasePage'
properties:
data:
type: array
items:
$ref: '#/components/schemas/Organization'
this ends up generating a class named OrganizationPage with
public class OrganizationPage implements Serializable {
but I require
public class OrganizationPage extends BasePage implements Serializable {
the documentation seems to indicate that it is required that the definition of BasePage be modified to add a discriminator field. I am unable to do that as that file is in a different project that is shared by different projects, some of which use older versions of openapi-generator and do not populate a discriminator field. Furthermore, a discriminator field is never required as the base class is never referenced in the API, only the subclass is, so serialization/deserialization doesn’t require a discriminator. However, there are utility methods that operate on the base class so all instances must extend the class.
openapi-generator version
openapi-generator-mave-plugin 5.1.0
OpenAPI declaration file content or url
OrganizationPage:
type: object
allOf:
- $ref: '#/components/schemas/BasePage'
properties:
data:
type: array
items:
$ref: '#/components/schemas/Organization'
base-page.yml contains
description: Page resource object for paged REST resource response. Extend this object to return a strongly-typed payload.
type: object
properties:
totalCount:
description: The total number of resources at the requested location taking query parameters into account
readOnly: true
type: integer
format: int64
first:
description: Link to the first page in the resource collection
readOnly: true
type: string
format: uri
prev:
description: Link to the first page in the resource collection
readOnly: true
type: string
format: uri
next:
description: Link to the first page in the resource collection
readOnly: true
type: string
format: uri
last:
description: Link to the first page in the resource collection
readOnly: true
type: string
format: uri
required:
- totalCount
Generation Details
mvn clean install produces:
[deprecated] inheritance without use of ‘discriminator.propertyName’ has been deprecated in the 5.x release. Composed schema name: null. Title: null
The above line is emitted a few times during the build but it isn’t clear if it is associated with this issue or not since it doesn’t identify the file, line, or object it is referencing.
Related issues/PRs
Both https://github.com/OpenAPITools/openapi-generator/issues/3100 and https://github.com/OpenAPITools/openapi-generator/issues/3172 have similarities to this issue.
Suggest a fix
The only fix I can think of is to add an attribute to the definition of the object to direct it to use inheritance instead of composition.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:9 (1 by maintainers)
Top GitHub Comments
Can this please be fixed? Because no there is no inheritance. Also check what happens if you have multiple discriminator or multiple allOf
After I got the Pet model working that @marcdejonge provided in https://github.com/OpenAPITools/openapi-generator/issues/9615#issuecomment-861304768, I figured out a workaround for my own issue. I had separate yaml files for my schema model classes, and by moving them into the same file as the endpoints under this, it worked for me!!!
Note, I also applied this fix to avoid the extra AllOf classes: https://github.com/OpenAPITools/openapi-generator/issues/3100#issuecomment-703481081