Skip to content

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 signatureIn the document
Json<T>, Form<T>, String, Bytesrequest 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, WebSocketUpgradea 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 signatureIn the document
Json<T> / Created<T> / NoContent200 / 201 / 204
Status<201, T>the responses of T, with its success status moved to 201
StatusCodea 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)
Redirect303, 307 and 308, described as "Redirect"
Responsenothing
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:

rust
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(..))]:

rust
#[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:

rust
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 ​

TypeIn 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, Bytesa text/plain or application/octet-stream body, plus 400/413 or 413
Bodyan application/octet-stream body, no rejection
RawForman untyped application/x-www-form-urlencoded object body plus 400, 413 and 415 on every method but GET; nothing on GET
RawPathParamsevery {name} of the route as a string path parameter, plus 400
Multiparta multipart/form-data object body (feature multipart)
WebSocketUpgradea 101 response (feature ws)
State, Extension, ConnectInfo, HeaderMap, Method, Uri, OriginalUri, MatchedPath, NestedPath, RawQuery, Request, Parts, Versionnothing, 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::Host400 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 inputa 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 inputevery 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 ​

TypeIn 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], Body200 as application/octet-stream, a binary string (a Blob in the TypeScript client)
HeaderMap, [(K, V); N], AppendHeaders<I>, Extension<T> alonean empty 200
(Extension<T>, U), parts followed by U, with an optional leading StatusCodeas 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 RedirectT'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 response200 as application/jsonl: under 3.2 {"itemSchema": {}} with no schema, under 3.1 and 3.0 a string schema plus x-autodoc-item-schema: {}
ErasedJson200 as application/json with an open schema, plus a 500 as plain text
Attachment<T>as T
Either to Either8 as a responseevery 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::Body as a response sets no content-type, though it is documented as application/octet-stream. Set the header in the handler, with a ([(CONTENT_TYPE, "application/octet-stream")], body) tuple.
  • axum_extra::response::JsonLines sets no Content-Type either, though it is documented as application/jsonl. Set it in the handler the same way.
  • Attachment's content_type() is chosen at run time and the document does not see it, so it shows T's media type.
  • ErasedJson documents a 500 because it answers one when serialization fails.
  • Host documents 400, the status its rejection answers.
  • WithRejection<E, R> documents E's input and a default response with no body for the rejection, since R is yours.
  • Headers<T> with a #[serde(flatten)] field matches only lowercase header names.
  • BytesMut is not supported. Use Bytes or Vec<u8>.
  • JsonLines documents an empty item schema ({}, any JSON value), because the item type is not part of the signature that can be read.
  • impl IntoResponse is not supported (below): return Response and add statuses with #[api(response(..))].

Operations ​

FromIn the document
handler function nameoperationId (deduplicated across modules) and a default summary
/// doc commentsummary (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.

Released under the MIT or Apache-2.0 license.