swagger-api / swagger-api/swagger-ui

Array Size Constraint Affects Individual Element Length

Open
#9,363 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

import jakarta.validation.constraints.Size;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
class FooController {

    @GetMapping("/foo")
    public ResponseEntity<String> foo(@Size(min = 1, max = 3) @RequestParam Set<String> strings) {
        return ResponseEntity.ok("Foo!");
    }
}

@Size(min = 1, max = 3) from the snippet above is java bean validation annotation, which restricts the size of a set. swagger-ui applies this constraint not only to an array, but also to the individual element of it, making it impossible to pass a string containing more than given number of characters.

Q&A (please complete the following information)
  • OS: Windows, MacOS
  • Browser: any
  • Swagger-UI version: 5.2.0
To reproduce...

Steps to reproduce the behavior:

  1. Go to dedicated GitHub project and clone it to your device.
  2. Build the project using Java 17 and Gradle 8.4
  3. Click on 'Run SwaggerIssueApplication.main()'
  4. Open link in your browser
  5. Scroll down to GET foo and type string with more than 3 characters
  6. See error
Expected behavior

The size of string should not be limited.

Screenshots

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with the linked swagger-issue project and its Swagger UI page, using the Java 17 and Gradle 8.4 setup described. Trace how the generated array schema applies the @Size constraint to the array and its string items. Done means strings longer than three characters are accepted while the set's minimum and maximum item counts remain enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.