java Swagger+Spring Boot,如何设置基于Spring Boot验证在API中传递的示例值
在我使用DTO传递信息的所有API调用中,在示例值中,我看到了DTO的所有字段,并在我的Spring Boot应用程序中对DTO应用了验证组,如
@NotNull(message = "error_card_expiry_month_required", groups = AddUpdateCard.class)
@JsonProperty("month")
private Integer Month;
@NotNull(message = "error_card_expiry_year_required", groups = AddUpdateCard.class)
@JsonProperty("year")
private Integer Year;
@NotBlank(message = "error_card_cvv_required",groups = AddUpdateCard.class)
@JsonProperty("cvv")
private String Cvv;
这里我使用了groups = Class.class
进行验证
如果可能的话,我如何告诉swagger使用它,以便它不会将整个DTO显示为示例值,而只显示我已验证的值
我只需要该API的已验证的@NotNull
注释值
我是否有可能或必须使用任何其他方法来实现这一点
# 1 楼答案
尝试将以下代码添加到每个字段
swagger使用@ApiModelProperty为给定属性创建DTO(requestbody)
它可能无法根据bean验证对有效的示例进行排序,但因为您知道自己的约束,所以可以选择您想要的任何示例值