-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add utoipa axum bindings #1004
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`.
This was referenced Aug 26, 2024
juhaku
force-pushed
the
add-utoipa-axum-bindings
branch
from
August 26, 2024 08:39
b7b1a6f
to
4278597
Compare
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
force-pushed
the
add-utoipa-axum-bindings
branch
from
August 26, 2024 08:40
4278597
to
969acbf
Compare
Can't wait for this feature! Please package and release it. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new crate
utoipa-axum
which provides bindings betweenaxum
andutoipa
. It aims to blend as much as possible to theexisting philosophy of axum way of registering handlers.
This commit introduces new
OpenApiRouter
what wrapsOpenApi
and axumRouter
which provides passthrough implementation for most of the axumRouter methods and collects and combines the
OpenApi
from registeredroutes. Routes registred only via
routes!()
macro will get added tothe
OpenApi
.Also this commit introduces
routes!()
macro which collects axumhandlers annotated with
#[utoipa::path()]
attribute macro to singlepaths intance which is then provided to the
OpenApiRouter
.Example of supported syntax.
Fixes #991 Fixes #394 Fixes #537