swagger-api / swagger-api/swagger-codegen

[Java] Generator produces a dedicated field for the discriminator

Open
#8,137 2 comments 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.