From 0a71247fb61a91c1f6d519762013c1445713a728 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 13 Oct 2021 17:42:41 -0700 Subject: codegen for API schema v0.4.0 --- fatcat-openapi/src/server/mod.rs | 256 +++++++++++++++++++++++++++++++++------ 1 file changed, 218 insertions(+), 38 deletions(-) (limited to 'fatcat-openapi/src/server/mod.rs') diff --git a/fatcat-openapi/src/server/mod.rs b/fatcat-openapi/src/server/mod.rs index ac07c6e..251c678 100644 --- a/fatcat-openapi/src/server/mod.rs +++ b/fatcat-openapi/src/server/mod.rs @@ -47,10 +47,10 @@ use crate::{ GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, - GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, - LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, - UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, - UpdateWebcaptureResponse, UpdateWorkResponse, + GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupEditorResponse, + LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, + UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, + UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, }; mod paths { @@ -110,6 +110,7 @@ mod paths { r"^/v0/editgroup/(?P[^/?#]*)/work$", r"^/v0/editgroup/(?P[^/?#]*)/work/edit/(?P[^/?#]*)$", r"^/v0/editgroup/(?P[^/?#]*)/work/(?P[^/?#]*)$", + r"^/v0/editor/lookup$", r"^/v0/editor/(?P[^/?#]*)$", r"^/v0/editor/(?P[^/?#]*)/annotations$", r"^/v0/editor/(?P[^/?#]*)/editgroups$", @@ -413,195 +414,196 @@ mod paths { regex::Regex::new(r"^/v0/editgroup/(?P[^/?#]*)/work/(?P[^/?#]*)$") .expect("Unable to create regex for EDITGROUP_EDITGROUP_ID_WORK_IDENT"); } - pub(crate) static ID_EDITOR_EDITOR_ID: usize = 52; + pub(crate) static ID_EDITOR_LOOKUP: usize = 52; + pub(crate) static ID_EDITOR_EDITOR_ID: usize = 53; lazy_static! { pub static ref REGEX_EDITOR_EDITOR_ID: regex::Regex = regex::Regex::new(r"^/v0/editor/(?P[^/?#]*)$") .expect("Unable to create regex for EDITOR_EDITOR_ID"); } - pub(crate) static ID_EDITOR_EDITOR_ID_ANNOTATIONS: usize = 53; + pub(crate) static ID_EDITOR_EDITOR_ID_ANNOTATIONS: usize = 54; lazy_static! { pub static ref REGEX_EDITOR_EDITOR_ID_ANNOTATIONS: regex::Regex = regex::Regex::new(r"^/v0/editor/(?P[^/?#]*)/annotations$") .expect("Unable to create regex for EDITOR_EDITOR_ID_ANNOTATIONS"); } - pub(crate) static ID_EDITOR_EDITOR_ID_EDITGROUPS: usize = 54; + pub(crate) static ID_EDITOR_EDITOR_ID_EDITGROUPS: usize = 55; lazy_static! { pub static ref REGEX_EDITOR_EDITOR_ID_EDITGROUPS: regex::Regex = regex::Regex::new(r"^/v0/editor/(?P[^/?#]*)/editgroups$") .expect("Unable to create regex for EDITOR_EDITOR_ID_EDITGROUPS"); } - pub(crate) static ID_FILE_EDIT_EDIT_ID: usize = 55; + pub(crate) static ID_FILE_EDIT_EDIT_ID: usize = 56; lazy_static! { pub static ref REGEX_FILE_EDIT_EDIT_ID: regex::Regex = regex::Regex::new(r"^/v0/file/edit/(?P[^/?#]*)$") .expect("Unable to create regex for FILE_EDIT_EDIT_ID"); } - pub(crate) static ID_FILE_LOOKUP: usize = 56; - pub(crate) static ID_FILE_REV_REV_ID: usize = 57; + pub(crate) static ID_FILE_LOOKUP: usize = 57; + pub(crate) static ID_FILE_REV_REV_ID: usize = 58; lazy_static! { pub static ref REGEX_FILE_REV_REV_ID: regex::Regex = regex::Regex::new(r"^/v0/file/rev/(?P[^/?#]*)$") .expect("Unable to create regex for FILE_REV_REV_ID"); } - pub(crate) static ID_FILE_IDENT: usize = 58; + pub(crate) static ID_FILE_IDENT: usize = 59; lazy_static! { pub static ref REGEX_FILE_IDENT: regex::Regex = regex::Regex::new(r"^/v0/file/(?P[^/?#]*)$") .expect("Unable to create regex for FILE_IDENT"); } - pub(crate) static ID_FILE_IDENT_HISTORY: usize = 59; + pub(crate) static ID_FILE_IDENT_HISTORY: usize = 60; lazy_static! { pub static ref REGEX_FILE_IDENT_HISTORY: regex::Regex = regex::Regex::new(r"^/v0/file/(?P[^/?#]*)/history$") .expect("Unable to create regex for FILE_IDENT_HISTORY"); } - pub(crate) static ID_FILE_IDENT_REDIRECTS: usize = 60; + pub(crate) static ID_FILE_IDENT_REDIRECTS: usize = 61; lazy_static! { pub static ref REGEX_FILE_IDENT_REDIRECTS: regex::Regex = regex::Regex::new(r"^/v0/file/(?P[^/?#]*)/redirects$") .expect("Unable to create regex for FILE_IDENT_REDIRECTS"); } - pub(crate) static ID_FILESET_EDIT_EDIT_ID: usize = 61; + pub(crate) static ID_FILESET_EDIT_EDIT_ID: usize = 62; lazy_static! { pub static ref REGEX_FILESET_EDIT_EDIT_ID: regex::Regex = regex::Regex::new(r"^/v0/fileset/edit/(?P[^/?#]*)$") .expect("Unable to create regex for FILESET_EDIT_EDIT_ID"); } - pub(crate) static ID_FILESET_REV_REV_ID: usize = 62; + pub(crate) static ID_FILESET_REV_REV_ID: usize = 63; lazy_static! { pub static ref REGEX_FILESET_REV_REV_ID: regex::Regex = regex::Regex::new(r"^/v0/fileset/rev/(?P[^/?#]*)$") .expect("Unable to create regex for FILESET_REV_REV_ID"); } - pub(crate) static ID_FILESET_IDENT: usize = 63; + pub(crate) static ID_FILESET_IDENT: usize = 64; lazy_static! { pub static ref REGEX_FILESET_IDENT: regex::Regex = regex::Regex::new(r"^/v0/fileset/(?P[^/?#]*)$") .expect("Unable to create regex for FILESET_IDENT"); } - pub(crate) static ID_FILESET_IDENT_HISTORY: usize = 64; + pub(crate) static ID_FILESET_IDENT_HISTORY: usize = 65; lazy_static! { pub static ref REGEX_FILESET_IDENT_HISTORY: regex::Regex = regex::Regex::new(r"^/v0/fileset/(?P[^/?#]*)/history$") .expect("Unable to create regex for FILESET_IDENT_HISTORY"); } - pub(crate) static ID_FILESET_IDENT_REDIRECTS: usize = 65; + pub(crate) static ID_FILESET_IDENT_REDIRECTS: usize = 66; lazy_static! { pub static ref REGEX_FILESET_IDENT_REDIRECTS: regex::Regex = regex::Regex::new(r"^/v0/fileset/(?P[^/?#]*)/redirects$") .expect("Unable to create regex for FILESET_IDENT_REDIRECTS"); } - pub(crate) static ID_RELEASE_EDIT_EDIT_ID: usize = 66; + pub(crate) static ID_RELEASE_EDIT_EDIT_ID: usize = 67; lazy_static! { pub static ref REGEX_RELEASE_EDIT_EDIT_ID: regex::Regex = regex::Regex::new(r"^/v0/release/edit/(?P[^/?#]*)$") .expect("Unable to create regex for RELEASE_EDIT_EDIT_ID"); } - pub(crate) static ID_RELEASE_LOOKUP: usize = 67; - pub(crate) static ID_RELEASE_REV_REV_ID: usize = 68; + pub(crate) static ID_RELEASE_LOOKUP: usize = 68; + pub(crate) static ID_RELEASE_REV_REV_ID: usize = 69; lazy_static! { pub static ref REGEX_RELEASE_REV_REV_ID: regex::Regex = regex::Regex::new(r"^/v0/release/rev/(?P[^/?#]*)$") .expect("Unable to create regex for RELEASE_REV_REV_ID"); } - pub(crate) static ID_RELEASE_IDENT: usize = 69; + pub(crate) static ID_RELEASE_IDENT: usize = 70; lazy_static! { pub static ref REGEX_RELEASE_IDENT: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)$") .expect("Unable to create regex for RELEASE_IDENT"); } - pub(crate) static ID_RELEASE_IDENT_FILES: usize = 70; + pub(crate) static ID_RELEASE_IDENT_FILES: usize = 71; lazy_static! { pub static ref REGEX_RELEASE_IDENT_FILES: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)/files$") .expect("Unable to create regex for RELEASE_IDENT_FILES"); } - pub(crate) static ID_RELEASE_IDENT_FILESETS: usize = 71; + pub(crate) static ID_RELEASE_IDENT_FILESETS: usize = 72; lazy_static! { pub static ref REGEX_RELEASE_IDENT_FILESETS: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)/filesets$") .expect("Unable to create regex for RELEASE_IDENT_FILESETS"); } - pub(crate) static ID_RELEASE_IDENT_HISTORY: usize = 72; + pub(crate) static ID_RELEASE_IDENT_HISTORY: usize = 73; lazy_static! { pub static ref REGEX_RELEASE_IDENT_HISTORY: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)/history$") .expect("Unable to create regex for RELEASE_IDENT_HISTORY"); } - pub(crate) static ID_RELEASE_IDENT_REDIRECTS: usize = 73; + pub(crate) static ID_RELEASE_IDENT_REDIRECTS: usize = 74; lazy_static! { pub static ref REGEX_RELEASE_IDENT_REDIRECTS: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)/redirects$") .expect("Unable to create regex for RELEASE_IDENT_REDIRECTS"); } - pub(crate) static ID_RELEASE_IDENT_WEBCAPTURES: usize = 74; + pub(crate) static ID_RELEASE_IDENT_WEBCAPTURES: usize = 75; lazy_static! { pub static ref REGEX_RELEASE_IDENT_WEBCAPTURES: regex::Regex = regex::Regex::new(r"^/v0/release/(?P[^/?#]*)/webcaptures$") .expect("Unable to create regex for RELEASE_IDENT_WEBCAPTURES"); } - pub(crate) static ID_WEBCAPTURE_EDIT_EDIT_ID: usize = 75; + pub(crate) static ID_WEBCAPTURE_EDIT_EDIT_ID: usize = 76; lazy_static! { pub static ref REGEX_WEBCAPTURE_EDIT_EDIT_ID: regex::Regex = regex::Regex::new(r"^/v0/webcapture/edit/(?P[^/?#]*)$") .expect("Unable to create regex for WEBCAPTURE_EDIT_EDIT_ID"); } - pub(crate) static ID_WEBCAPTURE_REV_REV_ID: usize = 76; + pub(crate) static ID_WEBCAPTURE_REV_REV_ID: usize = 77; lazy_static! { pub static ref REGEX_WEBCAPTURE_REV_REV_ID: regex::Regex = regex::Regex::new(r"^/v0/webcapture/rev/(?P[^/?#]*)$") .expect("Unable to create regex for WEBCAPTURE_REV_REV_ID"); } - pub(crate) static ID_WEBCAPTURE_IDENT: usize = 77; + pub(crate) static ID_WEBCAPTURE_IDENT: usize = 78; lazy_static! { pub static ref REGEX_WEBCAPTURE_IDENT: regex::Regex = regex::Regex::new(r"^/v0/webcapture/(?P[^/?#]*)$") .expect("Unable to create regex for WEBCAPTURE_IDENT"); } - pub(crate) static ID_WEBCAPTURE_IDENT_HISTORY: usize = 78; + pub(crate) static ID_WEBCAPTURE_IDENT_HISTORY: usize = 79; lazy_static! { pub static ref REGEX_WEBCAPTURE_IDENT_HISTORY: regex::Regex = regex::Regex::new(r"^/v0/webcapture/(?P[^/?#]*)/history$") .expect("Unable to create regex for WEBCAPTURE_IDENT_HISTORY"); } - pub(crate) static ID_WEBCAPTURE_IDENT_REDIRECTS: usize = 79; + pub(crate) static ID_WEBCAPTURE_IDENT_REDIRECTS: usize = 80; lazy_static! { pub static ref REGEX_WEBCAPTURE_IDENT_REDIRECTS: regex::Regex = regex::Regex::new(r"^/v0/webcapture/(?P[^/?#]*)/redirects$") .expect("Unable to create regex for WEBCAPTURE_IDENT_REDIRECTS"); } - pub(crate) static ID_WORK_EDIT_EDIT_ID: usize = 80; + pub(crate) static ID_WORK_EDIT_EDIT_ID: usize = 81; lazy_static! { pub static ref REGEX_WORK_EDIT_EDIT_ID: regex::Regex = regex::Regex::new(r"^/v0/work/edit/(?P[^/?#]*)$") .expect("Unable to create regex for WORK_EDIT_EDIT_ID"); } - pub(crate) static ID_WORK_REV_REV_ID: usize = 81; + pub(crate) static ID_WORK_REV_REV_ID: usize = 82; lazy_static! { pub static ref REGEX_WORK_REV_REV_ID: regex::Regex = regex::Regex::new(r"^/v0/work/rev/(?P[^/?#]*)$") .expect("Unable to create regex for WORK_REV_REV_ID"); } - pub(crate) static ID_WORK_IDENT: usize = 82; + pub(crate) static ID_WORK_IDENT: usize = 83; lazy_static! { pub static ref REGEX_WORK_IDENT: regex::Regex = regex::Regex::new(r"^/v0/work/(?P[^/?#]*)$") .expect("Unable to create regex for WORK_IDENT"); } - pub(crate) static ID_WORK_IDENT_HISTORY: usize = 83; + pub(crate) static ID_WORK_IDENT_HISTORY: usize = 84; lazy_static! { pub static ref REGEX_WORK_IDENT_HISTORY: regex::Regex = regex::Regex::new(r"^/v0/work/(?P[^/?#]*)/history$") .expect("Unable to create regex for WORK_IDENT_HISTORY"); } - pub(crate) static ID_WORK_IDENT_REDIRECTS: usize = 84; + pub(crate) static ID_WORK_IDENT_REDIRECTS: usize = 85; lazy_static! { pub static ref REGEX_WORK_IDENT_REDIRECTS: regex::Regex = regex::Regex::new(r"^/v0/work/(?P[^/?#]*)/redirects$") .expect("Unable to create regex for WORK_IDENT_REDIRECTS"); } - pub(crate) static ID_WORK_IDENT_RELEASES: usize = 85; + pub(crate) static ID_WORK_IDENT_RELEASES: usize = 86; lazy_static! { pub static ref REGEX_WORK_IDENT_RELEASES: regex::Regex = regex::Regex::new(r"^/v0/work/(?P[^/?#]*)/releases$") @@ -12618,6 +12620,60 @@ where } None => None, }; + let param_issne = query_params + .iter() + .filter(|e| e.0 == "issne") + .map(|e| e.1.to_owned()) + .nth(0); + let param_issne = match param_issne { + Some(param_issne) => { + let param_issne = ::from_str(¶m_issne); + match param_issne { + Ok(param_issne) => Some(param_issne), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter issne - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter issne")), + } + } + None => None, + }; + let param_issnp = query_params + .iter() + .filter(|e| e.0 == "issnp") + .map(|e| e.1.to_owned()) + .nth(0); + let param_issnp = match param_issnp { + Some(param_issnp) => { + let param_issnp = ::from_str(¶m_issnp); + match param_issnp { + Ok(param_issnp) => Some(param_issnp), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter issnp - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter issnp")), + } + } + None => None, + }; + let param_issn = query_params + .iter() + .filter(|e| e.0 == "issn") + .map(|e| e.1.to_owned()) + .nth(0); + let param_issn = match param_issn { + Some(param_issn) => { + let param_issn = ::from_str(¶m_issn); + match param_issn { + Ok(param_issn) => Some(param_issn), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter issn - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter issn")), + } + } + None => None, + }; let param_wikidata_qid = query_params .iter() .filter(|e| e.0 == "wikidata_qid") @@ -12678,6 +12734,9 @@ where let result = api_impl .lookup_container( param_issnl, + param_issne, + param_issnp, + param_issn, param_wikidata_qid, param_expand, param_hide, @@ -12918,6 +12977,105 @@ where Ok(response) } + // LookupEditor - GET /editor/lookup + &hyper::Method::GET if path.matched(paths::ID_EDITOR_LOOKUP) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::>(); + let param_username = query_params + .iter() + .filter(|e| e.0 == "username") + .map(|e| e.1.to_owned()) + .nth(0); + let param_username = match param_username { + Some(param_username) => { + let param_username = + ::from_str(¶m_username); + match param_username { + Ok(param_username) => Some(param_username), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter username - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter username")), + } + } + None => None, + }; + + let result = api_impl.lookup_editor(param_username, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + LookupEditorResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for LOOKUP_EDITOR_FOUND")); + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupEditorResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for LOOKUP_EDITOR_BAD_REQUEST")); + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupEditorResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for LOOKUP_EDITOR_NOT_FOUND")); + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupEditorResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for LOOKUP_EDITOR_GENERIC_ERROR")); + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); + } + } + + Ok(response) + } + // LookupFile - GET /file/lookup &hyper::Method::GET if path.matched(paths::ID_FILE_LOOKUP) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) @@ -13341,6 +13499,24 @@ where } None => None, }; + let param_hdl = query_params + .iter() + .filter(|e| e.0 == "hdl") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hdl = match param_hdl { + Some(param_hdl) => { + let param_hdl = ::from_str(¶m_hdl); + match param_hdl { + Ok(param_hdl) => Some(param_hdl), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hdl - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hdl")), + } + } + None => None, + }; let param_expand = query_params .iter() .filter(|e| e.0 == "expand") @@ -13394,6 +13570,7 @@ where param_doaj, param_dblp, param_oai, + param_hdl, param_expand, param_hide, &context, @@ -15432,6 +15609,7 @@ where _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { method_not_allowed() } + _ if path.matched(paths::ID_EDITOR_LOOKUP) => method_not_allowed(), _ if path.matched(paths::ID_EDITOR_EDITOR_ID) => method_not_allowed(), _ if path.matched(paths::ID_EDITOR_EDITOR_ID_ANNOTATIONS) => method_not_allowed(), _ if path.matched(paths::ID_EDITOR_EDITOR_ID_EDITGROUPS) => method_not_allowed(), @@ -15808,6 +15986,8 @@ impl RequestParser for ApiRequestParser { } // LookupCreator - GET /creator/lookup &hyper::Method::GET if path.matched(paths::ID_CREATOR_LOOKUP) => Ok("LookupCreator"), + // LookupEditor - GET /editor/lookup + &hyper::Method::GET if path.matched(paths::ID_EDITOR_LOOKUP) => Ok("LookupEditor"), // LookupFile - GET /file/lookup &hyper::Method::GET if path.matched(paths::ID_FILE_LOOKUP) => Ok("LookupFile"), // LookupRelease - GET /release/lookup -- cgit v1.2.3