Skip to content

Commit 0dc5518

Browse files
authored
Merge pull request #31 from j0k3r/feature/http-api-description
Add ability to set a description for a HttpApi
2 parents f19eb4d + 70d072e commit 0dc5518

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

docs/events/http-api.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ resources:
380380
- Ref: YourCognitoUserPoolName
381381
```
382382

383-
### Event / payload format
383+
## Event / payload format
384384

385385
HTTP API offers only a 'proxy' option for Lambda integration where an event submitted to the function contains the details of HTTP request such as headers, query string parameters etc.
386386
There are two formats for this event available (see [Working with AWS Lambda proxy integrations for HTTP APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html)), with the default being 2.0. It is possible to downgrade to 1.0 version by specifying `payload`. The payload version could be configured globally as:
@@ -405,7 +405,7 @@ functions:
405405
method: GET
406406
```
407407

408-
### Detailed Metrics
408+
## Detailed Metrics
409409

410410
With HTTP API we may configure detailed metrics that can be used setup monitoring and alerting in Cloudwatch.
411411

@@ -417,7 +417,7 @@ provider:
417417
metrics: true
418418
```
419419

420-
### Tags
420+
## Tags
421421

422422
When using HTTP API, it is possible to tag the corresponding API Gateway resources. By setting `provider.httpApi.useProviderTags` to `true`, all tags defined on `provider.tags` will be applied to API Gateway and API Gateway Stage.
423423

@@ -433,7 +433,7 @@ In the above example, the tag project: myProject will be applied to API Gateway
433433

434434
_Note: If the API Gateway has any existing tags applied outside of Serverless Framework, they will be removed during deployment._
435435

436-
### Disable Default Endpoint
436+
## Disable Default Endpoint
437437

438438
By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke your API, disable the default endpoint.
439439

@@ -443,14 +443,18 @@ provider:
443443
disableDefaultEndpoint: true
444444
```
445445

446-
### Service Naming
446+
## Service Naming
447447

448448
You can use the `shouldStartNameWithService` option to change the naming scheme for HTTP API from the default `${stage}-${service}` to `${service}-${stage}`.
449449

450+
You can also define your own name for the API instead of the default generated one and also define a description for it.
451+
450452
```yml
451453
provider:
452454
httpApi:
453455
shouldStartNameWithService: true
456+
name: app-dev-testApi
457+
description: My TestApi
454458
```
455459

456460
## Custom domains

lib/classes/service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const _ = require('lodash');
66
const semver = require('semver');
77
const { log } = require('@serverless/utils/log');
88
const resolveCliInput = require('../cli/resolve-input');
9-
const currentVersion = require('../../package').version;
10-
const isLocallyInstalled = require('../cli/is-locally-installed');
9+
// const currentVersion = require('../../package').version;
10+
// const isLocallyInstalled = require('../cli/is-locally-installed');
1111

1212
class Service {
1313
constructor(serverless, data) {

lib/plugins/aws/lib/naming.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,16 @@ module.exports = {
705705
? `${this.provider.serverless.service.service}-${this.provider.getStage()}`
706706
: `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
707707
},
708+
getHttpApiDescription() {
709+
if (
710+
this.provider.serverless.service.provider.httpApi &&
711+
this.provider.serverless.service.provider.httpApi.description
712+
) {
713+
return `${String(this.provider.serverless.service.provider.httpApi.description)}`;
714+
}
715+
716+
return undefined;
717+
},
708718
getHttpApiLogicalId() {
709719
return 'HttpApi';
710720
},

lib/plugins/aws/package/compile/events/http-api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class HttpApiEvents {
106106
if (this.config.id) return;
107107
const properties = {
108108
Name: this.provider.naming.getHttpApiName(),
109+
Description: this.provider.naming.getHttpApiDescription(),
109110
ProtocolType: 'HTTP',
110111
DisableExecuteApiEndpoint:
111112
this.config.disableDefaultEndpoint == null ? undefined : this.config.disableDefaultEndpoint,

lib/plugins/aws/provider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ class AwsProvider {
10711071
],
10721072
},
10731073
name: { type: 'string' },
1074+
description: { type: 'string' },
10741075
payload: { type: 'string' },
10751076
metrics: { type: 'boolean' },
10761077
useProviderTags: { const: true },

test/unit/lib/plugins/aws/lib/naming.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,4 +1087,15 @@ describe('#naming()', () => {
10871087
expect(sdk.naming.getHttpApiName()).to.equal('app-dev-testApi');
10881088
});
10891089
});
1090+
1091+
describe('#getHttpApiDescription()', () => {
1092+
it('should return nothing if custom description not provided', () => {
1093+
expect(sdk.naming.getHttpApiDescription()).to.equal(undefined);
1094+
});
1095+
1096+
it('should return the custom api description if provided', () => {
1097+
serverless.service.provider.httpApi = { description: 'My TestApi' };
1098+
expect(sdk.naming.getHttpApiDescription()).to.equal('My TestApi');
1099+
});
1100+
});
10901101
});

0 commit comments

Comments
 (0)