Skip to content

Commit

Permalink
Add support for webhooks (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
eranelbaz authored May 15, 2024
1 parent 1b5fd94 commit 872d31d
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 33 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Works well with [Stoplight.io](https://stoplight.io/)
- [`cookieParams`](#cookieparams)
- [`requestModels`](#requestmodels)
- [`methodResponses`](#methodresponses-and-responsemodels)
- [`webhooks`](#webhooks)
- [Install](#install)

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

```yml
functions:
Expand Down Expand Up @@ -435,6 +437,68 @@ functions:

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

#### `webhooks`
OpenAPI have an option to add your application `webhooks`, while this feature isn't supported by `serverless`.

For those the plugin will look for the webhooks under `custom.documentation.webhooks`.

For example

```yaml
custom:
documentation:
apiNamespace: MyApi
webhooks:
WebhookName:
post:
requestBody:
description: |
This is a request body description
responses:
200:
description: |
This is a expected response description
```

this will generate the next OpenAPI file

```yaml
components:
schemas:
MyApi.Webhooks.WebhookName:
type: object
webhooks:
WebhookName:
post:
requestBody:
description: |
This is a request body description
content:
application/json:
schema:
$ref: '#/components/schemas/MyApi.Webhooks.WebhookName'
responses:
'200':
description: |
This is a expected response description
```

With the next `api.d.ts`:

```typescript
export namespace MyApi {
export namespace Webhooks {
export type WebhookName = {
id: string,
name: string,
age: number
// ...
}
}
}
```


## Install

This plugin is **an extension**.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-openapi-typescript",
"version": "2.0.0",
"version": "2.1.0",
"description": "An extension of @conqa/serverless-openapi-documentation that also generates your OpenAPI models from TypeScript",
"main": "dist/index.js",
"scripts": {
Expand All @@ -14,6 +14,7 @@
"ts-json-schema-generator": "^1.1.2"
},
"devDependencies": {
"@types/node": "20.12.11",
"@conqa/serverless-openapi-documentation": "^1.1.0",
"@types/jest": "^27.0.1",
"@types/serverless": "^1.78.35",
Expand Down
Loading

0 comments on commit 872d31d

Please sign in to comment.