Webhooks and callbacks¶
The validation error is moved in webhooks and callbacks too, the same way as in paths:
@app.webhooks.post("item-created")
def item_created(item: Item) -> None:
"""Sent to subscribers when an item is created."""
callback_router = APIRouter()
@callback_router.post("{$callback_url}/updated")
def item_updated(update: ItemUpdate) -> None: ...
@app.post("/items", callbacks=callback_router.routes)
def create_item(item: Item) -> Item:
return item
override_validation_error(app)
| Operation | Documented codes |
|---|---|
POST /items |
200, 400 |
Webhook item-created |
200, 400 |
Callback {$callback_url}/updated |
200, 400 |
Without the override, the three would document 422.