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
After upgrading swagger-core from 2.2.22 to 2.2.25, the @Size constraint annotation is ignored for the request body parameters of collection type, while it was properly processed before. I am using OpenAPI 3.1.
Expected behavior
@Size#min is used to generate minItems and @Size#max is used to generate maxItems for the generated property schema
For example for the following endpoint
@GET
@Path("/test")
public void getTest(@Size(min = 1, max = 100) List<String> myList) {}
generated spec should have the following request body (working in 2.2.22)
public class ExampleResource {
@GET
@Path("/test")
public void getTest(@Size(min = 1, max = 100) List<String> myList) {}
}
Investigation with proposed solution
In ParameterProcessor.applyAnnotations there is a check for the @Size annotation. Inside it checks whether parameter.getSchema is an instance of ArraySchema, but it is now of type JsonSchema, so the information from @Size is not propagated to the schema (minItems/maxItems properties) and is removed in the generated spec. Proposed solution would be the same as solution in this issue, specifically "instead of using (parameter.getSchema() instanceof ArraySchema) a check is performed on the type/types fields of property to ensure that the property is an array schema".
Temporary workaround
Adding @ArraySchema(minItems=1, maxItems=100) corrects the generated contract and adds the minItems/maxItems back to the spec.
The text was updated successfully, but these errors were encountered:
Problem
After upgrading swagger-core from 2.2.22 to 2.2.25, the
@Size
constraint annotation is ignored for the request body parameters of collection type, while it was properly processed before. I am using OpenAPI 3.1.Expected behavior
@Size#min
is used to generateminItems
and@Size#max
is used to generatemaxItems
for the generated property schemaFor example for the following endpoint
generated spec should have the following request body (working in 2.2.22)
but instead the generated requestBody removes the
maxItems
andminItems
(in version 2.2.25)Reproducer
I am able to reproduce this by adding a test to
ReaderTest
classwith ExampleResource
Investigation with proposed solution
In
ParameterProcessor.applyAnnotations
there is a check for the@Size
annotation. Inside it checks whetherparameter.getSchema
is an instance ofArraySchema
, but it is now of typeJsonSchema
, so the information from@Size
is not propagated to the schema (minItems
/maxItems
properties) and is removed in the generated spec. Proposed solution would be the same as solution in this issue, specifically "instead of using(parameter.getSchema() instanceof ArraySchema)
a check is performed on thetype
/types
fields of property to ensure that the property is an array schema".Temporary workaround
Adding
@ArraySchema(minItems=1, maxItems=100)
corrects the generated contract and adds the minItems/maxItems back to the spec.The text was updated successfully, but these errors were encountered: