swagger-api / swagger-api/swagger-ui
Array Size Constraint Affects Individual Element Length
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:
- Go to dedicated GitHub project and clone it to your device.
- Build the project using Java 17 and Gradle 8.4
- Click on 'Run SwaggerIssueApplication.main()'
- Open link in your browser
- Scroll down to GET foo and type string with more than 3 characters
- See error
Expected behavior
The size of string should not be limited.
Screenshots
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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