Skip to content
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
1 change: 1 addition & 0 deletions ohkami/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ lambda_runtime = { version = "0.14", optional = true }
base64 = { version = "0.22" }
hmac = { version = "0.12", default-features = false }
sha2 = { version = "0.10", default-features = false }
uuid = { version = "1.17" }

# optional
mime_guess = { version = "2.0", optional = true }
Expand Down
19 changes: 17 additions & 2 deletions ohkami/src/handle/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ pub struct Path<T>(pub T);
/// is required to be impl.
///
/// ### required
/// - `type Errpr`
/// - `fn from_param`
/// - `type Error: IntoResponse`
/// - `fn from_param(param: Cow<'p, str>) -> Result<Self, Self::Error>`
pub trait FromParam<'p>: bound::Schema + Sized {
/// If this extraction never fails, `std::convert::Infallible` is recomended.
type Error: IntoResponse;
Expand Down Expand Up @@ -245,6 +245,21 @@ const _: () = {
};
}
signed_integers! { i8, i16, i32, i64, isize }

impl<'p> FromParam<'p> for uuid::Uuid {
type Error = Response;

fn from_param(param: Cow<'p, str>) -> Result<Self, Self::Error> {
uuid::Uuid::try_parse(&param).map_err(|_| {
#[cfg(debug_assertions)] {
crate::WARNING!(
"Failed to parse UUID from path param `{param}`",
);
}
Response::BadRequest().with_text("unexpected path")
})
}
}
};

impl<'req, P: FromParam<'req>> FromRequest<'req> for Path<P> {
Expand Down
3 changes: 3 additions & 0 deletions ohkami_openapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ license = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }

# for built-in utility impl of `Schema` trait
uuid = { version = "1.17" }

[features]
no-release-serialize = []
6 changes: 6 additions & 0 deletions ohkami_openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ const _: () = {
number().format("double")
}
}

impl Schema for uuid::Uuid {
fn schema() -> impl Into<schema::SchemaRef> {
string().format("uuid")
}
}

impl<S: Schema> Schema for Vec<S> {
fn schema() -> impl Into<schema::SchemaRef> {
Expand Down