我可以使用 Swagger 指示参数值的正则表达式要求吗?
Can I indicate a regular expression requirement for a parameter value using Swagger?
在我的 REST API 中,提交的参数值之一必须是遵循正则表达式的代码:
/[A-Z]{2}[0-9]{4}/
除了放在参数的description
属性中,还有什么办法可以让我在不符合我的正则表达式的情况下提示该值无效?
我无法在 Swagger 文档中找到任何提及正则表达式的内容,除了作为一种识别模式字段的方法(这不是我想要做的)。
您可以使用名为 pattern in your api's parameters if is not a body or in your scheme definitions for properties, it use standard ECMA 262 : (http://json-schema.org/latest/json-schema-validation.html#rfc.section.3.3)
的字段
[2019 年 7 月更新]
OpenAPI 3 规范 -
https://swagger.io/docs/specification/data-models/data-types/#pattern
在我的 REST API 中,提交的参数值之一必须是遵循正则表达式的代码:
/[A-Z]{2}[0-9]{4}/
除了放在参数的description
属性中,还有什么办法可以让我在不符合我的正则表达式的情况下提示该值无效?
我无法在 Swagger 文档中找到任何提及正则表达式的内容,除了作为一种识别模式字段的方法(这不是我想要做的)。
您可以使用名为 pattern in your api's parameters if is not a body or in your scheme definitions for properties, it use standard ECMA 262 : (http://json-schema.org/latest/json-schema-validation.html#rfc.section.3.3)
的字段[2019 年 7 月更新]
OpenAPI 3 规范 - https://swagger.io/docs/specification/data-models/data-types/#pattern