What gets inferred
Every extractor and return type in a handler signature describes itself. This page lists what each one adds to the document.
Requests
| In the signature | In the document |
|---|---|
Json<T>, Form<T>, String, Bytes | request body, plus axum's own rejections (400, 413, 415, 422 as plain text) |
Path<T> / Params<T> | path parameters: scalars, structs by field name, tuples by position, #[serde(flatten)] |
Query<T> (axum or validated) | query parameters with required taken from the schema, plus 400 |
Body<T>, Query<T>, Params<T> | 400 (and 413, 415 for bodies) with RequestRejection |
Auth<C> / Option<Auth<C>> | bearerAuth security scheme, security and 401 |
Headers<T> / Cookies<T> | one header or cookie parameter per field, plus 400 (Validation) |
Upload<T> | a multipart/form-data body, File fields as binary strings, plus 400, 413, 415 (Uploads) |
Multipart, WebSocketUpgrade | a multipart/form-data object body, a 101 response |
Socket<In, Out> | a 101 response and x-autodoc-websocket with both schemas (WebSockets) |
Security is decided once per operation, whatever the order of the arguments. Every scheme the route requires (a required input, .detail(..security..), a group's guard) is in one requirement object, so all of them are needed. The sides of an Either and an Option (the input or nothing) are alternatives, and the required schemes are added to each, so the anonymous {} is left only when nothing is required (Auth).
Path parameters always match the route template: every {name} segment is documented (as a string when the extractor does not describe it), and a parameter that is not in the template is dropped.
Responses
| In the signature | In the document |
|---|---|
Json<T> / Created<T> / NoContent | 200 / 201 / 204 |
Status<201, T> | the responses of T, with its success status moved to 201 |
StatusCode | a default response with no body |
(StatusCode, T) | T's responses under default, since the status is only known at run time |
(HeaderMap, T), ([(K, V); N], T), AppendHeaders<_> | as T; with a leading StatusCode, as (StatusCode, T) |
EventStream<T> / Sse<S> | 200 as text/event-stream (Event streams) |
Redirect | 303, 307 and 308, described as "Redirect" |
Response | nothing |
Result<T, E: DocError> | the success response plus every status E lists |
Status<C, T> is the way to answer with another success status while keeping the body documented:
pub async fn upload_avatar(
State(state): State<AppState>,
Params(path): Params<UserPath>,
Upload(form): Upload<NewAvatar>,
) -> Result<Status<201, Json<AvatarResponse>>, FindUserError> {C must be between 100 and 999, or the code does not build. A tuple that starts with a StatusCode can answer with any status at run time, so the document says default, which the test client accepts for every status.
Returning impl IntoResponse
An opaque impl IntoResponse hides what the handler returns, so there is nothing to read the statuses from, and the route does not compile. Return Response when you build the response by hand, which documents nothing, and add the statuses with #[api(response(..))]:
#[api(response(200, "The service banner"))]
async fn banner() -> Response {
(StatusCode::OK, "user-api").into_response()
}A typed error lists its statuses once, in DocError, and every handler that returns it gets them:
impl DocError for FindUserError {
fn responses() -> Vec<(u16, &'static str)> {
vec![(404, "user not found")]
}
fn describe(cx: &mut DocContext<'_>) {
cx.error_responses::<ErrorResponse>(&Self::responses());
}
}axum and axum-extra coverage
Every row compiles as a handler argument or return type and documents what it says. axum 0.8 types need no feature unless noted; axum-extra 0.12 types need the extra feature (see Compatibility).
Extractors
| Type | In the document |
|---|---|
Json<T>, Form<T> | request body and the 400, 413, 415, 422 rejections (Form<T> on a method without a body is read as the query) |
Path<T>, Query<T> | path and query parameters, plus 400 |
String, Bytes | a text/plain or application/octet-stream body, plus 400/413 or 413 |
Body | an application/octet-stream body, no rejection |
RawForm | an untyped application/x-www-form-urlencoded object body plus 400, 413 and 415 on every method but GET; nothing on GET |
RawPathParams | every {name} of the route as a string path parameter, plus 400 |
Multipart | a multipart/form-data object body (feature multipart) |
WebSocketUpgrade | a 101 response (feature ws) |
State, Extension, ConnectInfo, HeaderMap, Method, Uri, OriginalUri, MatchedPath, NestedPath, RawQuery, Request, Parts, Version | nothing, they read the request but add no parameter |
Option<T> | T, with its body and parameters optional |
Result<T, T::Rejection> | T's body and parameters without its 4xx rejections, since the handler sees the rejection and decides what to answer |
axum_extra::TypedHeader<H> | a required header parameter named H::name() with a string schema, plus 400 |
CookieJar, SignedCookieJar<K>, PrivateCookieJar<K> | nothing, the cookie names are not known |
axum_extra::extract::Host | 400 as plain text |
axum_extra::extract::{Query<T>, OptionalQuery<T>, Form<T>} | like axum's, and arrays are read; OptionalQuery makes the parameters optional |
axum_extra::extract::WithRejection<E, R> | E's input, with E's own rejection responses replaced by one default response with no body, since R is yours |
JsonLines<S> as an input | a required application/jsonl body: under 3.2 {"itemSchema": {}} with no schema, under 3.1 and 3.0 a string schema plus x-autodoc-item-schema: {} |
Either to Either8 as an input | every side's parameters and body, all optional (path parameters stay required); each side's security is an alternative, with the schemes the operation requires added to it (a side that needs none adds the anonymous {} only when nothing is required); the last side keeps its rejections |
Responses
| Type | In the document |
|---|---|
Json<T>, Html<T>, String, &'static str, Cow<'static, str>, Box<str> | 200 as application/json, text/html or text/plain |
Bytes, Vec<u8>, Box<[u8]>, Cow<'static, [u8]>, &'static [u8], [u8; N], Body | 200 as application/octet-stream, a binary string (a Blob in the TypeScript client) |
HeaderMap, [(K, V); N], AppendHeaders<I>, Extension<T> alone | an empty 200 |
(Extension<T>, U), parts followed by U, with an optional leading StatusCode | as U, or U under default with a leading StatusCode; up to four parts of HeaderMap, arrays, AppendHeaders and Extension, plus TypedHeader and the cookie jars with extra |
Result<T, E> where E is StatusCode, (StatusCode, String), (StatusCode, &'static str), (StatusCode, Json<U>), Infallible, Response or Redirect | T's responses, plus for E respectively: default with no body, default as text/plain, default as text/plain, default with U's JSON, nothing, default with no body, 303, 307 and 308 |
JsonLines<S> as a response | 200 as application/jsonl: under 3.2 {"itemSchema": {}} with no schema, under 3.1 and 3.0 a string schema plus x-autodoc-item-schema: {} |
ErasedJson | 200 as application/json with an open schema, plus a 500 as plain text |
Attachment<T> | as T |
Either to Either8 as a response | every side's responses; the media types of a shared status become a oneOf |
What the document does not see
These are written by the type at run time, so the document and the wire can differ:
axum::body::Bodyas a response sets nocontent-type, though it is documented asapplication/octet-stream. Set the header in the handler, with a([(CONTENT_TYPE, "application/octet-stream")], body)tuple.axum_extra::response::JsonLinessets noContent-Typeeither, though it is documented asapplication/jsonl. Set it in the handler the same way.Attachment'scontent_type()is chosen at run time and the document does not see it, so it showsT's media type.ErasedJsondocuments a500because it answers one when serialization fails.Hostdocuments400, the status its rejection answers.WithRejection<E, R>documentsE's input and adefaultresponse with no body for the rejection, sinceRis yours.Headers<T>with a#[serde(flatten)]field matches only lowercase header names.BytesMutis not supported. UseBytesorVec<u8>.JsonLinesdocuments an empty item schema ({}, any JSON value), because the item type is not part of the signature that can be read.impl IntoResponseis not supported (below): returnResponseand add statuses with#[api(response(..))].
Operations
| From | In the document |
|---|---|
| handler function name | operationId (deduplicated across modules) and a default summary |
/// doc comment | summary (first line) and description (the rest), with #[api] |
#[deprecated] | deprecated: true, with #[api] |
list_users becomes operation list_users with the summary "List users". Generic arguments are stripped, so search::<InMemory> is still search. An explicit operation_id always wins and is reserved before generated ids are deduplicated.
Schemas
Schemas live once under #/components/schemas and are referenced with $ref. Only schemas reachable from a published operation are kept, so hidden or excluded routes do not leak their types.
Request types are described the way serde deserializes them and response types the way serde serializes them:
- an
Option<T>field is optional in a request body, - but required and nullable in a response.
When one type is used in both directions and the two shapes differ, the request side is named …Input, for example Note and NoteInput.
Nothing to register
There is no list of schemas or paths to maintain. If a type appears in a handler, it appears in the document.