Skip to content
Merged
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
156 changes: 156 additions & 0 deletions crates/aide/src/axum/routing/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ where
self.api_route(P::PATH, crate::axum::routing::get(handler))
}

/// Add a typed `GET` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_get_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(P::PATH, crate::axum::routing::get_with(handler, transform))
}

/// Add a typed `DELETE` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -43,6 +61,27 @@ where
self.api_route(P::PATH, crate::axum::routing::delete(handler))
}

/// Add a typed `DELETE` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_delete_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(
P::PATH,
crate::axum::routing::delete_with(handler, transform),
)
}

/// Add a typed `HEAD` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -58,6 +97,24 @@ where
self.api_route(P::PATH, crate::axum::routing::head(handler))
}

/// Add a typed `HEAD` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_head_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(P::PATH, crate::axum::routing::head_with(handler, transform))
}

/// Add a typed `OPTIONS` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -73,6 +130,27 @@ where
self.api_route(P::PATH, crate::axum::routing::options(handler))
}

/// Add a typed `OPTIONS` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_options_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(
P::PATH,
crate::axum::routing::options_with(handler, transform),
)
}

/// Add a typed `PATCH` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -88,6 +166,27 @@ where
self.api_route(P::PATH, crate::axum::routing::patch(handler))
}

/// Add a typed `PATCH` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_patch_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(
P::PATH,
crate::axum::routing::patch_with(handler, transform),
)
}

/// Add a typed `POST` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -103,6 +202,24 @@ where
self.api_route(P::PATH, crate::axum::routing::post(handler))
}

/// Add a typed `POST` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_post_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(P::PATH, crate::axum::routing::post_with(handler, transform))
}

/// Add a typed `PUT` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -118,6 +235,24 @@ where
self.api_route(P::PATH, crate::axum::routing::put(handler))
}

/// Add a typed `PUT` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_put_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(P::PATH, crate::axum::routing::put_with(handler, transform))
}

/// Add a typed `TRACE` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
Expand All @@ -132,6 +267,27 @@ where
{
self.api_route(P::PATH, crate::axum::routing::trace(handler))
}

/// Add a typed `TRACE` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// This method additionally accepts a transform function. See [`crate::axum`] for more details.
pub fn typed_trace_with<H, I, O, T, P, F>(self, handler: H, transform: F) -> Self
where
H: axum::handler::Handler<T, S> + OperationHandler<I, O>,
T: SecondElementIs<P> + 'static,
I: OperationInput,
O: OperationOutput,
P: axum_extra::routing::TypedPath + schemars::JsonSchema + OperationInput,
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
{
self.api_route(
P::PATH,
crate::axum::routing::trace_with(handler, transform),
)
}
}

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