Skip to content

Commit

Permalink
utoipa-axum: Allow trailing comma in routes!() macro
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Turbo87 committed Dec 13, 2024
1 parent 2f7acf1 commit 0792413
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utoipa-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0792413

Please sign in to comment.