diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js index 2ff56e0e340..f89cac963b0 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js @@ -14,7 +14,10 @@ module.exports = { const requestParameters = {}; if (event.http.request && event.http.request.parameters) { Object.entries(event.http.request.parameters).forEach(([key, value]) => { - requestParameters[key] = value.required === undefined ? value : value.required; + requestParameters[key] = (() => { + if (!_.isObject(value)) return value; + return value.required != null ? value.required : true; + })(); }); } diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js index c1ab20a1c2e..a1a681de78a 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js @@ -4,6 +4,7 @@ const expect = require('chai').expect; const AwsCompileApigEvents = require('../../index'); const Serverless = require('../../../../../../../../Serverless'); const AwsProvider = require('../../../../../../provider/awsProvider'); +const runServerless = require('../../../../../../../../../test/utils/run-serverless'); describe('#compileMethods()', () => { let serverless; @@ -603,6 +604,43 @@ describe('#compileMethods()', () => { }); }); + it('should set required to true when omitted from mapped value', async () => { + const { cfTemplate } = await runServerless({ + cliArgs: ['package'], + fixture: 'function', + configExt: { + functions: { + foo: { + events: [ + { + http: { + path: 'users/create', + method: 'post', + integration: 'HTTP_PROXY', + request: { + uri: 'https://example.com', + parameters: { + querystrings: { + foo: { + mappedValue: 'bar', + }, + }, + }, + }, + }, + }, + ], + }, + }, + }, + }); + expect( + cfTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties.RequestParameters[ + 'method.request.querystring.foo' + ] + ).to.equal(true); + }); + it('should set authorizer config for AWS_IAM', () => { awsCompileApigEvents.validated.events = [ {