mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 18:23:01 -04:00
This changes the content length validation of the internal API to match the validation of the public broadcast API[1]. This removes the length check from JSONSchema, which isn’t sophisticated enough to deal with things like normalising newlines or handling different encodings. The admin app should catch these errors before they’re raised here, but it’s best to be belt and braces. 1.https://github.com/alphagov/notifications-api/blob/7ab0403ae7ab9c9a17b3fb6595c8c8d2f8b32cbb/app/v2/broadcast/post_broadcast.py#L53-L63
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from app.models import BroadcastStatusType
|
|
from app.schema_validation.definitions import uuid
|
|
|
|
create_broadcast_message_schema = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'description': 'POST create broadcast_message schema',
|
|
'type': 'object',
|
|
'title': 'Create broadcast_message',
|
|
'properties': {
|
|
'template_id': uuid,
|
|
'service_id': uuid,
|
|
'created_by': uuid,
|
|
'personalisation': {'type': 'object'},
|
|
'starts_at': {'type': 'string', 'format': 'datetime'},
|
|
'finishes_at': {'type': 'string', 'format': 'datetime'},
|
|
'areas': {"type": "array", "items": {"type": "string"}},
|
|
'simple_polygons': {"type": "array", "items": {"type": "array"}},
|
|
'content': {'type': 'string', 'minLength': 1},
|
|
'reference': {'type': 'string', 'minLength': 1, 'maxLength': 255},
|
|
},
|
|
'required': ['service_id', 'created_by'],
|
|
'allOf': [
|
|
{'oneOf': [
|
|
{'required': ['template_id']},
|
|
{'required': ['content']},
|
|
]},
|
|
{'oneOf': [
|
|
{'required': ['template_id']},
|
|
{'required': ['reference']},
|
|
]},
|
|
],
|
|
'additionalProperties': False
|
|
}
|
|
|
|
update_broadcast_message_schema = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'description': 'POST update broadcast_message schema',
|
|
'type': 'object',
|
|
'title': 'Update broadcast_message',
|
|
'properties': {
|
|
'personalisation': {'type': 'object'},
|
|
'starts_at': {'type': 'string', 'format': 'datetime'},
|
|
'finishes_at': {'type': 'string', 'format': 'datetime'},
|
|
'areas': {"type": "array", "items": {"type": "string"}},
|
|
'simple_polygons': {"type": "array", "items": {"type": "array"}},
|
|
},
|
|
'required': [],
|
|
'additionalProperties': False
|
|
}
|
|
|
|
update_broadcast_message_status_schema = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'description': 'POST update broadcast_message status schema',
|
|
'type': 'object',
|
|
'title': 'Update broadcast_message',
|
|
'properties': {
|
|
'status': {'type': 'string', 'enum': BroadcastStatusType.STATUSES},
|
|
'created_by': uuid,
|
|
},
|
|
'required': ['status', 'created_by'],
|
|
'additionalProperties': False
|
|
}
|