Skip to content

Commit 77a693b

Browse files
Feature/ccm 11662 sandbox examples 2 (#164)
* Sandbox examples for letters endpoint * More examples * CCM-12281: Extend documentation and examples for ManagementInformation in OAS spec * Further examples and scripts * sandbox examples should be source of truth * Add groupid to MI data * own review changes * copy examples before build * fix 405 errors * move examples * post review changes and return x headers --------- Co-authored-by: Mike Houston <[email protected]>
1 parent 2d3d128 commit 77a693b

File tree

80 files changed

+1427
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1427
-457
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ dist
2626
.reports
2727
/sandbox/*.log
2828
/sandbox-staging
29+
/specification/api/components/examples

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ lint-oas:
4040
npm run lint-oas
4141

4242
publish-oas:
43+
$(MAKE) copy-examples
4344
npm run publish-oas
4445

4546
set-target: guard-APIM_ENV
@@ -74,9 +75,11 @@ build-yml-oas-spec: guard-APIM_ENV
7475
$(MAKE) bundle-oas
7576

7677
serve-oas:
78+
$(MAKE) copy-examples
7779
npm run serve-oas
7880

7981
bundle-oas:
82+
$(MAKE) copy-examples
8083
npm run bundle-oas
8184

8285
generate-sandbox:
@@ -88,6 +91,9 @@ generate-sandbox:
8891
serve-swagger:
8992
npm run serve-swagger-docs
9093

94+
copy-examples:
95+
cp -r ./sandbox/data/examples/. ./specification/api/components/examples
96+
9197
config:: _install-dependencies version # Configure development environment (main) @Configuration
9298
npm install
9399
(cd docs && make install && cd ..)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"scripts": {
4949
"build": "npm run bundle-oas && npm run generate --buildver=$npm_config_buildver",
50-
"bundle-oas": "mkdir -p build && redocly bundle specification/api/notify-supplier-phase1.yml --dereferenced -k --remove-unused-components --ext yml > build/notify-supplier.yml",
50+
"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",
5353
"generate-sandbox": "openapi-generator-cli generate -g nodejs-express-server -i build/notify-supplier.json --skip-validate-spec -o sandbox-staging",

sandbox/api/openapi.yaml

Lines changed: 475 additions & 111 deletions
Large diffs are not rendered by default.

sandbox/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22

33
const config = {
44
ROOT_DIR: __dirname,
5-
URL_PORT: 3000,
5+
URL_PORT: 9000,
66
URL_PATH: 'http://127.0.0.1',
77
BASE_VERSION: '',
88
CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'),

sandbox/controllers/Controller.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class Controller {
1111
* payload will be an object consisting of a code and a payload. If not customized
1212
* send 200 and the payload as received in this method.
1313
*/
14+
Object.entries(payload.headers).forEach(([name, value]) => response.setHeader(name, String(value)));
1415
response.status(payload.code || 200);
15-
const responsePayload = payload.payload !== undefined ? payload.payload : payload;
16+
const responsePayload = payload.body !== undefined ? payload.body : payload;
1617
if (responsePayload instanceof Object) {
1718
response.json(responsePayload);
1819
} else {
@@ -91,12 +92,13 @@ class Controller {
9192

9293
if (request.openapi.schema.parameters !== undefined) {
9394
request.openapi.schema.parameters.forEach((param) => {
95+
9496
if (param.in === 'path') {
9597
requestParams[param.name] = request.openapi.pathParams[param.name];
9698
} else if (param.in === 'query') {
9799
requestParams[param.name] = request.query[param.name];
98100
} else if (param.in === 'header') {
99-
requestParams[param.name] = request.headers[param.name];
101+
requestParams[camelCase(param.name)] = request.headers[param.name.toLowerCase()];
100102
}
101103
});
102104
}
@@ -105,7 +107,8 @@ class Controller {
105107

106108
static async handleRequest(request, response, serviceOperation) {
107109
try {
108-
const serviceResponse = await serviceOperation(this.collectRequestParams(request));
110+
const requestParams = this.collectRequestParams(request);
111+
const serviceResponse = await serviceOperation(requestParams);
109112
Controller.sendResponse(response, serviceResponse);
110113
} catch (error) {
111114
Controller.sendError(response, error);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"data": {
3+
"attributes": {
4+
"groupId": "abc123",
5+
"lineItem": "envelope-business-standard",
6+
"quantity": 22,
7+
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
8+
"stockRemaining": 2000,
9+
"timestamp": "yesterday"
10+
},
11+
"type": "ManagementInformation"
12+
}
13+
}

specification/api/components/examples/createMI/requests/createMIRequest.json renamed to sandbox/data/examples/createMI/requests/createMI_NOTFOUND.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"data": {
33
"attributes": {
4-
"cost": 10.25,
54
"groupId": "abc123",
6-
"lineItem": "Letter",
5+
"lineItem": "envelope-business-standard",
76
"quantity": 22,
8-
"specificationId": "da0b1495-c7cb-468c-9d81-07dee089d728",
7+
"specificationId": "123456",
98
"stockRemaining": 2000,
109
"timestamp": "2023-11-17T14:27:51.413Z"
1110
},

sandbox/data/examples/createMI/requests/createMI.json renamed to sandbox/data/examples/createMI/requests/createMI_SUCCESS.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"data": {
33
"attributes": {
4-
"cost": 10.25,
5-
"lineItem": "Letter",
4+
"groupId": "abc123",
5+
"lineItem": "envelope-business-standard",
66
"quantity": 22,
7-
"specificationId": "da0b1495-c7cb-468c-9d81-07dee089d728",
7+
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
88
"stockRemaining": 2000,
99
"timestamp": "2023-11-17T14:27:51.413Z"
1010
},

sandbox/data/examples/createMI/responses/createMI.json

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

0 commit comments

Comments
 (0)