-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
I've recently run into the following issue on the openapi codegenerator project:
OpenAPITools/openapi-generator#8495
The issue was triggered by the removal of inheritance type relationships between schemas that defined a single $ref entry in their allOf array for example:
components:
schemas:
UserDTO:
type: object
properties:
id:
type: string
minLength: 1
maxLength: 20
CustomerDTO:
type: object
allOf:
- $ref: '#/components/schemas/UserDTO'
properties:
address:
type: string
minLength: 1
maxLength: 30
This sparked a bit of discussion internally on how to treat such a case. The spec itself says that this is simply model composition and does not imply a hierarchy between the models.
It appears to me that in a case where there is only a single reference in allOf this could very well be treated as an inheritance type relationship even without the use of a discriminator property. Adding a discriminator would not serve any purpose here unless there would actually be a polymorphic API endpoint.
From a code-generation perspective being able to treat a single allOf reference as an implicit inheritance would be desirable (in most cases reducing overhead and allowing for polymorphism) while the overhead of having to add a discriminator for such a case would not (data transfer, handling of discriminator).
Right now strictly adhering to the spec means not treating anything without a discriminator as a hierarchic relationship.