Can I specify a regex requirement for a parameter value using Swagger?

In my REST API, one of the parameter values ​​represented should be the code following the regular expression:

/[AZ]{2}[0-9]{4}/

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

I could not find mention of regex in the Swagger document, except as a way to identify patterned fields (which is not what I want to do).

+6
source share
1 answer

You can use a field called pattern in the API parameters, if it is not a body or in the definitions of your schema for properties, it uses the ECMA 262 standard: ( http://json-schema.org/latest/json-schema-validation.html # rfc.section.3.3 )

[UPDATE July 2019]

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

+15
source

Source: https://habr.com/ru/post/1235914/


All Articles