diff --git a/Cargo.lock b/Cargo.lock index 3ed2037a..9630eb56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3022,6 +3022,7 @@ dependencies = [ "revolt-quark", "rocket", "rocket_cors", + "rocket_empty", "rocket_okapi", "schemars", "serde", @@ -3061,6 +3062,7 @@ dependencies = [ "regex", "reqwest", "rocket", + "rocket_empty", "rocket_http", "rocket_okapi", "schemars", @@ -3179,6 +3181,16 @@ dependencies = [ "url", ] +[[package]] +name = "rocket_empty" +version = "0.1.0" +source = "git+https://github.com/insertish/rocket_empty?branch=rc1#5b987e4d5090d28c6658aca25f09f7458e0de0fe" +dependencies = [ + "okapi", + "rocket", + "rocket_okapi", +] + [[package]] name = "rocket_http" version = "0.5.0-rc.1" diff --git a/crates/delta/Cargo.toml b/crates/delta/Cargo.toml index c01d322f..2c3668ee 100644 --- a/crates/delta/Cargo.toml +++ b/crates/delta/Cargo.toml @@ -52,6 +52,7 @@ mobc = { version = "0.7.3" } mobc-redis = { version = "0.7.0", default-features = false, features = ["async-std-comp"] } # web +rocket_empty = { git = "https://github.com/insertish/rocket_empty", branch = "rc1" } rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] } mongodb = { version = "1.2.2", features = ["async-std-runtime"], default-features = false } rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "5843861a88958c16bfaa0b40f0d8910772bcd2f6" } diff --git a/crates/quark/Cargo.toml b/crates/quark/Cargo.toml index cd4a8ebd..2c7483f3 100644 --- a/crates/quark/Cargo.toml +++ b/crates/quark/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [features] mongo = [ "mongodb" ] -rocket_impl = [ "rocket" ] +rocket_impl = [ "rocket", "rocket_empty" ] test = [ "async-std", "mongo", "mongodb/async-std-runtime", "rocket_impl", "rauth" ] default = [ "test" ] @@ -66,6 +66,7 @@ web-push = "0.7.2" rauth = { optional = true, git = "https://github.com/insertish/rauth", rev = "001a9698c56cea79e69e4ae71d7bc2cb48aec1a6" } rocket = { optional = true, version = "=0.5.0-rc.1", default-features = false, features = ["json"] } rocket_http = { optional = true, version = "=0.5.0-rc.1" } +rocket_empty = { optional = true, git = "https://github.com/insertish/rocket_empty", branch = "rc1" } # Sentry sentry = "0.25.0" diff --git a/crates/quark/src/lib.rs b/crates/quark/src/lib.rs index 9a27ea80..1ec6e3c9 100644 --- a/crates/quark/src/lib.rs +++ b/crates/quark/src/lib.rs @@ -39,9 +39,12 @@ pub use permissions::defn::*; pub use permissions::{get_relationship, perms}; pub use util::r#ref::Ref; -pub use util::result::{EmptyResponse, Error, Result}; +pub use util::result::{Error, Result}; pub use util::variables; +#[cfg(feature = "rocket_impl")] +pub use rocket_empty::EmptyResponse; + #[cfg(feature = "rocket_impl")] use rocket::State; diff --git a/crates/quark/src/util/result.rs b/crates/quark/src/util/result.rs index 03ef7fc0..1dfdb67c 100644 --- a/crates/quark/src/util/result.rs +++ b/crates/quark/src/util/result.rs @@ -1,4 +1,4 @@ -use okapi::openapi3::{self, RefOr, SchemaObject}; +use okapi::openapi3::{self, SchemaObject}; use rocket::{ http::{ContentType, Status}, response::{self, Responder}, @@ -116,21 +116,9 @@ impl Error { } } -/// Empty 204 HTTP Response -pub struct EmptyResponse; - /// Result type with custom Error pub type Result = std::result::Result; -// ! FIXME: #[cfg] -impl<'r> Responder<'r, 'static> for EmptyResponse { - fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { - Response::build() - .status(rocket::http::Status { code: 204 }) - .ok() - } -} - /// HTTP response builder for Error enum impl<'r> Responder<'r, 'static> for Error { fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { @@ -241,24 +229,3 @@ impl rocket_okapi::response::OpenApiResponderInner for Error { }) } } - -impl rocket_okapi::response::OpenApiResponderInner for EmptyResponse { - fn responses( - _gen: &mut rocket_okapi::gen::OpenApiGenerator, - ) -> std::result::Result { - let mut responses = okapi::Map::new(); - - responses.insert( - "204".to_string(), - RefOr::Object(openapi3::Response { - description: "Success".to_string(), - ..Default::default() - }), - ); - - Ok(openapi3::Responses { - responses, - ..Default::default() - }) - } -}