From e526e4041e510099498a96606f6430dad8ae3b4a Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 12:46:35 +1300 Subject: [PATCH 1/8] schema-strict: add more validation keywords --- ocdskit/schema.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 8f9ff03..1e42814 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -203,8 +203,13 @@ 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 if the key is "quantity", "durationInDays", "numberOfTenderers" + * "required": ["id", "name"] if the key is "Organization" or "OrganizationReference" + * "required": ["id"] if the key is "Amendment" or "RelatedProcess" :param dict schema: a JSON schema :param bool unique_items: whether to add "uniqueItems" properties to array fields @@ -234,5 +239,14 @@ 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'] + elif key in ['Amendment', 'RelatedProcess']: + value['required'] = ['id'] + add_validation_properties(value, unique_items=unique_items, coordinates=coordinates) From a62b8262c1af4df5e28d569e9424a7e3633e575a Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 12:48:46 +1300 Subject: [PATCH 2/8] Fix flake8 error --- ocdskit/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 1e42814..77b13e7 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -248,5 +248,5 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): value['required'] = ['id', 'name'] elif key in ['Amendment', 'RelatedProcess']: value['required'] = ['id'] - + add_validation_properties(value, unique_items=unique_items, coordinates=coordinates) From bec5f85d5e7d024831eb1aa24f74cbea031e1854 Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:14:45 +1300 Subject: [PATCH 3/8] schema-strict: remove null type from required fields --- ocdskit/schema.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 77b13e7..341c876 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -246,7 +246,10 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): 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" add_validation_properties(value, unique_items=unique_items, coordinates=coordinates) From 4193690225fd10faa524077683ef14a91f89d606 Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:24:41 +1300 Subject: [PATCH 4/8] Fix flake8 error --- ocdskit/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 341c876..18bbd6f 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -250,6 +250,6 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): value['properties']['id']['type'] = "string" elif key in ['Amendment', 'RelatedProcess']: value['required'] = ['id'] - value['properties']['id']['type'] = "string" + value['properties']['id']['type'] = "string" add_validation_properties(value, unique_items=unique_items, coordinates=coordinates) From b80812d43e6df68c00ee99360e0d689ab9c795f4 Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:36:06 +1300 Subject: [PATCH 5/8] schema-strict: remove integer type from id fields --- ocdskit/schema.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index 18bbd6f..cfa1be5 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -251,5 +251,9 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): 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) From 8c6fb0945cbd3cb47624c04247a19d475bea9e4e Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:42:44 +1300 Subject: [PATCH 6/8] schema-strict: update docs --- ocdskit/schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ocdskit/schema.py b/ocdskit/schema.py index cfa1be5..667e9b1 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -211,6 +211,8 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): * "required": ["id", "name"] if the key is "Organization" or "OrganizationReference" * "required": ["id"] if the key is "Amendment" or "RelatedProcess" + Removes "integer" from "type" if the key is "id" + :param dict schema: a JSON schema :param bool unique_items: whether to add "uniqueItems" properties to array fields :param bool coordinates: whether the parent is a geospatial coordinates field From 539e9b66d4e10b818685cc0430820ae065da0c45 Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:49:08 +1300 Subject: [PATCH 7/8] schema-strict: update api and cli docs --- docs/cli/schema.rst | 10 +++++++++- ocdskit/schema.py | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) 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 667e9b1..61c9a4c 100644 --- a/ocdskit/schema.py +++ b/ocdskit/schema.py @@ -207,11 +207,11 @@ def add_validation_properties(schema, unique_items=True, coordinates=False): * "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 if the key is "quantity", "durationInDays", "numberOfTenderers" - * "required": ["id", "name"] if the key is "Organization" or "OrganizationReference" - * "required": ["id"] if the key is "Amendment" or "RelatedProcess" + * "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" if the key is "id" + 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 From ae10f051d8be25410ea1d8fb84d8087d44b26885 Mon Sep 17 00:00:00 2001 From: Duncan Dewhurst Date: Fri, 11 Feb 2022 14:51:52 +1300 Subject: [PATCH 8/8] Update changelog --- docs/changelog.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) ------------------