mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
feat(AWS HTTP API): Support shouldStartNameWithService option (#9758)
This commit is contained in:
parent
c9e851ea60
commit
ef5a8faf13
@ -443,3 +443,13 @@ provider:
|
||||
httpApi:
|
||||
disableDefaultEndpoint: true
|
||||
```
|
||||
|
||||
### Service Naming
|
||||
|
||||
You can use the `shouldStartNameWithService` option to change the naming scheme for HTTP API from the default `${stage}-${service}` to `${service}-${stage}`.
|
||||
|
||||
```yml
|
||||
provider:
|
||||
httpApi:
|
||||
shouldStartNameWithService: true
|
||||
```
|
||||
|
||||
@ -652,7 +652,10 @@ module.exports = {
|
||||
) {
|
||||
return `${String(this.provider.serverless.service.provider.httpApi.name)}`;
|
||||
}
|
||||
return `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
|
||||
|
||||
return _.get(this.provider.serverless.service.provider.httpApi, 'shouldStartNameWithService')
|
||||
? `${this.provider.serverless.service.service}-${this.provider.getStage()}`
|
||||
: `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
|
||||
},
|
||||
getHttpApiLogicalId() {
|
||||
return 'HttpApi';
|
||||
|
||||
@ -912,6 +912,7 @@ class AwsProvider {
|
||||
metrics: { type: 'boolean' },
|
||||
useProviderTags: { const: true },
|
||||
disableDefaultEndpoint: { type: 'boolean' },
|
||||
shouldStartNameWithService: { const: true },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
|
||||
@ -1025,4 +1025,28 @@ describe('#naming()', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getHttpApiName()', () => {
|
||||
it('should return the composition of service & stage name if custom name not provided and shouldStartNameWithService is true', () => {
|
||||
serverless.service.service = 'myService';
|
||||
serverless.service.provider.httpApi = { shouldStartNameWithService: true };
|
||||
expect(sdk.naming.getHttpApiName()).to.equal(
|
||||
`${serverless.service.service}-${sdk.naming.provider.getStage()}`
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the composition of stage & service name if custom name not provided', () => {
|
||||
serverless.service.service = 'myService';
|
||||
expect(sdk.naming.getHttpApiName()).to.equal(
|
||||
`${sdk.naming.provider.getStage()}-${serverless.service.service}`
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the custom api name if provided', () => {
|
||||
serverless.service.provider.httpApi = { name: 'app-dev-testApi' };
|
||||
serverless.service.service = 'myService';
|
||||
serverless.service.provider.stage = sdk.naming.provider.getStage();
|
||||
expect(sdk.naming.getHttpApiName()).to.equal('app-dev-testApi');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user