Skip to content

Commit

Permalink
openapi support all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 26, 2024
1 parent 749eeef commit fe991f0
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions middleware/openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ impl OpenAPI {

pub fn post(path: impl Into<Cow<'static, str>>) -> Self {
Self {
method: "GET",
method: "POST",
path: path.into(),
}
}

pub fn put(path: impl Into<Cow<'static, str>>) -> Self {
Self {
method: "GET",
method: "PUT",
path: path.into(),
}
}

pub fn patch(path: impl Into<Cow<'static, str>>) -> Self {
Self {
method: "GET",
method: "PATCH",
path: path.into(),
}
}

pub fn delete(path: impl Into<Cow<'static, str>>) -> Self {
Self {
method: "GET",
method: "DELETE",
path: path.into(),
}
}
Expand Down Expand Up @@ -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"),
},
);
Expand Down

0 comments on commit fe991f0

Please sign in to comment.