Skip to content

Commit ac92d8a

Browse files
authored
Merge pull request #398 from ohkami-rs/v0.23.2
v0.23.2
2 parents d38cb90 + e7db233 commit ac92d8a

File tree

19 files changed

+482
-115
lines changed

19 files changed

+482
-115
lines changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exclude = [
1818
]
1919

2020
[workspace.package]
21-
version = "0.23.1"
21+
version = "0.23.2"
2222
edition = "2021"
2323
authors = ["kanarus <[email protected]>"]
2424
homepage = "https://crates.io/crates/ohkami"

Diff for: ohkami/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ features = ["rt_tokio", "nightly", "sse", "ws"]
1818

1919
[dependencies]
2020
# workspace members
21-
ohkami_lib = { version = "=0.23.1", path = "../ohkami_lib" }
22-
ohkami_macros = { version = "=0.23.1", path = "../ohkami_macros" }
23-
ohkami_openapi = { optional = true, version = "=0.23.1", path = "../ohkami_openapi" }
21+
ohkami_lib = { version = "=0.23.2", path = "../ohkami_lib" }
22+
ohkami_macros = { version = "=0.23.2", path = "../ohkami_macros" }
23+
ohkami_openapi = { optional = true, version = "=0.23.2", path = "../ohkami_openapi" }
2424

2525
# workspace dependencies
2626
byte_reader = { workspace = true }

Diff for: ohkami/src/format/builtin/html.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,35 @@ use std::borrow::Cow;
44
#[cfg(feature="openapi")]
55
use crate::openapi;
66

7-
7+
/// # HTML format
8+
///
9+
/// ## Request
10+
///
11+
/// not supported
12+
///
13+
/// ## Response
14+
///
15+
/// - content type: `text/html; charset=UTF-8`
16+
/// - schema bound: `Into<Cow<'static, str>>`
17+
///
18+
/// ### example
19+
///
20+
/// ```
21+
/// use ohkami::format::HTML;
22+
///
23+
/// async fn handler() -> HTML<&'static str> {
24+
/// HTML(r#"
25+
/// <html>
26+
/// <head>
27+
/// <title>Sample Document</title>
28+
/// </head>
29+
/// <body>
30+
/// <h1>Sample Document</h1>
31+
/// </body>
32+
/// </html>
33+
/// "#)
34+
/// }
35+
/// ```
836
pub struct HTML<T = String>(pub T);
937

1038
impl<T: Into<Cow<'static, str>>> IntoBody for HTML<T> {

Diff for: ohkami/src/format/builtin/json.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,60 @@ use std::borrow::Cow;
55
#[cfg(feature="openapi")]
66
use crate::openapi;
77

8-
8+
/// # JSON format
9+
///
10+
/// When `openapi` feature is activated, schema bound additionally
11+
/// requires `openapi::Schema`.
12+
///
13+
/// ## Request
14+
///
15+
/// - content type: `application/json`
16+
/// - schema bound: `Deserialize<'_>`
17+
///
18+
/// ### example
19+
///
20+
/// ```
21+
/// # enum MyError {}
22+
/// use ohkami::format::JSON;
23+
/// use ohkami::serde::Deserialize;
24+
///
25+
/// #[derive(Deserialize)]
26+
/// struct CreateUserRequest<'req> {
27+
/// name: &'req str,
28+
/// age: Option<u8>,
29+
/// }
30+
///
31+
/// async fn create_user(
32+
/// JSON(body): JSON<CreateUserRequest<'_>>,
33+
/// ) -> Result<(), MyError> {
34+
/// todo!()
35+
/// }
36+
/// ```
37+
///
38+
/// ## Response
39+
///
40+
/// - content type: `application/json`
41+
/// - schema bound: `Serialize`
42+
///
43+
/// ### example
44+
///
45+
/// ```
46+
/// # enum MyError {}
47+
/// use ohkami::format::JSON;
48+
/// use ohkami::serde::Serialize;
49+
///
50+
/// #[derive(Serialize)]
51+
/// struct User {
52+
/// name: String,
53+
/// age: Option<u8>,
54+
/// }
55+
///
56+
/// async fn get_user(
57+
/// id: &str,
58+
/// ) -> Result<JSON<User>, MyError> {
59+
/// todo!()
60+
/// }
61+
/// ```
962
pub struct JSON<T: bound::Schema>(pub T);
1063

1164
impl<'req, T: Incoming<'req>> FromBody<'req> for JSON<T> {

Diff for: ohkami/src/format/builtin/multipart.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,47 @@ use ohkami_lib::serde_multipart;
55
#[cfg(feature="openapi")]
66
use crate::openapi;
77

8-
8+
/// # multipart/form-data format
9+
///
10+
/// When `openapi` feature is activated, schema bound additionally
11+
/// requires `openapi::Schema`.
12+
///
13+
/// ## Request
14+
///
15+
/// - content type: `multipart/form-data`
16+
/// - schema bound: `Deserialize<'_>`
17+
///
18+
/// ### example
19+
///
20+
/// ```
21+
/// # enum MyError {}
22+
/// use ohkami::format::{Multipart, File};
23+
/// use ohkami::serde::Deserialize;
24+
///
25+
/// #[derive(Deserialize)]
26+
/// struct SignUpForm<'req> {
27+
/// #[serde(rename = "user-name")]
28+
/// user_name: &'req str,
29+
///
30+
/// password: &'req str,
31+
///
32+
/// #[serde(rename = "user-icon")]
33+
/// user_icon: Option<File<'req>>,
34+
///
35+
/// #[serde(rename = "pet-photos")]
36+
/// pet_photos: Vec<File<'req>>,
37+
/// }
38+
///
39+
/// async fn sign_up(
40+
/// Multipart(form): Multipart<SignUpForm<'_>>,
41+
/// ) -> Result<(), MyError> {
42+
/// todo!()
43+
/// }
44+
/// ```
45+
///
46+
/// ## Response
47+
///
48+
/// not supported
949
pub use ohkami_lib::serde_multipart::File;
1050

1151
pub struct Multipart<T: bound::Schema>(pub T);

Diff for: ohkami/src/format/builtin/query.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,35 @@ use crate::openapi;
77

88
/// # Query parameters
99
///
10-
/// Deserialize query parameters into an instance of type `T`.
10+
/// Deserialize query parameters in a request into an instance of
11+
/// schema type `T: Deserialize<'_>`.
12+
///
13+
/// When `openapi` feature is activated, schema bound additionally
14+
/// requires `openapi::Schema`.
15+
///
16+
/// ### example
17+
///
18+
/// ```
19+
/// # enum MyError {}
20+
/// use ohkami::format::{JSON, Query};
21+
/// use ohkami::serde::Deserialize;
22+
///
23+
/// #[derive(Deserialize)]
24+
/// struct ListUsersMeta<'req> {
25+
/// name_prefix: Option<&'req str>,
26+
/// min_age: Option<u8>,
27+
/// max_age: Option<u8>,
28+
/// limit: Option<usize>,
29+
/// }
30+
/// # #[derive(ohkami::serde::Serialize)]
31+
/// # struct User {}
32+
///
33+
/// async fn list_users(
34+
/// Query(meta): Query<ListUsersMeta<'_>>,
35+
/// ) -> Result<JSON<Vec<User>>, MyError> {
36+
/// todo!()
37+
/// }
38+
/// ```
1139
///
1240
/// ### note
1341
///

Diff for: ohkami/src/format/builtin/text.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,54 @@ use std::borrow::Cow;
44
#[cfg(feature="openapi")]
55
use crate::openapi;
66

7-
7+
/// # plain text format
8+
///
9+
/// ## Request
10+
///
11+
/// - content type: `text/html; charset=UTF-8`
12+
/// - schema bound: `From<&'_ str>`
13+
///
14+
/// ### example
15+
///
16+
/// ```
17+
/// use ohkami::format::Text;
18+
///
19+
/// async fn accept_text(
20+
/// Text(text): Text<&str>,
21+
/// ) {
22+
/// println!("got plain text request: {text}");
23+
/// }
24+
/// ```
25+
///
26+
/// ## Response
27+
///
28+
/// - content type: `text/html; charset=UTF-8`
29+
/// - schema bound: `Into<Cow<'static, str>>`
30+
///
31+
/// ### note
32+
///
33+
/// For `&'static str`, `String` and `Cow<'static, str>`, this is
34+
/// useless because they can be directly available as plain text
35+
/// response.
36+
///
37+
/// ### example
38+
///
39+
/// ```
40+
/// use ohkami::format::Text;
41+
///
42+
/// async fn handler() -> Text<&'static str> {
43+
/// Text(r#"
44+
/// <html>
45+
/// <head>
46+
/// <title>Sample Document</title>
47+
/// </head>
48+
/// <body>
49+
/// <h1>Sample Document</h1>
50+
/// </body>
51+
/// </html>
52+
/// "#)
53+
/// }
54+
/// ```
855
pub struct Text<T>(pub T);
956

1057
impl<'req, T: From<&'req str>> FromBody<'req> for Text<T> {

Diff for: ohkami/src/format/builtin/urlencoded.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,60 @@ use std::borrow::Cow;
66
#[cfg(feature="openapi")]
77
use crate::openapi;
88

9-
9+
/// # URL encoded format
10+
///
11+
/// When `openapi` feature is activated, schema bound additionally
12+
/// requires `openapi::Schema`.
13+
///
14+
/// ## Request
15+
///
16+
/// - content type: `application/x-www-form-urlencoded`
17+
/// - schema bound: `Deserialize<'_>`
18+
///
19+
/// ### example
20+
///
21+
/// ```
22+
/// # enum MyError {}
23+
/// use ohkami::format::URLEncoded;
24+
/// use ohkami::serde::Deserialize;
25+
///
26+
/// #[derive(Deserialize)]
27+
/// struct CreateUserRequest<'req> {
28+
/// name: &'req str,
29+
/// age: Option<u8>,
30+
/// }
31+
///
32+
/// async fn create_user(
33+
/// URLEncoded(body): URLEncoded<CreateUserRequest<'_>>,
34+
/// ) -> Result<(), MyError> {
35+
/// todo!()
36+
/// }
37+
/// ```
38+
///
39+
/// ## Response
40+
///
41+
/// - content type: `application/x-www-form-urlencoded`
42+
/// - schema bound: `Serialize`
43+
///
44+
/// ### example
45+
///
46+
/// ```
47+
/// # enum MyError {}
48+
/// use ohkami::format::URLEncoded;
49+
/// use ohkami::serde::Serialize;
50+
///
51+
/// #[derive(Serialize)]
52+
/// struct User {
53+
/// name: String,
54+
/// age: Option<u8>,
55+
/// }
56+
///
57+
/// async fn get_user(
58+
/// id: &str,
59+
/// ) -> Result<URLEncoded<User>, MyError> {
60+
/// todo!()
61+
/// }
62+
/// ```
1063
pub struct URLEncoded<T: bound::Schema>(pub T);
1164

1265
impl<'req, T: Incoming<'req>> FromBody<'req> for URLEncoded<T> {

0 commit comments

Comments
 (0)