Skip to content

Commit afcbc94

Browse files
committed
annotate_schema: resolve branch $refs for oneOf/anyOf source and title
Previously each oneOf/anyOf branch's ResolvedProperty was always stamped with sources=[from_schema.location] (the schema containing the oneOf) and fell back to a bare letter title (a/b/c), even when the branch was itself a plain $ref to another schema. This made it impossible to tell, from resolvedProperties.json, which schema/bblock each branch actually corresponds to. Now, when a branch is (or starts with) a $ref, resolve it up front and use the referenced schema's location as the branch's source, falling back to its title when the branch itself doesn't declare one.
1 parent 4f7b75c commit afcbc94

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

ogc/na/annotate_schema.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,16 +1184,32 @@ def _flatten(bl):
11841184
branch_key = '\x00'.join(branch_path)
11851185
if branch_key not in self._resolved_properties:
11861186
branch_title = None
1187+
branch_source = from_schema.location
11871188
if isinstance(branch_schema, dict):
11881189
branch_title = branch_schema.get('title')
1190+
# If the branch is (or starts with) a $ref, resolve it so the
1191+
# branch's title/source reflect the referenced schema (e.g. the
1192+
# bblock it points to) rather than the schema the oneOf/anyOf
1193+
# itself lives in.
1194+
branch_ref = branch_schema.get('$ref')
1195+
if branch_ref:
1196+
try:
1197+
referenced_branch_schema = self.schema_resolver.resolve_schema(
1198+
branch_ref, from_schema)
1199+
except Exception:
1200+
referenced_branch_schema = None
1201+
if referenced_branch_schema:
1202+
branch_source = referenced_branch_schema.location
1203+
if not branch_title and isinstance(referenced_branch_schema.subschema, dict):
1204+
branch_title = referenced_branch_schema.subschema.get('title')
11891205
if not branch_title:
11901206
branch_title = chr(ord('a') + idx) if idx < 26 else str(idx)
11911207
self._resolved_properties[branch_key] = ResolvedProperty(
11921208
path=branch_path,
11931209
id=None, jsonld_type=None, vocab=None,
11941210
title=branch_title, description=None,
11951211
required=False, keyword='branch',
1196-
sources=[from_schema.location],
1212+
sources=[branch_source],
11971213
)
11981214
merge_contexts(onto_context,
11991215
process_subschema(branch_schema, from_schema,

0 commit comments

Comments
 (0)