Skip to content

Commit 10fe1f5

Browse files
committed
Fix $anchor schema refs in JSON validation
1 parent 7706428 commit 10fe1f5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ogc/bblocks/validation/json_.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ def validate(self, filename: Path, output_filename: Path, report: ValidationRepo
145145
schema_uri = self.bblock.schema.value.with_name(random_fn).as_uri()
146146
else:
147147
schema_uri = urljoin(self.bblock.schema.value, random_fn)
148-
if schema_ref.startswith('#/'):
148+
if schema_ref.startswith('#'):
149+
# $ref
149150
schema_ref = f"{self.bblock.annotated_schema.resolve()}{schema_ref}"
150151
elif not is_url(schema_ref):
151152
if '#' in schema_ref:
152153
path, fragment = schema_ref.split('#', 1)
153154
schema_ref = f"{self.bblock.annotated_schema.parent.resolve().joinpath(path)}#{fragment}"
154-
schema_uri = (f"{self.bblock.schema.parent.joinpath(path).with_name(random_fn).as_uri()}"
155-
f"#{fragment}")
155+
ppath = path.rsplit('/', 1)
156+
newpath = f"{ppath}/{random_fn}" if ppath else random_fn
157+
schema_uri = f"{self.bblock.schema.resolve_ref(newpath)}#{fragment}"
156158
else:
157159
schema_uri = self.bblock.schema.resolve_ref(schema_ref).with_name(random_fn).as_uri()
158160
snippet_schema = {'$ref': schema_ref}

0 commit comments

Comments
 (0)