Skip to content

Nullable meta annotations are ignored #973

Closed
@Sam-Kruglov

Description

@Sam-Kruglov

Describe the feature
JSR 303 allows for creating a constraint composition and it seems to not be supported. I can see the code responsible in org.springdoc.core.AbstractRequestService#applyBeanValidatorAnnotations and in io.swagger.v3.core.jackson.ModelResolver#applyBeanValidatorAnnotations.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    2.4.0
  • What modules and versions of springdoc-openapi are you using?
    openapi-ui, and security
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    A schema that contains @NotBlank inside a meta-annotation is not marked as required but should be.
  • Provide with a sample code (HelloController) or Test that reproduces the problem.
@Max(255)
@NotBlank
@Documented
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@interface UserFirstOrSecondName {

    String message() default "Invalid name";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}

@lombok.Value
class UserDto{
  @UserFirstOrSecondName String firstName;
}

@RestController
@RequestMapping("/users")
class UserControlle{
  @PostMapping
  void createUser(@Valid @RequestBody UserDto user){...}
}

Expected behavior

CreateUserDto:
      properties:
        firstName:
          type: string
      required:
        - firstName # this is missing
      type: object

Additional context
Also, I see that ModelResolver compares annotations by their simple name, while AbstractRequestService contains raw classes and there is only JSR 303 support (i.e. some annotations won't be picked like JSR 305, spring, jetbrains, findbugs, etc). I think that it'd be better to use simple names here as well. But I am not sure if this bug is actually in the swagger project

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions