From a192b0b84e46179a8f28218dfcbb5eb4e28dbf9d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Jan 2019 23:51:44 -0800 Subject: add a couple additional response types, for consistency --- rust/fatcat-api-spec/src/client.rs | 21 +++++++++++++++++++++ rust/fatcat-api-spec/src/lib.rs | 6 ++++++ rust/fatcat-api-spec/src/mimetypes.rs | 12 ++++++++++++ rust/fatcat-api-spec/src/server.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) (limited to 'rust/fatcat-api-spec/src') diff --git a/rust/fatcat-api-spec/src/client.rs b/rust/fatcat-api-spec/src/client.rs index 5937b7f2..c5cf4297 100644 --- a/rust/fatcat-api-spec/src/client.rs +++ b/rust/fatcat-api-spec/src/client.rs @@ -2570,6 +2570,13 @@ impl Api for Client { Ok(CreateEditgroupResponse::Forbidden(body)) } + 404 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(CreateEditgroupResponse::NotFound(body)) + } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; @@ -2619,6 +2626,13 @@ impl Api for Client { Ok(GetChangelogResponse::Success(body)) } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetChangelogResponse::BadRequest(body)) + } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; @@ -2669,6 +2683,13 @@ impl Api for Client { Ok(GetChangelogEntryResponse::FoundChangelogEntry(body)) } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetChangelogEntryResponse::BadRequest(body)) + } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; diff --git a/rust/fatcat-api-spec/src/lib.rs b/rust/fatcat-api-spec/src/lib.rs index cd281a3d..3f1afa67 100644 --- a/rust/fatcat-api-spec/src/lib.rs +++ b/rust/fatcat-api-spec/src/lib.rs @@ -448,6 +448,8 @@ pub enum CreateEditgroupResponse { NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, /// Forbidden Forbidden(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), /// Generic Error GenericError(models::ErrorResponse), } @@ -456,6 +458,8 @@ pub enum CreateEditgroupResponse { pub enum GetChangelogResponse { /// Success Success(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), /// Generic Error GenericError(models::ErrorResponse), } @@ -464,6 +468,8 @@ pub enum GetChangelogResponse { pub enum GetChangelogEntryResponse { /// Found Changelog Entry FoundChangelogEntry(models::ChangelogEntry), + /// Bad Request + BadRequest(models::ErrorResponse), /// Not Found NotFound(models::ErrorResponse), /// Generic Error diff --git a/rust/fatcat-api-spec/src/mimetypes.rs b/rust/fatcat-api-spec/src/mimetypes.rs index 83add9e3..11159610 100644 --- a/rust/fatcat-api-spec/src/mimetypes.rs +++ b/rust/fatcat-api-spec/src/mimetypes.rs @@ -601,6 +601,10 @@ pub mod responses { pub static ref CREATE_EDITGROUP_FORBIDDEN: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreateEditgroup + lazy_static! { + pub static ref CREATE_EDITGROUP_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroup lazy_static! { pub static ref CREATE_EDITGROUP_GENERIC_ERROR: Mime = mime!(Application / Json); } @@ -609,6 +613,10 @@ pub mod responses { pub static ref GET_CHANGELOG_SUCCESS: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for GetChangelog + lazy_static! { + pub static ref GET_CHANGELOG_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelog lazy_static! { pub static ref GET_CHANGELOG_GENERIC_ERROR: Mime = mime!(Application / Json); } @@ -617,6 +625,10 @@ pub mod responses { pub static ref GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for GetChangelogEntry + lazy_static! { + pub static ref GET_CHANGELOG_ENTRY_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelogEntry lazy_static! { pub static ref GET_CHANGELOG_ENTRY_NOT_FOUND: Mime = mime!(Application / Json); } diff --git a/rust/fatcat-api-spec/src/server.rs b/rust/fatcat-api-spec/src/server.rs index 2f1c5d27..03875a38 100644 --- a/rust/fatcat-api-spec/src/server.rs +++ b/rust/fatcat-api-spec/src/server.rs @@ -3431,6 +3431,18 @@ where } Ok(response) } + CreateEditgroupResponse::NotFound(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::CREATE_EDITGROUP_NOT_FOUND.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))); + } + Ok(response) + } CreateEditgroupResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -3491,6 +3503,16 @@ where Ok(response) } + GetChangelogResponse::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::GET_CHANGELOG_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } GetChangelogResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -3560,6 +3582,16 @@ where Ok(response) } + GetChangelogEntryResponse::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::GET_CHANGELOG_ENTRY_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } GetChangelogEntryResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); -- cgit v1.2.3