diff --git a/docs/changelog.rst b/docs/changelog.rst index 82f66d2..be6264f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,19 @@ Changelog ========= +1.0.5 (YYYY-MM-DD) +------------------ + +Changed +~~~~~~~ + +- :ref:`schema-strict`: Remove "integer" type from ID fields. Add validation rules: + + - "format": "email" if the key is "email" + - "minimum": 0 to "quantity", "durationInDays" and "numberOfTenderers fields + - "required": ["id", "name"] to "Organization" and "OrganizationReference" + - "required": ["id"] to "Amendment" and "RelatedProcess" + 1.0.4 (2022-02-10) ------------------ diff --git a/docs/cli/schema.rst b/docs/cli/schema.rst index df4751a..fd1b64f 100644 --- a/docs/cli/schema.rst +++ b/docs/cli/schema.rst @@ -89,7 +89,15 @@ Optional arguments: schema-strict ------------- -Adds "minItems" and "uniqueItems" if an array, "minProperties" if an object and "minLength" if a string and "enum", "format" and "pattern" are not set. +Adds: +* "minItems" and "uniqueItems" if an array, adds "minProperties" if an object +* "minLength" if a string and if "enum", "format" and "pattern" aren't set +* "format": "email" if the key is "email" +* "minimum": 0 to "quantity", "durationInDays" and "numberOfTenderers fields +* "required": ["id", "name"] to "Organization" and "OrganizationReference" +* "required": ["id"] to "Amendment" and "RelatedProcess" + +Removes "integer" from "type" for ID fields. Optional arguments: diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 8f9ff03..61c9a4c 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -203,8 +203,15 @@ def _deprecated(value): def add_validation_properties(schema, unique_items=True, coordinates=False): """ - Adds "minItems" and "uniqueItems" if an array, adds "minProperties" if an object, and adds "minLength" if a string - and if "enum", "format" and "pattern" aren't set. + Adds: + * "minItems" and "uniqueItems" if an array, adds "minProperties" if an object + * "minLength" if a string and if "enum", "format" and "pattern" aren't set + * "format": "email" if the key is "email" + * "minimum": 0 to "quantity", "durationInDays" and "numberOfTenderers fields + * "required": ["id", "name"] to "Organization" and "OrganizationReference" + * "required": ["id"] to "Amendment" and "RelatedProcess" + + Removes "integer" from "type" for ID fields. :param dict schema: a JSON schema :param bool unique_items: whether to add "uniqueItems" properties to array fields @@ -234,5 +241,21 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): if 'object' in schema['type']: schema.setdefault('minProperties', 1) - for value in schema.values(): + for key, value in schema.items(): + if key == 'email': + value['format'] = 'email' + elif key in ['quantity', 'durationInDays', 'numberOfTenderers']: + value['minimum'] = 0 + elif key in ['Organization', 'OrganizationReference']: + value['required'] = ['id', 'name'] + value['properties']['name']['type'] = "string" + value['properties']['id']['type'] = "string" + elif key in ['Amendment', 'RelatedProcess']: + value['required'] = ['id'] + value['properties']['id']['type'] = "string" + elif key == 'id': + if 'type' in value: + if 'integer' in value['type']: + value['type'].remove('integer') + add_validation_properties(value, unique_items=unique_items, coordinates=coordinates)