Skip to content

Commit 3116064

Browse files
authored
Add Fern Definition syntax for generating individual pages per webhook event (Docs, API Definitions) (#685)
1 parent 306129e commit 3116064

File tree

3 files changed

+75
-22
lines changed

3 files changed

+75
-22
lines changed

fern/products/api-def/ferndef-pages/webhooks.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,24 @@ You can inline the schema of the payload by doing the following:
6363
```
6464
</CodeBlock>
6565
66+
## Generate webhook reference
67+
68+
Fern Docs can automatically generate your webhook reference documentation from your definition. Set this up in your `docs.yml` file.
69+
70+
Your webhook reference can be a single documentation page:
71+
72+
```yml docs.yml
73+
navigation:
74+
- api: Webhook Reference # Display name for this page
75+
api-name: webhooks-v1 # Directory containing webhook definition
76+
```
77+
78+
Or you can configure individual documentation pages per webhook event:
79+
80+
```yaml title="docs.yml"
81+
navigation:
82+
- subpackage_api.newPlantWebhook # Format: subpackage_{name-of-api}.{webhook-event-name}
83+
```
84+
85+
For more information on how to configure your webhook reference in `docs.yml`, see [Generate your webhook reference](/docs/api-references/generate-webhook-reference).
86+

fern/products/api-def/openapi-pages/webhooks.mdx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ Fern supports two methods for defining webhooks in your OpenAPI specification:
88
1. Using OpenAPI 3.1's native webhook support (recommended)
99
2. Using Fern's `x-fern-webhook` extension
1010

11-
## OpenAPI 3.1 Webhooks
11+
## OpenAPI 3.1 webhooks
1212

1313
For OpenAPI 3.1 specifications, use the `webhooks` top-level field to define your webhook operations. Each webhook requires an `operationId` to be properly processed by Fern.
1414

15-
To create dedicated pages in your API reference documentation for each webhook
16-
event, include `tags` and complete `example` data in your schema. Then, [add a
17-
reference in your
18-
`docs.yml`](/docs/api-references/generate-webhook-reference#create-individual-documentation-pages-for-each-webhook-event-openapi).
19-
2015
```yaml openapi.yml {4, 7-8, 42-48}
2116
webhooks:
2217
newPlant:
@@ -71,15 +66,10 @@ webhooks:
7166
description: Return a 200 status to indicate that the data was received successfully
7267
```
7368
74-
## Fern Webhook Extension
69+
## Fern webhook extension
7570
7671
For OpenAPI 3.0, use the `x-fern-webhook: true` extension to define webhooks. Fern will treat the `requestBody` as the webhook payload.
7772

78-
To create dedicated pages in your API reference documentation for each webhook
79-
event, include `tags` and complete `example` data in your schema. Then, [add a
80-
reference in your
81-
`docs.yml`](/docs/api-references/generate-webhook-reference#create-individual-documentation-pages-for-each-webhook-event-openapi).
82-
8373
```yaml openapi.yml {6-8, 23-25}
8474
paths:
8575
/payment/updated/:
@@ -112,3 +102,24 @@ paths:
112102
The path that you choose when defining a webhook can be arbitrary. Since webhooks
113103
can be sent to any server, Fern just ignores the path.
114104
</Info>
105+
106+
## Generate webhook reference
107+
108+
Fern Docs can automatically generate your webhook reference documentation from your definition. Set this up in your `docs.yml` file.
109+
110+
Your webhook reference can be a single documentation page:
111+
112+
```yml docs.yml
113+
navigation:
114+
- api: Webhook Reference # Display name for this page
115+
api-name: webhooks-v1 # Name of webhook definition directory
116+
```
117+
118+
Or you can configure individual documentation pages per webhook event:
119+
120+
```yaml title="docs.yml"
121+
navigation:
122+
- subpackage_plants.newPlantWebhook # subpackage_{tag}.{webhook-event-name}
123+
```
124+
125+
For more information on how to configure your webhook reference in `docs.yml`, see [Generate your webhook reference](/docs/api-references/generate-webhook-reference).

fern/products/docs/pages/api-references/generate-webhook-ref.mdx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Generate your Webhook Reference
3-
description: Use Fern Docs to generate your Webhook Reference documentation from your API definition, using your choice of either OpenAPI or Fern Definition.
2+
title: Generate your webhook reference
3+
description: Use Fern Docs to generate your webhook reference documentation from your API definition, using your choice of either OpenAPI or Fern Definition.
44
---
55

6-
Similar to API References, Fern Docs can automatically generate your Webhook Reference documentation from your API definition.
6+
Similar to API References, Fern Docs can automatically generate your webhook reference documentation from your API definition.
77

88
Fern supports webhooks through:
99
- **OpenAPI 3.1+**: Use the native `webhooks` field with an `operationId` (recommended)
@@ -14,7 +14,9 @@ For more information on how to define webhooks, see:
1414
- [Webhooks in OpenAPI](../../openapi-definition/endpoints/webhooks)
1515
- [Webhooks in Fern Definition](../../fern-definition/webhooks)
1616

17-
Example:
17+
## Configure your webhook reference
18+
19+
Add a page title (`api`) and reference the name of the directory where your where your webhook definition is located (`api-name`).
1820

1921
```yml docs.yml {11-12}
2022
navigation:
@@ -31,9 +33,9 @@ navigation:
3133
api-name: webhooks-v1
3234
```
3335
34-
For a real-world example of webhook documentation generated from an API definition, check out [Webflow's Webhooks](https://developers.webflow.com/data/reference/webhooks/events/form-submission).
36+
For a real-world example of webhook documentation generated from an API definition, check out [Webflow's webhooks](https://developers.webflow.com/data/reference/webhooks/events/form-submission).
3537
36-
### Directory Structure
38+
### Directory structure
3739
Your webhooks should be defined in a dedicated folder within your Fern project:
3840
3941
<Tabs>
@@ -73,7 +75,7 @@ You can read more about how to define webhooks in your Fern Definition [here](/l
7375
</Tab>
7476
</Tabs>
7577

76-
### Include more than one Webhook Reference
78+
### Include more than one webhook reference
7779
To include multiple webhook definitions in your documentation, use the `webhook-name` property:
7880

7981
```yaml title="docs.yml"
@@ -99,15 +101,34 @@ fern/
99101
└── generators.yml
100102
```
101103

102-
### Create individual documentation pages for each webhook event (OpenAPI)
104+
### Create individual documentation pages for each webhook event
103105

104-
To display each webhook event as an individual page with rich examples, you need to define `tags` and `example` [in your webhook specification](/api-definitions/openapi/endpoints/webhooks) (or [overrides file](/api-definitions/overview/overrides)).
106+
To display each webhook event as an individual page with rich examples:
105107

106-
Then, reference individual webhook pages using the `subpackage_{tag}.{webhook-event-name}` format, where:
108+
<Tabs>
109+
<Tab title="OpenAPI">
110+
Reference individual webhook pages using the `subpackage_{tag}.{webhook-event-name}` format, where:
107111
- `{tag}` is the first tag (lowercase) from your webhook definition
108112
- `{webhook-event-name}` is the `operationId` from your webhook definition
109113

110114
```yaml title="docs.yml"
111115
navigation:
112116
- subpackage_plants.newPlantWebhook
113117
```
118+
119+
<Note>
120+
For OpenAPI, you must have the `tags` and `example` properties defined [in your webhook specification](/api-definitions/openapi/endpoints/webhooks).
121+
</Note>
122+
123+
</Tab>
124+
<Tab title="Fern Definition">
125+
Reference the individual webhook event using the `subpackage_{name}.{webhook-event-name}` format, where:
126+
- `{name}` is the name of your API as defined in the `api.yml` file for your webhook definition.
127+
- `{webhook-event-name}` is the identifier from your webhook definition
128+
129+
```yaml title="docs.yml"
130+
navigation:
131+
- subpackage_api.newPlantWebhook
132+
```
133+
</Tab>
134+
</Tabs>

0 commit comments

Comments
 (0)