-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Hello,
I have an OpenAPI Schema that uses inheritance like this.
ViewConnectionNoRelationship:
type: object
additionalProperties: false
allOf:
- $ref: "#/components/schemas/ViewConnectionBase"
- type: object
additionalProperties: false
properties:
name:
type: string
documentation:
type: string
required:
- name
- documentation
ViewConnectionRelationship:
type: object
additionalProperties: false
allOf:
- $ref: "#/components/schemas/ViewConnectionBase"
- type: object
additionalProperties: false
properties:
relationship_id:
type: string
required:
- relationship_idWith two schemas inheriting from a top schema.
ViewConnectionBase also has a discriminator like this :
discriminator:
propertyName: connection_type
mapping:
connection: "#/components/schemas/ViewConnectionNoRelationship"
relationship: "#/components/schemas/ViewConnectionRelationship"
I searched online and found this is how one should use discriminators for inheritance (based on https://swagger.io/specification/#discriminator-object, the AllOf example).
And for half of my use-case, generating a java client library, it works and generates correctly the inheritance ONLY if I use the discriminator like this. However, for oapi-codegen it doesn't work, and just refuses to merge schemas with discriminators involved, why so ?
At the very least, the library could just ignore the discriminator, since it can't do polymorphism via inheritance in Golang. If I correctly understand what I found, at first the library was using struct embeddings, but it was then later changed to schema merging.
As of right now (and from what I found), the discriminator on AllOf and OneOf/AnyOf is more of a "hint" for the deserializer to find the correct schema on the first try, so simply ignoring it for now in the case of AllOf should not be a problem.
Currently, the library doesn't even read the discriminator for OneOf and just gives it back to the developer to use, along with methods that error if the JSON schema is not matching, so I don't see why it couldn't just be ignored for AllOf.