Can I indicate a regular expression requirement for a parameter value using Swagger?

空扰寡人 提交于 2020-04-10 07:41:08

问题


In my REST API, one of the submitted parameter values must be a code following the regex:

/[A-Z]{2}[0-9]{4}/

Is there any way, besides putting it in the description property of the parameter, for me to indicate that the value is not valid if it does not match my regular expression?

I was not able to find any mention of regex's in the Swagger doc, except as a way to identify Patterned Fields (which is not what I want to do).


回答1:


You can use a field named 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)

[UPDATE Jul. 2019]

OpenAPI 3 spec - https://swagger.io/docs/specification/data-models/data-types/#pattern



来源:https://stackoverflow.com/questions/33700359/can-i-indicate-a-regular-expression-requirement-for-a-parameter-value-using-swag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!