API Reference¶
Decorators¶
document_action¶
from channels_spectacular import document_action
@document_action(
summary: str = "",
description: str = "",
payload = None,
responses: dict | None = None,
tags: list[str] | None = None,
action: str | None = None,
deprecated: bool = False,
)
Marks a consumer method as a client → server action.
Parameter |
Type |
Description |
|---|---|---|
|
|
Short human-readable description shown in the viewer sidebar |
|
|
Extended Markdown description |
|
see Payload types |
Incoming message schema |
|
|
Events the server emits in response |
|
|
Concrete message examples (see below) |
|
|
Groups the operation in the sidebar |
|
|
Override the inferred action name ( |
|
|
Marks the operation deprecated in the spec |
document_event¶
from channels_spectacular import document_event
@document_event(
event_type: str,
summary: str = "",
description: str = "",
payload = None,
tags: list[str] | None = None,
deprecated: bool = False,
)
Marks a consumer method as a server → client event handler.
Parameter |
Type |
Description |
|---|---|---|
|
|
The dotted event type string, e.g. |
|
|
Short description |
|
|
Extended Markdown description |
|
see Payload types |
Outbound message schema |
|
|
Concrete message examples (see below) |
|
|
Groups the operation in the viewer |
|
|
Marks the operation deprecated |
Examples format¶
Each entry in the examples list is a dict with:
Key |
Required |
Description |
|---|---|---|
|
no |
Short label shown in the viewer (e.g. |
|
no |
One-line description of the example |
|
yes |
Dict of concrete field values |
examples=[
{
"name": "Cash payment",
"summary": "Rider pays with cash at destination",
"payload": {
"action": "request_ride",
"pickup_lat": 6.5244,
"pickup_lng": 3.3792,
"fare": "1500.00",
"payment_method": "cash",
},
},
{
"name": "Card payment",
"payload": {
"action": "request_ride",
"fare": "1800.00",
"payment_method": "card",
},
},
]
Examples are passed through verbatim into the AsyncAPI messages[name].examples
field — no validation or transformation is applied.
AsyncAPIGenerator¶
from channels_spectacular import AsyncAPIGenerator
# Single consumer
generator = AsyncAPIGenerator(
consumer_class,
info: dict | None = None,
servers: dict | None = None,
channel_path: str | None = None,
)
# Multiple consumers
generator = AsyncAPIGenerator(
consumers: list[tuple[type, str]],
info: dict | None = None,
servers: dict | None = None,
)
A low-level generator. Use this when you need the spec as a Python object or YAML string outside of a Django request.
Methods¶
Method |
Returns |
Description |
|---|---|---|
|
|
Full AsyncAPI 3.0 spec as a Python dict |
|
|
YAML-serialized spec string |
Views¶
AsyncAPISpecView¶
GET /ws-docs/asyncapi.yaml
Returns the AsyncAPI spec as application/yaml.
Class attributes (all override CHANNELS_SPECTACULAR_SETTINGS):
Attribute |
Type |
Description |
|---|---|---|
|
|
Single annotated consumer class |
|
|
Multiple |
|
|
AsyncAPI |
|
|
AsyncAPI |
|
|
WebSocket path for the single-consumer case |
Either consumer or consumers must be set; passing neither raises ValueError.
AsyncAPIDocView¶
GET /ws-docs/
Renders the HTML page hosting the AsyncAPI React viewer.
Class attributes:
Attribute |
Type |
Description |
|---|---|---|
|
|
URL of the YAML spec (single-consumer case). Defaults to |
|
|
Multi-consumer mode: renders a switcher dropdown. Takes precedence over |
|
|
Override to provide a custom HTML template |
Management command¶
See Export command for the full export_asyncapi reference.