[Suggestion] Support OpenAPI 3.1 webhooks in code via @api.webhook(...) or similar
Author: oliverhaasCreated May 24, 2026Updated Jun 6, 2026
In my projects I often need to define the payload/schema for webhooks, and OpenAPI 3.1 supports this via "webhooks" (duh...). I would suggest adding a more convenient support for this to django-ninja:
from ninja import NinjaAPI, Schema
class Pet(Schema):
id: int
name: str
api = NinjaAPI()
@api.webhook("petCreated")
def pet_created(request, payload: Pet):
"""Fired when a pet is added to the catalog."""
# Never called - signature is read only to derive the requestBody.Renders in Swagger UI as a top-level Webhooks section, with Pet shared in components.schemas:
I can imagine a few different approaches to this, so let me know if there is any preference for something else.
I will open a PR in a second to show better what I mean.
Source: vitalik/django-ninja