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

feat: axum v0.8 support #168

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/aide-axum-sqlx-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
[dependencies]
sqlx-06 = { package = "axum-sqlx-tx", version = "0.5.0", optional = true }
sqlx-07 = { package = "axum-sqlx-tx", version = "0.8.0", optional = true }
aide = { version = "0.13", path = "../aide" }
aide = { version = "0.14", path = "../aide" }

[dev-dependencies]
sqlx = { version = "^0.7", features = ["postgres"] }
Expand Down
9 changes: 5 additions & 4 deletions crates/aide-axum-typed-multipart/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aide-axum-typed-multipart"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
authors = ["emonadeo"]
keywords = ["web", "axum", "multipart"]
Expand All @@ -10,11 +10,12 @@ description = "Type safe multipart/form-data handling for axum and aide"
readme = "README.md"

[dependencies]
aide = { version = "0.13", path = "../aide" }
axum = "0.7.4"
axum_typed_multipart = { version = "0.11.0" }
aide = { version = "0.14", path = "../aide" }
axum = "0.8.1"
axum_typed_multipart = { version = "0.15.1" }
indexmap = "2.2.2"
schemars = "0.8.16"
async-trait = "0.1.85"

[dev-dependencies]
bytes = "1.5.0"
Expand Down
10 changes: 3 additions & 7 deletions crates/aide-axum-typed-multipart/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ use aide::{
operation::set_body,
OperationInput,
};
use axum::{
async_trait,
extract::{multipart::Field, FromRequest, Request},
};
use axum_typed_multipart::{TryFromField, TryFromMultipart};
use axum::extract::{multipart::Field, FromRequest, Request};
use axum_typed_multipart::{async_trait, TryFromField, TryFromMultipart};
use indexmap::IndexMap;
use schemars::JsonSchema;

Expand All @@ -29,7 +26,6 @@ impl<T> Deref for TypedMultipart<T> {
}
}

#[async_trait]
impl<T, S> FromRequest<S> for TypedMultipart<T>
where
T: TryFromMultipart,
Expand All @@ -39,7 +35,7 @@ where

async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
let a = axum_typed_multipart::TypedMultipart::from_request(req, state).await?;
return Ok(Self(a));
Ok(Self(a))
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/aide/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aide"
version = "0.13.5"
version = "0.14.0"
authors = ["tamasfe"]
edition = "2021"
keywords = ["generate", "api", "openapi", "documentation", "specification"]
Expand All @@ -21,8 +21,8 @@ aide-macros = { version = "0.7.0", path = "../aide-macros", optional = true }
bytes = { version = "1", optional = true }
http = { version = "1.0.0", optional = true }

axum = { version = "0.7.1", optional = true, default-features = false }
axum-extra = { version = "0.9.0", optional = true }
axum = { version = "0.8.1", optional = true, default-features = false }
axum-extra = { version = "0.10.0", optional = true }
tower-layer = { version = "0.3", optional = true }
tower-service = { version = "0.3", optional = true }
cfg-if = "1.0.0"
Expand Down
5 changes: 1 addition & 4 deletions crates/aide/src/axum/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::{
};
use axum::{
body::Body,
extract::{
Extension, Form, Host, Json, MatchedPath, OriginalUri, Path, Query, RawQuery, State,
},
extract::{Extension, Form, Json, MatchedPath, OriginalUri, Path, Query, RawQuery, State},
};

#[cfg(not(feature = "axum-wasm"))]
Expand All @@ -37,7 +35,6 @@ impl OperationInput for MatchedPath {}
impl OperationInput for OriginalUri {}
impl OperationInput for Body {}
impl OperationInput for RawQuery {}
impl OperationInput for Host {}

#[cfg(feature = "axum-headers")]
impl<T> OperationInput for axum_extra::typed_header::TypedHeader<T>
Expand Down
22 changes: 13 additions & 9 deletions crates/aide/src/axum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ where
#[tracing::instrument(skip_all)]
pub fn route_service<T>(mut self, path: &str, service: T) -> Self
where
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static,
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static + std::marker::Sync,
T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand All @@ -525,7 +525,11 @@ where
#[tracing::instrument(skip_all)]
pub fn route_service_with_tsr<T>(mut self, path: &str, service: T) -> Self
where
T: Service<axum::extract::Request, Error = Infallible> + Clone + Send + 'static,
T: Service<axum::extract::Request, Error = Infallible>
+ Clone
+ Send
+ 'static
+ std::marker::Sync,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized,
Expand Down Expand Up @@ -580,7 +584,7 @@ where
/// to pass on the API documentation from the nested service as well.
pub fn nest_service<T>(mut self, path: &str, svc: T) -> Self
where
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static,
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static + std::marker::Sync,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add new Sync trait bound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh. It's what the compiler complained about

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand Down Expand Up @@ -616,8 +620,8 @@ where
/// See [`axum::Router::layer`] for details.
pub fn layer<L>(self, layer: L) -> ApiRouter<S>
where
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request<Body>> + Clone + Send + 'static,
L: Layer<Route> + Clone + Send + 'static + std::marker::Sync,
L::Service: Service<Request<Body>> + Clone + Send + 'static + std::marker::Sync,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
Expand All @@ -631,8 +635,8 @@ where
/// See [`axum::Router::route_layer`] for details.
pub fn route_layer<L>(mut self, layer: L) -> Self
where
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request<Body>> + Clone + Send + 'static,
L: Layer<Route> + Clone + Send + 'static + std::marker::Sync,
L::Service: Service<Request<Body>> + Clone + Send + 'static + std::marker::Sync,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
Expand All @@ -654,7 +658,7 @@ where
/// See [`axum::Router::fallback_service`] for details.
pub fn fallback_service<T>(mut self, svc: T) -> Self
where
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static,
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static + std::marker::Sync,
T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand Down Expand Up @@ -863,7 +867,7 @@ mod tests {
#[test]
fn test_nesting_with_nondefault_state() {
let _app: ApiRouter = ApiRouter::new()
.nest_api_service("/", ApiRouter::new().with_state(1_isize))
.nest_api_service("/home", ApiRouter::new().with_state(1_isize))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the change here needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bildschirmfoto 2025-01-03 um 03 54 46

.with_state(1_usize);
}

Expand Down
14 changes: 7 additions & 7 deletions crates/aide/src/axum/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ where
/// See [`axum::routing::method_routing::MethodRouter::layer`].
pub fn layer<L, NewError>(self, layer: L) -> ApiMethodRouter<S, NewError>
where
L: Layer<Route<E>> + Clone + Send + 'static,
L::Service: Service<Request<Body>> + Clone + Send + 'static,
L: Layer<Route<E>> + Clone + Send + 'static + std::marker::Sync,
L::Service: Service<Request<Body>> + Clone + Send + 'static + std::marker::Sync,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<NewError> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
E: 'static,
S: 'static,
NewError: 'static,
NewError: 'static + std::marker::Sync,
{
ApiMethodRouter {
router: self.router.layer(layer),
Expand All @@ -296,7 +296,7 @@ where
/// See [`axum::routing::method_routing::MethodRouter::on_service`].
pub fn on_service<T>(mut self, filter: MethodFilter, svc: T) -> Self
where
T: Service<Request<Body>, Error = E> + Clone + Send + 'static,
T: Service<Request<Body>, Error = E> + Clone + Send + 'static + std::marker::Sync,
T::Response: IntoResponse + 'static,
T::Future: Send + 'static,
{
Expand All @@ -307,7 +307,7 @@ where
/// See [`axum::routing::method_routing::MethodRouter::fallback_service`].
pub fn fallback_service<T>(mut self, svc: T) -> Self
where
T: Service<Request<Body>, Error = E> + Clone + Send + 'static,
T: Service<Request<Body>, Error = E> + Clone + Send + 'static + std::marker::Sync,
T::Response: IntoResponse + 'static,
T::Future: Send + 'static,
{
Expand All @@ -318,8 +318,8 @@ where
/// See [`axum::routing::method_routing::MethodRouter::route_layer`].
pub fn route_layer<L>(self, layer: L) -> ApiMethodRouter<S, E>
where
L: Layer<Route<E>> + Clone + Send + 'static,
L::Service: Service<Request<Body>, Error = E> + Clone + Send + 'static,
L: Layer<Route<E>> + Clone + Send + 'static + std::marker::Sync,
L::Service: Service<Request<Body>, Error = E> + Clone + Send + 'static + std::marker::Sync,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
E: 'static,
Expand Down
4 changes: 1 addition & 3 deletions crates/aide/src/helpers/no_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl<T> OperationOutput for NoApi<T> {

#[cfg(feature = "axum")]
mod axum {
use axum::body::Body;
use axum::extract::{FromRequest, FromRequestParts};
use axum::response::{IntoResponse, IntoResponseParts, Response, ResponseParts};
use axum::{async_trait, body::Body};
use http::request::Parts;
use http::Request;

Expand All @@ -91,7 +91,6 @@ mod axum {
}
}

#[async_trait]
impl<T, S> FromRequestParts<S> for NoApi<T>
where
T: FromRequestParts<S>,
Expand All @@ -104,7 +103,6 @@ mod axum {
}
}

#[async_trait]
impl<T, S> FromRequest<S> for NoApi<T>
where
T: FromRequest<S>,
Expand Down
4 changes: 1 addition & 3 deletions crates/aide/src/helpers/use_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ where

#[cfg(feature = "axum")]
mod axum {
use axum::body::Body;
use axum::extract::{FromRequest, FromRequestParts};
use axum::response::{IntoResponse, IntoResponseParts, Response, ResponseParts};
use axum::{async_trait, body::Body};
use http::request::Parts;
use http::Request;

Expand All @@ -135,7 +135,6 @@ mod axum {
}
}

#[async_trait]
impl<T, A, S> FromRequestParts<S> for UseApi<T, A>
where
T: FromRequestParts<S>,
Expand All @@ -151,7 +150,6 @@ mod axum {
}
}

#[async_trait]
impl<T, A, S> FromRequest<S> for UseApi<T, A>
where
T: FromRequest<S>,
Expand Down
4 changes: 1 addition & 3 deletions crates/aide/src/helpers/with_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ where
#[cfg(feature = "axum")]
mod axum {
use crate::helpers::with_api::ApiOverride;
use axum::body::Body;
use axum::extract::{FromRequest, FromRequestParts};
use axum::response::{IntoResponse, IntoResponseParts, Response, ResponseParts};
use axum::{async_trait, body::Body};
use http::request::Parts;
use http::Request;

Expand Down Expand Up @@ -189,7 +189,6 @@ mod axum {
}
}

#[async_trait]
impl<T, S> FromRequestParts<S> for WithApi<T>
where
T: ApiOverride,
Expand All @@ -206,7 +205,6 @@ mod axum {
}
}

#[async_trait]
impl<T, S> FromRequest<S> for WithApi<T>
where
T: ApiOverride,
Expand Down
5 changes: 2 additions & 3 deletions crates/axum-jsonschema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ description = "Request JSON schema validation for axum"
readme = "README.md"

[dependencies]
aide = { version = "0.13", path = "../aide", optional = true, features = ["axum"] }
async-trait = "0.1.57"
axum = { version = "0.7.1", default-features = false, features = ["json"] }
aide = { version = "0.14", path = "../aide", optional = true, features = ["axum"] }
axum = { version = "0.8.1", default-features = false, features = ["json"] }
http = "1.0.0"
itertools = "0.12.0"
jsonschema = { version = "0.17.0", default-features = false }
Expand Down
2 changes: 0 additions & 2 deletions crates/axum-jsonschema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::{
collections::{HashMap, VecDeque},
};

use async_trait::async_trait;
use axum::{
body::Body,
extract::{rejection::JsonRejection, FromRequest},
Expand All @@ -46,7 +45,6 @@ use serde_path_to_error::Segment;
/// message.
pub struct Json<T>(pub T);

#[async_trait]
impl<S, T> FromRequest<S> for Json<T>
where
S: Send + Sync,
Expand Down
4 changes: 2 additions & 2 deletions examples/example-axum-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ aide = { path = "../../crates/aide", features = [
tower-service = "0.3.2"
worker = { version = "0.5.0", features = ["http", "axum"] }
console_error_panic_hook = "0.1.7"
axum = { version = "0.7.1", default-features = false, features = ["macros", "form", "matched-path", "query", "original-uri"] }
axum = { version = "0.8.1", default-features = false, features = ["macros", "form", "matched-path", "query", "original-uri"] }
axum-jsonschema = { path = "../../crates/axum-jsonschema", features = ["aide"] }
axum-macros = "0.4.0"
axum-macros = "0.5.0"
schemars = { version = "0.8.10", features = ["uuid1"] }
serde = { version = "1.0.144", features = ["derive", "rc"] }
serde_json = "1.0.85"
Expand Down
7 changes: 5 additions & 2 deletions examples/example-axum-worker/src/todos/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ pub fn todo_routes(state: AppState) -> ApiRouter {
post_with(create_todo, create_todo_docs).get_with(list_todos, list_todos_docs),
)
.api_route(
"/:id",
"/{id}",
get_with(get_todo, get_todo_docs).delete_with(delete_todo, delete_todo_docs),
)
.api_route("/:id/complete", put_with(complete_todo, complete_todo_docs))
.api_route(
"/{id}/complete",
put_with(complete_todo, complete_todo_docs),
)
.with_state(state)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/example-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ aide = { path = "../../crates/aide", features = [
"axum-extra",
"macros",
] }
axum = { version = "0.7.1", features = ["macros"] }
axum = { version = "0.8.1", features = ["macros"] }
axum-jsonschema = { path = "../../crates/axum-jsonschema", features = ["aide"] }
axum-macros = "0.4.0"
axum-macros = "0.5.0"
schemars = { version = "0.8.10", features = ["uuid1"] }
serde = { version = "1.0.144", features = ["derive", "rc"] }
serde_json = "1.0.85"
Expand Down
7 changes: 5 additions & 2 deletions examples/example-axum/src/todos/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ pub fn todo_routes(state: AppState) -> ApiRouter {
post_with(create_todo, create_todo_docs).get_with(list_todos, list_todos_docs),
)
.api_route(
"/:id",
"/{id}",
get_with(get_todo, get_todo_docs).delete_with(delete_todo, delete_todo_docs),
)
.api_route("/:id/complete", put_with(complete_todo, complete_todo_docs))
.api_route(
"/{id}/complete",
put_with(complete_todo, complete_todo_docs),
)
.with_state(state)
}

Expand Down
Loading