Skip to content

Commit c552ef2

Browse files
CM-12450 - Post Letter, default response headers, no default status (#180)
* CM-12450 - Post Letter, default response headers, no default status * Review comment
1 parent 8f0d477 commit c552ef2

27 files changed

+219
-193
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"bundle-oas": "cp -r sandbox/data/examples/. specification/api/components/examples && mkdir -p build && redocly bundle specification/api/notify-supplier-phase1.yml --dereferenced -k --remove-unused-components --ext yml > build/notify-supplier.yml",
5151
"generate": "npm run generate:cs --buildver=$npm_config_buildver && npm run generate:html && npm run generate:ts --buildver=$npm_config_buildver && npm run generate:python",
5252
"generate-dependencies": "npm run generate-dependencies --workspaces --if-present",
53-
"generate-sandbox": "openapi-generator-cli generate -g nodejs-express-server -i build/notify-supplier.json --skip-validate-spec -o sandbox-staging",
53+
"generate-sandbox": "openapi-generator-cli generate -g nodejs-express-server -i build/notify-supplier.json -o sandbox-staging",
5454
"generate:cs": "./sdk/generate-cs.sh $npm_config_buildver",
5555
"generate:cs-server": "./server/generate-cs-server.sh $npm_config_buildver",
5656
"generate:html": "docker run --rm --user $(id -u) -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/build/notify-supplier.yml -g html -o /local/sdk/html --skip-validate-spec",

sandbox/api/openapi.yaml

Lines changed: 141 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ paths:
205205
schema:
206206
$ref: "#/components/schemas/listLetters_200_response"
207207
description: List of letters to process
208+
headers:
209+
X-Request-ID:
210+
description: |
211+
Unique request identifier, in the format of a GUID
212+
explode: false
213+
required: false
214+
schema:
215+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
216+
type: string
217+
style: simple
218+
X-Correlation-ID:
219+
description: |
220+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
221+
explode: false
222+
required: false
223+
schema:
224+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
225+
type: string
226+
style: simple
208227
"400":
209228
content:
210229
application/vnd.api+json:
@@ -213,7 +232,7 @@ paths:
213232
value:
214233
errors:
215234
- code: NOTIFY_INVALID_REQUEST
216-
detail: "Only 'limit' query parameter is supported"
235+
detail: Only 'limit' query parameter is supported
217236
id: rrt-1931948104716186917-c-geu2-10664-3111479-3.0
218237
links:
219238
about: https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier
@@ -223,8 +242,8 @@ paths:
223242
value:
224243
errors:
225244
- code: NOTIFY_INVALID_REQUEST
226-
detail: "The limit parameter must be a positive\
227-
\ number not greater than 2500"
245+
detail: The limit parameter must be a positive number not greater
246+
than 2500
228247
id: rrt-1931948104716186917-c-geu2-10664-3111479-3.0
229248
links:
230249
about: https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier
@@ -368,66 +387,28 @@ paths:
368387
type: Letter
369388
schema:
370389
$ref: "#/components/schemas/postLetters_request"
371-
required: true
372390
responses:
373-
"200":
374-
content:
375-
application/vnd.api+json:
376-
examples:
377-
post-letters-responses:
378-
value:
379-
data:
380-
- attributes:
381-
status: PENDING
382-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
383-
type: Letter
384-
- attributes:
385-
status: ACCEPTED
386-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
387-
type: Letter
388-
- attributes:
389-
status: PRINTED
390-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
391-
type: Letter
392-
- attributes:
393-
status: ENCLOSED
394-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
395-
type: Letter
396-
- attributes:
397-
status: DISPATCHED
398-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
399-
type: Letter
400-
- attributes:
401-
status: DELIVERED
402-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
403-
type: Letter
404-
- attributes:
405-
reasonCode: 100
406-
reasonText: failed validation
407-
status: RETURNED
408-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
409-
type: Letter
410-
- attributes:
411-
reasonCode: 100
412-
reasonText: failed validation
413-
status: CANCELLED
414-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
415-
type: Letter
416-
- attributes:
417-
reasonCode: 100
418-
reasonText: failed validation
419-
status: FAILED
420-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
421-
type: Letter
422-
- attributes:
423-
reasonCode: 100
424-
reasonText: failed validation
425-
status: RETURNED
426-
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
427-
type: Letter
391+
"202":
392+
description: 202 (Accepted) Acknowledges that status updates have been posted
393+
headers:
394+
X-Request-ID:
395+
description: |
396+
Unique request identifier, in the format of a GUID
397+
explode: false
398+
required: false
428399
schema:
429-
$ref: "#/components/schemas/listLetters_200_response"
430-
description: Letter Resources Updated successfully
400+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
401+
type: string
402+
style: simple
403+
X-Correlation-ID:
404+
description: |
405+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
406+
explode: false
407+
required: false
408+
schema:
409+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
410+
type: string
411+
style: simple
431412
"404":
432413
content:
433414
application/vnd.api+json:
@@ -551,6 +532,25 @@ paths:
551532
schema:
552533
$ref: "#/components/schemas/getLetterStatus_200_response"
553534
description: Letter status
535+
headers:
536+
X-Request-ID:
537+
description: |
538+
Unique request identifier, in the format of a GUID
539+
explode: false
540+
required: false
541+
schema:
542+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
543+
type: string
544+
style: simple
545+
X-Correlation-ID:
546+
description: |
547+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
548+
explode: false
549+
required: false
550+
schema:
551+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
552+
type: string
553+
style: simple
554554
"404":
555555
content:
556556
application/vnd.api+json:
@@ -756,7 +756,6 @@ paths:
756756
type: Letter
757757
schema:
758758
$ref: "#/components/schemas/patchLetter_request"
759-
required: true
760759
responses:
761760
"200":
762761
content:
@@ -773,6 +772,25 @@ paths:
773772
schema:
774773
$ref: "#/components/schemas/getLetterStatus_200_response"
775774
description: Letter resource updated successfully
775+
headers:
776+
X-Request-ID:
777+
description: |
778+
Unique request identifier, in the format of a GUID
779+
explode: false
780+
required: false
781+
schema:
782+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
783+
type: string
784+
style: simple
785+
X-Correlation-ID:
786+
description: |
787+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
788+
explode: false
789+
required: false
790+
schema:
791+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
792+
type: string
793+
style: simple
776794
"400":
777795
content:
778796
application/vnd.api+json:
@@ -889,6 +907,24 @@ paths:
889907
schema:
890908
type: string
891909
style: simple
910+
X-Request-ID:
911+
description: |
912+
Unique request identifier, in the format of a GUID
913+
explode: false
914+
required: false
915+
schema:
916+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
917+
type: string
918+
style: simple
919+
X-Correlation-ID:
920+
description: |
921+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
922+
explode: false
923+
required: false
924+
schema:
925+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
926+
type: string
927+
style: simple
892928
"404":
893929
content:
894930
application/vnd.api+json:
@@ -1049,7 +1085,6 @@ paths:
10491085
type: ManagementInformation
10501086
schema:
10511087
$ref: "#/components/schemas/createMI_request"
1052-
required: true
10531088
responses:
10541089
"201":
10551090
content:
@@ -1070,6 +1105,25 @@ paths:
10701105
schema:
10711106
$ref: "#/components/schemas/createMI_201_response"
10721107
description: Management Information created successfully
1108+
headers:
1109+
X-Request-ID:
1110+
description: |
1111+
Unique request identifier, in the format of a GUID
1112+
explode: false
1113+
required: false
1114+
schema:
1115+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
1116+
type: string
1117+
style: simple
1118+
X-Correlation-ID:
1119+
description: |
1120+
An optional ID which you can use to track transactions across multiple systems. It can take any value, but we recommend avoiding . characters. If not provided in the request, NHS Notify will default to a system generated ID in its place. The ID will be returned in a response header.
1121+
explode: false
1122+
required: false
1123+
schema:
1124+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
1125+
type: string
1126+
style: simple
10731127
"404":
10741128
content:
10751129
application/vnd.api+json:
@@ -1144,6 +1198,9 @@ components:
11441198
type: string
11451199
attributes:
11461200
$ref: "#/components/schemas/createMI_request_data_attributes"
1201+
required:
1202+
- attributes
1203+
- type
11471204
type: object
11481205
listLetters_200_response_data_inner_attributes:
11491206
properties:
@@ -1183,11 +1240,6 @@ components:
11831240
- specificationId
11841241
- status
11851242
type: object
1186-
patchLetter_request:
1187-
properties:
1188-
data:
1189-
$ref: "#/components/schemas/postLetters_request_data_inner"
1190-
type: object
11911243
listLetters_400_response:
11921244
properties:
11931245
errors:
@@ -1232,10 +1284,19 @@ components:
12321284
$ref: "#/components/schemas/listLetters_200_response_data_inner"
12331285
type: array
12341286
type: object
1287+
patchLetter_request:
1288+
properties:
1289+
data:
1290+
$ref: "#/components/schemas/postLetters_request_data_inner"
1291+
required:
1292+
- data
1293+
type: object
12351294
getLetterStatus_200_response:
12361295
properties:
12371296
data:
12381297
$ref: "#/components/schemas/listLetters_200_response_data_inner"
1298+
required:
1299+
- data
12391300
type: object
12401301
postLetters_request_data_inner_attributes:
12411302
properties:
@@ -1265,6 +1326,8 @@ components:
12651326
description: Reason text for the given status
12661327
example: failed validation
12671328
type: string
1329+
required:
1330+
- status
12681331
type: object
12691332
listLetters_200_response_data_inner:
12701333
properties:
@@ -1289,13 +1352,19 @@ components:
12891352
type: string
12901353
attributes:
12911354
$ref: "#/components/schemas/postLetters_request_data_inner_attributes"
1355+
required:
1356+
- attributes
1357+
- id
1358+
- type
12921359
type: object
12931360
postLetters_request:
12941361
properties:
12951362
data:
12961363
items:
12971364
$ref: "#/components/schemas/postLetters_request_data_inner"
12981365
type: array
1366+
required:
1367+
- data
12991368
type: object
13001369
createMI_request:
13011370
properties:
@@ -1390,3 +1459,7 @@ x-nhsd-apim:
13901459
- name: NHSD-Supplier-ID
13911460
header: NHSD-Supplier-ID
13921461
required: false
1462+
ratelimiting:
1463+
app-default:
1464+
limit: 300
1465+
timeunit: second

sandbox/controllers/Controller.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class Controller {
1313
*/
1414
Object.entries(payload.headers).forEach(([name, value]) => response.setHeader(name, String(value)));
1515
response.status(payload.code || 200);
16-
const responsePayload = payload.body !== undefined ? payload.body : payload;
17-
if (responsePayload instanceof Object) {
18-
response.json(responsePayload);
16+
if (payload.body) {
17+
if (payload.body instanceof Object) {
18+
response.json(payload.body);
19+
} else {
20+
response.end(payload.body);
21+
}
1922
} else {
20-
response.end(responsePayload);
23+
response.end();
2124
}
2225
}
2326

0 commit comments

Comments
 (0)