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 axum bindings for utoipa #1003

Closed
wants to merge 8 commits into from
Closed

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Aug 25, 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.

Fixes #991

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 25, 2024
@juhaku juhaku linked an issue Aug 25, 2024 that may be closed by this pull request
@juhaku juhaku changed the title Experiment axum bindings 2 Add axum bindings for utoipa Aug 25, 2024
@juhaku juhaku force-pushed the experiment-axum-bindings-2 branch 2 times, most recently from d0e66db to 9309d69 Compare August 26, 2024 08:03
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 experiment-axum-bindings-2 branch from 9309d69 to b7b1a6f Compare August 26, 2024 08:24
@juhaku
Copy link
Owner Author

juhaku commented Aug 26, 2024

Done here #1004 with better branch name

@juhaku juhaku closed this Aug 26, 2024
@juhaku juhaku deleted the experiment-axum-bindings-2 branch October 14, 2024 14:07
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
Development

Successfully merging this pull request may close these issues.

Axum bindings for utoipa - better path registration for axum
1 participant