Skip to content

@Size annotation on List<String> causes incorrect openapi spec to be generated. #4462

Closed
@caspianb

Description

@caspianb

Hopefully this is the correct library to handle this issue; I was referred here from springdoc/springdoc-openapi#2337 -- apologies if I got it wrong.

Using a simple DTO can reproduce this issue:

@Data
static class RequestDto {
    @Size(min = 1, max = 5)
    @Schema(description = "List of values.")
    private List<String> values;
}

The @Size validation is only (correctly) applied to the list size. However, the api spec itself is showing this:
image

Essentially, the API spec is stating that:

  1. the list must be between 1 and 5 elements (correct);
  2. the length of the string of each element must be between 1 and 5 characters (incorrect)

You can also see that the description is also being duplicated from the array down to the element as well. I am uncertain if this is intentional and or desirable so not sure if that should also be considered a bug as well.


Note that the actual runtime validation is only applied to point1 above (correct behavior IMO).
Point2 is not enforced by the validator at runtime even though the generated API spec is indicating that the string should be between 1 and 5 characters in length.

This also just started occurring when we updated springdoc-openapi-starter-webmvc-ui to 2.2.0 (from 2.1.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions