From b440f3f904aa7c6e61185b0effde75345f7a219a Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Fri, 8 Apr 2022 17:05:59 +0100 Subject: [PATCH 1/4] Use Draft-07 and Draft7Validator everywhere We were using the Draft4Validator in one place, so this updates it to the Draft7Validator instead. The schemas were mostly using draft 4 of the JSON schema, though there were a couple of schemas that were already of version 7. This updates them all to version 7, which is the latest version fully supported by the jsonschema Python package. There are some breaking changes in the newer version of the schema, but I could not see anywhere would these affect us. Some of these schemas were not valid in version 4, but are now valid in version 7 because `"required": []` was not valid in earlier versions. --- app/billing/billing_schemas.py | 2 +- .../broadcast_message_schema.py | 6 ++-- app/complaint/complaint_schema.py | 2 +- app/email_branding/email_branding_schema.py | 4 +-- app/inbound_sms/inbound_sms_schemas.py | 2 +- app/letter_branding/letter_branding_schema.py | 2 +- app/letters/letter_schemas.py | 2 +- .../notifications_letter_callback.py | 2 +- app/organisation/organisation_schema.py | 10 +++---- .../performance_dashboard_schema.py | 2 +- app/platform_stats/platform_stats_schema.py | 2 +- app/service/send_pdf_letter_schema.py | 2 +- .../service_broadcast_settings_schema.py | 2 +- app/service/service_callback_api_schema.py | 4 +-- app/service/service_contact_list_schema.py | 2 +- app/service/service_data_retention_schema.py | 4 +-- app/service/service_senders_schema.py | 6 ++-- app/template_folder/template_folder_schema.py | 6 ++-- app/user/users_schema.py | 8 ++--- app/v2/inbound_sms/inbound_sms_schemas.py | 6 ++-- app/v2/notifications/notification_schemas.py | 30 +++++++++---------- app/v2/template/template_schemas.py | 8 ++--- app/v2/templates/templates_schemas.py | 4 +-- tests/app/public_contracts/__init__.py | 4 +-- .../v0/GET_notification_return_email.json | 2 +- .../v0/GET_notification_return_sms.json | 2 +- .../schemas/v0/GET_notifications_return.json | 2 +- .../v0/POST_notification_return_email.json | 2 +- .../v0/POST_notification_return_sms.json | 2 +- .../schemas/v0/definitions.json | 2 +- 30 files changed, 67 insertions(+), 67 deletions(-) diff --git a/app/billing/billing_schemas.py b/app/billing/billing_schemas.py index 6c9180547..9c3ae9f46 100644 --- a/app/billing/billing_schemas.py +++ b/app/billing/billing_schemas.py @@ -1,7 +1,7 @@ from datetime import datetime create_or_update_free_sms_fragment_limit_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST annual billing schema", "type": "object", "title": "Create", diff --git a/app/broadcast_message/broadcast_message_schema.py b/app/broadcast_message/broadcast_message_schema.py index 9ac981b0a..823d3ab1b 100644 --- a/app/broadcast_message/broadcast_message_schema.py +++ b/app/broadcast_message/broadcast_message_schema.py @@ -2,7 +2,7 @@ from app.models import BroadcastStatusType from app.schema_validation.definitions import uuid create_broadcast_message_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST create broadcast_message schema', 'type': 'object', 'title': 'Create broadcast_message', @@ -32,7 +32,7 @@ create_broadcast_message_schema = { } update_broadcast_message_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST update broadcast_message schema', 'type': 'object', 'title': 'Update broadcast_message', @@ -47,7 +47,7 @@ update_broadcast_message_schema = { } update_broadcast_message_status_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST update broadcast_message status schema', 'type': 'object', 'title': 'Update broadcast_message', diff --git a/app/complaint/complaint_schema.py b/app/complaint/complaint_schema.py index d6c782405..1b0cfb1d9 100644 --- a/app/complaint/complaint_schema.py +++ b/app/complaint/complaint_schema.py @@ -1,6 +1,6 @@ complaint_count_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "complaint count request schema", "type": "object", "title": "Complaint count request", diff --git a/app/email_branding/email_branding_schema.py b/app/email_branding/email_branding_schema.py index c8fec0c81..b699d38de 100644 --- a/app/email_branding/email_branding_schema.py +++ b/app/email_branding/email_branding_schema.py @@ -1,7 +1,7 @@ from app.models import BRANDING_TYPES post_create_email_branding_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for getting email_branding", "type": "object", "properties": { @@ -15,7 +15,7 @@ post_create_email_branding_schema = { } post_update_email_branding_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for getting email_branding", "type": "object", "properties": { diff --git a/app/inbound_sms/inbound_sms_schemas.py b/app/inbound_sms/inbound_sms_schemas.py index f9cd703b1..0a5e68ac3 100644 --- a/app/inbound_sms/inbound_sms_schemas.py +++ b/app/inbound_sms/inbound_sms_schemas.py @@ -1,5 +1,5 @@ get_inbound_sms_for_service_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "schema for parameters allowed when searching for to field=", "type": "object", "properties": { diff --git a/app/letter_branding/letter_branding_schema.py b/app/letter_branding/letter_branding_schema.py index e13ef64b6..d6275c82d 100644 --- a/app/letter_branding/letter_branding_schema.py +++ b/app/letter_branding/letter_branding_schema.py @@ -1,5 +1,5 @@ post_letter_branding_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for creating or updating a letter brand", "type": "object", "properties": { diff --git a/app/letters/letter_schemas.py b/app/letters/letter_schemas.py index fdce5b3b5..13d10b277 100644 --- a/app/letters/letter_schemas.py +++ b/app/letters/letter_schemas.py @@ -1,5 +1,5 @@ letter_references = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "list of letter notification references", "type": "object", "title": "references", diff --git a/app/notifications/notifications_letter_callback.py b/app/notifications/notifications_letter_callback.py index 1bdf038fb..9108d5c45 100644 --- a/app/notifications/notifications_letter_callback.py +++ b/app/notifications/notifications_letter_callback.py @@ -17,7 +17,7 @@ register_errors(letter_callback_blueprint) dvla_sns_callback_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "sns callback received on s3 update", "type": "object", "title": "dvla internal sns callback", diff --git a/app/organisation/organisation_schema.py b/app/organisation/organisation_schema.py index 44018385e..acc90d42d 100644 --- a/app/organisation/organisation_schema.py +++ b/app/organisation/organisation_schema.py @@ -2,7 +2,7 @@ from app.models import INVITED_USER_STATUS_TYPES, ORGANISATION_TYPES from app.schema_validation.definitions import uuid post_create_organisation_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST organisation schema", "type": "object", "properties": { @@ -15,7 +15,7 @@ post_create_organisation_schema = { } post_update_organisation_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST organisation schema", "type": "object", "properties": { @@ -28,7 +28,7 @@ post_update_organisation_schema = { } post_link_service_to_organisation_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST link service to organisation schema", "type": "object", "properties": { @@ -39,7 +39,7 @@ post_link_service_to_organisation_schema = { post_create_invited_org_user_status_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST create organisation invite schema", "type": "object", "properties": { @@ -52,7 +52,7 @@ post_create_invited_org_user_status_schema = { post_update_invited_org_user_status_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST update organisation invite schema", "type": "object", "properties": { diff --git a/app/performance_dashboard/performance_dashboard_schema.py b/app/performance_dashboard/performance_dashboard_schema.py index 42cce7064..6c3b170f0 100644 --- a/app/performance_dashboard/performance_dashboard_schema.py +++ b/app/performance_dashboard/performance_dashboard_schema.py @@ -1,5 +1,5 @@ performance_dashboard_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Performance dashboard request schema", "type": "object", "title": "Performance dashboard request", diff --git a/app/platform_stats/platform_stats_schema.py b/app/platform_stats/platform_stats_schema.py index cb28a2620..57cf2ff5f 100644 --- a/app/platform_stats/platform_stats_schema.py +++ b/app/platform_stats/platform_stats_schema.py @@ -1,5 +1,5 @@ platform_stats_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "platform stats request schema", "type": "object", "title": "Platform stats request", diff --git a/app/service/send_pdf_letter_schema.py b/app/service/send_pdf_letter_schema.py index 078d9bdcc..e512c834d 100644 --- a/app/service/send_pdf_letter_schema.py +++ b/app/service/send_pdf_letter_schema.py @@ -1,5 +1,5 @@ send_pdf_letter_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST send uploaded pdf letter", "type": "object", "title": "Send an uploaded pdf letter", diff --git a/app/service/service_broadcast_settings_schema.py b/app/service/service_broadcast_settings_schema.py index 42b0df81d..38c5e1d53 100644 --- a/app/service/service_broadcast_settings_schema.py +++ b/app/service/service_broadcast_settings_schema.py @@ -1,5 +1,5 @@ service_broadcast_settings_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Set a services broadcast settings", "type": "object", "title": "Set a services broadcast settings", diff --git a/app/service/service_callback_api_schema.py b/app/service/service_callback_api_schema.py index 0f32a4c71..adc8bc6ad 100644 --- a/app/service/service_callback_api_schema.py +++ b/app/service/service_callback_api_schema.py @@ -1,7 +1,7 @@ from app.schema_validation.definitions import https_url, uuid create_service_callback_api_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service callback/inbound api schema", "type": "object", "title": "Create service callback/inbound api", @@ -14,7 +14,7 @@ create_service_callback_api_schema = { } update_service_callback_api_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service callback/inbound api schema", "type": "object", "title": "Create service callback/inbound api", diff --git a/app/service/service_contact_list_schema.py b/app/service/service_contact_list_schema.py index 2549292c6..5c3a042fa 100644 --- a/app/service/service_contact_list_schema.py +++ b/app/service/service_contact_list_schema.py @@ -1,7 +1,7 @@ from app.schema_validation.definitions import uuid create_service_contact_list_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST create service contact list schema", "type": "object", "title": "Create service contact list", diff --git a/app/service/service_data_retention_schema.py b/app/service/service_data_retention_schema.py index f2a4883bd..24944fedf 100644 --- a/app/service/service_data_retention_schema.py +++ b/app/service/service_data_retention_schema.py @@ -1,5 +1,5 @@ add_service_data_retention_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service data retention schema", "title": "Add service data retention for notification type api", "type": "object", @@ -12,7 +12,7 @@ add_service_data_retention_request = { update_service_data_retention_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service data retention schema", "title": "Update service data retention for notification type api", "type": "object", diff --git a/app/service/service_senders_schema.py b/app/service/service_senders_schema.py index 9d168cb8d..e39765d30 100644 --- a/app/service/service_senders_schema.py +++ b/app/service/service_senders_schema.py @@ -1,7 +1,7 @@ from app.schema_validation.definitions import uuid add_service_email_reply_to_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service email reply to address", "type": "object", "title": "Add new email reply to address for service", @@ -14,7 +14,7 @@ add_service_email_reply_to_request = { add_service_letter_contact_block_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST service letter contact block", "type": "object", "title": "Add new letter contact block for service", @@ -27,7 +27,7 @@ add_service_letter_contact_block_request = { add_service_sms_sender_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST add service SMS sender", "type": "object", "title": "Add new SMS sender for service", diff --git a/app/template_folder/template_folder_schema.py b/app/template_folder/template_folder_schema.py index 7e375b033..a7f823356 100644 --- a/app/template_folder/template_folder_schema.py +++ b/app/template_folder/template_folder_schema.py @@ -1,7 +1,7 @@ from app.schema_validation.definitions import nullable_uuid, uuid post_create_template_folder_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for getting template_folder", "type": "object", "properties": { @@ -12,7 +12,7 @@ post_create_template_folder_schema = { } post_update_template_folder_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for updating template_folder", "type": "object", "properties": { @@ -23,7 +23,7 @@ post_update_template_folder_schema = { } post_move_template_folder_schema = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST schema for renaming template_folder", "type": "object", "properties": { diff --git a/app/user/users_schema.py b/app/user/users_schema.py index 5ca9b9bf0..55f0e1b98 100644 --- a/app/user/users_schema.py +++ b/app/user/users_schema.py @@ -1,5 +1,5 @@ post_verify_code_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST schema for verifying a 2fa code', 'type': 'object', 'properties': { @@ -12,7 +12,7 @@ post_verify_code_schema = { post_verify_webauthn_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST schema for verifying a webauthn login attempt', 'type': 'object', 'properties': { @@ -24,7 +24,7 @@ post_verify_webauthn_schema = { post_send_user_email_code_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': ( 'POST schema for generating a 2fa email - "to" is required for legacy purposes. ' '"next" is an optional url to redirect to on sign in' @@ -43,7 +43,7 @@ post_send_user_email_code_schema = { post_send_user_sms_code_schema = { - '$schema': 'http://json-schema.org/draft-04/schema#', + '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'POST schema for generating a 2fa sms', 'type': 'object', 'properties': { diff --git a/app/v2/inbound_sms/inbound_sms_schemas.py b/app/v2/inbound_sms/inbound_sms_schemas.py index 068097d76..6583c9ade 100644 --- a/app/v2/inbound_sms/inbound_sms_schemas.py +++ b/app/v2/inbound_sms/inbound_sms_schemas.py @@ -1,7 +1,7 @@ from app.schema_validation.definitions import uuid get_inbound_sms_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "schema for query parameters allowed when getting list of received text messages", "type": "object", "properties": { @@ -12,7 +12,7 @@ get_inbound_sms_request = { get_inbound_sms_single_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET inbound sms schema response", "type": "object", "title": "GET response v2/inbound_sms", @@ -36,7 +36,7 @@ get_inbound_sms_single_response = { } get_inbound_sms_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET list of inbound sms response schema", "type": "object", "properties": { diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index e1bbfb596..5d1d923b4 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -7,7 +7,7 @@ from app.models import ( from app.schema_validation.definitions import personalisation, uuid template = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "template schema", "type": "object", "title": "notification content", @@ -20,7 +20,7 @@ template = { } notification_by_id = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET notification response schema", "type": "object", "title": "response v2/notification", @@ -32,7 +32,7 @@ notification_by_id = { get_notification_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET notification response schema", "type": "object", "title": "response v2/notification", @@ -67,7 +67,7 @@ get_notification_response = { } get_notifications_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "schema for query parameters allowed when getting list of notifications", "type": "object", "properties": { @@ -92,7 +92,7 @@ get_notifications_request = { } get_notifications_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET list of notifications response schema", "type": "object", "properties": { @@ -126,7 +126,7 @@ get_notifications_response = { } post_sms_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST sms notification schema", "type": "object", "title": "POST v2/notifications/sms", @@ -143,7 +143,7 @@ post_sms_request = { } sms_content = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "content schema for SMS notification response schema", "type": "object", "title": "notification content", @@ -155,7 +155,7 @@ sms_content = { } post_sms_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST sms notification response schema", "type": "object", "title": "response v2/notifications/sms", @@ -172,7 +172,7 @@ post_sms_response = { post_email_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST email notification schema", "type": "object", "title": "POST v2/notifications/email", @@ -189,7 +189,7 @@ post_email_request = { } email_content = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Email content for POST email notification", "type": "object", "title": "notification email content", @@ -202,7 +202,7 @@ email_content = { } post_email_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST email notification response schema", "type": "object", "title": "response v2/notifications/email", @@ -218,7 +218,7 @@ post_email_response = { } post_letter_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST letter notification schema", "type": "object", "title": "POST v2/notifications/letter", @@ -232,7 +232,7 @@ post_letter_request = { } post_precompiled_letter_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST precompiled letter notification schema", "type": "object", "title": "POST v2/notifications/letter", @@ -246,7 +246,7 @@ post_precompiled_letter_request = { } letter_content = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Letter content for POST letter notification", "type": "object", "title": "notification letter content", @@ -258,7 +258,7 @@ letter_content = { } post_letter_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST sms notification response schema", "type": "object", "title": "response v2/notifications/letter", diff --git a/app/v2/template/template_schemas.py b/app/v2/template/template_schemas.py index 48c3a606c..fbefdfbfc 100644 --- a/app/v2/template/template_schemas.py +++ b/app/v2/template/template_schemas.py @@ -2,7 +2,7 @@ from app.models import TEMPLATE_TYPES from app.schema_validation.definitions import personalisation, uuid get_template_by_id_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "schema for parameters allowed when getting template by id", "type": "object", "properties": { @@ -14,7 +14,7 @@ get_template_by_id_request = { } get_template_by_id_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET template by id schema response", "type": "object", "title": "reponse v2/template", @@ -42,7 +42,7 @@ get_template_by_id_response = { } post_template_preview_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST template schema", "type": "object", "title": "POST v2/template/{id}/preview", @@ -54,7 +54,7 @@ post_template_preview_request = { } post_template_preview_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST template preview schema response", "type": "object", "title": "reponse v2/template/{id}/preview", diff --git a/app/v2/templates/templates_schemas.py b/app/v2/templates/templates_schemas.py index 7aa83a9b5..da0d1ac1e 100644 --- a/app/v2/templates/templates_schemas.py +++ b/app/v2/templates/templates_schemas.py @@ -4,7 +4,7 @@ from app.v2.template.template_schemas import ( ) get_all_template_request = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "request schema for parameters allowed when getting all templates", "type": "object", "properties": { @@ -14,7 +14,7 @@ get_all_template_request = { } get_all_template_response = { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET response schema when getting all templates", "type": "object", "properties": { diff --git a/tests/app/public_contracts/__init__.py b/tests/app/public_contracts/__init__.py index 4b7607888..b09def2d7 100644 --- a/tests/app/public_contracts/__init__.py +++ b/tests/app/public_contracts/__init__.py @@ -2,7 +2,7 @@ import os import jsonschema from flask import json -from jsonschema import Draft4Validator +from jsonschema import Draft7Validator def return_json_from_response(response): @@ -22,5 +22,5 @@ def validate_v0(json_to_validate, schema_filename): def validate(json_to_validate, schema): - validator = Draft4Validator(schema) + validator = Draft7Validator(schema) validator.validate(json_to_validate, schema) diff --git a/tests/app/public_contracts/schemas/v0/GET_notification_return_email.json b/tests/app/public_contracts/schemas/v0/GET_notification_return_email.json index e6fb6b19f..fbd62a95c 100644 --- a/tests/app/public_contracts/schemas/v0/GET_notification_return_email.json +++ b/tests/app/public_contracts/schemas/v0/GET_notification_return_email.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET notification return schema - for email notifications", "type" : "object", "properties": { diff --git a/tests/app/public_contracts/schemas/v0/GET_notification_return_sms.json b/tests/app/public_contracts/schemas/v0/GET_notification_return_sms.json index 2127ffd46..3cab73c68 100644 --- a/tests/app/public_contracts/schemas/v0/GET_notification_return_sms.json +++ b/tests/app/public_contracts/schemas/v0/GET_notification_return_sms.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET notification return schema - for sms notifications", "type" : "object", "properties": { diff --git a/tests/app/public_contracts/schemas/v0/GET_notifications_return.json b/tests/app/public_contracts/schemas/v0/GET_notifications_return.json index 709cca9fe..d8a5a0d5d 100644 --- a/tests/app/public_contracts/schemas/v0/GET_notifications_return.json +++ b/tests/app/public_contracts/schemas/v0/GET_notifications_return.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "GET notification return schema - for sms notifications", "type" : "object", "properties": { diff --git a/tests/app/public_contracts/schemas/v0/POST_notification_return_email.json b/tests/app/public_contracts/schemas/v0/POST_notification_return_email.json index bd84f798a..28e646bb5 100644 --- a/tests/app/public_contracts/schemas/v0/POST_notification_return_email.json +++ b/tests/app/public_contracts/schemas/v0/POST_notification_return_email.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST notification return schema - for email notifications", "type" : "object", "properties": { diff --git a/tests/app/public_contracts/schemas/v0/POST_notification_return_sms.json b/tests/app/public_contracts/schemas/v0/POST_notification_return_sms.json index 3119c6d73..fd4851a39 100644 --- a/tests/app/public_contracts/schemas/v0/POST_notification_return_sms.json +++ b/tests/app/public_contracts/schemas/v0/POST_notification_return_sms.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "POST notification return schema - for sms notifications", "type" : "object", "properties": { diff --git a/tests/app/public_contracts/schemas/v0/definitions.json b/tests/app/public_contracts/schemas/v0/definitions.json index 5b12591dc..fb36b5cb4 100644 --- a/tests/app/public_contracts/schemas/v0/definitions.json +++ b/tests/app/public_contracts/schemas/v0/definitions.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Common definitions - usage example: {'$ref': 'definitions.json#/uuid'} (swap quotes for double quotes)", "uuid": { "type": "string", From 5feb38f50ae514369d2bff41623a0cc31def4d5f Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Tue, 12 Apr 2022 18:13:20 +0100 Subject: [PATCH 2/4] Bump jsonschema from 3.2.0 to 4.4.0 The big breaking change for our code (not mentioned in the changelog) is that the built-in validator for the `date-time` format now requires the `rfc3339-validator` package instead of the `strict-rfc3339` package. This updates the requirements file to use `rfc3339-validator`. Without this change, wrong `date-time` formats would always silently pass validation. --- app/letter_branding/letter_branding_schema.py | 2 +- requirements.in | 4 ++-- requirements.txt | 8 ++++---- tests/app/complaint/test_complaint_rest.py | 3 +-- tests/app/platform_stats/test_rest.py | 3 +-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/letter_branding/letter_branding_schema.py b/app/letter_branding/letter_branding_schema.py index d6275c82d..3c7acb7b0 100644 --- a/app/letter_branding/letter_branding_schema.py +++ b/app/letter_branding/letter_branding_schema.py @@ -6,5 +6,5 @@ post_letter_branding_schema = { "name": {"type": ["string", "null"]}, "filename": {"type": ["string", "null"]}, }, - "required": ("name", "filename") + "required": ["name", "filename"] } diff --git a/requirements.in b/requirements.in index 9d4ede6d9..d920aa8e4 100644 --- a/requirements.in +++ b/requirements.in @@ -13,13 +13,13 @@ click-datetime==0.2 git+https://github.com/benoitc/gunicorn.git@1299ea9e967a61ae2edebe191082fd169b864c64#egg=gunicorn[eventlet]==20.1.0 iso8601==1.0.2 itsdangerous==2.1.2 -jsonschema==3.2.0 +jsonschema==4.4.0 marshmallow-sqlalchemy==0.23.1 # pyup: <0.24.0 # marshmallow v3 throws errors marshmallow==2.21.0 # pyup: <3 # v3 throws errors psycopg2-binary==2.9.3 PyJWT==2.3.0 SQLAlchemy==1.4.35 -strict-rfc3339==0.7 +rfc3339-validator==0.1.4 rfc3987==1.3.8 cachetools==5.0.0 beautifulsoup4==4.10.0 diff --git a/requirements.txt b/requirements.txt index c3c3dd044..c6a820a2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -123,7 +123,7 @@ jmespath==0.10.0 # via # boto3 # botocore -jsonschema==3.2.0 +jsonschema==4.4.0 # via -r requirements.in kombu==5.2.3 # via celery @@ -200,6 +200,8 @@ requests==2.26.0 # govuk-bank-holidays # notifications-python-client # notifications-utils +rfc3339-validator==0.1.4 + # via -r requirements.in rfc3987==1.3.8 # via -r requirements.in rsa==4.7.2 @@ -218,8 +220,8 @@ six==1.16.0 # click-repl # eventlet # flask-marshmallow - # jsonschema # python-dateutil + # rfc3339-validator smartypants==2.0.1 # via notifications-utils soupsieve==2.2.1 @@ -231,8 +233,6 @@ sqlalchemy==1.4.35 # marshmallow-sqlalchemy statsd==3.3.0 # via notifications-utils -strict-rfc3339==0.7 - # via -r requirements.in urllib3==1.26.7 # via # botocore diff --git a/tests/app/complaint/test_complaint_rest.py b/tests/app/complaint/test_complaint_rest.py index ea44ca636..5f72e4ee2 100644 --- a/tests/app/complaint/test_complaint_rest.py +++ b/tests/app/complaint/test_complaint_rest.py @@ -87,5 +87,4 @@ def test_get_complaint_with_invalid_data_returns_400_status_code(client): ) assert response.status_code == 400 - assert response.json['errors'][0]['message'] == 'start_date time data {} does not match format %Y-%m-%d'.format( - start_date) + assert response.json['errors'][0]['message'] == 'start_date month must be in 1..12' diff --git a/tests/app/platform_stats/test_rest.py b/tests/app/platform_stats/test_rest.py index 27ba169e0..eda62b1dd 100644 --- a/tests/app/platform_stats/test_rest.py +++ b/tests/app/platform_stats/test_rest.py @@ -48,8 +48,7 @@ def test_get_platform_stats_validates_the_date(admin_request): _expected_status=400 ) - assert response['errors'][0]['message'] == 'start_date time data {} does not match format %Y-%m-%d'.format( - start_date) + assert response['errors'][0]['message'] == 'start_date month must be in 1..12' @freeze_time('2018-10-31 14:00') From 187e87c792873bbff211a94efecf6c29d99f8cef Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Wed, 13 Apr 2022 12:50:28 +0100 Subject: [PATCH 3/4] Remove one of our own jsonschema date-time formatters We have three different ways of checking the formats of datetimes. 1. The built-in way that comes with the jsonschema package ("date-time") 2. A new way we added for broadcasts ("datetime") https://github.com/alphagov/notifications-api/commit/61a5730596ca2990851bd4e3b69c9e0c578264c9 3. An old way we defined in "/tests/app/public_contracts/schemas/v0/definitions.json" In order to simplify things and make it clearer how datetimes are being validated, this replaces the few places where we were using option 3 with option 1 instead. Option 3 was only being used to validate code that is no longer used, the initial version of the API. --- .../app/public_contracts/schemas/v0/definitions.json | 4 ---- .../schemas/v0/email_notification.json | 12 +++--------- .../schemas/v0/sms_notification.json | 12 +++--------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/tests/app/public_contracts/schemas/v0/definitions.json b/tests/app/public_contracts/schemas/v0/definitions.json index fb36b5cb4..7b44b63f2 100644 --- a/tests/app/public_contracts/schemas/v0/definitions.json +++ b/tests/app/public_contracts/schemas/v0/definitions.json @@ -4,9 +4,5 @@ "uuid": { "type": "string", "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" - }, - "datetime": { - "type": "string", - "format": "date-time" } } diff --git a/tests/app/public_contracts/schemas/v0/email_notification.json b/tests/app/public_contracts/schemas/v0/email_notification.json index 013fb49ff..b1ac4821c 100644 --- a/tests/app/public_contracts/schemas/v0/email_notification.json +++ b/tests/app/public_contracts/schemas/v0/email_notification.json @@ -14,19 +14,13 @@ "type": "string", "enum": ["email"] }, - "created_at": {"$ref": "definitions.json#/datetime"}, - "sent_at": {"oneOf":[ - {"$ref": "definitions.json#/datetime"}, - {"type": "null"} - ]}, + "created_at": {"type": "string", "format": "date-time"}, + "sent_at": {"type": ["string", "null"], "format": "date-time"}, "sent_by": {"oneOf":[ {"type": "string"}, {"type": "null"} ]}, - "updated_at": {"oneOf":[ - {"$ref": "definitions.json#/datetime"}, - {"type": "null"} - ]}, + "updated_at": {"type": ["string", "null"], "format": "date-time"}, "status": { "type": "string", "enum": [ diff --git a/tests/app/public_contracts/schemas/v0/sms_notification.json b/tests/app/public_contracts/schemas/v0/sms_notification.json index d81def6ea..5110ad081 100644 --- a/tests/app/public_contracts/schemas/v0/sms_notification.json +++ b/tests/app/public_contracts/schemas/v0/sms_notification.json @@ -14,19 +14,13 @@ "type": "string", "enum": ["sms"] }, - "created_at": {"$ref": "definitions.json#/datetime"}, - "sent_at": {"oneOf":[ - {"$ref": "definitions.json#/datetime"}, - {"type": "null"} - ]}, + "created_at": {"type": "string", "format": "date-time"}, + "sent_at": {"type": ["string", "null"], "format": "date-time"}, "sent_by": {"oneOf":[ {"type": "string"}, {"type": "null"} ]}, - "updated_at": {"oneOf":[ - {"$ref": "definitions.json#/datetime"}, - {"type": "null"} - ]}, + "updated_at": {"type": ["string", "null"], "format": "date-time"}, "status": { "type": "string", "enum": [ From 9a249dc530487a6bf83062fb4460da0f1278f27d Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Tue, 19 Apr 2022 13:53:06 +0100 Subject: [PATCH 4/4] Use `jsonschema[format]` instead of `jsonschema` `jsonschema[format]` includes all the formatting dependencies of jsonschema, meaning that we don't have to specify `rfc3339-validator` and `rfc3987` ourselves in the requirements.in file. This also has the benefit of meaning that if the underlying formatting packages of jsonschema change, we will be covered and won't accidentally miss the fact that we need to change a package. --- requirements.in | 4 +--- requirements.txt | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/requirements.in b/requirements.in index d920aa8e4..053435929 100644 --- a/requirements.in +++ b/requirements.in @@ -13,14 +13,12 @@ click-datetime==0.2 git+https://github.com/benoitc/gunicorn.git@1299ea9e967a61ae2edebe191082fd169b864c64#egg=gunicorn[eventlet]==20.1.0 iso8601==1.0.2 itsdangerous==2.1.2 -jsonschema==4.4.0 +jsonschema[format]==4.4.0 marshmallow-sqlalchemy==0.23.1 # pyup: <0.24.0 # marshmallow v3 throws errors marshmallow==2.21.0 # pyup: <3 # v3 throws errors psycopg2-binary==2.9.3 PyJWT==2.3.0 SQLAlchemy==1.4.35 -rfc3339-validator==0.1.4 -rfc3987==1.3.8 cachetools==5.0.0 beautifulsoup4==4.10.0 lxml==4.8.0 diff --git a/requirements.txt b/requirements.txt index c6a820a2d..59c7bca31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,8 @@ alembic==1.7.4 # via flask-migrate amqp==5.0.9 # via kombu +arrow==1.2.2 + # via isoduration attrs==21.2.0 # via jsonschema awscli==1.21.4 @@ -94,6 +96,8 @@ flask-sqlalchemy @ git+https://github.com/mitsuhiko/flask-sqlalchemy.git@500e732 # via # -r requirements.in # flask-migrate +fqdn==1.5.1 + # via jsonschema gds-metrics==0.2.4 # via -r requirements.in geojson==2.5.0 @@ -105,11 +109,15 @@ greenlet==1.1.2 gunicorn @ git+https://github.com/benoitc/gunicorn.git@1299ea9e967a61ae2edebe191082fd169b864c64 # via -r requirements.in idna==3.3 - # via requests + # via + # jsonschema + # requests importlib-metadata==4.11.3 # via flask iso8601==1.0.2 # via -r requirements.in +isoduration==20.11.0 + # via jsonschema itsdangerous==2.1.2 # via # -r requirements.in @@ -123,7 +131,9 @@ jmespath==0.10.0 # via # boto3 # botocore -jsonschema==4.4.0 +jsonpointer==2.3 + # via jsonschema +jsonschema[format]==4.4.0 # via -r requirements.in kombu==5.2.3 # via celery @@ -180,6 +190,7 @@ pyrsistent==0.18.0 # via jsonschema python-dateutil==2.8.2 # via + # arrow # awscli-cwlogs # botocore python-json-logger==2.0.2 @@ -201,9 +212,9 @@ requests==2.26.0 # notifications-python-client # notifications-utils rfc3339-validator==0.1.4 - # via -r requirements.in + # via jsonschema rfc3987==1.3.8 - # via -r requirements.in + # via jsonschema rsa==4.7.2 # via awscli s3transfer==0.5.0 @@ -233,6 +244,8 @@ sqlalchemy==1.4.35 # marshmallow-sqlalchemy statsd==3.3.0 # via notifications-utils +uri-template==1.2.0 + # via jsonschema urllib3==1.26.7 # via # botocore @@ -244,6 +257,8 @@ vine==5.0.0 # kombu wcwidth==0.2.5 # via prompt-toolkit +webcolors==1.11.1 + # via jsonschema webencodings==0.5.1 # via bleach werkzeug==2.0.3