Skip to content

Commit c882db1

Browse files
authored
Document how to create individual pages for webhook events (Docs) (#594)
1 parent 14f615f commit c882db1

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

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

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,60 @@ Fern supports two methods for defining webhooks in your OpenAPI specification:
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-
```yaml openapi.yml {4}
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+
20+
```yaml openapi.yml {4, 7-8, 42-48}
1621
webhooks:
1722
newPlant:
1823
post:
19-
operationId: newPlantWebhook
24+
operationId: newPlantWebhook # Defines webhook
25+
summary: New Plant Added
26+
description: Information about a new plant that was added to the store
27+
tags:
28+
- Plants # Creates dedicated page
2029
requestBody:
21-
description: Information about a new Plant in the system
30+
description: The plant data when a new plant is added
2231
content:
2332
application/json:
2433
schema:
25-
$ref: '#/components/schemas/Plant'
34+
description: The Webhook payload for when a new plant is added to the store
35+
properties:
36+
triggerType:
37+
description: The type of event that triggered the request
38+
type: string
39+
example: "new_plant"
40+
payload:
41+
type: object
42+
description: The payload of data sent from the plant store
43+
properties:
44+
plantId:
45+
type: string
46+
description: The unique identifier for the plant
47+
example: "64f1a2b3c5d6e7f8a9b0c1d2"
48+
name:
49+
type: string
50+
description: The name of the plant
51+
example: "Monstera Deliciosa"
52+
price:
53+
type: number
54+
format: float
55+
description: The price of the plant in dollars
56+
example: 29.99
57+
addedAt:
58+
type: string
59+
format: date-time
60+
description: The timestamp when the plant was added
61+
example: "2024-01-15T10:30:00.000Z"
62+
example: # Full payload example for docs
63+
triggerType: "new_plant"
64+
payload:
65+
plantId: "64f1a2b3c5d6e7f8a9b0c1d2"
66+
name: "Monstera Deliciosa"
67+
price: 29.99
68+
addedAt: "2024-01-15T10:30:00.000Z"
2669
responses:
2770
'200':
2871
description: Return a 200 status to indicate that the data was received successfully
@@ -32,13 +75,20 @@ webhooks:
3275
3376
For OpenAPI 3.0, use the `x-fern-webhook: true` extension to define webhooks. Fern will treat the `requestBody` as the webhook payload.
3477

35-
```yaml openapi.yml {6}
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+
83+
```yaml openapi.yml {6-8, 23-25}
3684
paths:
3785
/payment/updated/:
3886
post:
3987
summary: Payment Initiated
4088
operationId: initiatePayment
41-
x-fern-webhook: true
89+
tags:
90+
- Payments # Creates dedicated page
91+
x-fern-webhook: true # Defines webhooks
4292
requestBody:
4393
content:
4494
application/json:
@@ -47,11 +97,15 @@ paths:
4797
properties:
4898
amount:
4999
type: number
100+
example: 99.99
50101
currency:
51102
$ref: '#/components/schemas/Currency'
52103
required:
53104
- amount
54-
- currency
105+
- currency
106+
example: # Full payload example for docs
107+
amount: 99.99
108+
currency: "USD"
55109
```
56110

57111
<Info>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,16 @@ fern/
9898
│ └── openapi.yml # Order webhook OpenAPI spec
9999
└── generators.yml
100100
```
101+
102+
### Create individual documentation pages for each webhook event (OpenAPI)
103+
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)).
105+
106+
Then, reference individual webhook pages using the `subpackage_{tag}.{webhook-event-name}` format, where:
107+
- `{tag}` is the first tag (lowercase) from your webhook definition
108+
- `{webhook-event-name}` is the `operationId` from your webhook definition
109+
110+
```yaml title="docs.yml"
111+
navigation:
112+
- subpackage_plants.newPlantWebhook
113+
```

0 commit comments

Comments
 (0)