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

Add support for webhooks #47

Merged
merged 7 commits into from
May 15, 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
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