Fix issue with modeling inheritence
See original GitHub issueCat and Dog have an Animal base model but we generate type AnimalUnion = Animal | Cat | Dog
instead of type Animal = Cat | Dog
In these cases the base model (e.g. Animal) contains common properties from the server, but never is actually returned. This is a workaround for the lack of anyOf
and oneOf
in the modeler.
For now an x-ms-
property that omits the base type would be sufficient.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:20 (12 by maintainers)
Top Results From Across the Web
How to fix fields clashes when using models multi-inheritance ...
The problem here is that foo field will clash with itself because it's defined in the two parent model classes. How to solve...
Read more >#20932 (Issues with model Manager and inheritance.) – Django
I've found a couple of issues with the current handling of managers with inheritance. Given: class AbstractEvent(models.Model): events = models.
Read more >Supporting Model Inheritance in Pynamo #439 - GitHub
Proxy Inheritance Behaviour Proxy models can only inherit: Models that correspond to actual tables (non-abstract models) Other proxy models.
Read more >Multi-Model Inheritance + Fixtures = Fixed - Greg Taylor
This fixes a subtle problem that some of you may have seen in the form of foreign keys pointing to the wrong objects...
Read more >Chapter 7 Inheritance, Modification, and Redeclaration
This chapter describes the inheritance concept in Modelica, together with the related ... The modifiers '=x' and '=Medium' are found in the model...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree the
type Animal = Cat | Dog;
would be appropriate when seeking to modeloneOf/anyOf
. I wish we hadoneOf/anyOf
support, but that doesn’t seem to be the scope of this issue.If we are going to infer an inheritance hierarchy using
allOf
, to be consistent I think one of the options that can be returned in the union type should be the base class. It may or may not be abstract, depending on the individual API implementation.The more I think about this though, is modeling hierarchical inheritance appropriate at all when using
allOf
? It seems like a nice way to share properties within API definitions, but is not intended to model hierarchical inheritance.Bottom line: I’m all for the original proposed solution for the case when
allOf
is used to model inheritance (e.g. ax-ms-
property). However, I just want to highlight he need to also ensure the discriminator field is generated to support type narrowing (as @xirzec 's comment appears to do).@jrpedrianes not without wrapping the generated client and doing something clever.
@bterlson how does CADL solve this problem? I feel like the answer for an extensible union has to be in the implicit existence of an
unknown
kind.