Skip to content

Commit fccb5f6

Browse files
manage.py (pre-commit): Update references to strict schemas
1 parent 84cd062 commit fccb5f6

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

manage.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,23 @@ def get_strict_schema(schema):
436436
Return the strict version of the schema.
437437
"""
438438
# Update schema metadata.
439-
release_with_underscores = release.replace(".", "__")
440-
schema["id"] = schema["id"].replace(release_with_underscores, f"{release_with_underscores}/strict")
439+
identifier = schema["id"].split("/")
440+
identifier[-1] = f"strict/{identifier[-1]}"
441+
schema["id"] = "/".join(identifier)
441442
schema["title"] = f'Strict {schema["title"][0].lower()}{schema["title"][1:]}'
442443
schema["description"] = (
443444
f'{schema["description"]} The strict schema adds additional validation rules planned for inclusion in OCDS 2.0. Use of the strict schema is a voluntary opportunity to improve data quality.' # noqa: E501
444445
)
445446

447+
# Update references to other schemas.
448+
reference_strict_schemas(schema)
449+
450+
# Reference compiled release schema.
451+
if schema["id"].endswith("record-schema.json"):
452+
schema["properties"]["compiledRelease"]["$ref"] = schema["properties"]["compiledRelease"]["$ref"].replace(
453+
"release-schema.json", "compiled-release-schema.json"
454+
)
455+
446456
# Add validation properties
447457
add_validation_properties(schema)
448458

@@ -484,6 +494,24 @@ def remove_nulls(schema):
484494
return schema
485495

486496

497+
def reference_strict_schemas(schema):
498+
"""
499+
Update $refs to reference strict schemas.
500+
"""
501+
if isinstance(schema, dict):
502+
for key, value in schema.items():
503+
if key == "$ref" and value.startswith("https://standard.open-contracting.org/schema/"):
504+
reference = value.split("/")
505+
reference[-1] = f"strict/{reference[-1]}"
506+
schema[key] = "/".join(reference)
507+
508+
reference_strict_schemas(value)
509+
510+
if isinstance(schema, list):
511+
for subschema in schema:
512+
reference_strict_schemas(subschema)
513+
514+
487515
@click.group()
488516
def cli():
489517
pass

0 commit comments

Comments
 (0)