-
Notifications
You must be signed in to change notification settings - Fork 1
Add UI-only route tests and remove unused mut from mount_route_ui #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -390,6 +390,14 @@ impl RustApi { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Add a UI route without registering OpenAPI operations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Use this for SSR or UI-only endpoints that should not appear in OpenAPI. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn route_ui(mut self, path: &str, method_router: MethodRouter) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.router = self.router.route(path, method_router); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Add a typed route | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn typed<P: crate::typed_path::TypedPath>(self, method_router: MethodRouter) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.route(P::PATH, method_router) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -438,6 +446,22 @@ impl RustApi { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.route_with_method(route.path, method_enum, route.handler) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Mount a UI route created with `#[rustapi::get]`, `#[rustapi::post]`, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This skips OpenAPI registration while still mounting the handler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This skips OpenAPI registration while still mounting the handler. | |
| /// This skips OpenAPI registration while still mounting the handler. | |
| /// | |
| /// # Example | |
| /// | |
| /// ```rust,ignore | |
| /// use rustapi_rs::prelude::*; | |
| /// | |
| /// struct AppState; | |
| /// | |
| /// #[rustapi::get("/ui")] | |
| /// async fn ui_home(state: State<AppState>) -> impl IntoResponse { | |
| /// // Render your UI here | |
| /// "Hello from UI" | |
| /// } | |
| /// | |
| /// #[tokio::main] | |
| /// async fn main() -> Result<()> { | |
| /// RustApi::new() | |
| /// .state(AppState) | |
| /// // Mount a UI route without registering it in the OpenAPI spec | |
| /// .mount_route_ui(route!(ui_home)) | |
| /// .run("127.0.0.1:8080") | |
| /// .await | |
| /// } | |
| /// ``` |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method-to-enum conversion logic is duplicated across multiple functions (mount_auto_routes_grouped, mount_route, and now mount_route_ui). Consider extracting this into a helper function to reduce duplication and ensure consistency in how method strings are converted to HTTP method enums.
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper function duplicates the path normalization logic from route_with_method. Consider extracting the path normalization into a shared helper function to avoid code duplication and ensure consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for
route_uicould be improved by adding an example section similar to theroutemethod. Consider adding a code example showing how to use this method for UI/SSR endpoints.