Skip to content

Commit 9d79324

Browse files
authored
Support for webhoooks tags (#49)
1 parent 872d31d commit 9d79324

9 files changed

+101
-1
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,26 @@ export namespace MyApi {
498498
}
499499
```
500500

501+
You can also add Webhook tags by using `webhookTags` keyword it will auto add tag to all webhooks
502+
```yaml
503+
custom:
504+
documentation:
505+
apiNamespace: MyApi
506+
webhookTags:
507+
- name: ProjectWebhooks
508+
description: This is the description for ProjectWebhooks
509+
webhooks:
510+
WebhookName:
511+
post:
512+
requestBody:
513+
description: |
514+
This is a request body description
515+
responses:
516+
200:
517+
description: |
518+
This is a expected response description
519+
```
520+
501521

502522
## Install
503523

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-openapi-typescript",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "An extension of @conqa/serverless-openapi-documentation that also generates your OpenAPI models from TypeScript",
55
"main": "dist/index.js",
66
"scripts": {

src/serverless-openapi-typescript.ts

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export default class ServerlessOpenapiTypeScript {
6969
return this.serverless.service.custom.documentation.webhooks || {};
7070
}
7171

72+
get webhookTags() {
73+
return (this.serverless.service.custom.documentation.webhookTags || []).map(tag => tag.name);
74+
}
75+
7276
log(msg) {
7377
this.serverless.cli.log(`[serverless-openapi-typescript] ${msg}`);
7478
}
@@ -104,6 +108,7 @@ export default class ServerlessOpenapiTypeScript {
104108
const webhook = this.webhooks[webhookName];
105109
const methodDefinition = webhook['post'];
106110
if (methodDefinition) {
111+
methodDefinition.tags = this.webhookTags;
107112
this.setWebhookModels(methodDefinition, webhookName);
108113
this.log(`Generating docs for webhook ${webhookName}`);
109114
}

test/fixtures/expect-openapi-full.yml

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ webhooks:
247247
'200':
248248
description: |
249249
This is a expected response description
250+
tags: []
250251
tags:
251252
- name: Project
252253
description: >
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
openapi: 3.1.0
2+
components:
3+
schemas:
4+
ProjectApi.Webhooks.OnCreateWebhook:
5+
type: object
6+
properties:
7+
id:
8+
type: string
9+
name:
10+
type: string
11+
required:
12+
- id
13+
- name
14+
additionalProperties: false
15+
info:
16+
title: ProjectApi
17+
description: DummyDescription
18+
paths: { }
19+
webhooks:
20+
OnCreateWebhook:
21+
post:
22+
requestBody:
23+
description: |
24+
This is a request body description
25+
content:
26+
application/json:
27+
schema:
28+
$ref: >-
29+
#/components/schemas/ProjectApi.Webhooks.OnCreateWebhook
30+
responses:
31+
'200':
32+
description: |
33+
This is a expected response description
34+
tags:
35+
- ProjectWebhooks
36+
tags:
37+
- name: ProjectApi
38+
description: DummyDescription

test/fixtures/expect-openapi-webhooks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ webhooks:
3131
'200':
3232
description: |
3333
This is a expected response description
34+
tags: []
3435
tags:
3536
- name: Project
3637
description: DummyDescription

test/serverless-openapi-typescript.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('ServerlessOpenapiTypeScript', () => {
1717
${'Hyphenated Functions'} | ${'hyphenated-functions'}
1818
${'Full Project'} | ${'full'}
1919
${'Webhooks'} | ${'webhooks'}
20+
${'Webhooks Tags'} | ${'webhooks-custom-tags'}
2021
`('when using $testCase', ({projectName}) => {
2122

2223
beforeEach(async () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export namespace ProjectApi {
2+
export namespace Webhooks {
3+
export type OnCreateWebhook = {
4+
id: string;
5+
name: string;
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
service: serverless-openapi-typescript-demo
2+
provider:
3+
name: aws
4+
5+
plugins:
6+
- ../node_modules/@conqa/serverless-openapi-documentation
7+
- ../src/index
8+
9+
custom:
10+
documentation:
11+
title: 'ProjectApi'
12+
description: DummyDescription
13+
apiNamespace: ProjectApi
14+
webhookTags:
15+
- name: ProjectWebhooks
16+
description: This is the description for ProjectWebhooks
17+
webhooks:
18+
OnCreateWebhook:
19+
post:
20+
requestBody:
21+
description: |
22+
This is a request body description
23+
responses:
24+
200:
25+
description: |
26+
This is a expected response description

0 commit comments

Comments
 (0)