springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 500 forks source link

Invalid items validation with @ArraySchema with implementation #2754

Closed istibekesi closed 1 month ago

istibekesi commented 1 month ago

Describe the bug

Using @ArraySchema annotation on a field with implementation parameter generates invalid openapi schema.

To Reproduce

public enum MyEnum {
    red,
    green
}

public enum MyOtherEnum {
    green,
    blue
}

@ArraySchema(schema = @Schema(implementation = MyOtherEnum.class))
@Size(min = 1, max = 3)
private List<MyEnum> setOfEnums;

Generated result:

"setOfEnums" : {
  "maxItems" : 3,
  "minItems" : 1,
  "type" : "array",
  "items" : {
    "maxLength" : 3,
    "minLength" : 1,
    "type" : "string",
    "enum" : [ "green", "blue" ]
  }
}

Expected behavior

"setOfEnums" : {
  "maxItems" : 3,
  "minItems" : 1,
  "type" : "array",
  "items" : {
    "type" : "string",
    "enum" : [ "green", "blue" ]
  }
}
bnasslahsen commented 1 month ago

@istibekesi,

This is not a springdoc-openapiissue, but generated directly in swagger-core:

ResolvedSchema resolvedSchema = ModelConverters.getInstance()
        .resolveAsResolvedSchema(
                new AnnotatedType(PersonDTO.class).resolveAsRef(false));
Assert.isTrue((((ArraySchema)resolvedSchema.schema.getProperties().get("setOfEnums")).getItems()).getMaxLength() == null, "maxLength should not be set");

Feel free to raise an issue here: https://github.com/swagger-api/swagger-core/issues