OpenAPI: Webhookイベント配信定義
OpenAPI 3.0でWebhookコールバックエンドポイントとイベントペイロードを文書化。イベントタイプ、署名検証ヘッダー、リトライポリシー、ペイロードスキーマを解説。
Webhooks
詳細な説明
OpenAPIでのWebhookの文書化
Webhookはイベント発生時に外部システムに通知するサーバー間HTTPコールバックです。OpenAPI 3.1では専用のwebhooksセクションが導入されましたが、3.0でもコールバックオブジェクトや期待されるペイロードスキーマの定義で文書化できます。
Webhookエンドポイント(受信側)
コンシューマーのエンドポイントが受け入れるべき内容を文書化します:
paths:
/webhooks/receive:
post:
summary: Receive webhook events
description: |
Your server should expose this endpoint to receive
webhook events. Verify the X-Webhook-Signature header
before processing.
parameters:
- name: X-Webhook-Signature
in: header
required: true
schema:
type: string
description: HMAC-SHA256 signature for payload verification
- name: X-Webhook-Event
in: header
required: true
schema:
type: string
enum:
- order.created
- order.updated
- payment.completed
- payment.failed
description: The event type
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookPayload'
responses:
'200':
description: Event received and acknowledged
'400':
description: Invalid signature or payload
Webhookペイロードスキーマ
components:
schemas:
WebhookPayload:
type: object
required:
- id
- event
- timestamp
- data
properties:
id:
type: string
description: Unique event ID for idempotency
event:
type: string
description: Event type (e.g., order.created)
timestamp:
type: string
description: ISO 8601 timestamp
data:
type: object
description: Event-specific payload data
署名検証
署名アルゴリズムを文書化します:通常、共有シークレットを使用した生リクエストボディのHMAC-SHA256。検証のためのサンプルコードまたはSDKドキュメントへの参照を含めます。
リトライポリシー
リトライ動作を文書化します:失敗した配信を何回リトライするか、バックオフ戦略(指数関数、固定間隔)、タイムアウトウィンドウ。これはWebhookコンシューマーが適切な処理を実装するための重要な情報です。
ユースケース
決済ゲートウェイ、ECプラットフォーム、またはカスタマーサーバーにイベント通知を送信するSaaS製品の文書化に使用。Stripeのような決済イベント、注文ステータス更新、CI/CDパイプライン通知に不可欠。