Skip to content

Commit

Permalink
Support for webhoooks tags
Browse files Browse the repository at this point in the history
  • Loading branch information
eranelbaz committed May 26, 2024
1 parent 872d31d commit b5b2fee
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,26 @@ export namespace MyApi {
}
```

You can also add Webhook tags by using `webhookTags` keyword it will auto add tag to all webhooks
```yaml
custom:
documentation:
apiNamespace: MyApi
webhookTags:
- name: ProjectWebhooks
description: This is the description for ProjectWebhooks
webhooks:
WebhookName:
post:
requestBody:
description: |
This is a request body description
responses:
200:
description: |
This is a expected response description
```


## Install

Expand Down
5 changes: 5 additions & 0 deletions src/serverless-openapi-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default class ServerlessOpenapiTypeScript {
return this.serverless.service.custom.documentation.webhooks || {};
}

get webhookTags() {
return (this.serverless.service.custom.documentation.webhookTags || []).map(tag => tag.name);
}

log(msg) {
this.serverless.cli.log(`[serverless-openapi-typescript] ${msg}`);
}
Expand Down Expand Up @@ -104,6 +108,7 @@ export default class ServerlessOpenapiTypeScript {
const webhook = this.webhooks[webhookName];
const methodDefinition = webhook['post'];
if (methodDefinition) {
methodDefinition.tags = this.webhookTags;
this.setWebhookModels(methodDefinition, webhookName);
this.log(`Generating docs for webhook ${webhookName}`);
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/expect-openapi-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ webhooks:
'200':
description: |
This is a expected response description
tags: []
tags:
- name: Project
description: >
Expand Down
38 changes: 38 additions & 0 deletions test/fixtures/expect-openapi-webhooks-custom-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.1.0
components:
schemas:
ProjectApi.Webhooks.OnCreateWebhook:
type: object
properties:
id:
type: string
name:
type: string
required:
- id
- name
additionalProperties: false
info:
title: ProjectApi
description: DummyDescription
paths: { }
webhooks:
OnCreateWebhook:
post:
requestBody:
description: |
This is a request body description
content:
application/json:
schema:
$ref: >-
#/components/schemas/ProjectApi.Webhooks.OnCreateWebhook
responses:
'200':
description: |
This is a expected response description
tags:
- ProjectWebhooks
tags:
- name: ProjectApi
description: DummyDescription
1 change: 1 addition & 0 deletions test/fixtures/expect-openapi-webhooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ webhooks:
'200':
description: |
This is a expected response description
tags: []
tags:
- name: Project
description: DummyDescription
Expand Down
1 change: 1 addition & 0 deletions test/serverless-openapi-typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('ServerlessOpenapiTypeScript', () => {
${'Hyphenated Functions'} | ${'hyphenated-functions'}
${'Full Project'} | ${'full'}
${'Webhooks'} | ${'webhooks'}
${'Webhooks Tags'} | ${'webhooks-custom-tags'}
`('when using $testCase', ({projectName}) => {

beforeEach(async () => {
Expand Down
8 changes: 8 additions & 0 deletions test/serverless-webhooks-custom-tags/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export namespace ProjectApi {
export namespace Webhooks {
export type OnCreateWebhook = {
id: string;
name: string;
}
}
}
26 changes: 26 additions & 0 deletions test/serverless-webhooks-custom-tags/resources/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
service: serverless-openapi-typescript-demo
provider:
name: aws

plugins:
- ../node_modules/@conqa/serverless-openapi-documentation
- ../src/index

custom:
documentation:
title: 'ProjectApi'
description: DummyDescription
apiNamespace: ProjectApi
webhookTags:
- name: ProjectWebhooks
description: This is the description for ProjectWebhooks
webhooks:
OnCreateWebhook:
post:
requestBody:
description: |
This is a request body description
responses:
200:
description: |
This is a expected response description

0 comments on commit b5b2fee

Please sign in to comment.