aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/fatcat-api/src/server.rs')
-rw-r--r--rust/fatcat-api/src/server.rs2102
1 files changed, 536 insertions, 1566 deletions
diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs
index 66539c55..5e799bd4 100644
--- a/rust/fatcat-api/src/server.rs
+++ b/rust/fatcat-api/src/server.rs
@@ -36,12 +36,9 @@ use swagger::{ApiError, Context, XSpanId};
#[allow(unused_imports)]
use models;
-use {Api, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse,
- CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse,
- EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse,
- EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse,
- FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse,
- ReleasePostResponse, WorkIdGetResponse, WorkPostResponse};
+use {Api, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse, EditgroupIdAcceptPostResponse,
+ EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse,
+ ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse};
header! { (Warning, "Warning") => [String] }
@@ -95,20 +92,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -116,88 +104,45 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.container_id_get(param_id, context).wait() {
Ok(rsp) => match rsp {
ContainerIdGetResponse::FetchASingleContainerById(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_FETCH_A_SINGLE_CONTAINER_BY_ID.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
ContainerIdGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_ID_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
ContainerIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -205,19 +150,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -231,20 +170,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -252,118 +182,67 @@ where
let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
let param_issn = query_params
.get("issn")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing required query parameter issn".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issn".to_string())))?
.first()
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Required query parameter issn was empty".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issn was empty".to_string())))?
.parse::<String>()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't parse query parameter issn - doesn't match schema: {}",
- e
- ),
- ))
- })?;
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issn - doesn't match schema: {}", e))))?;
match api.container_lookup_get(param_issn, context).wait() {
- Ok(rsp) => {
- match rsp {
- ContainerLookupGetResponse::FindASingleContainerByExternalIdentifer(
- body,
- ) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER.clone()));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- ContainerLookupGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_LOOKUP_GET_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- ContainerLookupGetResponse::NoSuchContainer(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER
- .clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- ContainerLookupGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ Ok(rsp) => match rsp {
+ ContainerLookupGetResponse::FindASingleContainerByExternalIdentifer(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
+ Ok(response)
}
- }
+ ContainerLookupGetResponse::BadRequest(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ ContainerLookupGetResponse::NoSuchContainer(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ ContainerLookupGetResponse::GenericErrorResponse(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ },
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -377,20 +256,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -405,11 +275,10 @@ where
let param_body = if let Some(param_body_raw) = param_body {
let deserializer = &mut serde_json::Deserializer::from_str(&param_body_raw);
- let param_body: Option<models::ContainerEntity> =
- serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::ContainerEntity> = serde_ignored::deserialize(deserializer, |path| {
+ warn!("Ignoring unknown field in body: {}", path);
+ unused_elements.push(path.to_string());
+ }).unwrap_or(None);
param_body
} else {
@@ -419,68 +288,38 @@ where
match api.container_post(param_body, context).wait() {
Ok(rsp) => match rsp {
ContainerPostResponse::Created(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_POST_CREATED.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_CREATED.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
ContainerPostResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_POST_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
ContainerPostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CONTAINER_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
@@ -488,19 +327,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -514,20 +347,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -535,110 +359,59 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.creator_id_get(param_id, context).wait() {
- Ok(rsp) => {
- match rsp {
- CreatorIdGetResponse::FetchASingleCreatorById(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID.clone()));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- CreatorIdGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_ID_GET_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- CreatorIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_ID_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
+ Ok(rsp) => match rsp {
+ CreatorIdGetResponse::FetchASingleCreatorById(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
}
- }
+ CreatorIdGetResponse::BadRequest(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ CreatorIdGetResponse::GenericErrorResponse(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ },
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -652,20 +425,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -673,96 +437,53 @@ where
let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
let param_orcid = query_params
.get("orcid")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing required query parameter orcid".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter orcid".to_string())))?
.first()
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Required query parameter orcid was empty".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))?
.parse::<String>()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't parse query parameter orcid - doesn't match schema: {}",
- e
- ),
- ))
- })?;
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))))?;
match api.creator_lookup_get(param_orcid, context).wait() {
Ok(rsp) => match rsp {
CreatorLookupGetResponse::FindASingleCreatorByExternalIdentifer(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
CreatorLookupGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_LOOKUP_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
CreatorLookupGetResponse::NoSuchCreator(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_LOOKUP_GET_NO_SUCH_CREATOR.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_NO_SUCH_CREATOR.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
CreatorLookupGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -770,19 +491,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -796,20 +511,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -824,11 +530,10 @@ where
let param_body = if let Some(param_body_raw) = param_body {
let deserializer = &mut serde_json::Deserializer::from_str(&param_body_raw);
- let param_body: Option<models::CreatorEntity> =
- serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::CreatorEntity> = serde_ignored::deserialize(deserializer, |path| {
+ warn!("Ignoring unknown field in body: {}", path);
+ unused_elements.push(path.to_string());
+ }).unwrap_or(None);
param_body
} else {
@@ -838,68 +543,38 @@ where
match api.creator_post(param_body, context).wait() {
Ok(rsp) => match rsp {
CreatorPostResponse::Created(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_POST_CREATED.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_CREATED.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
CreatorPostResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_POST_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
CreatorPostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::CREATOR_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
@@ -907,19 +582,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -933,20 +602,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -954,120 +614,71 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.editgroup_id_accept_post(param_id, context).wait() {
- Ok(rsp) => {
- match rsp {
- EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_.clone()));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- EditgroupIdAcceptPostResponse::EditgroupIsInAnUnmergableState(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ Ok(rsp) => match rsp {
+ EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
- EditgroupIdAcceptPostResponse::NoSuchEditgroup(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ Ok(response)
+ }
+ EditgroupIdAcceptPostResponse::EditgroupIsInAnUnmergableState(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP.clone()));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
- EditgroupIdAcceptPostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ Ok(response)
+ }
+ EditgroupIdAcceptPostResponse::NoSuchEditgroup(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE.clone()));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
+ Ok(response)
}
- }
+ EditgroupIdAcceptPostResponse::GenericErrorResponse(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ },
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1081,20 +692,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1102,88 +704,45 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.editgroup_id_get(param_id, context).wait() {
Ok(rsp) => match rsp {
EditgroupIdGetResponse::FetchEditgroupByIdentifier(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_FETCH_EDITGROUP_BY_IDENTIFIER.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditgroupIdGetResponse::NoSuchEditgroup(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITGROUP_ID_GET_NO_SUCH_EDITGROUP.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_NO_SUCH_EDITGROUP.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditgroupIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -1191,19 +750,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1217,74 +770,43 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
match api.editgroup_post(context).wait() {
Ok(rsp) => match rsp {
EditgroupPostResponse::SuccessfullyCreated(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITGROUP_POST_SUCCESSFULLY_CREATED.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_SUCCESSFULLY_CREATED.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditgroupPostResponse::InvalidRequestParameters(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITGROUP_POST_INVALID_REQUEST_PARAMETERS
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_INVALID_REQUEST_PARAMETERS.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditgroupPostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -1292,19 +814,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1318,20 +834,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1339,107 +846,59 @@ where
let param_username = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("username")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter username".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter username: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))?
};
- match api.editor_username_changelog_get(param_username, context)
- .wait()
- {
- Ok(rsp) => {
- match rsp {
- EditorUsernameChangelogGetResponse::FindChanges_(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_.clone()));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- EditorUsernameChangelogGetResponse::UsernameNotFound(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ match api.editor_username_changelog_get(param_username, context).wait() {
+ Ok(rsp) => match rsp {
+ EditorUsernameChangelogGetResponse::FindChanges_(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
- EditorUsernameChangelogGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ Ok(response)
+ }
+ EditorUsernameChangelogGetResponse::UsernameNotFound(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE.clone()));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
- Ok(response)
- }
+ Ok(response)
}
- }
+ EditorUsernameChangelogGetResponse::GenericErrorResponse(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ },
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1453,20 +912,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1474,89 +924,47 @@ where
let param_username = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("username")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter username".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter username: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))?
};
match api.editor_username_get(param_username, context).wait() {
Ok(rsp) => match rsp {
EditorUsernameGetResponse::FetchGenericInformationAboutAnEditor(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditorUsernameGetResponse::UsernameNotFound(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITOR_USERNAME_GET_USERNAME_NOT_FOUND
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_USERNAME_NOT_FOUND.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
EditorUsernameGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -1564,19 +972,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1590,20 +992,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1611,89 +1004,45 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.file_id_get(param_id, context).wait() {
Ok(rsp) => match rsp {
FileIdGetResponse::FetchASingleFileById(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
FileIdGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_ID_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
FileIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_ID_GET_GENERIC_ERROR_RESPONSE.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -1701,19 +1050,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1727,20 +1070,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1748,96 +1082,53 @@ where
let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
let param_sha1 = query_params
.get("sha1")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing required query parameter sha1".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter sha1".to_string())))?
.first()
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Required query parameter sha1 was empty".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))?
.parse::<String>()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't parse query parameter sha1 - doesn't match schema: {}",
- e
- ),
- ))
- })?;
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))))?;
match api.file_lookup_get(param_sha1, context).wait() {
Ok(rsp) => match rsp {
FileLookupGetResponse::FindASingleFileByExternalIdentifer(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
FileLookupGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_LOOKUP_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
FileLookupGetResponse::NoSuchFile(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_LOOKUP_GET_NO_SUCH_FILE.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_NO_SUCH_FILE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
FileLookupGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -1845,19 +1136,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -1871,20 +1156,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -1899,11 +1175,10 @@ where
let param_body = if let Some(param_body_raw) = param_body {
let deserializer = &mut serde_json::Deserializer::from_str(&param_body_raw);
- let param_body: Option<models::FileEntity> =
- serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::FileEntity> = serde_ignored::deserialize(deserializer, |path| {
+ warn!("Ignoring unknown field in body: {}", path);
+ unused_elements.push(path.to_string());
+ }).unwrap_or(None);
param_body
} else {
@@ -1913,68 +1188,38 @@ where
match api.file_post(param_body, context).wait() {
Ok(rsp) => match rsp {
FilePostResponse::Created(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response
- .headers
- .set(ContentType(mimetypes::responses::FILE_POST_CREATED.clone()));
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_POST_CREATED.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
FilePostResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_POST_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_POST_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
FilePostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::FILE_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::FILE_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
@@ -1982,19 +1227,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -2008,20 +1247,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -2029,110 +1259,59 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.release_id_get(param_id, context).wait() {
- Ok(rsp) => {
- match rsp {
- ReleaseIdGetResponse::FetchASingleReleaseById(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID.clone()));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- ReleaseIdGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_ID_GET_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
- ReleaseIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_ID_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
-
- Ok(response)
- }
+ Ok(rsp) => match rsp {
+ ReleaseIdGetResponse::FetchASingleReleaseById(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
}
- }
+ ReleaseIdGetResponse::BadRequest(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ ReleaseIdGetResponse::GenericErrorResponse(body) => {
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
+
+ Ok(response)
+ }
+ },
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -2146,20 +1325,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -2167,96 +1337,53 @@ where
let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
let param_doi = query_params
.get("doi")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing required query parameter doi".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter doi".to_string())))?
.first()
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Required query parameter doi was empty".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))?
.parse::<String>()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't parse query parameter doi - doesn't match schema: {}",
- e
- ),
- ))
- })?;
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))))?;
match api.release_lookup_get(param_doi, context).wait() {
Ok(rsp) => match rsp {
ReleaseLookupGetResponse::FindASingleReleaseByExternalIdentifer(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER.clone()));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response
+ .headers
+ .set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
ReleaseLookupGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_LOOKUP_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
ReleaseLookupGetResponse::NoSuchRelease(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(404), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_LOOKUP_GET_NO_SUCH_RELEASE.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(404), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_NO_SUCH_RELEASE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
ReleaseLookupGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE
- .clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -2264,19 +1391,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -2290,20 +1411,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -2318,11 +1430,10 @@ where
let param_body = if let Some(param_body_raw) = param_body {
let deserializer = &mut serde_json::Deserializer::from_str(&param_body_raw);
- let param_body: Option<models::ReleaseEntity> =
- serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::ReleaseEntity> = serde_ignored::deserialize(deserializer, |path| {
+ warn!("Ignoring unknown field in body: {}", path);
+ unused_elements.push(path.to_string());
+ }).unwrap_or(None);
param_body
} else {
@@ -2332,68 +1443,38 @@ where
match api.release_post(param_body, context).wait() {
Ok(rsp) => match rsp {
ReleasePostResponse::Created(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_POST_CREATED.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_CREATED.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
ReleasePostResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_POST_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
ReleasePostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::RELEASE_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
@@ -2401,19 +1482,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -2427,20 +1502,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -2448,89 +1514,45 @@ where
let param_id = {
let param = req.extensions
.get::<Router>()
- .ok_or_else(|| {
- Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- ))
- })?
+ .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
.find("id")
- .ok_or_else(|| {
- Response::with((
- status::BadRequest,
- "Missing path parameter id".to_string(),
- ))
- })?;
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
- .map_err(|_| {
- Response::with((
- status::BadRequest,
- format!(
- "Couldn't percent-decode path parameter as UTF-8: {}",
- param
- ),
- ))
- })?
+ .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| {
- Response::with((
- status::BadRequest,
- format!("Couldn't parse path parameter id: {}", e),
- ))
- })?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
match api.work_id_get(param_id, context).wait() {
Ok(rsp) => match rsp {
WorkIdGetResponse::FetchASingleWorkById(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(200), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(200), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
WorkIdGetResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::WORK_ID_GET_BAD_REQUEST.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_BAD_REQUEST.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
WorkIdGetResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::WORK_ID_GET_GENERIC_ERROR_RESPONSE.clone(),
- ));
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_GENERIC_ERROR_RESPONSE.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
}
@@ -2538,19 +1560,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},
@@ -2564,20 +1580,11 @@ where
let mut context = Context::default();
// Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists).
- fn handle_request<T>(
- req: &mut Request,
- api: &T,
- context: &mut Context,
- ) -> Result<Response, Response>
+ fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response>
where
T: Api,
{
- context.x_span_id = Some(
- req.headers
- .get::<XSpanId>()
- .map(XSpanId::to_string)
- .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()),
- );
+ context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()));
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
@@ -2592,11 +1599,10 @@ where
let param_body = if let Some(param_body_raw) = param_body {
let deserializer = &mut serde_json::Deserializer::from_str(&param_body_raw);
- let param_body: Option<models::WorkEntity> =
- serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::WorkEntity> = serde_ignored::deserialize(deserializer, |path| {
+ warn!("Ignoring unknown field in body: {}", path);
+ unused_elements.push(path.to_string());
+ }).unwrap_or(None);
param_body
} else {
@@ -2606,68 +1612,38 @@ where
match api.work_post(param_body, context).wait() {
Ok(rsp) => match rsp {
WorkPostResponse::Created(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
- let mut response =
- Response::with((status::Status::from_u16(201), body_string));
- response
- .headers
- .set(ContentType(mimetypes::responses::WORK_POST_CREATED.clone()));
+ let mut response = Response::with((status::Status::from_u16(201), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_POST_CREATED.clone()));
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
WorkPostResponse::BadRequest(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(400), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::WORK_POST_BAD_REQUEST.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(400), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_POST_BAD_REQUEST.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
WorkPostResponse::GenericErrorResponse(body) => {
- let body_string = serde_json::to_string(&body)
- .expect("impossible to fail to serialize");
-
- let mut response =
- Response::with((status::Status::from_u16(0), body_string));
- response.headers.set(ContentType(
- mimetypes::responses::WORK_POST_GENERIC_ERROR_RESPONSE.clone(),
- ));
-
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
+
+ let mut response = Response::with((status::Status::from_u16(0), body_string));
+ response.headers.set(ContentType(mimetypes::responses::WORK_POST_GENERIC_ERROR_RESPONSE.clone()));
+
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
if !unused_elements.is_empty() {
- response.headers.set(Warning(format!(
- "Ignoring unknown fields in body: {:?}",
- unused_elements
- )));
+ response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements)));
}
Ok(response)
}
@@ -2675,19 +1651,13 @@ where
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
- Err(Response::with((
- status::InternalServerError,
- "An internal error occurred".to_string(),
- )))
+ Err(Response::with((status::InternalServerError, "An internal error occurred".to_string())))
}
}
}
handle_request(req, &api_clone, &mut context).or_else(|mut response| {
- context
- .x_span_id
- .as_ref()
- .map(|header| response.headers.set(XSpanId(header.clone())));
+ context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone())));
Ok(response)
})
},