diff --git a/Cargo.lock b/Cargo.lock index 140acac..0e6d1eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,7 +101,7 @@ dependencies = [ [[package]] name = "axum-controller" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "axum-controller-macros", @@ -114,7 +114,7 @@ dependencies = [ [[package]] name = "axum-controller-macros" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "prettyplease", diff --git a/Cargo.toml b/Cargo.toml index d6b9bd2..2e673ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ keywords = ["axum", "controller", "macro", "routing"] license = "AGPL-3.0-or-later" readme = "README.md" repository = "https://git.vlt81.de/vault81/axum-controller" -version = "0.2.0" +version = "0.2.1" diff --git a/axum-controller-macros/Cargo.toml b/axum-controller-macros/Cargo.toml index 07964b2..f7f4c86 100644 --- a/axum-controller-macros/Cargo.toml +++ b/axum-controller-macros/Cargo.toml @@ -15,7 +15,7 @@ version.workspace = true prettyplease = "0.2" proc-macro2 = "1" quote = "1" -syn = { version = "2", features = ["parsing"] } +syn = { version = "2", features = ["extra-traits", "parsing", "printing"] } [dev-dependencies] axum = { version = "0.8", features = [] } diff --git a/axum-controller-macros/src/lib.rs b/axum-controller-macros/src/lib.rs index 8ef3719..88572fe 100644 --- a/axum-controller-macros/src/lib.rs +++ b/axum-controller-macros/src/lib.rs @@ -130,8 +130,9 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream { .into_iter() .map(move |route| { quote! { - .typed_route(#struct_name :: #route) - } + .typed_route(#struct_name :: #route) + + } }) .collect::>(); @@ -139,6 +140,23 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream { .nest(#route, __nested_router) }; + let nested_router_qoute = quote! { + axum::Router::new() + #nesting_call + }; + let unnested_router_quote = quote! { + __nested_router + }; + let maybe_nesting_call = if let syn::Expr::Lit(lit) = route { + if lit.eq(&syn::parse_quote!("/")) { + unnested_router_quote + } else { + nested_router_qoute + } + } else { + nested_router_qoute + }; + let middleware_calls = args .middlewares .clone() @@ -158,8 +176,7 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream { .with_state(state) ; - axum::Router::new() - #nesting_call + #maybe_nesting_call } } }; diff --git a/axum-controller/Cargo.toml b/axum-controller/Cargo.toml index ec6a70d..acf965c 100644 --- a/axum-controller/Cargo.toml +++ b/axum-controller/Cargo.toml @@ -12,8 +12,8 @@ repository.workspace = true version.workspace = true [dependencies] -axum-controller-macros = { path = "../axum-controller-macros", version = "0.2.0" } -axum-typed-routing = { path = "../vendor/axum-typed-routing", version = "0.2.0" } +axum-controller-macros = { path = "../axum-controller-macros", version = "0.2.1" } +axum-typed-routing = { path = "../vendor/axum-typed-routing", version = "0.2.0", features = [ "aide"] } [dev-dependencies] axum = "0.8" diff --git a/flake.nix b/flake.nix index b4b49a6..794f7e7 100644 --- a/flake.nix +++ b/flake.nix @@ -90,17 +90,17 @@ ''; }; packages = { - default = pkgs.callPackage ./package.nix { }; + # default = pkgs.callPackage ./package.nix { }; }; }) // { hydraJobs = let system = "x86_64-linux"; - packages = self.packages."${system}"; + # packages = self.packages."${system}"; devShells = self.devShells."${system}"; in { - inherit packages devShells; + inherit devShells; }; }; } diff --git a/vendor/axum-typed-routing/examples/basic.rs b/vendor/axum-typed-routing/examples/basic.rs index d86ba11..2a2332a 100644 --- a/vendor/axum-typed-routing/examples/basic.rs +++ b/vendor/axum-typed-routing/examples/basic.rs @@ -1,20 +1,20 @@ #![allow(unused)] -use axum::extract::{State, Json}; -use axum_typed_routing::{TypedRouter, route}; +use axum::extract::{Json, State}; +use axum_typed_routing::{route, TypedRouter}; #[route(GET "/item/:id?amount&offset")] async fn item_handler( - id: u32, - amount: Option, - offset: Option, - State(state): State, - Json(json): Json, + id: u32, + amount: Option, + offset: Option, + State(state): State, + Json(json): Json, ) -> String { - todo!("handle request") + todo!("handle request") } fn main() { let router: axum::Router = axum::Router::new() .typed_route(item_handler) .with_state("state".to_string()); -} \ No newline at end of file +} diff --git a/vendor/axum-typed-routing/tests/main.rs b/vendor/axum-typed-routing/tests/main.rs index a4680f7..55d2cc5 100644 --- a/vendor/axum-typed-routing/tests/main.rs +++ b/vendor/axum-typed-routing/tests/main.rs @@ -113,7 +113,6 @@ async fn test_wildcard() { assert_eq!(response.json::(), "foo/bar"); } - #[cfg(feature = "aide")] mod aide_support { use super::*; @@ -231,4 +230,3 @@ mod aide_support { .unwrap() } } -