The Wayback Machine - https://web.archive.org/web/20201217020409/https://github.com/springdoc/springdoc-openapi/issues/991
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic object #991

Closed
piotrooo opened this issue Dec 14, 2020 · 1 comment
Closed

Polymorphic object #991

piotrooo opened this issue Dec 14, 2020 · 1 comment

Comments

@piotrooo
Copy link

@piotrooo piotrooo commented Dec 14, 2020

Hello,
firstly thanks for a great project.

I have follwing structure of POJO's class:

@Schema(
        subTypes = {FirstClass.class, SecondClass.class},
        discriminatorProperty = "typeComment",
        discriminatorMapping = {
                @DiscriminatorMapping(value = "FIRST", schema = FirstClass.class),
                @DiscriminatorMapping(value = "SECOND", schema = SecondClass.class)
        }
)
@JsonTypeInfo(use = NAME, include = EXISTING_PROPERTY, property = "typeComment", visible = true)
@JsonSubTypes({
        @Type(value = FirstClass.class, name = "FIRST"),
        @Type(value = SecondClass.class, name = "SECOND")
})
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class BaseClass {
    private TypeComment typeComment;
    //getter/setter
}

@Schema(allOf = BaseClass.class)
@JsonPropertyOrder({"typeComment", "date", "queue", "number", "holdTime"})
public class FirstClass extends BaseClass {
    //getters/setters
}

@Schema(allOf = BaseClass.class)
@JsonPropertyOrder({"typeComment", "date"})
public class SecondClass extends BaseClass {
    //getters/setters
}

public enum TypeComment {
    FIRST,
    SECOND,
}

As you can see, I determine classes usign enum TypeComment. This produces following output in UI:

"systemComments": [
    {
        "typeComment": "FIRST",
        "date": "2020-12-14T14:47:25.823Z",
        "queue": "string",
        "number": "string",
        "holdTime": 0
    },
    {
        "typeComment": "FIRST",   <--- here is problem
        "date": "2020-12-14T14:47:25.823Z"
    }
]

There is any way to return correct typeComment depends on resolved class?
Desired output:

"systemComments": [
    {
        "typeComment": "FIRST",
        "date": "2020-12-14T14:47:25.823Z",
        "queue": "string",
        "number": "string",
        "holdTime": 0
    },
    {
        "typeComment": "SECOND",
        "date": "2020-12-14T14:47:25.823Z"
    }
]
@bnasslahsen
Copy link
Contributor

@bnasslahsen bnasslahsen commented Dec 14, 2020

@piotrooo,

We do not see any issue in the generated OpenAPI spec.
Please follow the contribution guide, if you have noticed any issue, but providing all the listed relevant information.

This ticket will be now closed. And can be reopened if any issue appears...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.