question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix issue with modeling inheritence

See original GitHub issue

Cat 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:open
  • Created 2 years ago
  • Reactions:3
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
craigsmithamcommented, Aug 23, 2021

I agree the type Animal = Cat | Dog; would be appropriate when seeking to model oneOf/anyOf. I wish we had oneOf/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. a x-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).

0reactions
xirzeccommented, Nov 17, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found