Redocly Webhook Documentation: A Practical OpenAPI 3.1 Guide
Quick answer: In OpenAPI 3.1, document webhooks with the top-level webhooks object, a map of named Path Item Objects that sit next to paths. Each entry describes the request the API provider sends and the response your e
Quick answer: In OpenAPI 3.1, document webhooks with the top-level webhooks object, a map of named Path Item Objects that sit next to paths. Each entry describes the request the API provider sends and the response your endpoint should return, and Redocly renders it as a first-class entry with an event badge. If you are still on OpenAPI 3.0, the x-webhooks extension gives you the same structure until you upgrade.
How the webhooks object works
A webhook reverses the normal direction: the provider sends, and the consumer exposes a URL that receives the event. Because the consumer chooses that URL, often through a separate registration call, the spec does not pin a path as paths does. The map key is the event name, and the value is a Path Item Object, usually with a post operation.
webhooks:
invoicePaid:
post:
summary: An invoice was paid
operationId: invoicePaid
tags:
- Billing events
security:
- WebhookSignature: []
parameters:
- in: header
name: X-Signature
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/InvoicePaidEvent'
responses:
'200':
description: Acknowledged; no response body needed
The requestBody references the event schema, and responses tells the consumer what status code acknowledges delivery. A valid 3.1 document can even contain only webhooks and no paths, since the spec requires at least one of paths, webhooks, or components.
Webhooks versus callbacks
Both model server-to-client HTTP calls, but they answer different integration patterns. Callbacks live inside an operation and tie to a specific request where the client supplies a target URL, while webhooks are standalone, top-level events that are not tied to a preceding call.
| Dimension | Webhooks | Callbacks |
|---|---|---|
| Location | Top-level webhooks object |
Inside a specific operation |
| Trigger | Autonomous event, out of band | Tied to the request that declares it |
| Target URL | Chosen during registration | Provided in the triggering request |
| Best fit | Long-lived event stream | Async result of one call |
Pick callbacks when the push is the delayed result of a single API call, such as a job finishing. Pick webhooks when the provider keeps emitting events over time, like billing or repository changes, with no single owning request. For the wider tooling trade-offs around this workflow, the comparison hub lines the two approaches up side by side.
What the schema alone does not say
OpenAPI describes the message shape, not the delivery contract. The details below belong in prose, and skipping them causes most integration bugs. The table lists what to cover and where.
| Detail | Where it goes | Why it matters |
|---|---|---|
| Event payload and example |
requestBody schema |
Lets consumers validate incoming data |
| Ack status code | responses |
Tells consumers what confirms receipt |
| Retry behavior | Prose | Providers often retry on a non-2xx or timeout |
| Signature header |
parameters and security
|
Consumers verify the sender before trusting data |
| Registration steps | A normal operation | Explains how to subscribe and set the URL |
| Delivery timing | Prose | Event cadence is outside the spec's scope |
Two points earn extra care. Document the retry and idempotency rule: a provider that does not get a 2xx may send the same event again, so the receiver should handle duplicates instead of processing a payment twice. Name the signature header and show verification, since a payload with no authentication story invites forged requests.
A common failure mode
One mistake is treating a webhook like a fixed path and writing a concrete URL into the spec. The consumer owns that URL, so hardcoding it makes the document wrong for every other integration. Another is shipping a schema with no responses block, leaving consumers guessing whether a 200 or 204 is expected. Keep the Path Item focused on the message and put registration and delivery rules in prose.
Frequently asked questions
Can I document webhooks in OpenAPI 3.0? Not with the native keyword. Use the top-level x-webhooks extension, which holds Path Item Objects and renders in Redocly, then move to the built-in webhooks object when you upgrade to 3.1.
Does Redocly render webhooks separately from paths? Yes. Redocly shows each webhook in the sidebar as a first-class entry with an event badge, and you can group it under a tag such as billing events so related operations stay together.
Should I use webhooks or AsyncAPI? OpenAPI webhooks cover HTTP callbacks that fit a request and response model. If your event system uses a broker, persistent channels, or non-HTTP transports, AsyncAPI models those patterns more directly.
Do I need a path for each webhook? No. The map key is the event name, and the consumer supplies the receiving URL through registration. The Path Item describes the message, not a route on the provider.
The bottom line
Treat a webhook entry as a contract for the message and its ack, not as a route and not as proof that your receiver works. Define the event schema and 200 response in OpenAPI 3.1, document retry and signature rules alongside it, and choose callbacks only when a single call owns the push. The reference tells developers what arrives; verifying signatures, handling duplicate delivery, and asserting the event flow still takes real request-level scenario testing, which is where Powerduck focuses alongside code review rather than replacing the work of receiving the events.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.