Search code examples
javaspringopenapiopenapi-generatoropenapi-generator-maven-plugin

OpenApi-generator do not insert @NotBlank annotation for string


I use openapi-generator-maven-plugin:7.1.0 with properties:

<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useSpringBoot3>true</useSpringBoot3>
<useSpringController>true</useSpringController>
<openApiNullable>false</openApiNullable>
<performBeanValidation>true</performBeanValidation>

It generates only @NotNull annotation in model, for required String field in spec, I have no idea how to generate @NotBlank also.


Solution

  • So at this point openapi-generator doesn't use @NotBlank and @NotEmpty annotations, only @NotNull. But it can be done via:

    x-field-extra-annotation: "@jakarta.validation.constraints.NotBlank"
    

    see https://stackoverflow.com/a/71526062/2728393