Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swagger

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).

like image 889
Alan McBee Avatar asked Nov 13 '15 19:11

Alan McBee


1 Answers

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

like image 54
Nelson G. Avatar answered Sep 27 '22 21:09

Nelson G.