Home » Java » java – Springfox Bean Validations @Size annotation does not work properly on List-Exceptionshub

java – Springfox Bean Validations @Size annotation does not work properly on List-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am using springfox bean validators to extract field limit information into the generated swagger json file,Here is the way I use:

    @ApiModelProperty("str1")
    @Size(min = 1, max = 200, message = "length 1-200")
    private String str1;

    @ApiModelProperty("list1")
    @Size(min = 1, max = 100, message = "size 1-100")
    private List<String> list1;

In the generated json file:

str1:- {
  type: "string",
  description: "str1",
  allowEmptyValue: false,
  minLength: 1,
  maxLength: 200
},
list1:- {
  type: "array",
  description: "list1",
  allowEmptyValue: false,
  items:- {
    type: "string"
  }
}

@Size annotation does not work properly on List

How to&Answers: