Skip to content

Ability to define different schemas for the same class #685

@simopahk

Description

@simopahk

I've run into a problem trying to reuse the same DTO under different OpenAPI schemas. When I have this hierarchy:

@Data
public class Company {
    @Schema(description = "name of the company")
    private String name;
}

@Data
public class Contract {
    @Schema(description = "unique id")
    private String id;

    @Schema(description = "client company")
    private Company client;

    @Schema(description = "partner company")
    private Company partner;
}}

then Company schema will only be exported once under the name "partner company" in the yml file. This means that the field "client" will have the description "partner company", which makes no sense in this case. I tried giving each field a different name in the Schema annotation, but it seems to be on purpose that you can rewrite a class' schema this way. Why is that?

I'd really like a solution to this problem, because I can't give the client a document with errors like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions