Skip to content

Commit

Permalink
Implement simplified extension mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Aug 2, 2023
1 parent fcf4ea0 commit 9e89b47
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
46 changes: 44 additions & 2 deletions ogc/bblocks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,50 @@ def annotate_schema(bblock: BuildingBlock,
ref_mapper=ref_mapper,
)

# follow_refs=False => only one schema
annotated_schema = annotator.process_schema(schema_url or schema_fn, context)
bb_extends = bblock.extends
override_schema = None
if bb_extends:
bb_path = None
if isinstance(bb_extends, dict):
bb_path = bb_extends.get('path')
bb_extends = bb_extends['itemIdentifier']

original_schema = load_yaml(filename=schema_fn, url=schema_url)
original_schema.pop('$schema', None)
if bb_path in (None, '', '.', '$'):
inserted_schema = original_schema
else:
bb_path = re.split(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',
re.sub(r'^[\.\$]', '', bb_path.strip()))
inserted_schema = {}
inner_schema = inserted_schema
for p in bb_path:
p = p.replace('"', '')
inner_schema['properties'] = {}

if p.endswith('[]'):
p = p[:-2]
inner_schema['properties'][p] = {
'type': 'array',
'items': {}
}
inner_schema = inner_schema['properties'][p]['items']
else:
inner_schema = inner_schema['properties'].setdefault(p, {})
for k, v in original_schema.items():
if k != '$schema' and not k.startswith('x-jsonld-'):
inner_schema[k] = v

override_schema = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'allOf': [
{'$ref': f"bblocks://{bb_extends}"},
inserted_schema,
],
**{k: v for k, v in original_schema.items() if k.startswith('x-jsonld-')}
}

annotated_schema = annotator.process_schema(schema_url or schema_fn, context, override_schema)

if not annotated_schema:
return result
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ asciidoc
pyyaml~=6.0
Mako~=1.2.4
jsonschema==4.17.3
ogc-na>=0.3.2
ogc-na @ git+https://github.com/opengeospatial/ogc-na-tools@main#egg=ogc-na
rdflib @ git+https://github.com/avillar/[email protected]#egg=rdflib
requests~=2.31.0
pyparsing~=3.0.9
Expand Down

0 comments on commit 9e89b47

Please sign in to comment.