swagger-api / swagger-api/swagger-codegen
[Java] Generator produces a dedicated field for the discriminator
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Origin: https://stackoverflow.com/q/50163882/131929
Is it correct that the generator produces a dedicated field for the discriminator?
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "errorType", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = SpecificError.class, name = "SpecificError"),
})
public class GeneralError {
@JsonProperty("errorType")
private String errorType = null;
...
errorType is the declared discriminator.
When Jackson serializes a SpecificError object it includes errorType twice:
{"errorType":"SpecificError","message":"message","errorType":null}
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 reproducing the generated Java model from the issue with Jackson serialization, then trace how the Java generator handles the declared discriminator and its corresponding field. Confirm whether the discriminator is emitted twice and identify the generator template or logic responsible; done means the generated model no longer serializes duplicate errorType properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100