swagger-api / swagger-api/swagger-codegen
[csharp] Constructor arguments not passed in multilevel inheritance
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When more than two levels of inheritance is described in definitions, the generated model classes in the C# client have problems with constructor arguments.
In my linked example, there are three classes defined, in an inheritance chain:
RootClassDerivedClassMostSpecificClass
The constructor of DerivedClass accepts arguments for its own property and the two that inherits from RootClass, and passes the values for the inherited ones into the base constructor.
The constructor of MostSpecificClass, however, accepts arguments for its own property and all others it inherits from DerivedClass and RootClass (which is correct), but it only passes on the value of DerivedProperty (the one defined in its immediate parent) into the base constructor, but not the values for properties inherited from RootClass (line 26).
This causes a warning because those constructor parameters (Id and RootProperty) are unused; but it's still very dangerous, because it results in code that actually compiles, but is functionally wrong.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
See test input and output here (generated with https://editor.swagger.io).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked test input and generated output for the RootClass, DerivedClass, and MostSpecificClass inheritance chain, focusing on line 26 of the generated C# model. Trace how constructor arguments are passed through multiple inheritance levels, then verify that all inherited values reach the appropriate base constructor and that the generated output no longer leaves Id or RootProperty unused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100