unloggedio / unlogged-sdk

Unlogged SDK for recording code execution
https://unlogged.io
Apache License 2.0
152 stars 16 forks source link

Validators (like NotNull etc) to be enabled during direct invoke. #61

Open kingkong-AI opened 3 weeks ago

kingkong-AI commented 3 weeks ago

Is your feature request related to a problem? Please describe.

Validators (like NotNull etc) don't work through direct invoke. When using direct invoke on a controller for the DTO consisting of Validations, the validations are not processed and even if they don't satisfy, calls are successful, which is not ideal.

Example:

DTO:

public class UserDto {

    private String id;

    @NotEmpty
    @Size(min=1, message = "User name must be greater than 1 characters")
    private String name;

    @Email(message = "Invalid Email")
    private String email;

    @NotBlank
    @Pattern(regexp = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=!])(?=\\S+$).{5,20}$",
            message = "Password must be 5 to 20 characters long, "
                    + "contain at least one digit, one lowercase letter, "
                    + "one uppercase letter, and one special character "
                    + "from @#$%^&+=!")
    private String password;

    @NotNull
    @Positive(message = "Value must be positive")
    @Max(120)
    private int age;

Controller:

    @PostMapping
    public Mono<UserDto> createUser(@Valid @RequestBody UserDto userDto) {
        return userService.createUser(userDto);
    }

Describe the solution you'd like

A solution where: All the validator annotations are processed properly even with direct invoke is expected, so that correct entries are populated in the database even with direct invoke.

Describe alternatives you've considered

No response

Additional context

No response