Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ dist
.DS_Store
.reports
/sandbox/*.log
/sandbox-staging
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bundle-oas:

generate-sandbox:
$(MAKE) build-json-oas-spec APIM_ENV=sandbox
jq --slurpfile status sandbox/HealthcheckEndpoint.json '.paths += $status[0]' build/notify-supplier.json > tmp.json && mv tmp.json build/notify-supplier.json
jq --slurpfile status sandbox/HealthcheckEndpoint.json '.paths += $$status[0]' build/notify-supplier.json > tmp.json && mv tmp.json build/notify-supplier.json
npm run generate-sandbox

serve-swagger:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"bundle-oas": "mkdir -p build && redocly bundle specification/api/notify-supplier-phase1.yml --dereferenced -k --remove-unused-components --ext yml > build/notify-supplier.yml",
"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",
"generate-dependencies": "npm run generate-dependencies --workspaces --if-present",
"generate-sandbox": "openapi-generator-cli generate -g nodejs-express-server -i build/notify-supplier.yml --skip-validate-spec -o sandbox",
"generate-sandbox": "openapi-generator-cli generate -g nodejs-express-server -i build/notify-supplier.json --skip-validate-spec -o sandbox-staging",
"generate:cs": "./sdk/generate-cs.sh $npm_config_buildver",
"generate:cs-server": "./server/generate-cs-server.sh $npm_config_buildver",
"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",
Expand Down
50 changes: 49 additions & 1 deletion sandbox/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ paths:
- FORWARDED
type: string
style: form
- description: |-
The ordinal number of the page of results to be retrieved. If omitted, the
first page of results will be returned. Use the links section in the response
body to determine whether any further pages of results exist.
explode: true
in: query
name: page
required: false
schema:
example: 1
type: number
style: form
responses:
"200":
content:
Expand Down Expand Up @@ -197,7 +209,7 @@ paths:
id: 2WL5eYSWGzCHlGmzNxuqVusPxDg
type: Letter
schema:
$ref: "#/components/schemas/listLetters_200_response"
$ref: "#/components/schemas/postLetters_200_response"
description: Letter Resources Updated successfully
"404":
content:
Expand Down Expand Up @@ -972,6 +984,38 @@ paths:
x-eov-operation-handler: controllers/DefaultController
components:
schemas:
listLetters_200_response_links:
additionalProperties: false
description: Contains links to other data pages
properties:
last:
description: URI of final page of data
example: https://dev.api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=10
format: uri
type: string
next:
description: URI of next page of data
example: https://dev.api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=5
format: uri
type: string
prev:
description: URI of prev page of data
example: https://dev.api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=7
format: uri
type: string
self:
description: URI of current page of data
example: https://dev.api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=6
format: uri
type: string
type: object
postLetters_200_response:
properties:
data:
items:
$ref: "#/components/schemas/listLetters_200_response_data_inner"
type: array
type: object
createMI_request_data:
properties:
type:
Expand Down Expand Up @@ -1086,6 +1130,8 @@ components:
items:
$ref: "#/components/schemas/listLetters_200_response_data_inner"
type: array
links:
$ref: "#/components/schemas/listLetters_200_response_links"
type: object
getLetterStatus_200_response:
properties:
Expand All @@ -1094,6 +1140,8 @@ components:
type: object
postLetters_request_data_inner_attributes:
properties:
specificationId:
type: string
status:
default: PENDING
description: The supplier status of an individual letter
Expand Down
4 changes: 2 additions & 2 deletions sandbox/controllers/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Controller {
if (codeGenDefinedBodyName !== undefined) {
return codeGenDefinedBodyName;
}
const refObjectPath = request.openapi.schema.requestBody.content['application/json'].schema.$ref;
const refObjectPath = request.openapi.schema.requestBody.content['application/vnd.api+json'].schema.$ref;
if (refObjectPath !== undefined && refObjectPath.length > 0) {
return (refObjectPath.substr(refObjectPath.lastIndexOf('/') + 1));
}
Expand All @@ -72,7 +72,7 @@ class Controller {
const requestParams = {};
if (request.openapi.schema.requestBody !== null) {
const { content } = request.openapi.schema.requestBody;
if (content['application/json'] !== undefined) {
if (content['application/vnd.api+json'] !== undefined) {
const requestBodyName = camelCase(this.getRequestBodyName(request));
requestParams[requestBodyName] = request.body;
} else if (content['multipart/form-data'] !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"data": [
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68ctLKWlhxsoil13zANnOXDs",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hADL5mBayE3gDOnQeQ7RGr",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hesrGUpMmPzvBErnZ3Nx1s",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68gtwhetFGlca6JdckCLduQJ",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68fX5yazsb8XtbIKvnH7lyFV",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68cdGh1HVxxqsSTVezoulItF",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68ctCLllXxrmkrrcent290Jv",
"type": "Letter"
}
],
"links": {
"last": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=10",
"prev": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=9",
"self": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=10"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"data": [
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68ctLKWlhxsoil13zANnOXDs",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hADL5mBayE3gDOnQeQ7RGr",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hesrGUpMmPzvBErnZ3Nx1s",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68gtwhetFGlca6JdckCLduQJ",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68fX5yazsb8XtbIKvnH7lyFV",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68cdGh1HVxxqsSTVezoulItF",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68ctCLllXxrmkrrcent290Jv",
"type": "Letter"
}
],
"links": {
"last": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=10",
"next": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=6",
"prev": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=4",
"self": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,67 @@
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"id": "31B68ctLKWlhxsoil13zANnOXDs",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hADL5mBayE3gDOnQeQ7RGr",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68hesrGUpMmPzvBErnZ3Nx1s",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68gtwhetFGlca6JdckCLduQJ",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68fX5yazsb8XtbIKvnH7lyFV",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68cdGh1HVxxqsSTVezoulItF",
"type": "Letter"
},
{
"attributes": {
"requestedProductionStatus": "ACTIVE",
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
"status": "PENDING"
},
"id": "31B68ctCLllXxrmkrrcent290Jv",
"type": "Letter"
}
]
],
"links": {
"last": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=10",
"next": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=2",
"self": "https://api.service.nhs.uk/nhs-notify-supplier/letters?status=PENDING&page=1"
}
}
24 changes: 22 additions & 2 deletions sandbox/expressServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const bodyParser = require('body-parser');
const OpenApiValidator = require('express-openapi-validator');
const logger = require('./logger');
const config = require('./config');
const getRawBody = require('raw-body');
const contentType = require('content-type');

class ExpressServer {
constructor(port, openApiYaml) {
Expand All @@ -29,8 +31,11 @@ class ExpressServer {
// this.setupAllowedMedia();
this.app.use(cors());
this.app.use(bodyParser.json({ limit: '14MB' }));
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: false }));
this.app.use(express.json({
type: ['application/json', 'application/vnd.api+json']
}));
this.app.use(express.urlencoded({ extended: true }));

this.app.use(cookieParser());
// Simple test to see that the server is up and responding
this.app.get('/hello', (req, res) => res.send(`Hello World. path: ${this.openApiPath}`));
Expand All @@ -53,6 +58,21 @@ class ExpressServer {
fileUploader: { dest: config.FILE_UPLOAD_PATH },
}),
);
this.app.use((err, req, res, next) => {
// Log full error
console.error('OpenAPI validation error:', err);

// Handle OpenAPI validation errors
if (err.status && err.errors) {
res.status(err.status).json({
message: err.message,
errors: err.errors,
});
} else {
// Fallback error handler
next(err);
}
});
}

launch() {
Expand Down
Loading
Loading