Skip to main content

reinhardt_openapi/
lib.rs

1#![warn(missing_docs)]
2
3//! # Reinhardt OpenAPI Router
4//!
5//! OpenAPI router wrapper that automatically adds documentation endpoints.
6//!
7//! ## Overview
8//!
9//! This crate provides a router wrapper that intercepts requests to OpenAPI
10//! documentation paths and serves them from memory, delegating all other
11//! requests to the wrapped handler.
12//!
13//! ## Example
14//!
15//! Apply `OpenApiRouter::wrap` inside the `#[routes]` function to expose OpenAPI
16//! documentation alongside your application routes:
17//!
18//! ```rust,ignore
19//! use reinhardt::routes;
20//! use reinhardt_openapi::OpenApiRouter;
21//! use reinhardt_urls::routers::UnifiedRouter;
22//!
23//! #[routes]
24//! pub fn routes() -> OpenApiRouter<UnifiedRouter> {
25//!     let router = UnifiedRouter::new()
26//!         // Mount your application routes here
27//!         .mount("/", some_app::urls::routes());
28//!
29//!     // Wrap with OpenAPI endpoints — served at:
30//!     // - /api/openapi.json (OpenAPI spec)
31//!     // - /api/docs (Swagger UI)
32//!     // - /api/redoc (Redoc UI)
33//!     OpenApiRouter::wrap(router).expect("Failed to wrap router with OpenAPI")
34//! }
35//! ```
36//!
37//! ## Separation Rationale
38//!
39//! This crate exists separately from `reinhardt-rest` to break a circular
40//! dependency chain:
41//!
42//! ```text
43//! reinhardt-urls → reinhardt-views → reinhardt-rest → reinhardt-urls (cycle!)
44//! ```
45//!
46//! By placing `OpenApiRouter` in its own crate that depends on both
47//! `reinhardt-urls` and `reinhardt-rest`, we avoid this cycle:
48//!
49//! ```text
50//! reinhardt-openapi
51//!     ├── reinhardt-urls (Route, Router trait)
52//!     └── reinhardt-rest (generate_openapi_schema, SwaggerUI, RedocUI)
53//! ```
54
55mod router_wrapper;
56
57pub use reinhardt_rest::openapi::SchemaError;
58pub use router_wrapper::AuthGuard;
59pub use router_wrapper::OpenApiRouter;