Skip to content

Commit

Permalink
Merge pull request #1075 from ikonst/2023-03-27-unevaluatedProperties…
Browse files Browse the repository at this point in the history
…-do-not-validate

Don't evaluate properties twice on behalf of `unevaluatedProperties` validation
  • Loading branch information
Julian committed Mar 28, 2023
2 parents cf1f6b0 + 1d5e77c commit 27d3608
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,19 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
"properties", "additionalProperties", "unevaluatedProperties",
]:
if keyword in schema:
if validator.is_type(schema[keyword], "boolean"):
for property, value in instance.items():
if validator.evolve(schema=schema[keyword]).is_valid(
{property: value},
):
evaluated_keys.append(property)
schema_value = schema[keyword]
if validator.is_type(schema_value, "boolean") and schema_value:
evaluated_keys += instance.keys()

if validator.is_type(schema[keyword], "object"):
for property, subschema in schema[keyword].items():
if property in instance and validator.evolve(
schema=subschema,
).is_valid(instance[property]):
elif validator.is_type(schema_value, "object"):
for property in schema_value:
if property in instance:
evaluated_keys.append(property)

if "patternProperties" in schema:
for property, value in instance.items():
for pattern, _ in schema["patternProperties"].items():
if re.search(pattern, property) and validator.evolve(
schema=schema["patternProperties"],
).is_valid({property: value}):
for property in instance:
for pattern in schema["patternProperties"]:
if re.search(pattern, property):
evaluated_keys.append(property)

if "dependentSchemas" in schema:
Expand Down

0 comments on commit 27d3608

Please sign in to comment.