Skip to content

Commit e70e2e1

Browse files
Zizico2jplatte
authored andcommitted
feat(axum): Typed routing *_with (#232)
1 parent 6269d0f commit e70e2e1

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

crates/aide/src/axum/routing/typed.rs

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ where
2828
self.api_route(P::PATH, crate::axum::routing::get(handler))
2929
}
3030

31+
/// Add a typed `GET` route to the router.
32+
///
33+
/// The path will be inferred from the first argument to the handler function which must
34+
/// implement [`TypedPath`].
35+
///
36+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
37+
pub fn typed_get_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
38+
where
39+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
40+
T: SecondElementIs<P> + 'static,
41+
I: OperationInput,
42+
O: OperationOutput,
43+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
44+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
45+
{
46+
self.api_route(P::PATH, crate::axum::routing::get_with(handler, transform))
47+
}
48+
3149
/// Add a typed `DELETE` route to the router.
3250
///
3351
/// The path will be inferred from the first argument to the handler function which must
@@ -43,6 +61,27 @@ where
4361
self.api_route(P::PATH, crate::axum::routing::delete(handler))
4462
}
4563

64+
/// Add a typed `DELETE` route to the router.
65+
///
66+
/// The path will be inferred from the first argument to the handler function which must
67+
/// implement [`TypedPath`].
68+
///
69+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
70+
pub fn typed_delete_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
71+
where
72+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
73+
T: SecondElementIs<P> + 'static,
74+
I: OperationInput,
75+
O: OperationOutput,
76+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
77+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
78+
{
79+
self.api_route(
80+
P::PATH,
81+
crate::axum::routing::delete_with(handler, transform),
82+
)
83+
}
84+
4685
/// Add a typed `HEAD` route to the router.
4786
///
4887
/// The path will be inferred from the first argument to the handler function which must
@@ -58,6 +97,24 @@ where
5897
self.api_route(P::PATH, crate::axum::routing::head(handler))
5998
}
6099

100+
/// Add a typed `HEAD` route to the router.
101+
///
102+
/// The path will be inferred from the first argument to the handler function which must
103+
/// implement [`TypedPath`].
104+
///
105+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
106+
pub fn typed_head_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
107+
where
108+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
109+
T: SecondElementIs<P> + 'static,
110+
I: OperationInput,
111+
O: OperationOutput,
112+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
113+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
114+
{
115+
self.api_route(P::PATH, crate::axum::routing::head_with(handler, transform))
116+
}
117+
61118
/// Add a typed `OPTIONS` route to the router.
62119
///
63120
/// The path will be inferred from the first argument to the handler function which must
@@ -73,6 +130,27 @@ where
73130
self.api_route(P::PATH, crate::axum::routing::options(handler))
74131
}
75132

133+
/// Add a typed `OPTIONS` route to the router.
134+
///
135+
/// The path will be inferred from the first argument to the handler function which must
136+
/// implement [`TypedPath`].
137+
///
138+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
139+
pub fn typed_options_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
140+
where
141+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
142+
T: SecondElementIs<P> + 'static,
143+
I: OperationInput,
144+
O: OperationOutput,
145+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
146+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
147+
{
148+
self.api_route(
149+
P::PATH,
150+
crate::axum::routing::options_with(handler, transform),
151+
)
152+
}
153+
76154
/// Add a typed `PATCH` route to the router.
77155
///
78156
/// The path will be inferred from the first argument to the handler function which must
@@ -88,6 +166,27 @@ where
88166
self.api_route(P::PATH, crate::axum::routing::patch(handler))
89167
}
90168

169+
/// Add a typed `PATCH` route to the router.
170+
///
171+
/// The path will be inferred from the first argument to the handler function which must
172+
/// implement [`TypedPath`].
173+
///
174+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
175+
pub fn typed_patch_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
176+
where
177+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
178+
T: SecondElementIs<P> + 'static,
179+
I: OperationInput,
180+
O: OperationOutput,
181+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
182+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
183+
{
184+
self.api_route(
185+
P::PATH,
186+
crate::axum::routing::patch_with(handler, transform),
187+
)
188+
}
189+
91190
/// Add a typed `POST` route to the router.
92191
///
93192
/// The path will be inferred from the first argument to the handler function which must
@@ -103,6 +202,24 @@ where
103202
self.api_route(P::PATH, crate::axum::routing::post(handler))
104203
}
105204

205+
/// Add a typed `POST` route to the router.
206+
///
207+
/// The path will be inferred from the first argument to the handler function which must
208+
/// implement [`TypedPath`].
209+
///
210+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
211+
pub fn typed_post_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
212+
where
213+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
214+
T: SecondElementIs<P> + 'static,
215+
I: OperationInput,
216+
O: OperationOutput,
217+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
218+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
219+
{
220+
self.api_route(P::PATH, crate::axum::routing::post_with(handler, transform))
221+
}
222+
106223
/// Add a typed `PUT` route to the router.
107224
///
108225
/// The path will be inferred from the first argument to the handler function which must
@@ -118,6 +235,24 @@ where
118235
self.api_route(P::PATH, crate::axum::routing::put(handler))
119236
}
120237

238+
/// Add a typed `PUT` route to the router.
239+
///
240+
/// The path will be inferred from the first argument to the handler function which must
241+
/// implement [`TypedPath`].
242+
///
243+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
244+
pub fn typed_put_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
245+
where
246+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
247+
T: SecondElementIs<P> + 'static,
248+
I: OperationInput,
249+
O: OperationOutput,
250+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
251+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
252+
{
253+
self.api_route(P::PATH, crate::axum::routing::put_with(handler, transform))
254+
}
255+
121256
/// Add a typed `TRACE` route to the router.
122257
///
123258
/// The path will be inferred from the first argument to the handler function which must
@@ -132,6 +267,27 @@ where
132267
{
133268
self.api_route(P::PATH, crate::axum::routing::trace(handler))
134269
}
270+
271+
/// Add a typed `TRACE` route to the router.
272+
///
273+
/// The path will be inferred from the first argument to the handler function which must
274+
/// implement [`TypedPath`].
275+
///
276+
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
277+
pub fn typed_trace_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
278+
where
279+
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
280+
T: SecondElementIs<P> + 'static,
281+
I: OperationInput,
282+
O: OperationOutput,
283+
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
284+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
285+
{
286+
self.api_route(
287+
P::PATH,
288+
crate::axum::routing::trace_with(handler, transform),
289+
)
290+
}
135291
}
136292

137293
/// A wrapper around `axum_extra::routing::TypedPath` to implement `OperationInput`.

0 commit comments

Comments
 (0)