Skip to content

Custom @NotNull annotations stopped working between 2.8.5 and 2.8.6 #3004

Closed
@kevinm416

Description

@kevinm416

Describe the bug

OpenAPI spec changes from 2.8.5 -> 2.8.6.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using? 3.4.5
  • What modules and versions of springdoc-openapi are you using? 2.8.6
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
public @interface NotNull {
  String message() default "must not be null";
  Class<?>[] groups() default {};
  Class<? extends Payload>[] payload() default {};
  String fieldOverride() default "";
}

public record Address(
    @NotNull String address1,
    Optional<String> address2) {}

In springdoc v2.8.5:

      "Address": {
        "properties": {
          "address1": {
            "type": "string"
          },
          "address2": {
            "type": "string"
          }
        },
        "required": [
          "address1"
        ],
        "type": "object"
      },

In springdoc 2.8.6:

      "Address": {
        "properties": {
          "address1": {
            "type": "string"
          },
          "address2": {
            "type": "string"
          }
        },
        "type": "object"
      },
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@RequestMapping("/api/hello")
public class HelloController {

  @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
  @Retention(RetentionPolicy.RUNTIME)
  @Documented
  public @interface NotNull {
    String message() default "must not be null";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
    String fieldOverride() default "";
  }

  public record Address(@NotNull String address1, Optional<String> address2) {}

  @GetMapping
  public Address getAddress() {
    return new Address("1", Optional.of("2"));
  }
}

Expected behavior

  • A clear and concise description of what you expected to happen.
    I expect address1 to remain a required field.

  • What is the expected result using OpenAPI Description (yml or json)?

      "Address": {
        "properties": {
          "address1": {
            "type": "string"
          },
          "address2": {
            "type": "string"
          }
        },
        "required": [
          "address1"
        ],
        "type": "object"
      },

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions