Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16978 Add valid parties to CORRECTION_CP_SPECIAL_RESOLUTION #142

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flask
jsonschema[format]
referencing
requests
strict-rfc3339
3 changes: 2 additions & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flask
jsonschema
referencing
requests
strict-rfc3339
strict-rfc3339
77 changes: 76 additions & 1 deletion src/registry_schemas/example_data/schema_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,82 @@
'legalType': 'CP',
'legalName': 'SUPER SUPER COOP'
},
'type': 'CLIENT'
'type': 'CLIENT',
'parties': [
{
'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': 'Completing Party',
'appointmentDate': '2022-01-01'
},
{
'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'
}
]
}
]
}

CORRECTION_CONVERSION = {
Expand Down
4 changes: 2 additions & 2 deletions src/registry_schemas/schemas/change_of_directors.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/directors#/definitions/director"
},
{
"$ref": "#definitions/actions"
"$ref": "#/definitions/actions"
}
]
}
}
}
}
}
}
}
41 changes: 23 additions & 18 deletions src/registry_schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/registry_schemas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"""


__version__ = '2.18.10' # pylint: disable=invalid-name
__version__ = '2.18.11' # pylint: disable=invalid-name
Loading