Skip to main content

documented_handler

Attribute Macro documented_handler 

Source
#[documented_handler]
Expand description

Extracts doc comments from a handler function and generates a companion const of type HandlerDoc (from typeway_core) containing the summary, description, operation ID, and tags.

The first line of the doc comment becomes the summary. All subsequent non-empty lines become the description. The function name becomes the operation_id. Tags can be specified via the attribute parameter.

§Generated output

For a function named list_users, the macro generates a constant named LIST_USERS_DOC of type typeway_core::HandlerDoc.

§Example

/// List all users.
///
/// Returns a paginated list of users with optional filtering.
#[documented_handler(tags = "users")]
async fn list_users(state: State<Db>) -> Json<Vec<User>> {
    // ...
}

// Generated:
// pub const LIST_USERS_DOC: typeway_core::HandlerDoc = typeway_core::HandlerDoc {
//     summary: "List all users.",
//     description: "Returns a paginated list of users with optional filtering.",
//     operation_id: "list_users",
//     tags: &["users"],
// };

§Tags

Multiple tags can be comma-separated:

#[documented_handler(tags = "users, admin")]