From 07924132d9ae0831ead30676b7bd981609d988f6 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 13 Dec 2024 10:21:14 +0100 Subject: [PATCH] utoipa-axum: Allow trailing comma in `routes!()` macro Once the `routes!()` invocation contains more than a couple of routes, it is likely that each route will be on its own line. Currently, the macro does not support trailing commas, which causes the git diff when adding a new route to be unnecessarily large. With this change trailing commas are supported, which shrinks the diff down to a single-line change. --- utoipa-axum/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utoipa-axum/src/lib.rs b/utoipa-axum/src/lib.rs index 7be427de..d3525dcd 100644 --- a/utoipa-axum/src/lib.rs +++ b/utoipa-axum/src/lib.rs @@ -123,7 +123,7 @@ pub use paste::paste; /// ``` #[macro_export] macro_rules! routes { - ( $handler:path $(, $tail:path)* ) => { + ( $handler:path $(, $tail:path)* $(,)? ) => { { use $crate::PathItemExt; let mut paths = utoipa::openapi::path::Paths::new(); @@ -252,6 +252,12 @@ mod tests { let _ = router.get_openapi(); } + #[test] + fn routes_with_trailing_comma_compiles() { + let _: OpenApiRouter = OpenApiRouter::new() + .routes(routes!(get_user, post_user, delete_user,)); + } + #[test] fn openapi_router_with_openapi() { use utoipa::OpenApi;