Fix runtime error on root route
This commit is contained in:
parent
11b201004a
commit
53c8b81450
4 changed files with 25 additions and 16 deletions
|
@ -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"
|
||||
|
|
|
@ -131,6 +131,7 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.map(move |route| {
|
||||
quote! {
|
||||
.typed_route(#struct_name :: #route)
|
||||
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -139,6 +140,17 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.nest(#route, __nested_router)
|
||||
};
|
||||
|
||||
let maybe_nesting_call = if route == syn::parse_quote!("/") {
|
||||
quote! {
|
||||
__nested_router
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
axum::Router::new()
|
||||
#nesting_call
|
||||
}
|
||||
};
|
||||
|
||||
let middleware_calls = args
|
||||
.middlewares
|
||||
.clone()
|
||||
|
@ -158,8 +170,7 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.with_state(state)
|
||||
;
|
||||
|
||||
axum::Router::new()
|
||||
#nesting_call
|
||||
#maybe_nesting_call
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
4
vendor/axum-typed-routing/examples/basic.rs
vendored
4
vendor/axum-typed-routing/examples/basic.rs
vendored
|
@ -1,6 +1,6 @@
|
|||
#![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(
|
||||
|
|
2
vendor/axum-typed-routing/tests/main.rs
vendored
2
vendor/axum-typed-routing/tests/main.rs
vendored
|
@ -113,7 +113,6 @@ async fn test_wildcard() {
|
|||
assert_eq!(response.json::<String>(), "foo/bar");
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "aide")]
|
||||
mod aide_support {
|
||||
use super::*;
|
||||
|
@ -231,4 +230,3 @@ mod aide_support {
|
|||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue