swagger-api / swagger-api/swagger-codegen

Model with inheritance recognized as interface

Open
#5,961 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Composition / Inheritance Issue: Bug Server: C-Sharp
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Using our custom generator based on the ASP.NET Core server generator, a single model ends up as interface instead of parent on models that inherit from it. All our other inheritances work perfectly. Format matches 100%, and renaming the fields (obviously we do not use the name Dummy in our project) does not help either.

Swagger-codegen version

2.2.1, 2.2.2

Swagger declaration file content or url

I've created a test dummy based on our code that shows the issue.
https://gist.github.com/fonix232/fdef76c0884570bc574737b87ddc8f64

Command line used for generation

java -cp our-custom-lib-1.0.0.jar:swagger-codegen-cli-2.2.1.jar io.swagger.codegen.SwaggerCodegen generate -i ../Specifications/dummy.yaml -l ourcustomgenerator -c ./dummy-config.json -o ../generated

But basically any generator will result in the same

Steps to reproduce
  1. Use the dummy yaml to generate any kind of client
  2. Enjoy the fact that your client models do not inherit from the model they should
Related issues

None that I could find

Suggest a Fix

No idea what can cause this issue, however adding the debugModels flag shows that after processing the Swagger definition even before the actual code is generated, codegen recognizes it as interface, not as parent

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 dummy YAML from the linked gist and run the shown SwaggerCodegen generate command with the debugModels flag. Trace how the Swagger definition classifies the inherited model before template generation. Done means generated models preserve the declared inheritance instead of treating the parent model as an interface.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.