Skip to content

Commit 872d31d

Browse files
authored
Add support for webhooks (#47)
1 parent 1b5fd94 commit 872d31d

14 files changed

+276
-33
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Works well with [Stoplight.io](https://stoplight.io/)
2323
- [`cookieParams`](#cookieparams)
2424
- [`requestModels`](#requestmodels)
2525
- [`methodResponses`](#methodresponses-and-responsemodels)
26+
- [`webhooks`](#webhooks)
2627
- [Install](#install)
2728

2829
---
@@ -114,6 +115,7 @@ The `documentation` section of the event configuration can contain the following
114115
* `pathParams`: a list of path parameters (see [pathParams](#pathparams) below) - **these _can_ be autogenerated for you from TypeScript**
115116
* `cookieParams`: a list of cookie parameters (see [cookieParams](#cookieparams) below)
116117
* `methodResponses`: an array of response models and applicable status codes (see [methodResponses](#methodresponses-and-responsemodels)) - **these _will_ be autogenerated for you from TypeScript**
118+
* `webhooks`: an object with all the webhooks with descriptions (see [webhooks](#webhooks)) - **these _will_ be autogenerated for you from TypeScript**
117119

118120
```yml
119121
functions:
@@ -435,6 +437,68 @@ functions:
435437

436438
Endpoints that are not attached to a custom tag, are still attached to the title ( which is the default tag ).
437439

440+
#### `webhooks`
441+
OpenAPI have an option to add your application `webhooks`, while this feature isn't supported by `serverless`.
442+
443+
For those the plugin will look for the webhooks under `custom.documentation.webhooks`.
444+
445+
For example
446+
447+
```yaml
448+
custom:
449+
documentation:
450+
apiNamespace: MyApi
451+
webhooks:
452+
WebhookName:
453+
post:
454+
requestBody:
455+
description: |
456+
This is a request body description
457+
responses:
458+
200:
459+
description: |
460+
This is a expected response description
461+
```
462+
463+
this will generate the next OpenAPI file
464+
465+
```yaml
466+
components:
467+
schemas:
468+
MyApi.Webhooks.WebhookName:
469+
type: object
470+
webhooks:
471+
WebhookName:
472+
post:
473+
requestBody:
474+
description: |
475+
This is a request body description
476+
content:
477+
application/json:
478+
schema:
479+
$ref: '#/components/schemas/MyApi.Webhooks.WebhookName'
480+
responses:
481+
'200':
482+
description: |
483+
This is a expected response description
484+
```
485+
486+
With the next `api.d.ts`:
487+
488+
```typescript
489+
export namespace MyApi {
490+
export namespace Webhooks {
491+
export type WebhookName = {
492+
id: string,
493+
name: string,
494+
age: number
495+
// ...
496+
}
497+
}
498+
}
499+
```
500+
501+
438502
## Install
439503

440504
This plugin is **an extension**.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-openapi-typescript",
3-
"version": "2.0.0",
3+
"version": "2.1.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": {
@@ -14,6 +14,7 @@
1414
"ts-json-schema-generator": "^1.1.2"
1515
},
1616
"devDependencies": {
17+
"@types/node": "20.12.11",
1718
"@conqa/serverless-openapi-documentation": "^1.1.0",
1819
"@types/jest": "^27.0.1",
1920
"@types/serverless": "^1.78.35",

0 commit comments

Comments
 (0)