springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.26k stars 493 forks source link

@Size should be considered as required (same as @NotNull) #2607

Closed asashour closed 3 months ago

asashour commented 4 months ago

When an object has a property marked as @Size(min=2) for example, it is expected that that field is shown are required.

This also applies for Java primitive types.

For example:

import jakarta.validation.constraints.*;

@RestController
@RequestMapping("something")
public class TestController {
  @PostMapping
  SomeObject test(@RequestBody @Valid SomeObject object) {
    return null;
  }

  private record SomeObject(
      @Size(min = 2) String name,
      boolean flag,
      @NotNull String sting) {
  }
}

Expectation: name, flag and string are all required.

Actual result: Only string is marked as required

bnasslahsen commented 3 months ago

@asashour,

The Size constraint min=2, is higher than required, and this is what is considered. Nothing else is planned for this case.