Skip to content

Commit 096ef7e

Browse files
committed
feat: support axum 0.8, aide 0.14, validator 0.20
1 parent c39f886 commit 096ef7e

File tree

10 files changed

+171
-307
lines changed

10 files changed

+171
-307
lines changed

Cargo.lock

+109-246
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axum-codec"
3-
version = "0.0.17"
3+
version = "0.0.19"
44
edition = "2021"
55
description = "A multi-codec extractor and response writer for Axum"
66
license = "MIT OR Apache-2.0"
@@ -14,8 +14,8 @@ all-features = true
1414
members = ["macros", ".", "examples/*"]
1515

1616
[dependencies]
17-
aide = { version = "0.13", optional = true, default-features = false, features = ["axum"] }
18-
axum = { version = "0.7", default-features = false }
17+
aide = { version = "0.14", optional = true, default-features = false, features = ["axum", "axum-json"] }
18+
axum = { version = "0.8", default-features = false }
1919
axum-codec-macros = { path = "macros", version = "0.0.12", default-features = false }
2020
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["std"], optional = true }
2121
# 0.6.3 added the #[bitcode(crate = "...")] option
@@ -31,10 +31,10 @@ serde_urlencoded = { version = "0.7", optional = true }
3131
serde_yaml = { version = "0.9", optional = true }
3232
thiserror = "1"
3333
toml = { version = "0.8", optional = true }
34-
validator = { version = "0.19", optional = true }
34+
validator = { version = "0.20", optional = true }
3535

3636
[dev-dependencies]
37-
axum = "0.7"
37+
axum = "0.8"
3838
serde = { version = "1", features = ["derive", "rc"] }
3939
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
4040
# cannot run `BorrowCodec` tests with `bitcode` since it doesn't support `Cow` (yet)

examples/aide-validator/Cargo.toml

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
aide = { version = "0.13", features = ["axum"] }
8-
axum = "0.7"
7+
aide = { version = "0.14", features = ["axum"] }
8+
axum = "0.8"
99
serde = { version = "1", features = ["derive", "rc"] }
1010
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
1111
axum-codec = { path = "../..", features = ["full-codecs", "macros", "aide", "validator"] }
12-
bitcode = "0.6"
13-
bincode = "2.0.0-rc.3"
14-
schemars = { version = "0.8", features = ["derive"] }
15-
validator = "0.18"
16-

examples/basic/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
axum = "0.7"
7+
axum = "0.8"
88
serde = { version = "1", features = ["derive", "rc"] }
99
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
1010
axum-codec = { path = "../..", features = ["macros", "validator", "json", "bincode", "msgpack", "toml", "yaml", "form"] }

examples/todo-api/Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
aide = { version = "0.13", features = ["axum"] }
8-
axum = "0.7"
7+
aide = { version = "0.14", features = ["axum"] }
8+
axum = "0.8"
99
serde = { version = "1", features = ["derive", "rc"] }
1010
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
1111
axum-codec = { path = "../..", features = ["full-codecs", "macros", "aide", "validator", "pretty-errors"] }
12-
schemars = { version = "0.8", features = ["derive"] }
13-

src/content.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ impl ContentType {
220220
}
221221
}
222222

223-
#[axum::async_trait]
224-
impl<S> FromRequestParts<S> for ContentType {
223+
impl<S> FromRequestParts<S> for ContentType
224+
where
225+
S: Sync,
226+
{
225227
type Rejection = Infallible;
226228

227229
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
@@ -278,7 +280,6 @@ impl From<Accept> for ContentType {
278280
}
279281
}
280282

281-
#[axum::async_trait]
282283
impl<S> FromRequestParts<S> for Accept
283284
where
284285
S: Send + Sync + 'static,

src/extract.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ impl<T: fmt::Display> fmt::Display for Codec<T> {
9595
}
9696
}
9797

98-
#[axum::async_trait]
9998
impl<T, S> FromRequest<S> for Codec<T>
10099
where
101100
T: for<'de> CodecDecode<'de>,
@@ -141,12 +140,15 @@ impl<T> aide::operation::OperationInput for Codec<T>
141140
where
142141
T: schemars::JsonSchema,
143142
{
144-
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
143+
fn operation_input(
144+
ctx: &mut aide::generate::GenContext,
145+
operation: &mut aide::openapi::Operation,
146+
) {
145147
axum::Json::<T>::operation_input(ctx, operation);
146148
}
147149

148150
fn inferred_early_responses(
149-
ctx: &mut aide::gen::GenContext,
151+
ctx: &mut aide::generate::GenContext,
150152
operation: &mut aide::openapi::Operation,
151153
) -> Vec<(Option<u16>, aide::openapi::Response)> {
152154
axum::Json::<T>::inferred_early_responses(ctx, operation)
@@ -161,14 +163,14 @@ where
161163
type Inner = T;
162164

163165
fn operation_response(
164-
ctx: &mut aide::gen::GenContext,
166+
ctx: &mut aide::generate::GenContext,
165167
operation: &mut aide::openapi::Operation,
166168
) -> Option<aide::openapi::Response> {
167169
axum::Json::<T>::operation_response(ctx, operation)
168170
}
169171

170172
fn inferred_responses(
171-
ctx: &mut aide::gen::GenContext,
173+
ctx: &mut aide::generate::GenContext,
172174
operation: &mut aide::openapi::Operation,
173175
) -> Vec<(Option<u16>, aide::openapi::Response)> {
174176
axum::Json::<T>::inferred_responses(ctx, operation)
@@ -326,7 +328,6 @@ where
326328
}
327329
}
328330

329-
#[axum::async_trait]
330331
impl<T, S> FromRequest<S> for BorrowCodec<T>
331332
where
332333
T: CodecDecode<'static>,
@@ -374,12 +375,15 @@ impl<T> aide::operation::OperationInput for BorrowCodec<T>
374375
where
375376
T: schemars::JsonSchema,
376377
{
377-
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
378+
fn operation_input(
379+
ctx: &mut aide::generate::GenContext,
380+
operation: &mut aide::openapi::Operation,
381+
) {
378382
axum::Json::<T>::operation_input(ctx, operation);
379383
}
380384

381385
fn inferred_early_responses(
382-
ctx: &mut aide::gen::GenContext,
386+
ctx: &mut aide::generate::GenContext,
383387
operation: &mut aide::openapi::Operation,
384388
) -> Vec<(Option<u16>, aide::openapi::Response)> {
385389
axum::Json::<T>::inferred_early_responses(ctx, operation)

src/handler.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub trait CodecHandler<T, I: Input, D, S>: Clone + Send + 'static {
3232
/// handler.
3333
pub struct CodecHandlerFn<H, I, D> {
3434
pub(crate) f: H,
35-
pub(crate) _marker: std::marker::PhantomData<(I, D)>,
35+
pub(crate) _marker: std::marker::PhantomData<(I, fn() -> D)>,
3636
}
3737

3838
impl<H, I, D> CodecHandlerFn<H, I, D> {
@@ -61,12 +61,15 @@ impl<H, I, D> aide::OperationInput for CodecHandlerFn<H, I, D>
6161
where
6262
I: aide::OperationInput,
6363
{
64-
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
64+
fn operation_input(
65+
ctx: &mut aide::generate::GenContext,
66+
operation: &mut aide::openapi::Operation,
67+
) {
6568
I::operation_input(ctx, operation);
6669
}
6770

6871
fn inferred_early_responses(
69-
ctx: &mut aide::gen::GenContext,
72+
ctx: &mut aide::generate::GenContext,
7073
operation: &mut aide::openapi::Operation,
7174
) -> Vec<(Option<u16>, aide::openapi::Response)> {
7275
I::inferred_early_responses(ctx, operation)
@@ -81,14 +84,14 @@ where
8184
type Inner = D;
8285

8386
fn operation_response(
84-
ctx: &mut aide::gen::GenContext,
87+
ctx: &mut aide::generate::GenContext,
8588
operation: &mut aide::openapi::Operation,
8689
) -> Option<aide::openapi::Response> {
8790
D::operation_response(ctx, operation)
8891
}
8992

9093
fn inferred_responses(
91-
ctx: &mut aide::gen::GenContext,
94+
ctx: &mut aide::generate::GenContext,
9295
operation: &mut aide::openapi::Operation,
9396
) -> Vec<(Option<u16>, aide::openapi::Response)> {
9497
D::inferred_responses(ctx, operation)
@@ -113,9 +116,9 @@ where
113116

114117
impl<T, H, I, D, S> Handler<T, S> for CodecHandlerFn<H, I, D>
115118
where
116-
H: CodecHandler<T, I, D, S>,
117-
S: Send + Sync + 'static,
118-
I: Input + Send + 'static,
119+
H: CodecHandler<T, I, D, S> + Sync,
120+
S: Send + 'static,
121+
I: Input + Send + Sync + 'static,
119122
D: IntoCodecResponse + Send + 'static,
120123
{
121124
type Future = Pin<Box<dyn Future<Output = Response> + Send>>;

src/rejection.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ impl aide::OperationOutput for CodecRejection {
6060
type Inner = Message;
6161

6262
fn operation_response(
63-
ctx: &mut aide::gen::GenContext,
63+
ctx: &mut aide::generate::GenContext,
6464
operation: &mut aide::openapi::Operation,
6565
) -> Option<aide::openapi::Response> {
6666
axum::Json::<Message>::operation_response(ctx, operation)
6767
}
6868

6969
fn inferred_responses(
70-
ctx: &mut aide::gen::GenContext,
70+
ctx: &mut aide::generate::GenContext,
7171
operation: &mut aide::openapi::Operation,
7272
) -> Vec<(Option<u16>, aide::openapi::Response)> {
7373
axum::Json::<Message>::inferred_responses(ctx, operation)
@@ -79,14 +79,14 @@ impl aide::OperationOutput for CodecRejection {
7979
type Inner = String;
8080

8181
fn operation_response(
82-
ctx: &mut aide::gen::GenContext,
82+
ctx: &mut aide::generate::GenContext,
8383
operation: &mut aide::openapi::Operation,
8484
) -> Option<aide::openapi::Response> {
8585
axum::Json::<String>::operation_response(ctx, operation)
8686
}
8787

8888
fn inferred_responses(
89-
ctx: &mut aide::gen::GenContext,
89+
ctx: &mut aide::generate::GenContext,
9090
operation: &mut aide::openapi::Operation,
9191
) -> Vec<(Option<u16>, aide::openapi::Response)> {
9292
axum::Json::<String>::inferred_responses(ctx, operation)
@@ -118,14 +118,14 @@ impl aide::OperationOutput for Message {
118118
type Inner = Self;
119119

120120
fn operation_response(
121-
ctx: &mut aide::gen::GenContext,
121+
ctx: &mut aide::generate::GenContext,
122122
operation: &mut aide::openapi::Operation,
123123
) -> Option<aide::openapi::Response> {
124124
axum::Json::<Self>::operation_response(ctx, operation)
125125
}
126126

127127
fn inferred_responses(
128-
ctx: &mut aide::gen::GenContext,
128+
ctx: &mut aide::generate::GenContext,
129129
operation: &mut aide::openapi::Operation,
130130
) -> Vec<(Option<u16>, aide::openapi::Response)> {
131131
axum::Json::<Self>::inferred_responses(ctx, operation)

src/routing.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ macro_rules! method_router_chain_method {
8080
#[must_use]
8181
pub fn $name<T, H, I, D>(mut self, handler: H) -> Self
8282
where
83-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
84-
I: Input + Send + 'static,
85-
D: IntoCodecResponse + Send + Sync + 'static,
83+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
84+
I: Input + Send + Sync + 'static,
85+
D: IntoCodecResponse + Send + 'static,
8686
S: Clone + Send + Sync + 'static,
87-
T: 'static
87+
T: Sync + 'static
8888
{
8989
self.inner = self.inner.$name(CodecHandlerFn::new(handler));
9090
self
@@ -99,11 +99,11 @@ macro_rules! method_router_chain_method {
9999
#[must_use]
100100
pub fn $name<T, H, I, D>(mut self, handler: H) -> Self
101101
where
102-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
103-
I: Input + Send + 'static,
102+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
103+
I: Input + Send + Sync + 'static,
104104
D: IntoCodecResponse + Send + 'static,
105105
S: Clone + Send + Sync + 'static,
106-
T: 'static,
106+
T: Sync + 'static,
107107
{
108108
self.inner = self.inner.$name(CodecHandlerFn::<H, I, D>::new(handler));
109109
self
@@ -113,11 +113,11 @@ macro_rules! method_router_chain_method {
113113
#[must_use]
114114
pub fn $with<T, H, I, D, F>(mut self, handler: H, transform: F) -> Self
115115
where
116-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
117-
I: Input + Send + 'static,
116+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
117+
I: Input + Send + Sync + 'static,
118118
D: IntoCodecResponse + Send + 'static,
119119
S: Clone + Send + Sync + 'static,
120-
T: 'static,
120+
T: Sync + 'static,
121121
F: FnOnce(aide::transform::TransformOperation) -> aide::transform::TransformOperation,
122122
{
123123
self.inner = self.inner.$with(CodecHandlerFn::<H, I, D>::new(handler), transform);
@@ -153,11 +153,11 @@ macro_rules! method_router_top_level {
153153
#[doc = concat!("Route `", stringify!($name) ,"` requests to the given handler. See [`axum::routing::", stringify!($name) , "`] for more details.")]
154154
pub fn $name<T, H, I, D, S>(handler: H) -> MethodRouter<S, Infallible>
155155
where
156-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
157-
I: Input + Send + 'static,
156+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
157+
I: Input + Send + Sync + 'static,
158158
D: IntoCodecResponse + Send + 'static,
159159
S: Clone + Send + Sync + 'static,
160-
T: 'static
160+
T: Sync + 'static
161161
{
162162
MethodRouter::from(routing::$name(CodecHandlerFn::new(handler)))
163163
}
@@ -170,11 +170,11 @@ macro_rules! method_router_top_level {
170170
#[doc = concat!("Route `", stringify!($name) ,"` requests to the given handler. See [`axum::routing::", stringify!($name) , "`] for more details.")]
171171
pub fn $name<T, H, I, D, S>(handler: H) -> MethodRouter<S, Infallible>
172172
where
173-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
174-
I: Input + Send + 'static,
173+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
174+
I: Input + Send + Sync + 'static,
175175
D: IntoCodecResponse + Send + 'static,
176176
S: Clone + Send + Sync + 'static,
177-
T: 'static,
177+
T: Sync + 'static,
178178
{
179179
MethodRouter::from(aide::axum::routing::$name(
180180
CodecHandlerFn::<H, I, D>::new(handler),
@@ -185,11 +185,11 @@ macro_rules! method_router_top_level {
185185
#[must_use]
186186
pub fn $with<T, H, I, D, S, F>(handler: H, transform: F) -> MethodRouter<S, Infallible>
187187
where
188-
H: CodecHandler<T, I, D, S> + Clone + Send + 'static,
189-
I: Input + Send + 'static,
188+
H: CodecHandler<T, I, D, S> + Clone + Send + Sync + 'static,
189+
I: Input + Send + Sync + 'static,
190190
D: IntoCodecResponse + Send + 'static,
191191
S: Clone + Send + Sync + 'static,
192-
T: 'static,
192+
T: Sync + 'static,
193193
F: FnOnce(aide::transform::TransformOperation) -> aide::transform::TransformOperation,
194194
{
195195
MethodRouter::from(aide::axum::routing::$with(CodecHandlerFn::<H, I, D>::new(handler), transform))

0 commit comments

Comments
 (0)