Ability to define different schemas for the same class
See original GitHub issueI’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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Multiple Types - JSON Schema
The basic declaration of multiple types is through the "type" keyword, ... In general, when multiple (or no) types are defined in the...
Read more >OpenAPI - different schema per operation on same resource
I'm using OpenAPI 3.0 to describe an API where each resource has a subtly different schema based on its operation ...
Read more >Multiple Schema - an overview | ScienceDirect Topics
Multiple schemas are grouped into catalogs, which can then be grouped into ... Interoperability refers to the ability of multiple systems with different ......
Read more >When Do Schemas And Classes Deviate - Wiki
Database and schemas differ from each other by their nature. ... 1) We shall depart from the simplest case: a schema with one...
Read more >Schema in Psychology: Definition, Types, Examples
A schema is a cognitive framework or concept that helps organize and interpret information. We use schemas because they allow us to take ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tobre6,
Because we rely on swagger-core project, currently complex (object) payloads are always resolved as a reference to a schema defined in components.
For your problem, you can set up 2 different schemas as follow:
This produces, the result you expect:
I vote this as well. Type of object doesn’t define exact use of it:
@Valid @Schema(description = “Net weight of the shipment”) private WeightModel netWeight; @Valid @Schema(description = “The gross weight of the shipment, in KG-s”) private WeightModel grossWeight;