Skip to content

Add ability to set a description for a HttpApi #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/events/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ resources:
- Ref: YourCognitoUserPoolName
```

### Event / payload format
## Event / payload format

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.
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:
Expand All @@ -405,7 +405,7 @@ functions:
method: GET
```

### Detailed Metrics
## Detailed Metrics

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

Expand All @@ -417,7 +417,7 @@ provider:
metrics: true
```

### Tags
## Tags

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.

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

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

### Disable Default Endpoint
## Disable Default Endpoint

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.

Expand All @@ -443,14 +443,18 @@ provider:
disableDefaultEndpoint: true
```

### Service Naming
## Service Naming

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

You can also define your own name for the API instead of the default generated one and also define a description for it.

```yml
provider:
httpApi:
shouldStartNameWithService: true
name: app-dev-testApi
description: My TestApi
```

## Custom domains
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const _ = require('lodash');
const semver = require('semver');
const { log } = require('@serverless/utils/log');
const resolveCliInput = require('../cli/resolve-input');
const currentVersion = require('../../package').version;
const isLocallyInstalled = require('../cli/is-locally-installed');
// const currentVersion = require('../../package').version;
// const isLocallyInstalled = require('../cli/is-locally-installed');

class Service {
constructor(serverless, data) {
Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/aws/lib/naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,16 @@ module.exports = {
? `${this.provider.serverless.service.service}-${this.provider.getStage()}`
: `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
},
getHttpApiDescription() {
if (
this.provider.serverless.service.provider.httpApi &&
this.provider.serverless.service.provider.httpApi.description
) {
return `${String(this.provider.serverless.service.provider.httpApi.description)}`;
}

return undefined;
},
getHttpApiLogicalId() {
return 'HttpApi';
},
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/package/compile/events/http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class HttpApiEvents {
if (this.config.id) return;
const properties = {
Name: this.provider.naming.getHttpApiName(),
Description: this.provider.naming.getHttpApiDescription(),
ProtocolType: 'HTTP',
DisableExecuteApiEndpoint:
this.config.disableDefaultEndpoint == null ? undefined : this.config.disableDefaultEndpoint,
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ class AwsProvider {
],
},
name: { type: 'string' },
description: { type: 'string' },
payload: { type: 'string' },
metrics: { type: 'boolean' },
useProviderTags: { const: true },
Expand Down
11 changes: 11 additions & 0 deletions test/unit/lib/plugins/aws/lib/naming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,15 @@ describe('#naming()', () => {
expect(sdk.naming.getHttpApiName()).to.equal('app-dev-testApi');
});
});

describe('#getHttpApiDescription()', () => {
it('should return nothing if custom description not provided', () => {
expect(sdk.naming.getHttpApiDescription()).to.equal(undefined);
});

it('should return the custom api description if provided', () => {
serverless.service.provider.httpApi = { description: 'My TestApi' };
expect(sdk.naming.getHttpApiDescription()).to.equal('My TestApi');
});
});
});