Skip to content

@Size on collections query parameter is generating openapi maximum/minimum to the contained type  #2393

Closed
@CharlyRien

Description

@CharlyRien

Describe the bug
After upgrading from springdoc 2.1.0 to springdoc 2.2.0, a new behavior is occurring that is breaking our openapi doc generated.
If you are using Jakarta Collections validator on controller query parameters (for example @SiZe in my case) the minItems and maxItems are added to the openapi doc generated as expected but it is also adding now the maximum/minimum (with the same number as minItems and maxItems) to the type of the items contained in the collection.

To Reproduce
Steps to reproduce the behavior:
Use @SiZe on Set for example for a query parameter in your controller methods

  • What version of spring-boot you are using?
    spring-boot 3.1.2
  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-common-2.2.0.jar
    springdoc-openapi-starter-webflux-api-2.2.0.jar
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    actual:
      parameters:
      - in: query
        name: article_ids
        required: false
        schema:
          type: array
          items:
            type: integer
            format: int64
            maximum: 50
            minimum: 1
          maxItems: 50
          minItems: 1
          uniqueItems: true

expected:

      parameters:
      - in: query
        name: article_ids
        required: false
        schema:
          type: array
          items:
            type: integer
            format: int64
          maxItems: 50
          minItems: 1
          uniqueItems: true
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@RequestMapping(value = ["/api/product-discovery/product-cards"], produces = [MediaType.APPLICATION_JSON_VALUE])
@Validated
class Controller{
    @GetMapping(params = ["article_ids"])
    @Operation(description = "", tags = ["product-cards"])
    fun getProductCardsByArticleIds(
        @RequestParam(name = "article_ids", required = false) @Size(min = 1, max = 50) articleIds: Set<Long>
    ) = ResponseEntity.ok()
}

Expected behavior
@SiZe should only affect the number of items in the collection not the size of the type contained in the collection

      parameters:
      - in: query
        name: article_ids
        required: false
        schema:
          type: array
          items:
            type: integer
            format: int64
          maxItems: 50
          minItems: 1
          uniqueItems: true

Screenshots

Additional context
We are using Kotlin

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