Compare commits

..

No commits in common. "main" and "v0.3.5" have entirely different histories.
main ... v0.3.5

6 changed files with 32 additions and 37 deletions

View file

@ -6,10 +6,6 @@ All notable changes to this project will be documented in this file.
- Nothing yet - Nothing yet
## [0.3.6] - 2025-04-17
- Better error messages when having route.rs files with invalid code
## [0.3.5] - 2025-04-16 ## [0.3.5] - 2025-04-16
- Moved macrotest to dev deps - Moved macrotest to dev deps

2
Cargo.lock generated
View file

@ -94,7 +94,7 @@ dependencies = [
[[package]] [[package]]
name = "axum-folder-router" name = "axum-folder-router"
version = "0.3.6" version = "0.3.5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "axum-folder-router" name = "axum-folder-router"
version = "0.3.6" version = "0.3.5"
edition = "2021" edition = "2021"
readme = "./README.md" readme = "./README.md"
authors = ["Tristan Druyen <ek36g2vcc@mozmail.com>"] authors = ["Tristan Druyen <ek36g2vcc@mozmail.com>"]

View file

@ -172,37 +172,36 @@ pub fn route_registrations(
let method_registrations = methods_for_route(route_path); let method_registrations = methods_for_route(route_path);
if !method_registrations.is_empty() { if method_registrations.is_empty() {
let first_method = &method_registrations[0]; return quote! {
let first_method_ident = format_ident!("{}", first_method); compile_error!(concat!(
"No routes defined in your route.rs's !\n",
let mod_path_tokens = generate_mod_path_tokens(&mod_path); "ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
));
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);
} }
}
if route_registrations.is_empty() { let first_method = &method_registrations[0];
return quote! { let first_method_ident = format_ident!("{}", first_method);
compile_error!(concat!(
"No routes defined in your route.rs's !\n", let mod_path_tokens = generate_mod_path_tokens(&mod_path);
"Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
)); 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);
} }
TokenStream::from_iter(route_registrations) TokenStream::from_iter(route_registrations)

View file

@ -4,14 +4,14 @@ use std::{
}; };
use syn::{ use syn::{
parse::{Parse, ParseStream},
parse_file,
Ident, Ident,
Item, Item,
LitStr, LitStr,
Result, Result,
Token, Token,
Visibility, Visibility,
parse::{Parse, ParseStream},
parse_file,
}; };
#[derive(Debug)] #[derive(Debug)]

View file

@ -1,5 +1,5 @@
error: No routes defined in your route.rs's ! 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 --> tests/failures/no_routes.rs:6:1
| |
6 | #[folder_router("../../../../tests/failures/no_routes", AppState)] 6 | #[folder_router("../../../../tests/failures/no_routes", AppState)]