Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Jun 12, 2021
1 parent f76998f commit 1134617
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
4 changes: 2 additions & 2 deletions rocket-okapi/src/request/from_data_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a, T: JsonSchema + Deserialize<'a>> OpenApiFromData<'a> for Json<T> {
"application/json".to_owned(),
MediaType {
schema: Some(schema),
..okapi::openapi3::MediaType::default()
..MediaType::default()
},
);
map
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<'a> OpenApiFromData<'a> for Data<'a> {
"application/octet-stream".to_owned(),
MediaType {
schema: Some(schema),
..okapi::openapi3::MediaType::default()
..MediaType::default()
},
);
map
Expand Down
45 changes: 4 additions & 41 deletions rocket-okapi/src/response/responder_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use rocket::fs::NamedFile;
use rocket::serde::json::{Json, Value};
use schemars::JsonSchema;
use serde::Serialize;
use std::fmt::Debug;
use std::result::Result as StdResult;

type Result = crate::Result<Responses>;

Expand Down Expand Up @@ -108,21 +106,10 @@ macro_rules! status_responder {
status_responder!(Accepted, 202);
status_responder!(Created, 201);
status_responder!(BadRequest, 400);
// status_responder!(Unauthorized, 401);
// status_responder!(Forbidden, 403);
status_responder!(Unauthorized, 401);
status_responder!(Forbidden, 403);
status_responder!(NotFound, 404);

// impl<'r, T> OpenApiResponderInner<'r> for rocket::response::status::Custom<T>
// where
// T: OpenApiResponderInner<'r> + Send
// {
// fn responses(_: &mut OpenApiGenerator) -> Result {
// let mut responses = Responses::default();
// set_status_code(&mut responses, xxx)?;
// Ok(responses)
// }
// }

macro_rules! response_content_wrapper {
($responder: ident, $mime: literal) => {
impl<T: OpenApiResponderInner> OpenApiResponderInner
Expand All @@ -145,34 +132,10 @@ response_content_wrapper!(MsgPack, "application/msgpack");
response_content_wrapper!(Plain, "text/plain");
response_content_wrapper!(Xml, "text/xml");

// impl<'r, T, E> OpenApiResponderInner<'r> for StdResult<T, E>
// where
// T: OpenApiResponderInner<'r> + Send,
// E: Debug + Send
// {
// default fn responses(gen: &mut OpenApiGenerator) -> Result {
// let mut responses = T::responses(gen)?;
// ensure_status_code_exists(&mut responses, 500);
// Ok(responses)
// }
// }

/*
impl<'r, 'o, T, E> OpenApiResponderInner for StdResult<T, E>
where
T: OpenApiResponderInner + Send,
E: Responder<'r, 'o> + Debug + Send + 'r,
{
default fn responses(_: &mut OpenApiGenerator) -> Result {
Err(OpenApiError::new("Unable to generate OpenAPI spec for Result<T, E> response, as E implements Responder but not OpenApiResponderInner.".to_owned()))
}
}
*/

impl<'r, 'o, T, E> OpenApiResponderInner for StdResult<T, E>
impl<'r, 'o, T, E> OpenApiResponderInner for std::result::Result<T, E>
where
T: OpenApiResponderInner,
E: OpenApiResponderInner + Debug,
E: OpenApiResponderInner,
{
fn responses(gen: &mut OpenApiGenerator) -> Result {
let ok_responses = T::responses(gen)?;
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn add_schema_response(
) -> Result<()> {
let media = MediaType {
schema: Some(schema),
..okapi::openapi3::MediaType::default()
..MediaType::default()
};
add_content_response(responses, status, content_type, media)
}
Expand Down

0 comments on commit 1134617

Please sign in to comment.