ogc-na 0.2.10__py3-none-any.whl → 0.2.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ogc-na might be problematic. Click here for more details.
- ogc/na/annotate_schema.py +45 -40
- {ogc_na-0.2.10.dist-info → ogc_na-0.2.11.dist-info}/METADATA +1 -1
- {ogc_na-0.2.10.dist-info → ogc_na-0.2.11.dist-info}/RECORD +5 -5
- {ogc_na-0.2.10.dist-info → ogc_na-0.2.11.dist-info}/WHEEL +0 -0
- {ogc_na-0.2.10.dist-info → ogc_na-0.2.11.dist-info}/top_level.txt +0 -0
ogc/na/annotate_schema.py
CHANGED
|
@@ -402,12 +402,16 @@ class SchemaAnnotator:
|
|
|
402
402
|
prop_value[ANNOTATION_ID] = terms[prop]
|
|
403
403
|
if prop in types:
|
|
404
404
|
prop_value[ANNOTATION_TYPE] = types[prop]
|
|
405
|
-
|
|
405
|
+
|
|
406
|
+
process_subschema(prop_value)
|
|
406
407
|
|
|
407
408
|
properties.update({p: {ANNOTATION_ID: terms[p]} for p in empty_properties if p in terms})
|
|
408
409
|
|
|
409
410
|
def process_subschema(subschema):
|
|
410
411
|
|
|
412
|
+
if not subschema:
|
|
413
|
+
return
|
|
414
|
+
|
|
411
415
|
self._follow_ref(subschema, fn, url, base_url)
|
|
412
416
|
|
|
413
417
|
# Annotate oneOf, allOf, anyOf
|
|
@@ -426,7 +430,7 @@ class SchemaAnnotator:
|
|
|
426
430
|
process_properties(subschema)
|
|
427
431
|
elif schema_type == 'array':
|
|
428
432
|
for k in ('prefixItems', 'items', 'contains'):
|
|
429
|
-
|
|
433
|
+
process_subschema(subschema.get(k))
|
|
430
434
|
|
|
431
435
|
# Annotate $defs
|
|
432
436
|
for defs_prop in ('$defs', 'definitions'):
|
|
@@ -453,7 +457,7 @@ class ContextBuilder:
|
|
|
453
457
|
"""
|
|
454
458
|
|
|
455
459
|
def __init__(self, fn: Path | str | None = None, url: str | None = None,
|
|
456
|
-
compact: bool = True):
|
|
460
|
+
compact: bool = True, ref_mapper: Callable[[str], str] | None = None):
|
|
457
461
|
"""
|
|
458
462
|
:param fn: file to load the annotated schema from
|
|
459
463
|
:param url: URL to load the annotated schema from
|
|
@@ -461,6 +465,7 @@ class ContextBuilder:
|
|
|
461
465
|
self.context = {'@context': {}}
|
|
462
466
|
self._parsed_schemas: dict[str | Path, dict] = {}
|
|
463
467
|
self.compact = compact
|
|
468
|
+
self._ref_mapper = ref_mapper
|
|
464
469
|
|
|
465
470
|
context = self._build_context(fn, url)
|
|
466
471
|
self.context = {'@context': context}
|
|
@@ -502,7 +507,7 @@ class ContextBuilder:
|
|
|
502
507
|
if prefixes:
|
|
503
508
|
own_context.update(prefixes)
|
|
504
509
|
|
|
505
|
-
def read_properties(where: dict):
|
|
510
|
+
def read_properties(where: dict, into_context: dict):
|
|
506
511
|
if not isinstance(where, dict):
|
|
507
512
|
return
|
|
508
513
|
for prop, prop_val in where.get('properties', {}).items():
|
|
@@ -513,56 +518,56 @@ class ContextBuilder:
|
|
|
513
518
|
if ANNOTATION_TYPE in prop_val:
|
|
514
519
|
prop_context['@type'] = compact_uri(prop_val[ANNOTATION_TYPE])
|
|
515
520
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
521
|
+
process_subschema(prop_val, prop_context.setdefault('@context', {}))
|
|
522
|
+
|
|
523
|
+
if not prop_context['@context']:
|
|
524
|
+
prop_context.pop('@context', None)
|
|
519
525
|
|
|
520
|
-
if len(prop_context) == 1:
|
|
526
|
+
if isinstance(prop_context, dict) and len(prop_context) == 1:
|
|
521
527
|
# shorten to just the id
|
|
522
528
|
prop_context = next(iter(prop_context.values()))
|
|
523
529
|
|
|
524
|
-
|
|
530
|
+
into_context[prop] = prop_context
|
|
531
|
+
|
|
532
|
+
def process_subschema(ss, into_context: dict):
|
|
525
533
|
|
|
526
|
-
def process_subschema(ss):
|
|
527
534
|
if isinstance(ss, dict):
|
|
528
535
|
if '$ref' in ss:
|
|
529
536
|
ref_fn, ref_url = resolve_ref(ss['$ref'], fn, url, base_url)
|
|
530
537
|
merge_dicts(self._build_context(ref_fn, ref_url), own_context)
|
|
531
|
-
read_properties(ss)
|
|
538
|
+
read_properties(ss, into_context)
|
|
532
539
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
540
|
+
for i in ('allOf', 'anyOf', 'oneOf'):
|
|
541
|
+
l = ss.get(i)
|
|
542
|
+
if isinstance(l, list):
|
|
543
|
+
for sub_schema in l:
|
|
544
|
+
process_subschema(sub_schema, into_context)
|
|
538
545
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
546
|
+
for i in ('$defs', 'definitions'):
|
|
547
|
+
d = ss.get(i)
|
|
548
|
+
if isinstance(d, dict):
|
|
549
|
+
for sub_schema in d.values():
|
|
550
|
+
process_subschema(sub_schema, into_context)
|
|
544
551
|
|
|
545
|
-
|
|
552
|
+
process_subschema(schema, own_context)
|
|
546
553
|
|
|
547
554
|
if self.compact:
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
own_context = compact_context
|
|
555
|
+
|
|
556
|
+
def compact_branch(branch, existing_terms):
|
|
557
|
+
|
|
558
|
+
for term in list(branch.keys()):
|
|
559
|
+
if term[0] == '@':
|
|
560
|
+
# skip special terms
|
|
561
|
+
continue
|
|
562
|
+
if term in existing_terms and existing_terms[term] == branch[term]:
|
|
563
|
+
# same term exists in ancestor -> delete
|
|
564
|
+
del branch[term]
|
|
565
|
+
|
|
566
|
+
for term, term_value in branch.items():
|
|
567
|
+
if isinstance(term_value, dict) and '@context' in term_value:
|
|
568
|
+
compact_branch(term_value['@context'], {**existing_terms, **branch})
|
|
569
|
+
|
|
570
|
+
compact_branch(own_context, {})
|
|
566
571
|
|
|
567
572
|
self._parsed_schemas[fn or url] = own_context
|
|
568
573
|
return own_context
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ogc-na
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.11
|
|
4
4
|
Summary: OGC Naming Authority tools
|
|
5
5
|
Author-email: Rob Atkinson <ratkinson@ogc.org>, Piotr Zaborowski <pzaborowski@ogc.org>, Alejandro Villar <avillar@ogc.org>
|
|
6
6
|
Project-URL: Homepage, https://github.com/opengeospatial/ogc-na-tools/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
ogc/na/__init__.py,sha256=uzcNiJ3uKFNJ1HBfKxIwgAy2HMUFsLAe5RkrUg8ncac,464
|
|
2
|
-
ogc/na/annotate_schema.py,sha256=
|
|
2
|
+
ogc/na/annotate_schema.py,sha256=wEvqVbdRXpAKSLQz231H7B11m-mZekDrtULjXPMMIVk,22473
|
|
3
3
|
ogc/na/domain_config.py,sha256=x_X4YiNo1etaa4N6KrZFRsFgWPPKk1rLqVE3ZP3rrps,13030
|
|
4
4
|
ogc/na/download.py,sha256=2afrLyl4WsAlxkCgXsl47fs9mNKfDmhVpeT2iwNSoq0,3354
|
|
5
5
|
ogc/na/ingest_json.py,sha256=3g47V01eKAPGK6EVGxyzhJhp4uE3mSfvI5gV4L3awZQ,32327
|
|
@@ -10,7 +10,7 @@ ogc/na/util.py,sha256=ySu2mSAhUYwYFH78Bmo9Z35DM4fHqb1ExLEYPjno3fs,7990
|
|
|
10
10
|
ogc/na/validation.py,sha256=FkXx1Pwot4ztg9Vv2LrODfYxpknG9-67BmY3Ep7avd4,3535
|
|
11
11
|
ogc/na/input_filters/__init__.py,sha256=PvWEI-rj5NNR_Cl903wHtS08oTywjDYEfappY5JtVkI,1169
|
|
12
12
|
ogc/na/input_filters/csv.py,sha256=O2E3ivjP9i5tGtyvb6UjmR4eM7toVkzP58EUm6bxvfw,2530
|
|
13
|
-
ogc_na-0.2.
|
|
14
|
-
ogc_na-0.2.
|
|
15
|
-
ogc_na-0.2.
|
|
16
|
-
ogc_na-0.2.
|
|
13
|
+
ogc_na-0.2.11.dist-info/METADATA,sha256=2VI9Kdkv6M2EkPv3AtvUe2uUwz5mu10zWa7SVaMW8b0,3528
|
|
14
|
+
ogc_na-0.2.11.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
15
|
+
ogc_na-0.2.11.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
|
|
16
|
+
ogc_na-0.2.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|