#[openapi]Expand description
Declares OpenAPI metadata for a controller route method.
#[openapi] is valid only on methods inside a #[routes] impl block. It is
metadata-only behavior: it does not change request execution, but it enriches
the RouteMetadata emitted by #[routes] so CLI and OpenAPI builders can
generate useful documentation.
Basic syntax:
ⓘ
#[routes]
impl UsersController {
#[get("/:id")]
#[openapi(
summary = "Fetch a user by id",
tags = ["users"],
status = 200,
response = UserDto,
)]
async fn show(&self, Path(id): Path<String>) -> Json<UserDto> {
Json(self.service.find(id).await)
}
}Supported metadata includes summaries, tags, status codes, request schemas,
and response schemas. DTO schema names are recorded for tooling; they do not
serialize or validate requests at runtime. Common errors include missing
summary, non-string tags, invalid status values, duplicate metadata, or
placing the attribute outside a route method.