Skip to content

Commit

Permalink
Update axum to v0.8.0 (#1269)
Browse files Browse the repository at this point in the history
* Update `axum` dependencies to 0.8.0

* utoipa-axum: Add missing `Sync` requirements

* utoipa-axum: Remove obsolete `colonized_params()` fn

axum 0.8 uses the same syntax as OpenAPI now :)

* utoipa-swagger-ui: Adjust to axum 0.8 path syntax changes

* examples/axum-multipart: Use `path` dependencies

Otherwise there is no way to fixing this example ahead of the release...

* utoipa-axum: Remove obsolete `path_template()` fn

axum 0.8 uses the same syntax as OpenAPI now :)

* Add changelog entries
  • Loading branch information
Turbo87 authored Jan 2, 2025
1 parent 1d71a24 commit d522f74
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 56 deletions.
8 changes: 4 additions & 4 deletions examples/axum-multipart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2021"

[dependencies]
axum = { version = "0.7", features = ["multipart"] }
axum = { version = "0.8.0", features = ["multipart"] }
tokio = { version = "1", features = ["full"] }
tower = "0.5"
utoipa = { version = "5", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "8", features = ["axum"] }
utoipa-axum = "0.1"
utoipa = { path = "../../utoipa", features = ["axum_extras"] }
utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["axum"] }
utoipa-axum = { path = "../../utoipa-axum" }
serde = { features = ["derive"], version = "1" }

[workspace]
2 changes: 1 addition & 1 deletion examples/axum-utoipa-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.7"
axum = "0.8.0"
tokio = { version = "1", features = ["full"] }
tower = "0.5"
utoipa = { path = "../../utoipa", features = ["axum_extras", "debug"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-utoipa-nesting-vendored/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = ["Elli Example <[email protected]>"]


[dependencies]
axum = "0.7"
axum = "0.8.0"
hyper = { version = "1.0.1", features = ["full"] }
tokio = { version = "1.17", features = ["full"] }
tower = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.7"
axum = "0.8.0"
tokio = { version = "1.17", features = ["full"] }
utoipa = { path = "../../utoipa", features = ["axum_extras"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/todo-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Elli Example <[email protected]>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.7"
axum = "0.8.0"
hyper = { version = "1.0.1", features = ["full"] }
tokio = { version = "1.17", features = ["full"] }
tower = "0.5"
Expand Down
1 change: 1 addition & 0 deletions utoipa-axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)
* Added mutable getter for the openapi instance of a OpenApiRouter (https://github.com/juhaku/utoipa/pull/1262)
* utoipa-axum: Add basic path params test (https://github.com/juhaku/utoipa/pull/1268)

Expand Down
4 changes: 2 additions & 2 deletions utoipa-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version.workspace = true
debug = []

[dependencies]
axum = { version = "0.7", default-features = false }
axum = { version = "0.8.0", default-features = false }
utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, features = [
"macros",
] }
Expand All @@ -25,7 +25,7 @@ paste = "1.0"

[dev-dependencies]
utoipa = { path = "../utoipa", features = ["debug"] }
axum = { version = "0.7", default-features = false, features = ["json"] }
axum = { version = "0.8.0", default-features = false, features = ["json"] }
http = "1.2"
insta = { version = "1.41", features = ["json"] }
serde = "1"
Expand Down
55 changes: 16 additions & 39 deletions utoipa-axum/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ use axum::Router;
use tower_layer::Layer;
use tower_service::Service;

#[inline]
fn colonized_params<S: AsRef<str>>(path: S) -> String
where
String: From<S>,
{
String::from(path).replace('}', "").replace('{', ":")
}

#[inline]
fn path_template<S: AsRef<str>>(path: S) -> String {
path.as_ref()
.split('/')
.map(|segment| {
if !segment.is_empty() && segment[0..1] == *":" {
Cow::Owned(format!("{{{}}}", &segment[1..]))
} else {
Cow::Borrowed(segment)
}
})
.collect::<Vec<_>>()
.join("/")
}

/// Wrapper type for [`utoipa::openapi::path::Paths`] and [`axum::routing::MethodRouter`].
///
/// This is used with [`OpenApiRouter::routes`] method to register current _`paths`_ to the
Expand Down Expand Up @@ -63,8 +40,8 @@ where
/// routes.
fn layer<L, NewError>(self, layer: L) -> UtoipaMethodRouter<S, NewError>
where
L: Layer<Route<E>> + Clone + Send + 'static,
L::Service: Service<Request> + Clone + Send + 'static,
L: Layer<Route<E>> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<NewError> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Expand Down Expand Up @@ -103,8 +80,8 @@ where
{
fn layer<L, NewError>(self, layer: L) -> UtoipaMethodRouter<S, NewError>
where
L: Layer<Route<E>> + Clone + Send + 'static,
L::Service: Service<Request> + Clone + Send + 'static,
L: Layer<Route<E>> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<NewError> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Expand Down Expand Up @@ -211,7 +188,7 @@ where
/// Pass through method for [`axum::Router::fallback_service`].
pub fn fallback_service<T>(self, service: T) -> Self
where
T: Service<Request, Error = Infallible> + Clone + Send + 'static,
T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand All @@ -221,8 +198,8 @@ where
/// Pass through method for [`axum::Router::layer`].
pub fn layer<L>(self, layer: L) -> Self
where
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request> + Clone + Send + 'static,
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Expand All @@ -245,11 +222,11 @@ where
};
let path = if path.is_empty() { "/" } else { path };

self.0.route(&colonized_params(path), method_router)
self.0.route(path, method_router)
} else {
paths.paths.iter().fold(self.0, |this, (path, _)| {
let path = if path.is_empty() { "/" } else { path };
this.route(&colonized_params(path), method_router.clone())
this.route(path, method_router.clone())
})
};

Expand All @@ -273,14 +250,14 @@ where

/// Pass through method for [`axum::Router<S>::route`].
pub fn route(self, path: &str, method_router: MethodRouter<S>) -> Self {
Self(self.0.route(&colonized_params(path), method_router), self.1)
Self(self.0.route(path, method_router), self.1)
}

/// Pass through method for [`axum::Router::route_layer`].
pub fn route_layer<L>(self, layer: L) -> Self
where
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request> + Clone + Send + 'static,
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Expand All @@ -291,7 +268,7 @@ where
/// Pass through method for [`axum::Router<S>::route_service`].
pub fn route_service<T>(self, path: &str, service: T) -> Self
where
T: Service<Request, Error = Infallible> + Clone + Send + 'static,
T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand Down Expand Up @@ -336,19 +313,19 @@ where
}

let api = self.1.nest_with_path_composer(
path_for_nested_route(&path_template(path), "/"),
path_for_nested_route(path, "/"),
router.1,
path_for_nested_route,
);
let router = self.0.nest(&colonized_params(path), router.0);
let router = self.0.nest(path, router.0);

Self(router, api)
}

/// Pass through method for [`axum::Router::nest_service`]. _**This does nothing for OpenApi paths.**_
pub fn nest_service<T>(self, path: &str, service: T) -> Self
where
T: Service<Request, Error = Infallible> + Clone + Send + 'static,
T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
{
Expand Down
1 change: 1 addition & 0 deletions utoipa-gen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)
* Replace `assert-json-diff` with snapshot testing via `insta` (https://github.com/juhaku/utoipa/pull/1253)
* scripts/test.sh: Fix `auto_into_responses` feature declaration (https://github.com/juhaku/utoipa/pull/1252)

Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ utoipa = { path = "../utoipa", features = [
serde_json = "1"
serde = "1"
actix-web = { version = "4", features = ["macros"], default-features = false }
axum = { version = "0.7", default-features = false, features = [
axum = { version = "0.8.0", default-features = false, features = [
"json",
"query",
] }
Expand Down
6 changes: 6 additions & 0 deletions utoipa-rapidoc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - utoipa-rapidoc

## Unreleased

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)

## 5.0.0 - Oct 14 2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion utoipa-rapidoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, feat
] }
actix-web = { version = "4", optional = true, default-features = false }
rocket = { version = "0.5", features = ["json"], optional = true }
axum = { version = "0.7", default-features = false, features = [
axum = { version = "0.8.0", default-features = false, features = [
"json",
], optional = true }

Expand Down
6 changes: 6 additions & 0 deletions utoipa-redoc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - utoipa-redoc

## Unreleased

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)

## 5.0.0 - Oct 14 2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion utoipa-redoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, feat
] }
actix-web = { version = "4", optional = true }
rocket = { version = "0.5", features = ["json"], optional = true }
axum = { version = "0.7", default-features = false, optional = true }
axum = { version = "0.8.0", default-features = false, optional = true }

[dev-dependencies]
utoipa-redoc = { path = ".", features = ["actix-web", "axum", "rocket"] }
Expand Down
6 changes: 6 additions & 0 deletions utoipa-scalar/CHANAGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - utoipa-scalar

## Unreleased

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)

## 0.2.0 - Oct 14 2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion utoipa-scalar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, feat
] }
actix-web = { version = "4", optional = true, default-features = false }
rocket = { version = "0.5", features = ["json"], optional = true }
axum = { version = "0.7", default-features = false, optional = true }
axum = { version = "0.8.0", default-features = false, optional = true }

[dev-dependencies]
utoipa-scalar = { path = ".", features = ["actix-web", "axum", "rocket"] }
Expand Down
6 changes: 6 additions & 0 deletions utoipa-swagger-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - utoipa-swagger-ui

## Unreleased

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)

## 8.1.0 - Dec 19 2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion utoipa-swagger-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rust-embed = { version = "8" }
mime_guess = { version = "2.0" }
actix-web = { version = "4", optional = true, default-features = false, features = ["macros"] }
rocket = { version = "0.5", features = ["json"], optional = true }
axum = { version = "0.7", default-features = false, features = [
axum = { version = "0.8.0", default-features = false, features = [
"json",
], optional = true }
utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, features = [
Expand Down
4 changes: 2 additions & 2 deletions utoipa-swagger-ui/src/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
let mut router = if path == "/" {
router
.route(path, handler.clone())
.route(&format!("{}*rest", path), handler)
.route(&format!("{}{{*rest}}", path), handler)
} else {
let path = if path.ends_with('/') {
&path[..path.len() - 1]
Expand All @@ -70,7 +70,7 @@ where
routing::get(|| async move { axum::response::Redirect::to(&slash_path) }),
)
.route(&format!("{}/", path), handler.clone())
.route(&format!("{}/*rest", path), handler)
.route(&format!("{}/{{*rest}}", path), handler)
};

if let Some(BasicAuth { username, password }) = config.basic_auth {
Expand Down
1 change: 1 addition & 0 deletions utoipa/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ to look into changes introduced to **`utoipa-gen`**.

### Changed

* Update axum to v0.8 (https://github.com/juhaku/utoipa/pull/1269)
* Replace `assert-json-diff` with snapshot testing via `insta` (https://github.com/juhaku/utoipa/pull/1254)

## 5.3.0 - Dec 19 2024
Expand Down

0 comments on commit d522f74

Please sign in to comment.