pub struct RouteConfig {
pub summary: Option<String>,
pub description: Option<String>,
pub tags: Vec<String>,
pub responses: BTreeMap<u16, ResponseConfig>,
}Expand description
Configuration for a route’s OpenAPI documentation.
RouteConfig provides a builder pattern for adding metadata,
response definitions, and other OpenAPI documentation to routes.
§Examples
use fastrust::RouteConfig;
#[derive(schemars::JsonSchema, serde::Serialize)]
struct User {
id: i32,
name: String,
}
let config = RouteConfig::default()
.summary("Get a user")
.description("Returns a user by ID")
.tag("users")
.response::<User>(200, "User found")
.empty_response(404, "User not found");Fields§
§summary: Option<String>Short summary of the route.
description: Option<String>Long description (supports Markdown).
Tags for grouping routes in documentation.
responses: BTreeMap<u16, ResponseConfig>Response definitions by status code.
Implementations§
Source§impl RouteConfig
impl RouteConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty RouteConfig.
§Examples
use fastrust::RouteConfig;
let config = RouteConfig::new();Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets the route description.
The description supports Markdown formatting and is displayed in the Swagger UI.
§Arguments
description- The description text
Sourcepub fn summary(self, summary: impl Into<String>) -> Self
pub fn summary(self, summary: impl Into<String>) -> Self
Sets the route summary.
The summary is a short title displayed in the Swagger UI.
§Arguments
summary- The summary text
Sourcepub fn tag(self, tag: impl Into<String>) -> Self
pub fn tag(self, tag: impl Into<String>) -> Self
Adds a tag to the route.
Tags are used to group routes in the Swagger UI. Can be called multiple times to add multiple tags.
§Arguments
tag- The tag to add
Sourcepub fn ok<T: JsonSchema>(self) -> Self
pub fn ok<T: JsonSchema>(self) -> Self
Adds a 200 OK response with a typed schema.
This is a convenience method for adding a successful response with a JSON body schema.
§Type Parameters
T- The response type (must implementJsonSchema)
§Examples
use fastrust::RouteConfig;
#[derive(schemars::JsonSchema, serde::Serialize)]
struct User { id: i32 }
let config = RouteConfig::new().ok::<User>();Sourcepub fn response<T: JsonSchema>(
self,
status: u16,
description: impl Into<String>,
) -> Self
pub fn response<T: JsonSchema>( self, status: u16, description: impl Into<String>, ) -> Self
Adds a response with a specific status code and typed JSON body.
§Type Parameters
T- The response type (must implementJsonSchema)
§Arguments
status- The HTTP status codedescription- The response description
§Examples
use fastrust::RouteConfig;
#[derive(schemars::JsonSchema, serde::Serialize)]
struct User { id: i32 }
let config = RouteConfig::new().response::<User>(201, "User created");Sourcepub fn empty_response(self, status: u16, description: impl Into<String>) -> Self
pub fn empty_response(self, status: u16, description: impl Into<String>) -> Self
Trait Implementations§
Source§impl Clone for RouteConfig
impl Clone for RouteConfig
Source§fn clone(&self) -> RouteConfig
fn clone(&self) -> RouteConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more