如何在springdoc中针对特定字段禁用JSR-303注释处理?
我有以下请求类 MyRequestTO ,其中字段 name 实际上是可选的。 @NotBlank 注释仅应用于未包装的 JsonNullable 。这意味着用户在发送 MyRequestTO 时可以省略字段,但如果设置为空,则不能为空。但是,open根据需要标记 name 字段。将 @Schema 注释更改为 @Schema(type = "string", required = false) 无助。
MyRequestTO
name
@NotBlank
JsonNullable
@Schema
@Schema(type = "string", required = false)
我希望避免必须编写自己的注释并使用 org.springdoc.core.customizers.OpenApiCustomiser 的解决方案。所需的解决方案也应该适用于其他类型,如带有 @NotNull 注释的 @NotNull 。
org.springdoc.core.customizers.OpenApiCustomiser
@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) {