swagger-api / swagger-api/swagger-codegen

[csharp] Constructor arguments not passed in multilevel inheritance

Open
#8,455 0 comments 0 reactions 0 assignees View on GitHub

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:

  • RootClass
  • DerivedClass
  • MostSpecificClass

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.