Skip to content

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

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

Open
kevinm416 opened this issue May 21, 2025 · 0 comments
Open

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

kevinm416 opened this issue May 21, 2025 · 0 comments

Comments

@kevinm416
Copy link

kevinm416 commented May 21, 2025

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"
      },
@kevinm416 kevinm416 changed the title @NotNull annotations stopped working between 2.8.5 and 2.8.6 Custom @NotNull annotations stopped working between 2.8.5 and 2.8.6 May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant