Skip to content
Open
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
22 changes: 11 additions & 11 deletions legal-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions legal-api/src/legal_api/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ def build_schema_error_response(errors):
formatted_errors = []
for error in errors:
validation_errors = []
for context in error.context:
for context in error.context or []:
validation_errors.append({
"message": context.message,
"jsonPath": context.json_path,
"validator": context.validator,
"validatorValue": context.validator_value
})
formatted_errors.append({"path": "/".join(error.path), "error": error.message, "context": validation_errors})
formatted_errors.append({
"path": "/".join(str(part) for part in error.path),
"error": error.message,
"context": validation_errors
})
return formatted_errors


Expand Down
10 changes: 4 additions & 6 deletions legal-api/tests/unit/services/filings/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ def test_validate_schema_bad_cr(app):
"""Assert that an invalid AR returns an error."""
# validate_schema(json_data: Dict = None) -> Tuple(int, str):
cr = copy.deepcopy(CORRECTION_REGISTRATION)
cr['filing']['correction']['parties'][0]['officer']['firstName'] = \
'this_first_name_maximum_length_is_over'
cr['filing']['correction']['parties'][0]['officer']['middleName'] = \
'this_first_name_maximum_length_is_over'
cr['filing']['correction']['parties'][0]['officer']['firstName'] = 'a' * 61

with app.app_context():
err = schemas.validate_against_schema(cr)

assert {'error': "", 'path': 'filing', 'context': []}.keys() == err.msg[0].keys()
assert "is not valid under any of the given schemas" in err.msg[0]['error']

assert "is too long" in err.msg[0]['error']
assert err.msg[0]['path'] == 'correction/parties/0/officer/firstName'

assert err.code == HTTPStatus.UNPROCESSABLE_ENTITY