From a7bbddeab810b1db37d2f4936c319d9be149804a Mon Sep 17 00:00:00 2001 From: James Date: Tue, 2 Nov 2021 12:01:47 +0000 Subject: [PATCH] schema: Annotations to oneOf and add oneOfEnumSelectorField https://github.com/openownership/lib-cove-bods/issues/64 This involves changes to build_schemas_for_testing that are required by the change from anyOf to oneOf. But actually, this code should have been required before but the compile tool was not processing anyOf properly. https://github.com/OpenDataServices/compile-to-json-schema/issues/28 https://github.com/openownership/data-standard/pull/376 --- docs/schema/changelog.rst | 2 ++ schema/components.json | 3 ++- tests/bods_validate.py | 11 +++++++++++ tests/schema/meta-schema.json | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/schema/changelog.rst b/docs/schema/changelog.rst index d3de47a2..b168d54d 100644 --- a/docs/schema/changelog.rst +++ b/docs/schema/changelog.rst @@ -21,6 +21,7 @@ Added - ``Country.name`` is now a required field (previously it was defined as "MUST" in the description). - ``Jurisdiction.name`` is now a required field (previously it was defined as "MUST" in the description). - ``SecuritiesListing.stockExchangeJurisdiction`` has minimum and maximum lengths to match the two lists that values could be from. +- Annotations have ``oneOfEnumSelectorField`` added to provide hints to validation code which will produce better error messages. Changed ------- @@ -31,6 +32,7 @@ Changed - Clarified ``Country.code`` is from the ISO 3166-1 list (previously it was unclear which ISO list was meant and used "digit" when it meant "letter"). - Clarified ``Jurisdiction.code`` is from the ISO 3166-1 or ISO 3166-2 list (previously it was unclear which ISO list was meant and used "digit" when it meant "letter"). - Clarified ``SecuritiesListing.stockExchangeJurisdiction`` is from the ISO 3166-1 or ISO 3166-2 list (previously it was unclear which ISO list was meant and used "digit" when it meant "letter"). +- Annotations changes from a ``anyOf`` to a ``oneOf``. This is technically correct and also is needed to improve validation messages. [0.2] - 2019-06-30 diff --git a/schema/components.json b/schema/components.json index 8a069059..be848dc5 100644 --- a/schema/components.json +++ b/schema/components.json @@ -395,7 +395,8 @@ "statementPointerTarget", "motivation" ], - "anyOf": [ + "oneOfEnumSelectorField": "motivation", + "oneOf": [ { "properties": { "motivation": { diff --git a/tests/bods_validate.py b/tests/bods_validate.py index 2ce0bf9d..85fd01b8 100755 --- a/tests/bods_validate.py +++ b/tests/bods_validate.py @@ -39,6 +39,17 @@ def build_schemas_for_testing(): ) with open(os.path.join(absolute_path_to_schema_dir, source_file), "w") as fp: created_json = json.loads(ctjs.get_as_string()) + # The items in the annotations objects must not have additionalProperties set + # They factor out common elements of the oneOf bits as allowed in + # https://json-schema.org/understanding-json-schema/reference/combining.html#factoring-schemas + # But additionalProperties is applied to the oneOf schema only, not the full item and that causes issues + if source_file.endswith('entity-statement.json') or source_file.endswith('ownership-or-control-statement.json') or source_file.endswith('person-statement.json'): + for j in range(0, 2): + created_json['properties']['annotations']['items']['oneOf'][j]['additionalProperties'] = True + if source_file.endswith('bods-package.json'): + for i in range(0, 3): + for j in range(0, 2): + created_json['items']['oneOf'][i]['properties']['annotations']['items']['oneOf'][j]['additionalProperties'] = True # write with correct indentation fp.write(json.dumps(created_json, ensure_ascii=False, indent=2, separators=(',', ': ')) + '\n') diff --git a/tests/schema/meta-schema.json b/tests/schema/meta-schema.json index 0e377fb9..8fd05a9d 100644 --- a/tests/schema/meta-schema.json +++ b/tests/schema/meta-schema.json @@ -252,6 +252,9 @@ }, "propertyOrder": { "type": "integer" + }, + "oneOfEnumSelectorField": { + "type": "string" } }, "dependencies": {