fix(AWS API Gateway): Ensure to log deprecation at initialization stage

This commit is contained in:
Mariusz Nowak 2020-11-03 13:16:03 +01:00 committed by Mariusz Nowak
parent 0c28844188
commit b6d033a044
2 changed files with 22 additions and 11 deletions

View File

@ -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}`;

View File

@ -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,