Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

@Size on a request parameter lowers the minLength/minItems set for @NotBlank/@NotEmpty #3449

Backlog

Description

@AdzerKI

Describe the bug

For a request parameter, SchemaUtils.applyValidationsToSchema writes @Size.min() into minLength / minItems unconditionally. @Size(max = 10) has min = 0, so the minLength: 1 that @NotBlank gives the parameter schema is replaced with 0 (same for @NotEmpty and minItems).

To Reproduce

  • Spring Boot 4.2.0
  • springdoc-openapi-starter-webmvc-api 3.2.1
@GetMapping("/search")
public String search(@RequestParam @NotBlank @Size(max = 10) String name,
        @RequestParam @NotEmpty @Size(max = 3) List<String> tags) {
    return null;
}

Actual:

{ "type": "string", "maxLength": 10, "minLength": 0 }
{ "type": "array", "items": { "type": "string" }, "maxItems": 3, "minItems": 0 }

Expected behavior

minLength: 1 and minItems: 1: @Size should only raise a minimum that is already on the schema, never lower it.

Additional context

swagger-core has the same ordering issue when it resolves the parameter schema (swagger-api/swagger-core#5339, fix in swagger-api/swagger-core#5340). With that fix the schema reaches springdoc with minLength: 1, and applyValidationsToSchema still resets it to 0. I will open a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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