From 7a56361c81e8f0c54588c5a7bdde864b315bd33e Mon Sep 17 00:00:00 2001 From: Chris Gabel Date: Tue, 22 Aug 2023 17:09:58 -0700 Subject: [PATCH 1/6] added parties to CORRECTION_CP_SPECIAL_RESOLUTION --- .../example_data/schema_data.py | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/registry_schemas/example_data/schema_data.py b/src/registry_schemas/example_data/schema_data.py index 8265463..8baf119 100644 --- a/src/registry_schemas/example_data/schema_data.py +++ b/src/registry_schemas/example_data/schema_data.py @@ -2598,7 +2598,69 @@ 'legalType': 'CP', 'legalName': 'SUPER SUPER COOP' }, - 'type': 'CLIENT' + 'type': 'CLIENT', + 'parties': [ + { + 'officer': { + 'id': 1, + 'firstName': 'Joe', + 'lastName': 'Swanson', + 'middleName': 'P', + 'email': 'joe@email.com', + 'organizationName': '', + 'partyType': 'person' + }, + 'mailingAddress': { + 'streetAddress': 'mailing_address - address line one', + 'streetAddressAdditional': '', + 'addressCity': 'mailing_address city', + 'addressCountry': 'CA', + 'postalCode': 'H0H0H0', + 'addressRegion': 'BC' + }, + 'deliveryAddress': { + 'streetAddress': 'delivery_address - address line one', + 'streetAddressAdditional': '', + 'addressCity': 'delivery_address city', + 'addressCountry': 'CA', + 'postalCode': 'H0H0H0', + 'addressRegion': 'BC' + }, + 'roles': [ + { + 'roleType': 'Completing Party', + 'appointmentDate': '2022-01-01' + }, + { + 'roleType': 'Partner', + 'appointmentDate': '2022-01-01' + } + ] + }, + { + 'officer': { + 'id': 2, + 'firstName': 'Peter', + 'lastName': 'Griffin', + 'middleName': '', + 'partyType': 'person' + }, + 'mailingAddress': { + 'streetAddress': 'mailing_address - address line one', + 'streetAddressAdditional': '', + 'addressCity': 'mailing_address city', + 'addressCountry': 'CA', + 'postalCode': 'H0H0H0', + 'addressRegion': 'BC' + }, + 'roles': [ + { + 'roleType': 'Partner', + 'appointmentDate': '2022-01-01' + } + ] + } + ] } CORRECTION_CONVERSION = { From ed470af6df9749874d20b184036f5e4a9ea5483b Mon Sep 17 00:00:00 2001 From: Chris Gabel Date: Wed, 23 Aug 2023 11:43:30 -0700 Subject: [PATCH 2/6] added 2 more parties to CORRECTION_CP_SPECIAL_RES --- .../example_data/schema_data.py | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/registry_schemas/example_data/schema_data.py b/src/registry_schemas/example_data/schema_data.py index 8baf119..df96808 100644 --- a/src/registry_schemas/example_data/schema_data.py +++ b/src/registry_schemas/example_data/schema_data.py @@ -2655,7 +2655,53 @@ }, 'roles': [ { - 'roleType': 'Partner', + 'roleType': 'Director', + 'appointmentDate': '2022-01-01' + } + ] + }, + { + 'officer': { + 'id': 3, + 'firstName': 'Lois', + 'lastName': 'Griffin', + 'middleName': '', + 'partyType': 'person' + }, + 'mailingAddress': { + 'streetAddress': 'mailing_address - address line one', + 'streetAddressAdditional': '', + 'addressCity': 'mailing_address city', + 'addressCountry': 'CA', + 'postalCode': 'H0H0H0', + 'addressRegion': 'BC' + }, + 'roles': [ + { + 'roleType': 'Director', + 'appointmentDate': '2022-01-01' + } + ] + }, + { + 'officer': { + 'id': 4, + 'firstName': 'Glenn', + 'lastName': 'Quagmire', + 'middleName': '', + 'partyType': 'person' + }, + 'mailingAddress': { + 'streetAddress': 'mailing_address - address line one', + 'streetAddressAdditional': '', + 'addressCity': 'mailing_address city', + 'addressCountry': 'CA', + 'postalCode': 'H0H0H0', + 'addressRegion': 'BC' + }, + 'roles': [ + { + 'roleType': 'Director', 'appointmentDate': '2022-01-01' } ] From 117edcb636d5054b6faa38299d5da7662b210161 Mon Sep 17 00:00:00 2001 From: Chris Gabel Date: Wed, 23 Aug 2023 11:53:52 -0700 Subject: [PATCH 3/6] removed "partner" type --- src/registry_schemas/example_data/schema_data.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/registry_schemas/example_data/schema_data.py b/src/registry_schemas/example_data/schema_data.py index df96808..461bb4b 100644 --- a/src/registry_schemas/example_data/schema_data.py +++ b/src/registry_schemas/example_data/schema_data.py @@ -2631,10 +2631,6 @@ 'roleType': 'Completing Party', 'appointmentDate': '2022-01-01' }, - { - 'roleType': 'Partner', - 'appointmentDate': '2022-01-01' - } ] }, { @@ -2660,7 +2656,7 @@ } ] }, - { + { 'officer': { 'id': 3, 'firstName': 'Lois', From 6e5bf649225d9ac11e1d437b976ea6793bc78c79 Mon Sep 17 00:00:00 2001 From: Chris Gabel Date: Wed, 23 Aug 2023 12:01:35 -0700 Subject: [PATCH 4/6] editing party list --- .../example_data/schema_data.py | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/registry_schemas/example_data/schema_data.py b/src/registry_schemas/example_data/schema_data.py index 461bb4b..922dc0f 100644 --- a/src/registry_schemas/example_data/schema_data.py +++ b/src/registry_schemas/example_data/schema_data.py @@ -2600,39 +2600,6 @@ }, 'type': 'CLIENT', 'parties': [ - { - 'officer': { - 'id': 1, - 'firstName': 'Joe', - 'lastName': 'Swanson', - 'middleName': 'P', - 'email': 'joe@email.com', - 'organizationName': '', - 'partyType': 'person' - }, - 'mailingAddress': { - 'streetAddress': 'mailing_address - address line one', - 'streetAddressAdditional': '', - 'addressCity': 'mailing_address city', - 'addressCountry': 'CA', - 'postalCode': 'H0H0H0', - 'addressRegion': 'BC' - }, - 'deliveryAddress': { - 'streetAddress': 'delivery_address - address line one', - 'streetAddressAdditional': '', - 'addressCity': 'delivery_address city', - 'addressCountry': 'CA', - 'postalCode': 'H0H0H0', - 'addressRegion': 'BC' - }, - 'roles': [ - { - 'roleType': 'Completing Party', - 'appointmentDate': '2022-01-01' - }, - ] - }, { 'officer': { 'id': 2, @@ -2650,6 +2617,10 @@ 'addressRegion': 'BC' }, 'roles': [ + { + 'roleType': 'Completing Party', + 'appointmentDate': '2022-01-01' + }, { 'roleType': 'Director', 'appointmentDate': '2022-01-01' From 9c4e654db031f2172a6338bffdcb83176675b3a2 Mon Sep 17 00:00:00 2001 From: Leo Dube Date: Tue, 29 Aug 2023 10:52:29 -0700 Subject: [PATCH 5/6] Bump version to 2.18.11 --- src/registry_schemas/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registry_schemas/version.py b/src/registry_schemas/version.py index 616ccc5..52a1d83 100644 --- a/src/registry_schemas/version.py +++ b/src/registry_schemas/version.py @@ -23,4 +23,4 @@ """ -__version__ = '2.18.10' # pylint: disable=invalid-name +__version__ = '2.18.11' # pylint: disable=invalid-name From 960598bab41239f2471f1f932b852b78b544a560 Mon Sep 17 00:00:00 2001 From: Vysakh Menon Date: Mon, 14 Aug 2023 10:13:40 -0700 Subject: [PATCH 6/6] Cherry-pick 46fe420 --- requirements.txt | 1 + requirements/prod.txt | 3 +- .../schemas/change_of_directors.json | 4 +- src/registry_schemas/utils.py | 41 +++++++++++-------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/requirements.txt b/requirements.txt index bf7119d..eb2ba82 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ flask jsonschema[format] +referencing requests strict-rfc3339 diff --git a/requirements/prod.txt b/requirements/prod.txt index d66a1f9..7b0091c 100755 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,4 +1,5 @@ flask jsonschema +referencing requests -strict-rfc3339 \ No newline at end of file +strict-rfc3339 diff --git a/src/registry_schemas/schemas/change_of_directors.json b/src/registry_schemas/schemas/change_of_directors.json index e9676a4..82c32c9 100644 --- a/src/registry_schemas/schemas/change_of_directors.json +++ b/src/registry_schemas/schemas/change_of_directors.json @@ -44,7 +44,7 @@ "$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/directors#/definitions/director" }, { - "$ref": "#definitions/actions" + "$ref": "#/definitions/actions" } ] } @@ -52,4 +52,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/registry_schemas/utils.py b/src/registry_schemas/utils.py index 96831a6..543c539 100644 --- a/src/registry_schemas/utils.py +++ b/src/registry_schemas/utils.py @@ -19,7 +19,9 @@ from os import listdir, path from typing import Tuple -from jsonschema import Draft7Validator, RefResolver, SchemaError +from jsonschema import Draft7Validator, SchemaError +from referencing import Registry, Resource +from referencing.jsonschema import DRAFT7 BASE_URI = 'https://bcrs.gov.bc.ca/.well_known/schemas' @@ -83,26 +85,29 @@ def validate(json_data: json, if not schema_store: schema_store = get_schema_store(validate_schema, schema_search_path) - schema = schema_store.get(f'{BASE_URI}/{schema_id}') + schema_uri = f'{BASE_URI}/{schema_id}' + schema = schema_store.get(schema_uri) if validate_schema: Draft7Validator.check_schema(schema) - schema_file_path = path.join(schema_search_path, schema_id) - resolver = RefResolver(f'file://{schema_file_path}.json', schema, schema_store) - - if Draft7Validator(schema, - format_checker=Draft7Validator.FORMAT_CHECKER, - resolver=resolver - ) \ - .is_valid(json_data): - return True, None - - errors = Draft7Validator(schema, - format_checker=Draft7Validator.FORMAT_CHECKER, - resolver=resolver - ) \ - .iter_errors(json_data) - return False, errors + def retrieve_resource(uri): + contents = schema_store.get(uri) + return Resource.from_contents(contents) + + registry = Registry(retrieve=retrieve_resource).with_resource( + schema_uri, + DRAFT7.create_resource(schema) + ) + + validator = Draft7Validator( + {'$ref': schema_uri}, + registry=registry, + format_checker=Draft7Validator.FORMAT_CHECKER + ) + if not validator.is_valid(json_data): + return False, validator.iter_errors(json_data) + + return True, None except SchemaError as error: # handle schema error