Skip to content
\n

This throws an exception:

\n
Exception has occurred: SchemaError\n'^([\\\\p{L}\\\\p{Z}\\\\p{N}_.:\\\\/=+\\\\-@]{1,128})$' is not a 'regex'\n\nFailed validating 'format' in metaschema['allOf'][1]['properties']['properties']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['pattern']:\n    {'format': 'regex', 'type': 'string'}\n\nOn schema['properties']['name']['pattern']:\n    '^([\\\\p{L}\\\\p{Z}\\\\p{N}_.:\\\\/=+\\\\-@]{1,128})$'\nre.error: bad escape \\p at position 3\n\nThe above exception was the direct cause of the following exception:\n\n  File \"/Users/terryr/src/openapi-validator-bug/test.py\", line 14, in <module>\n    validate(claim_xrd, schema)\njsonschema.exceptions.SchemaError: '^([\\\\p{L}\\\\p{Z}\\\\p{N}_.:\\\\/=+\\\\-@]{1,128})$' is not a 'regex'\n\nFailed validating 'format' in metaschema['allOf'][1]['properties']['properties']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['pattern']:\n    {'format': 'regex', 'type': 'string'}\n\nOn schema['properties']['name']['pattern']:\n    '^([\\\\p{L}\\\\p{Z}\\\\p{N}_.:\\\\/=+\\\\-@]{1,128})$'\n
\n

The regex module is able to handle this.

\n
import regex\n\nprint(regex.match('^([\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]{1,128})$', 'foo'))
\n

outputs:

\n
<regex.Match object; span=(0, 3), match='foo'>\n
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hi @messedupryan

\n

OpenAPI's regular expressions use syntax of regex from JavaScript (ECMA 262). That means POSIX classes are not part of the standard. You can find equipments in JS here. If you require POSIX classes in your case the best option for you would be to extend openapi validator with pattern validator of your choice.

","upvoteCount":2,"url":"https://github.com/python-openapi/openapi-schema-validator/discussions/119#discussioncomment-6713969"}}}
Discussion options

You must be logged in to vote

Hi @messedupryan

OpenAPI's regular expressions use syntax of regex from JavaScript (ECMA 262). That means POSIX classes are not part of the standard. You can find equipments in JS here. If you require POSIX classes in your case the best option for you would be to extend openapi validator with pattern validator of your choice.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by messedupryan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants