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.

Polymorphic lists do not have correct type

See original GitHub issue

When I have a polymorphic list like in the example below, the generated C# client defines the list as of the first type (in this case Dog). Dog and Snake in this example are both derived from the same model.

"friends": {
  "type": "array",
  "items": {
    "oneOf": [
      {
        "$ref": "#/components/schemas/Dog"
      },
      {
        "$ref": "#/components/schemas/Snake"
      }
    ]
  }
}
public System.Collections.Generic.ICollection<Dog> Friends { get; set; }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nrawecommented, Jan 25, 2021

Just wanted to note that this is also an issue for TypeScript generation as well. I’m not sure if the output would be entirely the same, and I can provide a sample input/output if that helps? Many thanks.

1reaction
DerKobecommented, Jul 30, 2020

Both models Dog and Snake have the same base class in C# which is expressed via

allOf:
  - $ref: "#/components/schemas/Animal"

in each of those models. In my case all $refs in the list have the same base class so it would be possible to infere the base class and pick it as the collection’s type. But I don’t know what to do in other cases where the is a mixed $refs list with no common base model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - why polymorphism doesn't treat generic collections ...
Now, the problem with Java generic types is that the type information is discarded by the compiler and it is not available at...
Read more >
Recitation 4: Datatype pitfalls, polymorphism, lists
We have to be careful: If id is a data constructor (e.g., Penny), then we're comparing e to see if it has the...
Read more >
Can't wrap my head around how to use Polymorphic ...
I'm trying to extract the data from a xml file produced by the Tiled2D map editor. I originally had an untyped function that...
Read more >
Is return-type-(only)-polymorphism in Haskell a good thing?
I actually think that return type polymorphism is one of the best features of type classes. After having used it for a while,...
Read more >
Chapter 6 Polymorphism and its limitations
1.1 Weakly polymorphic types ... Therefore, after placing an int in store, we cannot use it to store any value other than an...
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