Skip to content

Commit

Permalink
Fix schema_uri for example snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Sep 29, 2023
1 parent f9f017c commit 30ce63e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ogc/bblocks/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import json
import os
import random
import shutil
from json import JSONDecodeError
from pathlib import Path
from time import time
from typing import Any, Sequence, Callable
from urllib.parse import urlsplit
from urllib.request import urlopen
Expand Down Expand Up @@ -356,18 +358,18 @@ def validate_test_resources(bblock: BuildingBlock,
snippet_schema_validator = schema_validator
else:
schema_ref = snippet['schema-ref']
random_fn = f"example.{time()}.{random.randint(0,1000)}.yaml"
schema_uri = bblock.schema.with_name(random_fn).as_uri()
if schema_ref.startswith('#/'):
schema_ref = f"{bblock.schema}{schema_ref}"
schema_uri = bblock.schema.with_name('snippet-schema.yaml').as_uri()
elif not is_url(schema_ref):
if '#' in schema_ref:
path, fragment = schema_ref.split('#', 1)
schema_ref = f"{bblock.schema.parent.joinpath(path)}#{fragment}"
schema_uri = f"{bblock.schema.parent.joinpath(path).as_uri()}#{fragment}"
schema_uri = (f"{bblock.schema.parent.joinpath(path).with_name(random_fn).as_uri()}"
f"#{fragment}")
else:
schema_uri = bblock.schema.parent.joinpath(schema_ref).as_uri()
else:
schema_uri = bblock.schema.as_uri()
schema_uri = bblock.schema.parent.joinpath(schema_ref).with_name(random_fn).as_uri()
snippet_schema = {'$ref': schema_ref}
snippet_schema_validator = get_json_validator(snippet_schema,
schema_uri)
Expand Down

0 comments on commit 30ce63e

Please sign in to comment.