Skip to content
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

Support Bean Validation on records with Optionals #2042

Closed
lpandzic opened this issue Jan 18, 2023 · 1 comment
Closed

Support Bean Validation on records with Optionals #2042

lpandzic opened this issue Jan 18, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@lpandzic
Copy link

Given the controller:

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
public class FooController {

    @PostMapping("fooRecord")
    public void fooRecord(@RequestBody FooRecord foo) {

    }

    @PostMapping("fooClass")
    public void fooClass(@RequestBody FooClass foo) {

    }

    record FooRecord(@NotNull Optional<@Size(max = 1000) String> value) {

    }

    @Value
    static class FooClass {
        @NotNull
        @Size(max = 1000)
        String value;

        public Optional<String> getValue() {
            return Optional.of(value);
        }
    }
}

currently with latest springdoc generated openapi looks like:

      "FooRecord":{
        "required":[
          "value"
        ],
        "type":"object",
        "properties":{
          "value":{
            "type":"string"
          }
        }
      },
      "FooClass":{
        "required":[
          "value"
        ],
        "type":"object",
        "properties":{
          "value":{
            "maxLength":1000,
            "minLength":0,
            "type":"string"
          }
        }
      },

under components schemas.
The problematic part is the FooRecord component.

The result I'd expect in ideal case would be

      "FooRecord":{
        "type":"object",
        "properties":{
          "value":{
            "maxLength":1000,
            "minLength":0,
            "type":"string"
          }
        }
      },
@bnasslahsen
Copy link
Contributor

@lpandzic,

This logic is handled in the swagger-core library.
Please submit this Enhancement in the correct Github repo:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants