Skip to content

Commit

Permalink
Add missed_properties to ContextBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Feb 19, 2024
1 parent 6947475 commit 1e18ae2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ogc/na/annotate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def __init__(self, location: Path | str = None,
self.location = location

self.visited_properties: dict[str, str | None] = {}
self._missed_properties: dict[str, Any] = {} # Dict instead of set to keep order of insertion
context = self._build_context(self.location, compact)
if context:
context['@version'] = version
Expand Down Expand Up @@ -682,6 +683,8 @@ def read_properties(subschema: dict, from_schema: ReferencedSchema,
full_property_path = schema_path + [prop]
full_property_path_str = f"{schema_path_str}/{prop}"
self.visited_properties.setdefault(full_property_path_str, None)
if from_schema == root_schema:
self._missed_properties.setdefault(full_property_path_str, True)
if not isinstance(prop_val, dict):
continue
prop_context = {'@context': {}}
Expand All @@ -691,10 +694,12 @@ def read_properties(subschema: dict, from_schema: ReferencedSchema,
elif term.startswith(ANNOTATION_PREFIX) and term not in ANNOTATION_IGNORE_EXPAND:
if term == ANNOTATION_ID:
self.visited_properties[full_property_path_str] = term_val
self._missed_properties[full_property_path_str] = False
prop_context['@' + term[len(ANNOTATION_PREFIX):]] = term_val

if isinstance(prop_context.get('@id'), str):
self.visited_properties[full_property_path_str] = prop_context['@id']
self._missed_properties[full_property_path_str] = False
if prop_context['@id'] == '@nest':
process_subschema(prop_val, from_schema, onto_context, full_property_path)
else:
Expand Down Expand Up @@ -854,6 +859,10 @@ def compact_uris(branch, context_stack=None):
self._parsed_schemas[schema_location] = own_context
return own_context

@property
def missed_properties(self):
return [k for (k, v) in self._missed_properties.items() if v]


def dump_annotated_schema(schema: AnnotatedSchema, subdir: Path | str = 'annotated',
root_dir: Path | str | None = None,
Expand Down

0 comments on commit 1e18ae2

Please sign in to comment.