Skip to content

Commit

Permalink
utoipa-axum: Allow trailing comma in routes!() macro (#1238)
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 authored and juhaku committed Dec 18, 2024
1 parent 4f09bc8 commit 8ccef78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions utoipa-axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changed

* Allow trailing comma in `routes!()` macro (https://github.com/juhaku/utoipa/pull/1238)

### Fixed

* Fix axum path nesting (https://github.com/juhaku/utoipa/pull/1231)
Expand Down
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 8ccef78

Please sign in to comment.