Skip to content

Commit

Permalink
Release 2.6.1. Event.validateBody() treats an undefined body as null.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff committed May 28, 2020
1 parent 9104b91 commit 735b41c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 90 deletions.
133 changes: 55 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cassava",
"version": "2.6.0",
"version": "2.6.1",
"description": "AWS API Gateway Router",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -37,29 +37,29 @@
},
"homepage": "https://github.com/Giftbit/cassava#readme",
"devDependencies": {
"@types/aws-lambda": "^8.10.50",
"@types/aws-lambda": "^8.10.51",
"@types/chai": "^4.2.11",
"@types/cookie": "^0.3.3",
"@types/cookie": "^0.4.0",
"@types/mocha": "^7.0.2",
"@types/negotiator": "^0.6.1",
"@types/node": "^10.12.18",
"@types/uuid": "^7.0.2",
"@types/uuid": "^8.0.0",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"gh-pages": "^2.2.0",
"mocha": "^7.1.1",
"mocha": "^7.2.0",
"rimraf": "^3.0.2",
"touch": "^3.1.0",
"ts-node": "^8.8.2",
"typedoc": "^0.17.4",
"typescript": "^3.8.3"
"ts-node": "^8.10.2",
"typedoc": "^0.17.7",
"typescript": "^3.9.3"
},
"dependencies": {
"cookie": "^0.4.0",
"cookie": "^0.4.1",
"jsonschema": "^1.2.6",
"negotiator": "^0.6.2",
"uuid": "^7.0.3"
"uuid": "^8.1.0"
}
}
14 changes: 13 additions & 1 deletion src/RouterEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,19 @@ describe("RouterEvent", () => {
latitude: "49.2391",
longitude: "-124.0227"
};
chai.assert.throws(() => evt.validateBody(coordinateSchema));
chai.assert.throws(() => evt.validateBody(coordinateSchema), RestError);
});

it("throws a RestError on undefined body", () => {
const evt = new RouterEvent();
evt.body = undefined;
chai.assert.throws(() => evt.validateBody(coordinateSchema), RestError);
});

it("throws a RestError on null body", () => {
const evt = new RouterEvent();
evt.body = null;
chai.assert.throws(() => evt.validateBody(coordinateSchema), RestError);
});

it("allows customization of the RestError status code", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/RouterEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class RouterEvent {
* The actual implementation comes from https://github.com/tdegrunt/jsonschema .
*/
validateBody(schema: jsonschema.Schema, options?: ValidateBodyOptions): void {
const result = jsonschema.validate(this.body, schema, {propertyName: "requestBody", ...options} as jsonschema.Options);
const result = jsonschema.validate(this.body ?? null, schema, {propertyName: "requestBody", ...options} as jsonschema.Options);
if (result.errors.length) {
throw new RestError(
options && typeof options.httpStatusCode === "number" ? options.httpStatusCode : 422,
Expand Down

0 comments on commit 735b41c

Please sign in to comment.