compare_schemas() function¶
- yggdrasil_rapidjson.compare_schemas(schemaA, schemaB, dont_raise=False)¶
Compare two JSON schemas for compatibility.
- Parameters:
schemaA (str, dict) – first JSON schema for comparison
schemaB (str, dict) – second JSON schema for comparison
dont_raise (bool) – if True, an error will not be raised if the schemas are incompatible.
- Returns:
True if the schemas are compatible, False otherwise.
>>> compare_schemas('{"type": "number"}', '{"type": ["number", "schema"]}') True >>> compare_schemas({"type": "number"}, {"type": ["number", "schema"]}) True
dont_raise
If dont_raise is True (default:
False), then the comparison will return False when the two schemas are incompatible rather than raising an error.>>> compare_schemas({"type": "number"}, {"type": "string"}) Traceback (most recent call last): ComparisonError: { "message": "Incompatible schema property 'type': [\"number\"] vs [\"string\"].", "schemaIteratorRef": "#", "schemaHandlerRef": "#" } >>> compare_schemas({"type": "number"}, {"type": "string"}, dont_raise=True) False