swagger-api / swagger-api/swagger-codegen

Inheritance and repeating properties in child

Open
#2,982 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Composition / Inheritance
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I'm looking at generated examples and not sure if I understand why it works like this.
If you would take a look at https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/Cat.cs - you would see, that it inherits from Animal, which is ok.

Now the interesting thing is, that it repeats all the properties available in Animal - like ClassName, Color - which I can't understand - isn't the very purpose of inheritance to avoid repeating those properties? They even get compiler warnings, as such properties are already defined in base class and new modifier is not used.

That is not only in C# code generation, Java works the same. Is this by design?

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 generated samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/Cat.cs and its Animal base class, then compare the corresponding Java output. Trace those generated properties back through the relevant code-generation templates and check whether the repeated declarations and compiler warnings are intentional. Done means establishing the expected inheritance behavior and documenting the precise scope of any generator change.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.