-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Schema description of one field overrides descriptions of other fields of same class #3900
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
Comments
According to the specification all properties except I would say that it is more consistent behavior to always ignore (maybe with a warning) any properties of the Looks like the restriction on the |
Looks like it was adopted in 3.1.0: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-19 |
It's indeed adopted in 3.1.0 |
This issue still exists in 2.2.15 at least. |
is the issue fixed in OAS 3.1 or do we need to do something different in the code?
|
Still issue with swagger-ui 5.2.0, camel-openapi 4.3.0 and springdoc-openapi-starter 2.2.0. Not sure which is in effect.
|
Me and @garciagiovane found the solution at this documentation at section If we document variables that have the same type, and they have different schemas with different descriptions, at compile time the last variable description will overwrite the other ones because they have the same type. |
See #3561 |
Following OAI/OpenAPI-Specification#2033, would it be possible to generate something like this? "components" : {
"schemas" : {
"RouteDto" : {
"type" : "object",
"properties" : {
"startPoint" : {
"description" : "Point where the route begins",
"allOf" : [
"$ref" : "#/components/schemas/GeoPointDto"
]
},
"intermediatePoint" : {
"description" : "Intermediate point of the route",
"allOf" : [
"$ref" : "#/components/schemas/GeoPointDto"
]
},
"endPoint" : {
"description" : "Point where the route ends",
"allOf" : [
"$ref" : "#/components/schemas/GeoPointDto"
]
}
}
},
"GeoPointDto" : {
"type" : "object",
"properties" : {
"lon" : {
"type" : "number",
"description" : "Longitude of geo point ( -180, 180 >",
"format" : "double"
},
"lat" : {
"type" : "number",
"description" : "Latitude of geo point < -90, 90 >",
"format" : "double"
}
}
}
}
} |
Unfortunately, there doesn't seem to be a way to have the schema generated like that. The |
I also encountered the same problem, I don't know when it can be solved? As for the method mentioned above using subclassing, I feel it is not a good solution. |
I just wrote a unit test for this and it actually worked. At least the default ModelConverter adds the descriptions correctly when configured to used OpenAPI v3.1. package io.swagger.v3.core.resolving.v31;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.resolving.SwaggerTestBase;
import org.testng.annotations.Test;
public class Ticket3900Test extends SwaggerTestBase {
@Test
public void testArraySchemaItemsValidation() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
io.swagger.v3.oas.models.media.Schema model = context.resolve(new AnnotatedType(Route.class));
SerializationMatchers.assertEqualsToYaml31(model, "type: object\n" +
"properties:\n" +
" startPoint:\n" +
" $ref: '#/components/schemas/GeoPoint'\n" +
" description: Point where the route begins\n" +
" intermediatePoint:\n" +
" $ref: '#/components/schemas/GeoPoint'\n" +
" description: Intermediate point of the route\n" +
" endPoint:\n" +
" $ref: '#/components/schemas/GeoPoint'\n" +
" description: Point where the route ends");
}
private static class GeoPoint {
@io.swagger.v3.oas.annotations.media.Schema(description = "Longitude of geo point ( -180, 180 >")
public double lon;
@io.swagger.v3.oas.annotations.media.Schema(description = "Latitude of geo point < -90, 90 >")
public double lat;
}
private static class Route {
@io.swagger.v3.oas.annotations.media.Schema(description = "Point where the route begins")
public GeoPoint startPoint;
@io.swagger.v3.oas.annotations.media.Schema(description = "Intermediate point of the route")
public GeoPoint intermediatePoint;
@io.swagger.v3.oas.annotations.media.Schema(description = "Point where the route ends")
public GeoPoint endPoint;
}
} For the folks that came here from springdoc-openapi. When setting the OpenAPI version to 3.1 in the configuration bean, it seems to work as expected. See e.g. changes made here: springdoc/springdoc-openapi#2833 |
In OpenAPI 3.0.x different configuration options are available in 2.2.24+ releases |
TBH, I don't see a way to configure things for OpenAPI 3.0. My proposed solution #3900 (comment) cannot be generated with Swagger. |
Let's take an example of two simple classes:
Expected behavior is to have three fields inside RouteDto with different descirption each.
Actual behavior is that all fields has same description = "Point where the route ends" which is the description of third field.
UI:

JSON:
The text was updated successfully, but these errors were encountered: