From 6774d386e3fb42c2a556d7217af63938d76737cb Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 15 Dec 2023 15:13:24 -0600 Subject: [PATCH] validator: Fix loading of a single schema file Normally a single file is a processed schema, but sometimes for testing we want to pass in a single schema to check the processed output. Signed-off-by: Rob Herring --- dtschema/validator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dtschema/validator.py b/dtschema/validator.py index 8db54f1..6137dfe 100644 --- a/dtschema/validator.py +++ b/dtschema/validator.py @@ -330,6 +330,7 @@ class DTValidator: def __init__(self, schema_files, filter=None): self.schemas = {} self.resolver = jsonschema.RefResolver('', None, handlers={'http': self.http_handler}) + schema_cache = None if len(schema_files) == 1 and os.path.isfile(schema_files[0]): # a processed schema file @@ -345,6 +346,11 @@ def __init__(self, schema_files, filter=None): print("preprocessed schema file is not valid JSON or YAML\n", file=sys.stderr) raise + # Ensure the cache is a processed schema and not just a single schema file + if '$id' in schema_cache: + schema_cache = None + + if schema_cache: # Convert old format to new if isinstance(schema_cache, list): d = {}