swagger-api / swagger-api/swagger-codegen-generators
Generated code does not implement model inheritance correctly
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
In our business project based on Spring Boot, we're using swagger-codegen to generate model classes and REST controller interfaces for our API described in an OpenAPI 3.0 YAML file. However, the recent release 1.0.16 does not correctly generate model classes if they come with an inheritance structure. There are basically two errors involved:
-
The API model is not correctly generated into a classes and interfaces inheritance hierarchy. In our situation, a parent model which should be generated as an interface is in fact generated as a class, but the inheriting model class still uses "implements" instead of "extends" which would then be the correct statement.
-
If using a discriminator mapping, the generated code does not correctly implement that due to an error in the typeInfoAnnotation.mustache template.
Since I already figured where the errors occur within the swagger-codegen-generators project, I am going to provide a pull request which fixes this issue shortly.
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 in the swagger-codegen-generators model-generation templates, especially typeInfoAnnotation.mustache, and reproduce the OpenAPI 3.0 inheritance and discriminator cases described in the issue. Done means generated model classes and interfaces form the intended hierarchy, use the correct inheritance statement, and implement discriminator mapping correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100