Skip to main content

api_doc

Attribute Macro api_doc 

Source
#[api_doc]
Expand description

Enrich a route handler’s auto-generated OpenAPI documentation.

See the openapi module and the autumn_macros::api_doc attribute docs for details on the supported keys.

§Example

use autumn_web::prelude::*;

#[get("/users/{id}")]
#[api_doc(summary = "Fetch a user by id", tag = "users")]
async fn get_user(Path(id): Path<i32>) -> String {
    format!("User {id}")
}

Enrich a route handler’s auto-generated OpenAPI documentation.

Applied on top of a route macro (#[get], #[post], etc.), this attribute lets you override or add documentation fields that cannot be inferred from the handler signature (summaries, descriptions, tags, custom success status codes).

The route macro consumes this attribute and folds the metadata into the route’s ApiDoc. When no route macro is applied, the attribute is a no-op.

§Supported keys

KeyTypeEffect
summarystringShort one-line description
descriptionstringLonger multi-line description
tagstringSingle OpenAPI tag for grouping
tags[string, ...]Multiple OpenAPI tags
operation_idstringOverride the default operation id
statusintegerSuccess HTTP status code (defaults to 200)
hiddenflag / boolExclude the route from the generated spec

§Examples

use autumn_web::prelude::*;

#[get("/users/{id}")]
#[api_doc(summary = "Fetch a user by id", tag = "users")]
async fn get_user(Path(id): Path<i32>) -> String {
    format!("User {id}")
}

#[post("/users")]
#[api_doc(description = "Create a new user", status = 201)]
async fn create_user(Json(req): Json<serde_json::Value>) -> Json<serde_json::Value> {
    Json(req)
}

#[get("/internal/metrics")]
#[api_doc(hidden)]
async fn metrics() -> &'static str { "" }