comparison data_schema/__init__.py @ 40:2376224a9717

FIX: when processing schema references and the resolved schema contains conditionals they must be evaluated
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 19 Jul 2023 15:19:23 +0200
parents 78f5ef0ee087
children ea8c2d01a9d9
comparison
equal deleted inserted replaced
39:78f5ef0ee087 40:2376224a9717
1153 yield ValidationProblem(code=ERRORS.E10029, hint=obj, context=context, 1153 yield ValidationProblem(code=ERRORS.E10029, hint=obj, context=context,
1154 cause=res) 1154 cause=res)
1155 1155
1156 1156
1157 def process_schema_references(schema, context, check_single_ref_key=True): 1157 def process_schema_references(schema, context, check_single_ref_key=True):
1158 """
1159
1160 .. note:: If a new dereferenced schema is found schema conditionals are
1161 evaluated also. So the resolved schema containing conditionals
1162 behaves according to the given conditions.
1163
1164 """
1158 try: 1165 try:
1159 ref = schema[SCHEMA_REF_KEY] 1166 ref = schema[SCHEMA_REF_KEY]
1160 except (KeyError, TypeError): 1167 except (KeyError, TypeError):
1161 return schema 1168 return schema
1162 # if `$ref' is found it MUST be the only key 1169 # if `$ref' is found it MUST be the only key
1165 schema = try_get_reference(ref, context, schema) 1172 schema = try_get_reference(ref, context, schema)
1166 if not isinstance(schema, _Schema): 1173 if not isinstance(schema, _Schema):
1167 raise SchemaError( 1174 raise SchemaError(
1168 "dereferenced schema is not a `_Schema': {}".format(ref)) 1175 "dereferenced schema is not a `_Schema': {}".format(ref))
1169 schema = copy.deepcopy(schema) 1176 schema = copy.deepcopy(schema)
1177 # process schema conditionals "cond" and "match" again
1178 schema = process_schema_conditionals(schema, context)
1170 return process_schema_references(schema, context, check_single_ref_key=True) 1179 return process_schema_references(schema, context, check_single_ref_key=True)
1171 1180
1172 1181
1173 def process_schema_conditionals(schema, context): 1182 def process_schema_conditionals(schema, context):
1174 """Lisp-like `cond` to provide schema modifications 1183 """Lisp-like `cond` to provide schema modifications