@@ -436,13 +436,23 @@ def get_strict_schema(schema):
436
436
Return the strict version of the schema.
437
437
"""
438
438
# 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 )
441
442
schema ["title" ] = f'Strict { schema ["title" ][0 ].lower ()} { schema ["title" ][1 :]} '
442
443
schema ["description" ] = (
443
444
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
444
445
)
445
446
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
+
446
456
# Add validation properties
447
457
add_validation_properties (schema )
448
458
@@ -484,6 +494,24 @@ def remove_nulls(schema):
484
494
return schema
485
495
486
496
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
+
487
515
@click .group ()
488
516
def cli ():
489
517
pass
0 commit comments