From 166e34e9e0625d9da6211c07ff9096b8860b3e61 Mon Sep 17 00:00:00 2001 From: jimasp <464080+jimasp@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:55:49 +0000 Subject: [PATCH] EM-1575 add blockreplace script for spec --- .redocly.lint-ignore.yaml | 7 +- package.json | 2 +- scripts/apply_block_replacements.py | 28 ++++ .../multicast-notification-service.yaml | 152 +---------------- .../create-or-update-subscription-body.yaml | 153 ++++++++++++++++++ 5 files changed, 189 insertions(+), 153 deletions(-) create mode 100644 scripts/apply_block_replacements.py create mode 100644 specification/requestBody/create-or-update-subscription-body.yaml diff --git a/.redocly.lint-ignore.yaml b/.redocly.lint-ignore.yaml index a664dd6..bef45cb 100644 --- a/.redocly.lint-ignore.yaml +++ b/.redocly.lint-ignore.yaml @@ -1,5 +1,10 @@ # This file instructs Redocly's linter to ignore the rules contained for specific parts of your API. -# See https://redoc.ly/docs/cli/ for more information. +# See https://redocly.com/docs/cli/ for more information. specification/multicast-notification-service.yaml: info-license: - '#/info' +specification/requestBody/create-or-update-subscription-body.yaml: + struct: + - '#/content/blockReplace/action' + - '#/content/blockReplace/actioning' + - '#/content/blockReplace/actioned' diff --git a/package.json b/package.json index 8ddb2b6..c4ef22a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "OAS (Swagger v3) API Definition for Template API", "scripts": { "lint": "redocly lint specification/multicast-notification-service.yaml", - "publish": "mkdir -p build && redocly bundle specification/multicast-notification-service.yaml --dereferenced --remove-unused-components --ext json | poetry run python scripts/set_version.py > build/multicast-notification-service.json", + "publish": "mkdir -p build && redocly bundle specification/multicast-notification-service.yaml --dereferenced --remove-unused-components --ext json | poetry run python scripts/apply_block_replacements.py | poetry run python scripts/set_version.py > build/multicast-notification-service.json", "serve": "redocly preview-docs -p 5000 build/multicast-notification-service.json", "check-licenses": "node_modules/.bin/license-checker --failOn GPL --failOn LGPL" }, diff --git a/scripts/apply_block_replacements.py b/scripts/apply_block_replacements.py new file mode 100644 index 0000000..a15d8db --- /dev/null +++ b/scripts/apply_block_replacements.py @@ -0,0 +1,28 @@ +import sys +import json + + +def apply_nested_replacements(data, replacements=None): + if isinstance(data, dict): + if "blockReplace" in data: + replacements = data["blockReplace"] + del data["blockReplace"] + + for key, value in data.items(): + if isinstance(value, str) and replacements: + for placeholder, replacement in replacements.items(): + value = value.replace(f"[[{placeholder}]]", replacement) + data[key] = value + else: + apply_nested_replacements(value, replacements) # recurse + + elif isinstance(data, list): + for index, item in enumerate(data): + apply_nested_replacements(item, replacements) # recurse + + +input_data = sys.stdin.read() +json_data = json.loads(input_data) +apply_nested_replacements(json_data) +# send to stdout +print(json.dumps(json_data, indent=2)) diff --git a/specification/multicast-notification-service.yaml b/specification/multicast-notification-service.yaml index 2d321d2..7072521 100644 --- a/specification/multicast-notification-service.yaml +++ b/specification/multicast-notification-service.yaml @@ -453,157 +453,7 @@ paths: - $ref: "parameters/headers/authorization.yaml" - $ref: "parameters/headers/x-correlation-id.yaml" requestBody: - required: true - content: - application/fhir+json: - schema: - type: "object" - required: - - "resourceType" - - "status" - - "reason" - - "criteria" - - "channel" - properties: - resourceType: - type: "string" - description: "The subscription FHIR Resource: https://hl7.org/fhir/R4/subscription.html" - status: - type: "string" - description: "The status of the subscription. When creating a subscription, the value must be `requested`." - end: - type: "string" - format: "date-time" - description: | - Optional expiry date/time for the subscription. As per the [FHIR R4 instant data type](https://hl7.org/fhir/R4/datatypes.html#instant) time shall be specified to at least the second and include a time zone. - For example: YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g. 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z) - reason: - type: "string" - description: "A description of why this subscription is required. You may provide an empty string." - criteria: - type: "string" - description: | - Criteria for the subscription. Provide your criteria with each condition separated by `&;`. If you are requesting a generic subscription to all signals of a certain type the separator is not required. For example, `eventType=gpreg-change-gp-req-1&;generalpractitioner=XY11` - or `eventType=gpreg-change-gp-req-1`. A valid criteria must contain a permitted value for `eventType`. Additional criteria depends on the event and are documentated on our [Signal Catalogue page](https://digital.nhs.uk/developer/api-catalogue?query=mns+event+publish-subscribe). - channel: - type: "object" - required: - - "type" - - "endpoint" - - "payload" - description: "The channel on which to report matches to the criteria. SQS Endpoints must be unique per event type; attempts to add a subscription with an endpoint which is already in-use will fail with a HTTP 409 (Conflict)" - properties: - type: - type: "string" - description: "The type of channel to send notifications on. Of the options within [FHIR](https://hl7.org/fhir/R4/valueset-subscription-channel-type.html), MNS currently only supports `message`." - endpoint: - type: "string" - description: "The endpoint which signals will be delivered to. MNS currently only supports delivery to [MESH](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh) mailboxes and [AWS SQS](https://aws.amazon.com/sqs/) endpoints. Note: for MESH delivery you must provide the full mailbox ID and for SQS delivery you must provide the full SQS ARN of your desired queue." - payload: - type: "string" - description: "The mime type to send the payload in. MNS supports `application/json` and `application/fhir+json` (FHIR R4 Bundle)." - hydration: - type: "object" - required: - - "enabled" - description: "Optional block to configure hydration properties - hydration is disabled by default." - properties: - enabled: - type: "boolean" - description: "A flag to enable (true) or disable (false) signal hydration." - headers: - type: object - description: "An optional dictionary of HTTP headers that will be sent in the request to the API endpoint specified in the signal." - additionalProperties: - type: string - description: "HTTP header that will be sent in the request to the API endpoint specified in the signal." - examples: - pdsChangeofGPSubscription: - description: "Create a pds change of GP subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=pds-change-of-gp-1" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue1" - payload: "application/json" - pdsChangeofGPSubscriptionMeshDelivery: - description: "Create a pds change of GP subscription with MESH delivery" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=pds-change-of-gp-1" - channel: - type: "message" - endpoint: "mesh://MYMAILBOXOT101?workflow_id=myWorkflow101" - payload: "application/json" - nhsNumberChangeSubscription: - description: "Create an NHS number change subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=nhs-number-change-1" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" - payload: "application/json" - pdsDeathNotificationSubscription: - description: "Create a pds death notification subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=pds-death-notification-1" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" - payload: "application/fhir+json" - immunisationVaccinationSubscription: - description: "Create an immunisation vaccination subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=imms-vaccinations-1" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" - payload: "application/json" - validatedGPRegistrationRequestSubscription: - description: "Create a validated GP registration request event subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=gpreg-change-gp-req-1&;supplierNACS=Y12345&;registrationencountercode=3" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" - payload: "application/fhir+json" - patientflagsChangeSubscription: - description: "Create a Patient Flags Change subscription" - value: - resourceType: "Subscription" - status: "requested" - end: "2022-04-05T17:31:00.000Z" - reason: "A description of why this subscription should be created." - criteria: "eventType=patientflags-change-1&;flagtype=NRAF&;generalpractitioner=XY11" - channel: - type: "message" - endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" - payload: "application/fhir+json" - - + $ref: "requestBody/create-or-update-subscription-body.yaml" responses: 201: description: Created - the subscription has been successfully created diff --git a/specification/requestBody/create-or-update-subscription-body.yaml b/specification/requestBody/create-or-update-subscription-body.yaml new file mode 100644 index 0000000..06b03c6 --- /dev/null +++ b/specification/requestBody/create-or-update-subscription-body.yaml @@ -0,0 +1,153 @@ +required: true +content: + blockReplace: + action: "Create" + actioning: "creating" + actioned: "created" + application/fhir+json: + schema: + type: "object" + required: + - "resourceType" + - "status" + - "reason" + - "criteria" + - "channel" + properties: + resourceType: + type: "string" + description: "The subscription FHIR Resource: https://hl7.org/fhir/R4/subscription.html" + status: + type: "string" + description: "The status of the subscription. When [[actioning]] a subscription, the value must be `requested`." + end: + type: "string" + format: "date-time" + description: | + Optional expiry date/time for the subscription. As per the [FHIR R4 instant data type](https://hl7.org/fhir/R4/datatypes.html#instant) time shall be specified to at least the second and include a time zone. + For example: YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g. 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z) + reason: + type: "string" + description: "A description of why this subscription is required. You may provide an empty string." + criteria: + type: "string" + description: | + Criteria for the subscription. Provide your criteria with each condition separated by `&;`. If you are requesting a generic subscription to all signals of a certain type the separator is not required. For example, `eventType=gpreg-change-gp-req-1&;generalpractitioner=XY11` + or `eventType=gpreg-change-gp-req-1`. A valid criteria must contain a permitted value for `eventType`. Additional criteria depends on the event and are documentated on our [Signal Catalogue page](https://digital.nhs.uk/developer/api-catalogue?query=mns+event+publish-subscribe). + channel: + type: "object" + required: + - "type" + - "endpoint" + - "payload" + description: "The channel on which to report matches to the criteria. SQS Endpoints must be unique per event type; attempts to add a subscription with an endpoint which is already in-use will fail with a HTTP 409 (Conflict)" + properties: + type: + type: "string" + description: "The type of channel to send notifications on. Of the options within [FHIR](https://hl7.org/fhir/R4/valueset-subscription-channel-type.html), MNS currently only supports `message`." + endpoint: + type: "string" + description: "The endpoint which signals will be delivered to. MNS currently only supports delivery to [MESH](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh) mailboxes and [AWS SQS](https://aws.amazon.com/sqs/) endpoints. Note: for MESH delivery you must provide the full mailbox ID and for SQS delivery you must provide the full SQS ARN of your desired queue." + payload: + type: "string" + description: "The mime type to send the payload in. MNS supports `application/json` and `application/fhir+json` (FHIR R4 Bundle)." + hydration: + type: "object" + required: + - "enabled" + description: "Optional block to configure hydration properties - hydration is disabled by default." + properties: + enabled: + type: "boolean" + description: "A flag to enable (true) or disable (false) signal hydration." + headers: + type: object + description: "An optional dictionary of HTTP headers that will be sent in the request to the API endpoint specified in the signal." + additionalProperties: + type: string + description: "HTTP header that will be sent in the request to the API endpoint specified in the signal." + examples: + pdsChangeofGPSubscription: + description: "[[action]] a pds change of GP subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=pds-change-of-gp-1" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue1" + payload: "application/json" + pdsChangeofGPSubscriptionMeshDelivery: + description: "[[action]] a pds change of GP subscription with MESH delivery" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=pds-change-of-gp-1" + channel: + type: "message" + endpoint: "mesh://MYMAILBOXOT101?workflow_id=myWorkflow101" + payload: "application/json" + nhsNumberChangeSubscription: + description: "[[action]] an NHS number change subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=nhs-number-change-1" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" + payload: "application/json" + pdsDeathNotificationSubscription: + description: "[[action]] a pds death notification subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=pds-death-notification-1" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" + payload: "application/fhir+json" + immunisationVaccinationSubscription: + description: "[[action]] an immunisation vaccination subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=imms-vaccinations-1" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" + payload: "application/json" + validatedGPRegistrationRequestSubscription: + description: "[[action]] a validated GP registration request event subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=gpreg-change-gp-req-1&;supplierNACS=Y12345&;registrationencountercode=3" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" + payload: "application/fhir+json" + patientflagsChangeSubscription: + description: "[[action]] a Patient Flags Change subscription" + value: + resourceType: "Subscription" + status: "requested" + end: "2022-04-05T17:31:00.000Z" + reason: "A description of why this subscription should be [[actioned]]." + criteria: "eventType=patientflags-change-1&;flagtype=NRAF&;generalpractitioner=XY11" + channel: + type: "message" + endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2" + payload: "application/fhir+json" \ No newline at end of file