diff options
author | Julian Berman <Julian@GrayVines.com> | 2023-03-28 16:46:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-28 16:46:09 -0400 |
commit | 27d360860a7c021d9cb402330692dc6a874d62f7 (patch) | |
tree | e72ccecbfd6f4d24988a0689a1d56a3aea35d3f2 | |
parent | cf1f6b02ab6fcf32f46f039720fa0add728f236f (diff) | |
parent | 1d5e77c60ef16b5b6d57cefc6acb2641dcbaf972 (diff) | |
download | jsonschema-27d360860a7c021d9cb402330692dc6a874d62f7.tar.gz |
Merge pull request #1075 from ikonst/2023-03-27-unevaluatedProperties-do-not-validate
Don't evaluate properties twice on behalf of `unevaluatedProperties` validation
-rw-r--r-- | jsonschema/_utils.py | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 3f1a440..e811be7 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -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: |