You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following class representing a location is serialized into an array of two numbers (latitude, longitude):
@Schema(implementation = Double.class, minItems = 2, maxItems = 2, example = "[40.5044403760272, -76.37894009358867]",
description = "Array of two elements: latitude and longitude, in that order.", type = SchemaType.ARRAY)
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class Location {
private double latitude;
private double longitude;
}
The schema type generated from this class is correct:
"Location" : {
"description" : "Array of two elements: latitude and longitude, in that order.",
"type" : "array",
"examples" : [ [ 40.5044403760272, -76.37894009358867 ] ],
"maxItems" : 2,
"minItems" : 2,
"items" : {
"type" : "number",
"format" : "double"
}
}
So is the schema representing a field that uses the type:
This schema is incorrect, as it suggests the location field is an array of Location, which itself is an array of two numbers, so effectively a two-dimensional array.
Is this misbehaving in Swagger UI or some other consumer of the OpenAPI? What you show actually seems correct. That is, it represents a one-dimension array. For it to be two-dimensions there would need to be an additional items.
Is this misbehaving in Swagger UI or some other consumer of the OpenAPI? What you show actually seems correct. That is, it represents a one-dimension array. For it to be two-dimensions there would need to be an additional items.
True, on the other hand, why there is the type : array repeated, if it's inside the Location type itself already? Having the type : array and "$ref" : "#/components/schemas/Location" instead of "items": { "$ref" : "#/components/schemas/Location" } seems to be inconsistent.
@MikeEdgar thanks for taking a look on it. To give a bit more context, the issue seems to be related to when adding @Schema to the attribute location.
Without annotating the attribute, it generates:
Describe the bug
The following class representing a location is serialized into an array of two numbers (latitude, longitude):
The schema type generated from this class is correct:
So is the schema representing a field that uses the type:
However, once we add a
Schema
annotation on the field as well, even only to add a description:the generated schema looks as follows:
This schema is incorrect, as it suggests the location field is an array of
Location
, which itself is an array of two numbers, so effectively a two-dimensional array.Expected behavior
No response
Actual behavior
openapi.json
How to Reproduce?
Output of
uname -a
orver
Linux fedora 6.12.9-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 9 16:05:40 UTC 2025 x86_64 GNU/Linux
Output of
java -version
Java version: 21, vendor: Eclipse Adoptium, runtime: /home/rsynek/.sdkman/candidates/java/21-tem
Quarkus version or git rev
3.17.6
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Additional information
No response
The text was updated successfully, but these errors were encountered: