diff --git a/src/generate.rs b/src/generate.rs index bc53f38..62d7651 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -172,36 +172,37 @@ pub fn route_registrations( let method_registrations = methods_for_route(route_path); - if method_registrations.is_empty() { - return quote! { - compile_error!(concat!( - "No routes defined in your route.rs's !\n", - "ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)" - )); + if !method_registrations.is_empty() { + let first_method = &method_registrations[0]; + let first_method_ident = format_ident!("{}", first_method); + + let mod_path_tokens = generate_mod_path_tokens(&mod_path); + + let mut builder = quote! { + axum::routing::#first_method_ident(#root_namespace_ident::#mod_path_tokens::#first_method_ident) }; - } - let first_method = &method_registrations[0]; - let first_method_ident = format_ident!("{}", first_method); + for method in &method_registrations[1..] { + let method_ident = format_ident!("{}", method); - let mod_path_tokens = generate_mod_path_tokens(&mod_path); + builder = quote! { + #builder.#method_ident(#root_namespace_ident::#mod_path_tokens::#method_ident) + }; + } - let mut builder = quote! { - axum::routing::#first_method_ident(#root_namespace_ident::#mod_path_tokens::#first_method_ident) - }; - - for method in &method_registrations[1..] { - let method_ident = format_ident!("{}", method); - - builder = quote! { - #builder.#method_ident(#root_namespace_ident::#mod_path_tokens::#method_ident) + let registration = quote! { + router = router.route(#axum_path, #builder); }; + route_registrations.push(registration); } - - let registration = quote! { - router = router.route(#axum_path, #builder); + } + if route_registrations.is_empty() { + return quote! { + compile_error!(concat!( + "No routes defined in your route.rs's !\n", + "Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)" + )); }; - route_registrations.push(registration); } TokenStream::from_iter(route_registrations) diff --git a/src/parse.rs b/src/parse.rs index 5295aff..6b1d9fc 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -4,14 +4,14 @@ use std::{ }; use syn::{ + parse::{Parse, ParseStream}, + parse_file, Ident, Item, LitStr, Result, Token, Visibility, - parse::{Parse, ParseStream}, - parse_file, }; #[derive(Debug)] diff --git a/tests/failures/no_routes.stderr b/tests/failures/no_routes.stderr index 4d8ff91..f0c99d1 100644 --- a/tests/failures/no_routes.stderr +++ b/tests/failures/no_routes.stderr @@ -1,5 +1,5 @@ error: No routes defined in your route.rs's ! - ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete) + Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete) --> tests/failures/no_routes.rs:6:1 | 6 | #[folder_router("../../../../tests/failures/no_routes", AppState)]