From d0a8f961edbaa147c48e872da77c127aa134178a Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 22 Apr 2018 12:19:40 -0600 Subject: [PATCH 1/8] feat: add in i18n support for validator Also includes the ability to customize error format --- package-lock.json | 24 +++++++++++++++++++ package.json | 2 ++ src/middlewares/validator.js | 46 +++++++++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91a71ac41..90d054a43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,6 +68,15 @@ "integrity": "sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4=", "dev": true }, + "accept-language": { + "version": "3.0.18", + "resolved": "https://registry.npmjs.org/accept-language/-/accept-language-3.0.18.tgz", + "integrity": "sha1-9QJfF79lpGaoRYOMz5jNuHfYM4Q=", + "requires": { + "bcp47": "1.1.2", + "stable": "0.1.7" + } + }, "acorn": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", @@ -110,6 +119,11 @@ "json-schema-traverse": "0.3.1" } }, + "ajv-i18n": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ajv-i18n/-/ajv-i18n-3.1.0.tgz", + "integrity": "sha1-tImXjZediEf8QRxmqzXVwhG2MAw=" + }, "ajv-keywords": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.0.0.tgz", @@ -1358,6 +1372,11 @@ "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==", "dev": true }, + "bcp47": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/bcp47/-/bcp47-1.1.2.tgz", + "integrity": "sha1-NUvjMH/9CEM6ePXh4glYRfifx/4=" + }, "bcrypt-pbkdf": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", @@ -6778,6 +6797,11 @@ } } }, + "stable": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.7.tgz", + "integrity": "sha512-LmxBix+nUtyihSBpxXAhRakYEy49fan2suysdS1fUZcKjI+krXmH8DCZJ3yfngfrOnIFNU8O73EgNTzO2jI53w==" + }, "stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-1.0.1.tgz", diff --git a/package.json b/package.json index df8110d71..ea96c8927 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,9 @@ "dependencies": { "@types/aws-lambda": "^8.10.1", "@types/http-errors": "^1.6.1", + "accept-language": "^3.0.18", "ajv": "^6.0.0", + "ajv-i18n": "^3.1.0", "ajv-keywords": "^3.0.0", "content-type": "^1.0.4", "http-errors": "^1.6.2", diff --git a/src/middlewares/validator.js b/src/middlewares/validator.js index f1d82df96..b657198f5 100644 --- a/src/middlewares/validator.js +++ b/src/middlewares/validator.js @@ -1,13 +1,41 @@ const createError = require('http-errors') const Ajv = require('ajv') const ajvKeywords = require('ajv-keywords') +const ajvLocalize = require('ajv-i18n') const {deepEqual} = require('assert') let ajv let previousConstructorOptions -const defaults = {v5: true, $data: true, allErrors: true} +const defaults = { + v5: true, + format: 'full', + coerceTypes: 'array', // important for query string params + allErrors: true, + useDefaults: true, + $data: true // required for ajv-keywords +} + +module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors => errors }) => { + const acceptLanguage = require('accept-language') + acceptLanguage.languages([ + 'en', + 'ar', + 'cz', + 'de', + 'es', + 'fr', + 'hu', + 'it', + 'ja', + 'nb', + 'pl', + 'pt-BR', + 'ru', + 'sk', + 'sv', + 'zh' + ]) -module.exports = ({inputSchema, outputSchema, ajvOptions}) => { const options = Object.assign({}, defaults, ajvOptions) lazyLoadAjv(options) @@ -23,15 +51,21 @@ module.exports = ({inputSchema, outputSchema, ajvOptions}) => { const valid = validateInput(handler.event) if (!valid) { - const error = new createError.BadRequest('Event object failed validation') - error.details = validateInput.errors - throw error + handler.event.headers = Object.assign({}, handler.event.headers) + const locale = handler.event.headers['Accept-Language'] + ? acceptLanguage.get(handler.event.headers['Accept-Language']) + : 'en' + ajvLocalize[locale](validateInput.errors) + + throw new createError.BadRequest( + errorFormat(validateInput.errors) + ) } return next() }, after (handler, next) { - if (!outputSchema) { + if (!outputSchema || (!handler.response && handler.error)) { return next() } From 6713689de037301f7f83260f412364019b2d9e6b Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 22 Apr 2018 12:46:35 -0600 Subject: [PATCH 2/8] fix: add tests to cover i18n and errorFormat - revert how error was returned to pass tests - lint code --- package.json | 2 +- src/middlewares/__tests__/validator.js | 63 ++++++++++++++++++++++++++ src/middlewares/validator.js | 9 ++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ea96c8927..21439878b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "types": "./index.d.ts", "scripts": { - "test:lint": "eslint --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .", + "test:lint": "eslint --fix --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .", "test:typings": "typings-tester --config tsconfig.json index.d.ts middlewares.d.ts", "test:unit": "jest --verbose --coverage", "test:unit:watch": "jest --verbose --coverage --watch", diff --git a/src/middlewares/__tests__/validator.js b/src/middlewares/__tests__/validator.js index 9cf24e686..501d6d06e 100644 --- a/src/middlewares/__tests__/validator.js +++ b/src/middlewares/__tests__/validator.js @@ -59,6 +59,43 @@ describe('πŸ“¦ Middleware Validator', () => { } handler(event, {}, (err, res) => { expect(err.message).toEqual('Event object failed validation') + expect(err.details).toEqual([{'dataPath': '', 'keyword': 'required', 'message': 'should have required property foo', 'params': {'missingProperty': 'foo'}, 'schemaPath': '#/required'}]) + }) + }) + + test('It should handle invalid schema as a BadRequest in a different language', () => { + const handler = middy((event, context, cb) => { + cb(null, event.body) // propagates the body as a response + }) + + const schema = { + required: ['body', 'foo'], + properties: { + // this will pass validation + body: { + type: 'string' + }, + // this won't as it won't be in the event + foo: { + type: 'string' + } + } + } + + handler.use(validator({ + inputSchema: schema + })) + + // invokes the handler, note that property foo is missing + const event = { + headers: { + 'Accept-Language': 'fr-CA, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5' + }, + body: JSON.stringify({something: 'somethingelse'}) + } + handler(event, {}, (err, res) => { + expect(err.message).toEqual('Event object failed validation') + expect(err.details).toEqual([{'dataPath': '', 'keyword': 'required', 'message': 'requiert la propriΓ©tΓ© foo', 'params': {'missingProperty': 'foo'}, 'schemaPath': '#/required'}]) }) }) @@ -147,4 +184,30 @@ describe('πŸ“¦ Middleware Validator', () => { }) }) }) + + describe('πŸ— errorFormat constructor options', () => { + const schema = {required: ['email'], properties: {email: {type: 'string', enum: ['abc@abc.com']}}} + + test('It should format the error.details', () => { + const handler = middy((event, context, cb) => { + cb(null, {}) + }) + + handler.use(validator({inputSchema: schema, + errorFormat: errors => errors.map(error => ({ + detail: error.message, + source: { + pointer: error.schemaPath.substr(1), + parameter: error.dataPath.substr(1) + }, + meta: error.params + })) + })) + + handler({email: 'abc@abc'}, {}, (err) => { + expect(err.details[0].detail).toEqual('should be equal to one of predefined values') + expect(err.details[0].source.parameter).toEqual('email') + }) + }) + }) }) diff --git a/src/middlewares/validator.js b/src/middlewares/validator.js index b657198f5..b6da49448 100644 --- a/src/middlewares/validator.js +++ b/src/middlewares/validator.js @@ -8,11 +8,10 @@ let ajv let previousConstructorOptions const defaults = { v5: true, - format: 'full', coerceTypes: 'array', // important for query string params allErrors: true, useDefaults: true, - $data: true // required for ajv-keywords + $data: true // required for ajv-keywords } module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors => errors }) => { @@ -51,15 +50,15 @@ module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors const valid = validateInput(handler.event) if (!valid) { + const error = new createError.BadRequest('Event object failed validation') handler.event.headers = Object.assign({}, handler.event.headers) const locale = handler.event.headers['Accept-Language'] ? acceptLanguage.get(handler.event.headers['Accept-Language']) : 'en' ajvLocalize[locale](validateInput.errors) - throw new createError.BadRequest( - errorFormat(validateInput.errors) - ) + error.details = errorFormat(validateInput.errors) + throw error } return next() From 26c0775fa8fea999162c17fc42d52d3398864a5c Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 22 Apr 2018 17:26:50 -0600 Subject: [PATCH 3/8] fix: pr change requests --- package-lock.json | 19 ------------------- package.json | 3 +-- src/middlewares/validator.js | 15 +++++++++------ 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90d054a43..333d01033 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,15 +68,6 @@ "integrity": "sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4=", "dev": true }, - "accept-language": { - "version": "3.0.18", - "resolved": "https://registry.npmjs.org/accept-language/-/accept-language-3.0.18.tgz", - "integrity": "sha1-9QJfF79lpGaoRYOMz5jNuHfYM4Q=", - "requires": { - "bcp47": "1.1.2", - "stable": "0.1.7" - } - }, "acorn": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", @@ -1372,11 +1363,6 @@ "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==", "dev": true }, - "bcp47": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/bcp47/-/bcp47-1.1.2.tgz", - "integrity": "sha1-NUvjMH/9CEM6ePXh4glYRfifx/4=" - }, "bcrypt-pbkdf": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", @@ -6797,11 +6783,6 @@ } } }, - "stable": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.7.tgz", - "integrity": "sha512-LmxBix+nUtyihSBpxXAhRakYEy49fan2suysdS1fUZcKjI+krXmH8DCZJ3yfngfrOnIFNU8O73EgNTzO2jI53w==" - }, "stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-1.0.1.tgz", diff --git a/package.json b/package.json index 21439878b..95ece2c4a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "types": "./index.d.ts", "scripts": { - "test:lint": "eslint --fix --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .", + "test:lint": "eslint --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .", "test:typings": "typings-tester --config tsconfig.json index.d.ts middlewares.d.ts", "test:unit": "jest --verbose --coverage", "test:unit:watch": "jest --verbose --coverage --watch", @@ -66,7 +66,6 @@ "dependencies": { "@types/aws-lambda": "^8.10.1", "@types/http-errors": "^1.6.1", - "accept-language": "^3.0.18", "ajv": "^6.0.0", "ajv-i18n": "^3.1.0", "ajv-keywords": "^3.0.0", diff --git a/src/middlewares/validator.js b/src/middlewares/validator.js index b6da49448..d4ee9b961 100644 --- a/src/middlewares/validator.js +++ b/src/middlewares/validator.js @@ -3,6 +3,7 @@ const Ajv = require('ajv') const ajvKeywords = require('ajv-keywords') const ajvLocalize = require('ajv-i18n') const {deepEqual} = require('assert') +const parseFn = require(`negotiator/lib/language`) let ajv let previousConstructorOptions @@ -14,9 +15,8 @@ const defaults = { $data: true // required for ajv-keywords } -module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors => errors }) => { - const acceptLanguage = require('accept-language') - acceptLanguage.languages([ +const chooseLanguage = (event) => { + const results = parseFn(event.headers['Accept-Language'], [ 'en', 'ar', 'cz', @@ -34,7 +34,11 @@ module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors 'sv', 'zh' ]) + if (!results.length) return 'en' + return results[0] +} +module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors => errors }) => { const options = Object.assign({}, defaults, ajvOptions) lazyLoadAjv(options) @@ -52,9 +56,8 @@ module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors if (!valid) { const error = new createError.BadRequest('Event object failed validation') handler.event.headers = Object.assign({}, handler.event.headers) - const locale = handler.event.headers['Accept-Language'] - ? acceptLanguage.get(handler.event.headers['Accept-Language']) - : 'en' + console.log(chooseLanguage(handler.event)) + const locale = chooseLanguage(handler.event) ajvLocalize[locale](validateInput.errors) error.details = errorFormat(validateInput.errors) From 6586d1bd7cad2f47fdb91cd051051497de702717 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 22 Apr 2018 17:33:06 -0600 Subject: [PATCH 4/8] fix: remove errorFormat --- src/middlewares/validator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlewares/validator.js b/src/middlewares/validator.js index d4ee9b961..c4f101ad4 100644 --- a/src/middlewares/validator.js +++ b/src/middlewares/validator.js @@ -38,7 +38,7 @@ const chooseLanguage = (event) => { return results[0] } -module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors => errors }) => { +module.exports = ({ inputSchema, outputSchema, ajvOptions }) => { const options = Object.assign({}, defaults, ajvOptions) lazyLoadAjv(options) @@ -60,7 +60,7 @@ module.exports = ({ inputSchema, outputSchema, ajvOptions, errorFormat = errors const locale = chooseLanguage(handler.event) ajvLocalize[locale](validateInput.errors) - error.details = errorFormat(validateInput.errors) + error.details = validateInput.errors throw error } From 781030b85a0041acf2d7cd9f109992ef88b6e8bd Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 22 Apr 2018 17:36:11 -0600 Subject: [PATCH 5/8] chore: lint and update tests --- src/middlewares/__tests__/validator.js | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/middlewares/__tests__/validator.js b/src/middlewares/__tests__/validator.js index 501d6d06e..523ed4c35 100644 --- a/src/middlewares/__tests__/validator.js +++ b/src/middlewares/__tests__/validator.js @@ -184,30 +184,4 @@ describe('πŸ“¦ Middleware Validator', () => { }) }) }) - - describe('πŸ— errorFormat constructor options', () => { - const schema = {required: ['email'], properties: {email: {type: 'string', enum: ['abc@abc.com']}}} - - test('It should format the error.details', () => { - const handler = middy((event, context, cb) => { - cb(null, {}) - }) - - handler.use(validator({inputSchema: schema, - errorFormat: errors => errors.map(error => ({ - detail: error.message, - source: { - pointer: error.schemaPath.substr(1), - parameter: error.dataPath.substr(1) - }, - meta: error.params - })) - })) - - handler({email: 'abc@abc'}, {}, (err) => { - expect(err.details[0].detail).toEqual('should be equal to one of predefined values') - expect(err.details[0].source.parameter).toEqual('email') - }) - }) - }) }) From a296341f5a30a2a0c7443c306cc1459cd908a48f Mon Sep 17 00:00:00 2001 From: Luciano Mammino Date: Tue, 24 Apr 2018 22:38:39 +0100 Subject: [PATCH 6/8] Proposed alternative implementation that assumes you are using this in combination with the content-negotiation middleware --- src/middlewares/__tests__/validator.js | 38 ++++++++++++++++-- src/middlewares/validator.js | 53 +++++++++++++------------- 2 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/middlewares/__tests__/validator.js b/src/middlewares/__tests__/validator.js index 523ed4c35..449023179 100644 --- a/src/middlewares/__tests__/validator.js +++ b/src/middlewares/__tests__/validator.js @@ -88,9 +88,7 @@ describe('πŸ“¦ Middleware Validator', () => { // invokes the handler, note that property foo is missing const event = { - headers: { - 'Accept-Language': 'fr-CA, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5' - }, + preferredLanguage: 'fr', body: JSON.stringify({something: 'somethingelse'}) } handler(event, {}, (err, res) => { @@ -99,6 +97,40 @@ describe('πŸ“¦ Middleware Validator', () => { }) }) + test('It should handle invalid schema as a BadRequest in a different language (with normalization)', () => { + const handler = middy((event, context, cb) => { + cb(null, event.body) // propagates the body as a response + }) + + const schema = { + required: ['body', 'foo'], + properties: { + // this will pass validation + body: { + type: 'string' + }, + // this won't as it won't be in the event + foo: { + type: 'string' + } + } + } + + handler.use(validator({ + inputSchema: schema + })) + + // invokes the handler, note that property foo is missing + const event = { + preferredLanguage: 'pt', + body: JSON.stringify({something: 'somethingelse'}) + } + handler(event, {}, (err, res) => { + expect(err.message).toEqual('Event object failed validation') + expect(err.details).toEqual([{'dataPath': '', 'keyword': 'required', 'message': 'deve ter a propriedade requerida foo', 'params': {'missingProperty': 'foo'}, 'schemaPath': '#/required'}]) + }) + }) + test('It should validate response', () => { const expectedResponse = { body: 'Hello world', diff --git a/src/middlewares/validator.js b/src/middlewares/validator.js index c4f101ad4..9ee7baf15 100644 --- a/src/middlewares/validator.js +++ b/src/middlewares/validator.js @@ -2,8 +2,7 @@ const createError = require('http-errors') const Ajv = require('ajv') const ajvKeywords = require('ajv-keywords') const ajvLocalize = require('ajv-i18n') -const {deepEqual} = require('assert') -const parseFn = require(`negotiator/lib/language`) +const { deepEqual } = require('assert') let ajv let previousConstructorOptions @@ -12,30 +11,31 @@ const defaults = { coerceTypes: 'array', // important for query string params allErrors: true, useDefaults: true, - $data: true // required for ajv-keywords + $data: true, // required for ajv-keywords + defaultLanguage: 'en' } -const chooseLanguage = (event) => { - const results = parseFn(event.headers['Accept-Language'], [ - 'en', - 'ar', - 'cz', - 'de', - 'es', - 'fr', - 'hu', - 'it', - 'ja', - 'nb', - 'pl', - 'pt-BR', - 'ru', - 'sk', - 'sv', - 'zh' - ]) - if (!results.length) return 'en' - return results[0] +const availableLanguages = Object.keys(ajvLocalize) + +/* in ajv-i18n Portuguese is represented as pt-BR */ +const languageNormalizationMap = { + 'pt': 'pt-BR', + 'pt-br': 'pt-BR', + 'pt_BR': 'pt-BR', + 'pt_br': 'pt-BR' +} + +const normalizePreferredLanguage = (lang) => languageNormalizationMap[lang] || lang + +const chooseLanguage = ({ preferredLanguage }, defaultLanguage) => { + if (preferredLanguage) { + const lang = normalizePreferredLanguage(preferredLanguage) + if (availableLanguages.includes(lang)) { + return lang + } + } + + return defaultLanguage } module.exports = ({ inputSchema, outputSchema, ajvOptions }) => { @@ -56,9 +56,8 @@ module.exports = ({ inputSchema, outputSchema, ajvOptions }) => { if (!valid) { const error = new createError.BadRequest('Event object failed validation') handler.event.headers = Object.assign({}, handler.event.headers) - console.log(chooseLanguage(handler.event)) - const locale = chooseLanguage(handler.event) - ajvLocalize[locale](validateInput.errors) + const language = chooseLanguage(handler.event, options.defaultLanguage) + ajvLocalize[language](validateInput.errors) error.details = validateInput.errors throw error From 5316c67bca1566b2cf75db0176ef8db7d5ab3497 Mon Sep 17 00:00:00 2001 From: Luciano Mammino Date: Mon, 30 Apr 2018 20:04:25 +0100 Subject: [PATCH 7/8] Updated documentation --- docs/middlewares.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/middlewares.md b/docs/middlewares.md index 2b9f88545..a910419a7 100644 --- a/docs/middlewares.md +++ b/docs/middlewares.md @@ -439,7 +439,7 @@ handler Fetches parameters from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html). -Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs [here](https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/). +Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs [here](https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/). By default parameters are assigned to the Node.js `process.env` object. They can instead be assigned to the function handler's `context` object by setting the `setToContext` flag to `true`. By default all parameters are added with uppercase names. @@ -529,6 +529,8 @@ This middleware can be used in combination with [`httpErrorHandler`](#httperrorhandler) to automatically return the right response to the user. +It can also be used in combination with [`httpcontentnegotiation`](#httpContentNegotiation) to load localised translations for the error messages (based on the currently requested language). This feature uses internally [`ajv-i18n`](http://npm.im/ajv-i18n) module, so reference to this module for options and more advanced use cases. By default the language used will be English (`en`), but you can redefine the default language by passing it in the `ajvOptions` options with the key `defaultLanguage` and specifying as value one of the [supported locales](https://www.npmjs.com/package/ajv-i18n#supported-locales). + ### Options - `inputSchema` (object) (optional): The JSON schema object that will be used @@ -536,7 +538,7 @@ response to the user. - `outputSchema` (object) (optional): The JSON schema object that will be used to validate the output (`handler.response`) of the Lambda handler. - `ajvOptions` (object) (optional): Options to pass to [ajv](https://epoberezkin.github.io/ajv/) - class constructor. Defaults are `{v5: true, $data: true, allErrors: true}` + class constructor. Defaults are `{v5: true, coerceTypes: 'array', $data: true, allErrors: true, useDefaults: true, defaultLanguage: 'en'}` ### Sample Usage From a6e97bde78aaf13b63d849ed3030652364c42c0e Mon Sep 17 00:00:00 2001 From: Luciano Mammino Date: Mon, 30 Apr 2018 20:06:35 +0100 Subject: [PATCH 8/8] version bump --- README.md | 4 +++- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36c4ab95e..f74597c7f 100644 --- a/README.md +++ b/README.md @@ -602,7 +602,9 @@ Middy factory function. Use it to wrap your existing handler to enable middlewar ## middlewareFunction β‡’ void \| Promise **Kind**: global typedef -**Returns**: void \| Promise - - A middleware can return a Promise instead of using the `next` function as a callback. In this case middy will wait for the promise to resolve (or reject) and it will automatically propagate the result to the next middleware. +**Returns**: void \| Promise - - A middleware can return a Promise instead of using the `next` function as a callback. + In this case middy will wait for the promise to resolve (or reject) and it will automatically + propagate the result to the next middleware. | Param | Type | Description | | --- | --- | --- | diff --git a/package-lock.json b/package-lock.json index de7a313cd..55e3be41d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "middy", - "version": "0.12.1", + "version": "0.13.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index de91ba95a..7033133a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "middy", - "version": "0.12.1", + "version": "0.13.0", "description": "πŸ›΅ The stylish Node.js middleware engine for AWS Lambda", "main": "./index.js", "files": [