kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

BUG: json schema validator is not parsing correctly the PATTERN parameter #683

Open giowe opened 4 years ago

giowe commented 4 years ago

The error can be reproduced simply adding the pattern key in a parameter

"email": {
   "type": "string",
   "pattern": "S+@S+\.S+"
}

when you pass some parameters to the validation-error shows this message:


            {
                "path": "email",
                "errorCode": "pattern.openapi.requestValidation",
                "message": "should match pattern "S+@S+\.S+",
                "location": "body"
            }

as you can see it automatically adds quotes (") at the beginning and at the end of the regex and it is actually testing for THAT specific regex! To pass this regex validation in fact you must pass this json payload to you body

{
    "email": "\"S@SSS\""
}

instead of <anystring>@<anystring>.<anystring> as intended

jsdevel commented 4 years ago

@giowe can you please submit a pr to fix this?

coryasilva commented 1 year ago

@giowe I think you need to escape your backslash. Passing the json in was a false positive since the regex is rather permissive.

"pattern": "S+@S+\\.S+"

Okay to close?