Skip to content

Conversation

@Tuntii
Copy link
Owner

@Tuntii Tuntii commented Jan 19, 2026

Motivation

  • Verify that UI/SSR routes mounted via route_ui/mount_route_ui are registered with the router but are excluded from the OpenAPI spec.
  • Eliminate an unnecessary mut from the mount_route_ui signature to remove a compiler warning and tidy the API.

Description

  • Added two unit tests test_route_ui_excludes_openapi and test_mount_route_ui_excludes_openapi to crates/rustapi-core/src/app.rs which assert UI routes are mounted while openapi_spec().paths remains empty.
  • Imported crate::handler::Route into the test module and adjusted test assertions to check app.openapi_spec() before calling into_router().
  • Removed the unused mut from the pub fn mount_route_ui(self, ...) signature to address an unused_mut warning.

Testing

  • Ran cargo test -p rustapi-core --lib and all tests completed successfully with 205 passed; 0 failed.

Codex Task

Copilot AI review requested due to automatic review settings January 19, 2026 22:50
@Tuntii Tuntii closed this Jan 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for UI/SSR routes that are mounted to the router but excluded from the OpenAPI specification. It introduces route_ui and mount_route_ui methods as counterparts to existing route and mount_route methods, along with comprehensive test coverage.

Changes:

  • Added route_ui and mount_route_ui methods to allow mounting UI/SSR endpoints without OpenAPI registration
  • Added helper method route_with_method_ui that mirrors route_with_method but skips OpenAPI registration
  • Added unit tests test_route_ui_excludes_openapi and test_mount_route_ui_excludes_openapi to verify the new functionality
  • Updated documentation in docs/README.md with examples showing the distinction between API and UI routes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
docs/README.md Added example demonstrating UI route usage with route_ui and clarified OpenAPI inclusion behavior
crates/rustapi-core/src/app.rs Added route_ui, mount_route_ui, and route_with_method_ui methods with corresponding unit tests to support UI-only routes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +502 to +515
/// Helper to mount a single method handler without OpenAPI registration
fn route_with_method_ui(
self,
path: &str,
method: http::Method,
handler: crate::handler::BoxedHandler,
) -> Self {
use crate::router::MethodRouter;

let path = if !path.starts_with('/') {
format!("/{}", path)
} else {
path.to_string()
};
Copy link

Copilot AI Jan 19, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +453 to +460
let method_enum = match route.method {
"GET" => http::Method::GET,
"POST" => http::Method::POST,
"PUT" => http::Method::PUT,
"DELETE" => http::Method::DELETE,
"PATCH" => http::Method::PATCH,
_ => http::Method::GET,
};
Copy link

Copilot AI Jan 19, 2026

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 uses AI. Check for mistakes.

/// Add a UI route without registering OpenAPI operations.
///
/// Use this for SSR or UI-only endpoints that should not appear in OpenAPI.
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for route_ui could be improved by adding an example section similar to the route method. Consider adding a code example showing how to use this method for UI/SSR endpoints.

Suggested change
/// Use this for SSR or UI-only endpoints that should not appear in OpenAPI.
/// Use this for SSR or UI-only endpoints that should not appear in OpenAPI.
///
/// # Example
///
/// ```rust,ignore
/// use rustapi_rs::prelude::*;
///
/// async fn ui_index() -> impl IntoResponse {
/// Html("<html><body><h1>Welcome</h1></body></html>")
/// }
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// RustApi::new()
/// // API route registered in OpenAPI
/// .route("/api/health", get(health_check))
/// // UI route not included in OpenAPI
/// .route_ui("/", get(ui_index))
/// .run("127.0.0.1:8080")
/// .await
/// }
/// ```

Copilot uses AI. Check for mistakes.

/// Mount a UI route created with `#[rustapi::get]`, `#[rustapi::post]`, etc.
///
/// This skips OpenAPI registration while still mounting the handler.
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for mount_route_ui could be improved by adding an example section similar to the mount_route method above. Consider adding a code example showing how to use this method with macro-generated routes.

Suggested change
/// 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 uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants