From fe991f09d7221cbfc3883e829456cd50a97113fc Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Mon, 26 Aug 2024 15:52:26 +0800 Subject: [PATCH] openapi support all methods --- middleware/openapi/src/lib.rs | 50 ++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/middleware/openapi/src/lib.rs b/middleware/openapi/src/lib.rs index a09ca613..17bd081b 100644 --- a/middleware/openapi/src/lib.rs +++ b/middleware/openapi/src/lib.rs @@ -47,28 +47,28 @@ impl OpenAPI { pub fn post(path: impl Into>) -> Self { Self { - method: "GET", + method: "POST", path: path.into(), } } pub fn put(path: impl Into>) -> Self { Self { - method: "GET", + method: "PUT", path: path.into(), } } pub fn patch(path: impl Into>) -> Self { Self { - method: "GET", + method: "PATCH", path: path.into(), } } pub fn delete(path: impl Into>) -> Self { Self { - method: "GET", + method: "DELETE", path: path.into(), } } @@ -162,9 +162,45 @@ where .await }) } - // "PUT" => axum::routing::put, - // "PATCH" => axum::routing::patch, - // "DELETE" => axum::routing::delete, + "PUT" => { + // TODO: By moving `procedure` into the closure we hang onto the types for the duration of the program which is probs undesirable. + post(move |parts: Parts, body: Bytes| async move { + let ctx = (ctx_fn)(&parts); + + handle_procedure( + ctx, + &mut serde_json::Deserializer::from_slice(&body), + procedure, + ) + .await + }) + } + "PATCH" => { + // TODO: By moving `procedure` into the closure we hang onto the types for the duration of the program which is probs undesirable. + post(move |parts: Parts, body: Bytes| async move { + let ctx = (ctx_fn)(&parts); + + handle_procedure( + ctx, + &mut serde_json::Deserializer::from_slice(&body), + procedure, + ) + .await + }) + } + "DELETE" => { + // TODO: By moving `procedure` into the closure we hang onto the types for the duration of the program which is probs undesirable. + post(move |parts: Parts, body: Bytes| async move { + let ctx = (ctx_fn)(&parts); + + handle_procedure( + ctx, + &mut serde_json::Deserializer::from_slice(&body), + procedure, + ) + .await + }) + } _ => panic!("Unsupported method"), }, );