pub struct Router<S = ()> { /* private fields */ }Expand description
A drop-in replacement for axum::Router that adds OpenAPI documentation support.
This Router works seamlessly with handlers decorated with #[rovo] and provides
a fluent API for building documented APIs with Swagger UI integration.
§Example
use rovo::{Router, rovo, routing::get, aide::axum::IntoApiResponse};
use rovo::aide::openapi::OpenApi;
use rovo::response::Json;
#[rovo]
async fn documented_handler() -> impl IntoApiResponse {
Json(())
}
let mut api = OpenApi::default();
api.info.title = "My API".to_string();
let app = Router::new()
.route("/documented", get(documented_handler))
.with_oas(api);Implementations§
Source§impl<S> Router<S>
impl<S> Router<S>
Sourcepub fn route<M>(self, path: &str, method_router: M) -> Selfwhere
M: Into<ApiMethodRouter<S>>,
pub fn route<M>(self, path: &str, method_router: M) -> Selfwhere
M: Into<ApiMethodRouter<S>>,
Add a route to the router
Sourcepub fn with_oas(self, api: OpenApi) -> Self
pub fn with_oas(self, api: OpenApi) -> Self
Configure OpenAPI spec with default routes (/api.json and /api.yaml)
This automatically sets up endpoints for both JSON and YAML formats.
Sourcepub fn with_oas_route(self, api: OpenApi, route: impl Into<String>) -> Self
pub fn with_oas_route(self, api: OpenApi, route: impl Into<String>) -> Self
Configure OpenAPI spec with custom base route
This sets up endpoints with the specified base route. For example, “/openapi” creates:
- /openapi.json
- /openapi.yaml
Sourcepub fn with_state(self, state: S) -> Router
pub fn with_state(self, state: S) -> Router
Add state to the router and finalize the API
Sourcepub fn finish_api(self, api: &mut OpenApi) -> Router<S>
pub fn finish_api(self, api: &mut OpenApi) -> Router<S>
Finish building the API and return an axum Router for further configuration
Sourcepub fn finish_api_with_extension(self, api: OpenApi) -> Router<S>
pub fn finish_api_with_extension(self, api: OpenApi) -> Router<S>
Finish the API with OpenAPI spec embedded via Extension layer
Sourcepub fn into_inner(self) -> AideApiRouter<S>
pub fn into_inner(self) -> AideApiRouter<S>
Convert into the underlying aide ApiRouter
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Router<S>
impl<S = ()> !RefUnwindSafe for Router<S>
impl<S> Send for Router<S>
impl<S> Sync for Router<S>
impl<S> Unpin for Router<S>
impl<S = ()> !UnwindSafe for Router<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more