Skip to content

Commit

Permalink
Refactor solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ostefano committed Apr 4, 2024
1 parent 05c56f1 commit 3ee4784
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions stix2validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,11 @@ def patch_schema(schema_data: dict, schema_path: str) -> dict:
"http://json-schema.org/draft/", "https://json-schema.org/draft/"
)
if "$id" in schema_data:
schema_data["$id"] = schema_path
schema_path = pathlib.Path(schema_path)
if schema_path.is_absolute():
schema_data["$id"] = str(schema_path.as_uri())
else:
schema_data["$id"] = str(schema_path)
return schema_data


Expand Down Expand Up @@ -596,12 +600,6 @@ def load_validator(schema_path, schema, schema_dir):
Returns:
An instance of Draft202012Validator.
"""
schema_path = pathlib.Path(schema_path)
if schema_path.is_absolute():
schema_path = schema_path.as_uri()
else:
schema_path = schema_path
schema_path = str(schema_path)
schema = patch_schema(schema, schema_path)
retrieve_callback = functools.partial(retrieve_from_filesystem, schema_dir=schema_dir)
registry = Registry(
Expand Down

0 comments on commit 3ee4784

Please sign in to comment.