OpenApi-generator do not insert @NotBlank annotation for string

1k views Asked by At

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.

1

There are 1 answers

0
pswrdf On BEST ANSWER

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