swagger-api / swagger-api/swagger-codegen
[Java] Polymorphism - need to list all subclasses twice
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
When using polymorphic model classes, I end up having to list all subclasses twice on the abstract superclass, if I want to use custom names for the subclasses. Once using
@ApiModel(value = "Super", subTypes = {Sub1.class, Sub2.class, ...}, discriminator = "type")
and once using
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({
@JsonSubTypes.Type(value = Sub1.class, name = "sub1"),
@JsonSubTypes.Type(value = Sub2.class, name = "sub2")
)}
Without the json annotations, things don't (de)serialize correctly, and without the swagger ones, the generated swagger spec and derived client libraries are incorrect.
Feature request: Have swagger-codegen just use the Json annotations, if the swagger ones aren't present. In fact, I see no need for the Swagger annotations, given that things will not (de)serialize correctly without the Json ones.
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 by locating swagger-codegen's Java annotation handling and the path that produces the Swagger specification and client libraries. Compare how JsonTypeInfo and JsonSubTypes are represented when Swagger annotations are absent; done means custom subclass names are reused without duplicating Swagger annotations and the generated outputs remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, json
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100