mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Using jsonschema for create_template.
Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required. This version is backward compatible with Draft4. When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
This commit is contained in:
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
||||
from uuid import UUID
|
||||
|
||||
from iso8601 import iso8601, ParseError
|
||||
from jsonschema import (Draft4Validator, ValidationError, FormatChecker)
|
||||
from jsonschema import (Draft7Validator, ValidationError, FormatChecker)
|
||||
from notifications_utils.recipients import (validate_phone_number, validate_email_address, InvalidPhoneError,
|
||||
InvalidEmailError)
|
||||
|
||||
@@ -43,7 +43,7 @@ def validate(json_to_validate, schema):
|
||||
"https://en.wikipedia.org/wiki/ISO_8601")
|
||||
return True
|
||||
|
||||
validator = Draft4Validator(schema, format_checker=format_checker)
|
||||
validator = Draft7Validator(schema, format_checker=format_checker)
|
||||
errors = list(validator.iter_errors(json_to_validate))
|
||||
if errors.__len__() > 0:
|
||||
raise ValidationError(build_error_message(errors))
|
||||
|
||||
Reference in New Issue
Block a user