Skip to content

Commit

Permalink
schema: Annotations to oneOf and add oneOfEnumSelectorField
Browse files Browse the repository at this point in the history
openownership/lib-cove-bods#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.
OpenDataServices/compile-to-json-schema#28

#376
  • Loading branch information
jarofgreen committed Nov 4, 2021
1 parent 8dffb7b commit a7bbdde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/schema/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion schema/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
"statementPointerTarget",
"motivation"
],
"anyOf": [
"oneOfEnumSelectorField": "motivation",
"oneOf": [
{
"properties": {
"motivation": {
Expand Down
11 changes: 11 additions & 0 deletions tests/bods_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 3 additions & 0 deletions tests/schema/meta-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
},
"propertyOrder": {
"type": "integer"
},
"oneOfEnumSelectorField": {
"type": "string"
}
},
"dependencies": {
Expand Down

0 comments on commit a7bbdde

Please sign in to comment.