swagger-express-middleware
swagger-express-middleware copied to clipboard
Query Parameter Validation should enforce RegEx patterns for non-string parameters
"parameters" : [ { "name" : "id", "in" : "query", "pattern": "^\\d{5}$", "description" : "id value", "required" : true, "type" : "integer", "format" : "int64" } ],
This parameter never gets validated according to the pattern, I've tried looking into codebase to see if there's something related to pattern and couldnt find it.
The pattern validation works when tried from swagger-ui
Parameters are validated by the parseParameter()
function, which ultimately delegates to the jsonValidate()
function. JSON Schema validation is done by tv4.
In your case, it appears that the problem is that you have a pattern
property on an integer
parameter. Patterns only apply to string parameters.
Parameters are validated by the
parseParameter()
function, which ultimately delegates to thejsonValidate()
function. JSON Schema validation is done by tv4.In your case, it appears that the problem is that you have a
pattern
property on aninteger
parameter. Patterns only apply to string parameters.
Confirmed, the pattern works with string parameters. is there any way to validate integer request parameter with regex pattern ?
Unfortunately, the JSON Schema spec says that the pattern
property only applies to string properties. However, I can definitely see an argument that Swagger Express Middleware should support this, since the incoming query parameter is a string until Swagger Express Middleware converts it to an integer.
I'm going to re-open this issue and mark it as an enhancement. No promises as to when I'll get to it though. Although I'd gladly welcome a PR.