From 85cc4476b35b144ed28e71302230df2d626a4e60 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 16 Jun 2020 16:10:45 +0200 Subject: [PATCH] fix(AWS API Gateway): Fix handling of usagePlan array Improves leaky logic introduces with https://github.com/serverless/serverless/pull/5982 Exposed by regression introduced with https://github.com/serverless/serverless/pull/7827 --- .../aws/package/compile/events/apiGateway/lib/apiKeys.js | 3 ++- .../package/compile/events/apiGateway/lib/apiKeys.test.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.js index 3b28abfaa..7c8fceffd 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.js @@ -50,8 +50,9 @@ module.exports = { const name = Object.keys(apiKeyDefinition)[0]; if ( _.isObject(apiKeyDefinition) && + Array.isArray(this.serverless.service.provider.usagePlan) && _.flatten( - (this.serverless.service.provider.usagePlan || []).map(item => Object.keys(item)) + this.serverless.service.provider.usagePlan.map(item => Object.keys(item)) ).includes(name) ) { keyNumber = 0; diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.test.js index c5e343aaf..8b9cbc24e 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/apiKeys.test.js @@ -39,6 +39,11 @@ describe('#compileApiKeys()', () => { }, ]; + // Added purely to test https://github.com/serverless/serverless/issues/7844 regression + awsCompileApigEvents.serverless.service.provider.usagePlan = { + quota: { limit: 5000 }, + }; + return awsCompileApigEvents.compileApiKeys().then(() => { const expectedApiKeys = [ {