feat: add bounded binary API request bodies
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
use api_macros::api;
|
||||
|
||||
pub struct Response;
|
||||
|
||||
#[api]
|
||||
pub trait InvalidBinaryMethod {
|
||||
#[get("/payload")]
|
||||
async fn download(&self, #[binary] body: api_macros::BinaryBody) -> Response;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: GET operations cannot declare a request body
|
||||
--> tests/ui/invalid_binary_method.rs:8:14
|
||||
|
|
||||
8 | async fn download(&self, #[binary] body: api_macros::BinaryBody) -> Response;
|
||||
| ^^^^^^^^
|
||||
@@ -0,0 +1,11 @@
|
||||
use api_macros::api;
|
||||
|
||||
pub struct Response;
|
||||
|
||||
#[api]
|
||||
pub trait InvalidBinaryType {
|
||||
#[put("/payload")]
|
||||
async fn upload(&self, #[binary] body: Vec<u8>) -> Response;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: binary request bodies must use api_macros::BinaryBody
|
||||
--> tests/ui/invalid_binary_type.rs:8:44
|
||||
|
|
||||
8 | async fn upload(&self, #[binary] body: Vec<u8>) -> Response;
|
||||
| ^^^^^^^
|
||||
@@ -0,0 +1,16 @@
|
||||
use api_macros::api;
|
||||
|
||||
pub struct JsonBody;
|
||||
pub struct Response;
|
||||
|
||||
#[api]
|
||||
pub trait MixedRequestBodies {
|
||||
#[post("/payload")]
|
||||
async fn upload(
|
||||
&self,
|
||||
#[body] json: JsonBody,
|
||||
#[binary] binary: api_macros::BinaryBody,
|
||||
) -> Response;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: an API operation may declare only one JSON or binary request body
|
||||
--> tests/ui/mixed_request_bodies.rs:12:19
|
||||
|
|
||||
12 | #[binary] binary: api_macros::BinaryBody,
|
||||
| ^^^^^^
|
||||
@@ -0,0 +1,15 @@
|
||||
use api_macros::api;
|
||||
|
||||
pub struct Response;
|
||||
|
||||
#[api]
|
||||
pub trait MultipleBinaryBodies {
|
||||
#[post("/payload")]
|
||||
async fn upload(
|
||||
&self,
|
||||
#[binary] first: api_macros::BinaryBody,
|
||||
#[binary] second: api_macros::BinaryBody,
|
||||
) -> Response;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: an API operation may declare only one JSON or binary request body
|
||||
--> tests/ui/multiple_binary_bodies.rs:11:19
|
||||
|
|
||||
11 | #[binary] second: api_macros::BinaryBody,
|
||||
| ^^^^^^
|
||||
@@ -1,4 +1,4 @@
|
||||
error: an API operation may declare only one request body
|
||||
error: an API operation may declare only one JSON or binary request body
|
||||
--> tests/ui/multiple_bodies.rs:13:17
|
||||
|
|
||||
13 | #[body] second: SecondBody,
|
||||
|
||||
Reference in New Issue
Block a user