def _load_schema(name, path=__file__): """Load a schema from disk""" path = os.path.join(os.path.dirname(path), name + '.yaml') with open(path) as handle: schema = yaml.safe_load(handle) fast_schema = rapidjson_schema.loads(rapidjson.dumps(schema)) return path, (schema, fast_schema)
def _load_schema(name): """Load a schema from disk""" path = os.path.join(os.path.dirname(__file__), name + '.yaml') with open(path) as handle: schema = yaml.safe_load(handle) fast_schema = rapidjson_schema.loads(rapidjson.dumps(schema)) return path, (schema, fast_schema)
def schema(): return rapidjson_schema.loads(schema_text)
def test_init_invalid_schema(): with raises(ValueError): rapidjson_schema.loads('')
import rapidjson_schema schema = """ { "title": "Person", "type": "object", "properties": { "firstName": { "type": "integer" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 } }, "required": ["firstName"] } """ s = rapidjson_schema.loads(schema) print(s.validate('{"firstName":"a","lastName":"b"}')) print(s.validate('{}'))