This throws an exception:
\nException 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})$'\nThe regex module is able to handle this.
import regex\n\nprint(regex.match('^([\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]{1,128})$', 'foo'))outputs:
\n<regex.Match object; span=(0, 3), match='foo'>\nOpenAPI'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"}}}-
|
I am trying to see if there is any way to support regex POSIX classes like \p{L} or \p{N} with the open-api-schema-validator. In testing, it would appear that the limitation here is that jsonschema uses Is this something that could be addressed by open-api-schema-validator? For reference, here is an example of what I want to accomplish: from openapi_schema_validator import validate
schema = {
"additionalProperties": False,
"type": "object",
"properties": {'name': {'description': 'Sample Name',
'type': 'string',
'pattern': '^([\p{L}\p{Z}\p{N}_.:\/=+\-@]{1,128})$'}
}
}
doc = {'name': 'some-Name'}
validate(doc, schema)This throws an exception: The import regex
print(regex.match('^([\p{L}\p{Z}\p{N}_.:\/=+\-@]{1,128})$', 'foo'))outputs: |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
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.