From ba7eccfbad133e39062e41e02686d997275b44d4 Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Fri, 19 Jan 2024 00:59:43 +0530 Subject: [PATCH] fix(jsonschema): skips populating default if property not in instance This commit fixes an issue in the set_default wrapper of the validator where a property that may not be in the manifest is being set if it has a default associated with it. This leads to inconsistencies when attributes like additionalProperties are used. --- riocli/jsonschema/validate.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/riocli/jsonschema/validate.py b/riocli/jsonschema/validate.py index 2c5f24cf..67da70f6 100644 --- a/riocli/jsonschema/validate.py +++ b/riocli/jsonschema/validate.py @@ -25,6 +25,11 @@ def set_defaults(validator, properties, instance, schema): for p, sub_schema in properties.items(): if "default" not in sub_schema: continue + + # Skip if property is not in instance + if p not in instance: + continue + if isinstance(instance, dict): instance.setdefault(p, sub_schema["default"]) if isinstance(instance, list):