Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utoipa axum bindings #1004

Merged
merged 8 commits into from
Aug 26, 2024
Merged

Add utoipa axum bindings #1004

merged 8 commits into from
Aug 26, 2024

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Aug 26, 2024

This PR adds a new crate utoipa-axum which provides bindings between
axum and utoipa. It aims to blend as much as possible to the
existing philosophy of axum way of registering handlers.

This commit introduces new OpenApiRouter what wraps OpenApi and axum
Router which provides passthrough implementation for most of the axum
Router methods and collects and combines the OpenApi from registered
routes. Routes registred only via routes!() macro will get added to
the OpenApi.

Also this commit introduces routes!() macro which collects axum
handlers annotated with #[utoipa::path()] attribute macro to single
paths intance which is then provided to the OpenApiRouter.

Example of supported syntax.

let user_router: OpenApiRouter = OpenApiRouter::new()
    .routes(routes!(search_user))
    .routes(routes!(get_user, post_user, delete_user));

Fixes #991 Fixes #394 Fixes #537

juhaku added 7 commits August 25, 2024 14:08
Experiment with proof of concept utoipa axum bindings.
Experiment with axum Router and Handler bindings with utoipa. Bind axum
router to the utoipa OpenApi and `#[utoipa::path]` attribute macro.

Wip: for axum, find the `State<T>` of the stateful handler to
implement correct type for `axum::handler::Handler` trait.
Working bindings with axum and utoipa that handles `#[utoipa::path]`
macro merging with with `axum::Router` and `utoipa::openapi::OpenApi`.

Missing some documentation, test finalization and parhaps some utility
functions.

Some polish could be done for the `tags`. Now there is no tags when
using `OpenApiRouter` on operations. The `tags` behavior must be unified
somehow.

Finally write an example app with `OpenApiRouter` to `examples`.
@juhaku juhaku added the enhancement New feature or request label Aug 26, 2024
@juhaku juhaku force-pushed the add-utoipa-axum-bindings branch from b7b1a6f to 4278597 Compare August 26, 2024 08:39
This PR adds a new crate `utoipa-axum` which provides bindings between
`axum` and `utoipa`. It aims to blend as much as possible to the
existing philosophy of axum way of registering handlers.

This commit introduces new `OpenApiRouter` what wraps `OpenApi` and axum
`Router` which provides passthrough implementation for most of the axum
Router methods and collects and combines the `OpenApi` from registered
routes. Routes registred only via `routes!()` macro will get added to
the `OpenApi`.

Also this commit introduces `routes!()` macro which collects axum
handlers annotated with `#[utoipa::path()]` attribute macro to single
paths intance which is then provided to the `OpenApiRouter`.

Example of supported sytanx.
```rust
let user_router: OpenApiRouter = OpenApiRouter::new()
    .routes(routes!(search_user))
    .routes(routes!(get_user, post_user, delete_user));
```

Fixes #991
@juhaku juhaku force-pushed the add-utoipa-axum-bindings branch from 4278597 to 969acbf Compare August 26, 2024 08:40
@juhaku juhaku merged commit a0db8b9 into master Aug 26, 2024
18 checks passed
@juhaku juhaku deleted the add-utoipa-axum-bindings branch August 26, 2024 08:58
@Borderliner
Copy link

Can't wait for this feature! Please package and release it.

@juhaku
Copy link
Owner Author

juhaku commented Aug 27, 2024

Will do that shortly, shouldn't be too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Released
2 participants