diff --git a/README.md b/README.md index cc0dc22..8053799 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/serverless-openapi-typescript.ts b/src/serverless-openapi-typescript.ts index 2474a4e..2fe3b34 100644 --- a/src/serverless-openapi-typescript.ts +++ b/src/serverless-openapi-typescript.ts @@ -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}`); } @@ -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}`); } diff --git a/test/fixtures/expect-openapi-full.yml b/test/fixtures/expect-openapi-full.yml index d2ffd30..d872cf0 100644 --- a/test/fixtures/expect-openapi-full.yml +++ b/test/fixtures/expect-openapi-full.yml @@ -247,6 +247,7 @@ webhooks: '200': description: | This is a expected response description + tags: [] tags: - name: Project description: > diff --git a/test/fixtures/expect-openapi-webhooks-custom-tags.yml b/test/fixtures/expect-openapi-webhooks-custom-tags.yml new file mode 100644 index 0000000..2485d38 --- /dev/null +++ b/test/fixtures/expect-openapi-webhooks-custom-tags.yml @@ -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 \ No newline at end of file diff --git a/test/fixtures/expect-openapi-webhooks.yml b/test/fixtures/expect-openapi-webhooks.yml index 98b9b3a..4446885 100644 --- a/test/fixtures/expect-openapi-webhooks.yml +++ b/test/fixtures/expect-openapi-webhooks.yml @@ -31,6 +31,7 @@ webhooks: '200': description: | This is a expected response description + tags: [] tags: - name: Project description: DummyDescription diff --git a/test/serverless-openapi-typescript.spec.ts b/test/serverless-openapi-typescript.spec.ts index 644eb62..cf4088c 100644 --- a/test/serverless-openapi-typescript.spec.ts +++ b/test/serverless-openapi-typescript.spec.ts @@ -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 () => { diff --git a/test/serverless-webhooks-custom-tags/api.d.ts b/test/serverless-webhooks-custom-tags/api.d.ts new file mode 100644 index 0000000..10fd014 --- /dev/null +++ b/test/serverless-webhooks-custom-tags/api.d.ts @@ -0,0 +1,8 @@ +export namespace ProjectApi { + export namespace Webhooks { + export type OnCreateWebhook = { + id: string; + name: string; + } + } +} diff --git a/test/serverless-webhooks-custom-tags/resources/serverless.yml b/test/serverless-webhooks-custom-tags/resources/serverless.yml new file mode 100644 index 0000000..929469b --- /dev/null +++ b/test/serverless-webhooks-custom-tags/resources/serverless.yml @@ -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