How can I disable JSR-303 annotation processing in springdoc for specific fields?
I have the following request class MyRequestTO
where the field name
is actually optional. The @NotBlank
annotation is only applied to the unwrapped JsonNullable
. This means the user is allowed to omit the field when sending MyRequestTO
but if set it must not be blank. However the open api doc marks the name
field as required. Changing the @Schema
annotation to @Schema(type = "string", required = false)
does not help.
I want to avoid a solution where I have to write my own annotation and make use of org.springdoc.core.customizers.OpenApiCustomiser
. The desired solution should also work for other types like JsonNullable<Boolean>
annotated with @NotNull
.
public class MyRequestTO {
@Schema(type = "string")
@NotBlank
private JsonNullable<String> name = JsonNullable.undefined();
public JsonNullable<String> getName() {
return name;
}
public void setName(JsonNullable<String> name) {
this.name = name;
}
}
Relevant dependencies
implementation "org.openapitools:jackson-databind-nullable:0.2.1"
implementation "org.springdoc:springdoc-openapi-ui:1.5.5"