| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Thanks for the improvement. Ideally we should have a test case for the functionality, even just what you wrote above, but at a minimum I'd say we should expose the availability of StdRegex on the module, say RAPIDJSON_SCHEMA_USES_STDREGEX or something like that, similar to the RAPIDJSON_VERSION attribute. What do you think? |
Sorry, something went wrong.
Update README to set environmental variable to 1
You're right it is good to have it exposed on the module, I added it (but I'm not sure if I should add something on typings/rapidjson/init.pyi, let me know if I'm missing something there). I also added an small test case to validate that we can use other regex when the variable is set |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
RapidJson uses an in-house regex engine that has limited syntax, we can use std::regex by defining
This patch extends that functionality to python-rapidjson by using the environmental variable RAPIDJSON_SCHEMA_USE_STDREGEX
For example, the following schema uses negative-lookahead (not supported by default engine):
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "some_id", "type": "object", "additionalProperties": False, "required": ["metadata"], "patternProperties": { "^(?!metadata$).+": { "type": "string" } }, "properties": { "metadata": { "type": "integer" } } }Using this schema leads to a ValidationError using this json {"a": "a", "metadata": 1}:
>>> import rapidjson >>> schema_dict = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "some_id", "type": "object", "additionalProperties": False, "required": ["metadata"], "patternProperties": { "^(?!metadata$).+": { "type": "string" } }, "properties": { "metadata": { "type": "integer" } } } >>> validator = rapidjson.Validator(rapidjson.dumps(schema_dict)) >>> validator(rapidjson.dumps({"a": "a", "metadata": 1})) Traceback (most recent call last): File "<python-input-2>", line 1, in <module> validator(rapidjson.dumps({"a": "a", "metadata": 1})) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rapidjson.ValidationError: ('additionalProperties', '#', '#/a')Expected behavior:
>>> import rapidjson >>> schema_dict = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "some_id", "type": "object", "additionalProperties": False, "required": ["metadata"], "patternProperties": { "^(?!metadata$).+": { "type": "string" } }, "properties": { "metadata": { "type": "integer" } } } >>> validator = rapidjson.Validator(rapidjson.dumps(schema_dict)) >>> validator(rapidjson.dumps({"a": "a", "metadata": 1})) # no error raised by the validator