Skip to content

Type-use annotations are not picked up when used in defining parameters #3000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dabeck81 opened this issue May 21, 2025 · 1 comment
Open

Comments

@dabeck81
Copy link

dabeck81 commented May 21, 2025

I have a use case in which I am using type-use annotations for parameters.
Take following example:

    @PostMapping("euroMillions")
    public ResponseEntity<String> euroMillions(@Parameter(description = "the numbers")
                                               @RequestParam @Size(min = 5, max = 5) List<@Max(50) @Min(1) Integer> numbers,
                                               @Parameter(description = "the stars")
                                               @RequestParam @Size(min = 2, max = 2) List<@Max(12) @Min(1) Integer> stars) {
        return ResponseEntity.ok("ok");
    }

I am expecting to see the @Max and @Min translated to maximum and minimum properties in the Openapi-definition, but instead it translates to:

        "parameters": [
          {
            "name": "numbers",
            "in": "query",
            "description": "the numbers",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "integer",
                "format": "int32",
>>>> maximum and minimum properties are missing
              },
              "maxItems": 5,
              "minItems": 5
            }
          },
          {
            "name": "stars",
            "in": "query",
            "description": "the stars",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "integer",
                "format": "int32",
>>>> maximum and minimum properties are missing
              },
              "maxItems": 2,
              "minItems": 2
            }
          }
        ]

If I move away from the parameters and make a RequestBody like so:

    @PostMapping("euroMillions2")
    public ResponseEntity<String> euroMillions2(@RequestBody LotteryTicket lotteryTicket) {
        return ResponseEntity.ok("ok");
    }
public class LotteryTicket {

    @Size(min = 5, max = 5)
    private List<@Max(50) @Min(1) Integer> numbers;
    
    @Size(min = 2, max = 2) 
    private List<@Max(12) @Min(1) Integer> stars;
}

The definition is correctly processed and the minimum and maximum properties are set for the lotteryTicket-schema:

  "components": {
    "schemas": {
      "LotteryTicket": {
        "type": "object",
        "properties": {
          "numbers": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32",
              "maximum": 50,
              "minimum": 1
            },
            "maxItems": 5,
            "minItems": 5
          },
          "stars": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32",
              "maximum": 12,
              "minimum": 1
            },
            "maxItems": 2,
            "minItems": 2
          }
        }
      }
    }
  }

I tested this on the latest snapshot-version of springdoc: 2.8.9-SNAPSHOT

@mymx2
Copy link

mymx2 commented May 28, 2025

got it. i wolud create a feat pull request for this.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants