karlvr/openapi-generator-plus

allOf could pick one parent schema to be inherited

Closed this issue · 0 comments

As of 0.31 if there are multiple reference schemas in an allOf, and we don't support multiple-inheritance, we decide to use interfaces for everything. This means that we end up absorbing the model and repeating a lot of code for properties.

The OpenAPI spec states that allOf does not imply hierarchy. Only a discriminator implies hierarchy.

I don't want to use inheritance just for the sake of saving lines of code... this is a code generator, and we don't really need to worry about how much code we generate. It's worse to have inheritance that doesn't really make sense. But if one and only one of the referenced schemas also contained a discriminator, then perhaps we could choose to take an inheritance approach with that one.

We would still generate the schema that contains the discriminator—the root of the allOf hierarchy—as an interface, as perhaps not all of the schemas that form part of the discriminator will be eligible to use this approach, so we would instead extend from the abstract implementation object that we created from the interface.