Swagger Java日期格式验证抛出异常



请帮助我解决与swagger验证相关的问题,因为相同的regex在java中工作,但在swagger中失败。

工作java代码:

@Test
public void test1() {
String regex = "^((19|20)\d\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])$";
Assert.assertTrue("Date: matched.", Pattern.matches(regex, "19881231")); -- true
}

Swagger Contract.yml

properties:
lineofValue:
type: string
pattern: ^AB|CD$
description:  mandatory
date:
type: string
pattern: ^((19|20)\d\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])$
description:  mandatory

样品需求:

{
"lineofValue":"AB"
"date":"19881231"
}

例外:

{
"code": "400",
"status": 400,
"message": "Validation Failed: ECMA 262 regex "^((19|20)\\d\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])$" does not match input string "19881231""
}

通过Swagger Documentation,您似乎不需要像在Java:中那样转义/字符

properties:
lineofValue:
type: string
pattern: ^AB|CD$
description:  mandatory
date:
type: string
pattern: ^((19|20)dd)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])$
description:  mandatory

最新更新