Skip to content

Commit af4356a

Browse files
CM-12450 - Post Letter, default response headers, no default status
1 parent 8f0d477 commit af4356a

27 files changed

+205
-182
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: 128 additions & 58 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:
@@ -368,66 +387,28 @@ paths:
368387
type: Letter
369388
schema:
370389
$ref: "#/components/schemas/postLetters_request"
371-
required: true
372390
responses:
373391
"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
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:
@@ -773,6 +773,25 @@ paths:
773773
schema:
774774
$ref: "#/components/schemas/getLetterStatus_200_response"
775775
description: Letter resource updated successfully
776+
headers:
777+
X-Request-ID:
778+
description: |
779+
Unique request identifier, in the format of a GUID
780+
explode: false
781+
required: false
782+
schema:
783+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
784+
type: string
785+
style: simple
786+
X-Correlation-ID:
787+
description: |
788+
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.
789+
explode: false
790+
required: false
791+
schema:
792+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
793+
type: string
794+
style: simple
776795
"400":
777796
content:
778797
application/vnd.api+json:
@@ -889,6 +908,24 @@ paths:
889908
schema:
890909
type: string
891910
style: simple
911+
X-Request-ID:
912+
description: |
913+
Unique request identifier, in the format of a GUID
914+
explode: false
915+
required: false
916+
schema:
917+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
918+
type: string
919+
style: simple
920+
X-Correlation-ID:
921+
description: |
922+
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.
923+
explode: false
924+
required: false
925+
schema:
926+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
927+
type: string
928+
style: simple
892929
"404":
893930
content:
894931
application/vnd.api+json:
@@ -1049,7 +1086,6 @@ paths:
10491086
type: ManagementInformation
10501087
schema:
10511088
$ref: "#/components/schemas/createMI_request"
1052-
required: true
10531089
responses:
10541090
"201":
10551091
content:
@@ -1070,6 +1106,25 @@ paths:
10701106
schema:
10711107
$ref: "#/components/schemas/createMI_201_response"
10721108
description: Management Information created successfully
1109+
headers:
1110+
X-Request-ID:
1111+
description: |
1112+
Unique request identifier, in the format of a GUID
1113+
explode: false
1114+
required: false
1115+
schema:
1116+
example: dcb9c8dc-c2f4-4d5f-8674-a2e913e040b2
1117+
type: string
1118+
style: simple
1119+
X-Correlation-ID:
1120+
description: |
1121+
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.
1122+
explode: false
1123+
required: false
1124+
schema:
1125+
example: 11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA
1126+
type: string
1127+
style: simple
10731128
"404":
10741129
content:
10751130
application/vnd.api+json:
@@ -1144,6 +1199,9 @@ components:
11441199
type: string
11451200
attributes:
11461201
$ref: "#/components/schemas/createMI_request_data_attributes"
1202+
required:
1203+
- attributes
1204+
- type
11471205
type: object
11481206
listLetters_200_response_data_inner_attributes:
11491207
properties:
@@ -1187,6 +1245,8 @@ components:
11871245
properties:
11881246
data:
11891247
$ref: "#/components/schemas/postLetters_request_data_inner"
1248+
required:
1249+
- data
11901250
type: object
11911251
listLetters_400_response:
11921252
properties:
@@ -1236,6 +1296,8 @@ components:
12361296
properties:
12371297
data:
12381298
$ref: "#/components/schemas/listLetters_200_response_data_inner"
1299+
required:
1300+
- data
12391301
type: object
12401302
postLetters_request_data_inner_attributes:
12411303
properties:
@@ -1265,6 +1327,8 @@ components:
12651327
description: Reason text for the given status
12661328
example: failed validation
12671329
type: string
1330+
required:
1331+
- status
12681332
type: object
12691333
listLetters_200_response_data_inner:
12701334
properties:
@@ -1289,13 +1353,19 @@ components:
12891353
type: string
12901354
attributes:
12911355
$ref: "#/components/schemas/postLetters_request_data_inner_attributes"
1356+
required:
1357+
- attributes
1358+
- id
1359+
- type
12921360
type: object
12931361
postLetters_request:
12941362
properties:
12951363
data:
12961364
items:
12971365
$ref: "#/components/schemas/postLetters_request_data_inner"
12981366
type: array
1367+
required:
1368+
- data
12991369
type: object
13001370
createMI_request:
13011371
properties:

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

sandbox/data/examples/postLetter/responses/postLetters.json

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)