Skip to content
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

Support for webhoooks tags #49

Merged
merged 2 commits into from
May 27, 2024
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
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-openapi-typescript",
"version": "2.1.0",
"version": "2.2.0",
"description": "An extension of @conqa/serverless-openapi-documentation that also generates your OpenAPI models from TypeScript",
"main": "dist/index.js",
"scripts": {
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