How do you document and test webhook or callback endpoints (server-initiated calls to a client-registered URL) in OpenAPI 3.1?
Short answer
OpenAPI 3.1 introduced the `webhooks` top-level field (distinct from regular `paths`), specifically for documenting server-to-client callback patterns where your API calls a URL the client registered, rather than the client calling your API -- letting you describe the expected…
Advertisement
AModel answer
OpenAPI 3.1 introduced the `webhooks` top-level field (distinct from regular `paths`), specifically for documenting server-to-client callback patterns where your API calls a URL the client registered, rather than the client calling your API -- letting you describe the expected payload shape a webhook consumer should expect to receive, which Swashbuckle and newer OpenAPI tooling increasingly support as OpenAPI 3.1 adoption grows.
Example
// Conceptual OpenAPI 3.1 webhooks section (YAML) // webhooks: // orderCompleted: // post: // requestBody: // content: // application/json: // schema: // $ref: '#/components/schemas/OrderCompletedPayload'
Real-world example
A payments platform documents its webhook payload shape (sent to merchant-registered callback URLs when a payment completes) using OpenAPI 3.1's webhooks section, giving integrators a clear, versioned contract for what their webhook receiver endpoint should expect.
Likely follow-ups
- What OpenAPI version does Swashbuckle currently target, and does it support 3.1's webhooks field?
- How do webhook payloads differ from a typical request/response documented in `paths`?
Related topics