From b6d033a044e722f9cd0bd751c4067bf05aa50558 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 3 Nov 2020 13:16:03 +0100 Subject: [PATCH] fix(AWS API Gateway): Ensure to log deprecation at initialization stage --- lib/plugins/aws/lib/naming.js | 14 +++----------- .../compile/events/apiGateway/index.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/plugins/aws/lib/naming.js b/lib/plugins/aws/lib/naming.js index eadd3d3bd..0a84d1b9c 100644 --- a/lib/plugins/aws/lib/naming.js +++ b/lib/plugins/aws/lib/naming.js @@ -250,17 +250,9 @@ module.exports = { return `${this.provider.serverless.service.provider.apiName}`; } - if (_.get(this.provider.serverless.service.provider.apiGateway, 'shouldStartNameWithService')) { - return `${this.provider.serverless.service.service}-${this.provider.getStage()}`; - } - - this.provider.serverless._logDeprecation( - 'AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE', - 'Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".\n' + - 'Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.' - ); - - return `${this.provider.getStage()}-${this.provider.serverless.service.service}`; + return _.get(this.provider.serverless.service.provider.apiGateway, 'shouldStartNameWithService') + ? `${this.provider.serverless.service.service}-${this.provider.getStage()}` + : `${this.provider.getStage()}-${this.provider.serverless.service.service}`; }, generateApiGatewayDeploymentLogicalId(id) { return `ApiGatewayDeployment${id}`; diff --git a/lib/plugins/aws/package/compile/events/apiGateway/index.js b/lib/plugins/aws/package/compile/events/apiGateway/index.js index eeef6d953..8a804e677 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/index.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/index.js @@ -3,6 +3,7 @@ /* eslint-disable global-require */ const BbPromise = require('bluebird'); +const _ = require('lodash'); const validate = require('./lib/validate'); const compileRestApi = require('./lib/restApi'); @@ -207,6 +208,24 @@ class AwsCompileApigEvents { // used for the generated method logical ids (GET, PATCH, PUT, DELETE, OPTIONS, ...) this.apiGatewayMethodLogicalIds = []; + if ( + this.serverless.service.provider.name === 'aws' && + !this.serverless.service.provider.apiName && + !_.get(this.serverless.service.provider.apiGateway, 'shouldStartNameWithService') && + !_.get(this.serverless.service.provider.apiGateway, 'restApiId') && + Object.values(this.serverless.service.functions).some( + ({ events }) => events && events.some(({ http }) => http) + ) + ) { + this.serverless._logDeprecation( + 'AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE', + 'Starting with next major version, API Gateway naming will be changed from ' + + '"{stage}-{service}" to "{service}-{stage}".\n' + + 'Set "provider.apiGateway.shouldStartNameWithService" to "true" ' + + 'to adapt to the new behavior now.' + ); + } + Object.assign( this, validate,