diff options
Diffstat (limited to 'rust/fatcat-api')
-rw-r--r-- | rust/fatcat-api/README.md | 2 | ||||
-rw-r--r-- | rust/fatcat-api/api.yaml | 38 | ||||
-rw-r--r-- | rust/fatcat-api/api/swagger.yaml | 48 | ||||
-rw-r--r-- | rust/fatcat-api/src/client.rs | 11 | ||||
-rw-r--r-- | rust/fatcat-api/src/lib.rs | 8 | ||||
-rw-r--r-- | rust/fatcat-api/src/mimetypes.rs | 6 | ||||
-rw-r--r-- | rust/fatcat-api/src/models.rs | 89 | ||||
-rw-r--r-- | rust/fatcat-api/src/server.rs | 14 |
8 files changed, 165 insertions, 51 deletions
diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md index 2d14b35f..f363f381 100644 --- a/rust/fatcat-api/README.md +++ b/rust/fatcat-api/README.md @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.1.0 -- Build date: 2018-05-17T03:54:00.627Z +- Build date: 2018-05-17T05:00:05.471Z This autogenerated project defines an API crate `fatcat` which contains: * An `Api` trait defining the API in Rust. diff --git a/rust/fatcat-api/api.yaml b/rust/fatcat-api/api.yaml index b5993244..9ec1f1fb 100644 --- a/rust/fatcat-api/api.yaml +++ b/rust/fatcat-api/api.yaml @@ -143,19 +143,25 @@ definitions: type: integer editor_id: type: integer - # TODO: work_edits array, etc. ["edits"]["work"] or ["work_edits"]? - changelogentry: - type: object - required: - - index - properties: - index: - type: integer - editgroup_id: - type: integer - timestamp: + description: type: string - format: date-time + # TODO: work_edits array, etc. ["edits"]["work"] or ["work_edits"]? + changelogentries: + type: array + items: + type: object + required: + - index + - editgroup_id + - timestamp + properties: + index: + type: integer + editgroup_id: + type: integer + timestamp: + type: string + format: date-time x-entity-responses: &ENTITYRESPONSES 400: @@ -390,7 +396,7 @@ paths: 200: description: Found Merged Changes schema: - $ref: "#/definitions/changelogentry" + $ref: "#/definitions/changelogentries" 404: description: Not Found schema: @@ -423,9 +429,13 @@ paths: get: responses: 200: - description: Found Editgroup + description: Found Entity schema: $ref: "#/definitions/editgroup" + 400: + description: Bad Request + schema: + $ref: "#/definitions/error_response" 404: description: Not Found schema: diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml index 8dddf317..009d0e08 100644 --- a/rust/fatcat-api/api/swagger.yaml +++ b/rust/fatcat-api/api/swagger.yaml @@ -26,7 +26,7 @@ paths: refName: "creator_entity" formatString: "{:?}" example: "???" - model_key: "changelogentry" + model_key: "changelogentries_inner" uppercase_operation_id: "CREATOR_POST" consumesJson: true responses: @@ -186,7 +186,7 @@ paths: refName: "container_entity" formatString: "{:?}" example: "???" - model_key: "changelogentry" + model_key: "changelogentries_inner" uppercase_operation_id: "CONTAINER_POST" consumesJson: true responses: @@ -346,7 +346,7 @@ paths: refName: "file_entity" formatString: "{:?}" example: "???" - model_key: "changelogentry" + model_key: "changelogentries_inner" uppercase_operation_id: "FILE_POST" consumesJson: true responses: @@ -506,7 +506,7 @@ paths: refName: "release_entity" formatString: "{:?}" example: "???" - model_key: "changelogentry" + model_key: "changelogentries_inner" uppercase_operation_id: "RELEASE_POST" consumesJson: true responses: @@ -666,7 +666,7 @@ paths: refName: "work_entity" formatString: "{:?}" example: "???" - model_key: "changelogentry" + model_key: "changelogentries_inner" uppercase_operation_id: "WORK_POST" consumesJson: true responses: @@ -818,11 +818,11 @@ paths: 200: description: "Found Merged Changes" schema: - $ref: "#/definitions/changelogentry" + $ref: "#/definitions/changelogentries" x-responseId: "FoundMergedChanges" x-uppercaseResponseId: "FOUND_MERGED_CHANGES" uppercase_operation_id: "EDITOR_USERNAME_CHANGELOG_GET" - uppercase_data_type: "CHANGELOGENTRY" + uppercase_data_type: "CHANGELOGENTRIES" producesJson: true 404: description: "Not Found" @@ -894,14 +894,23 @@ paths: example: "56" responses: 200: - description: "Found Editgroup" + description: "Found Entity" schema: $ref: "#/definitions/editgroup" - x-responseId: "FoundEditgroup" - x-uppercaseResponseId: "FOUND_EDITGROUP" + x-responseId: "FoundEntity" + x-uppercaseResponseId: "FOUND_ENTITY" uppercase_operation_id: "EDITGROUP_ID_GET" uppercase_data_type: "EDITGROUP" producesJson: true + 400: + description: "Bad Request" + schema: + $ref: "#/definitions/error_response" + x-responseId: "BadRequest" + x-uppercaseResponseId: "BAD_REQUEST" + uppercase_operation_id: "EDITGROUP_ID_GET" + uppercase_data_type: "ERRORRESPONSE" + producesJson: true 404: description: "Not Found" schema: @@ -1214,14 +1223,23 @@ definitions: type: "integer" editor_id: type: "integer" + description: + type: "string" example: + description: "description" editor_id: 6 id: 0 upperCaseName: "EDITGROUP" - changelogentry: - type: "object" + changelogentries: + type: "array" + items: + $ref: "#/definitions/changelogentries_inner" + upperCaseName: "CHANGELOGENTRIES" + changelogentries_inner: required: + - "editgroup_id" - "index" + - "timestamp" properties: index: type: "integer" @@ -1230,11 +1248,7 @@ definitions: timestamp: type: "string" format: "date-time" - example: - index: 0 - editgroup_id: 6 - timestamp: "2000-01-23T04:56:07.000+00:00" - upperCaseName: "CHANGELOGENTRY" + upperCaseName: "CHANGELOGENTRIES_INNER" x-entity-props: state: type: "string" diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index 09b43e4b..0c1345de 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -616,7 +616,14 @@ impl Api for Client { response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::Editgroup>(&buf)?; - Ok(EditgroupIdGetResponse::FoundEditgroup(body)) + Ok(EditgroupIdGetResponse::FoundEntity(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::<models::ErrorResponse>(&buf)?; + + Ok(EditgroupIdGetResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); @@ -724,7 +731,7 @@ impl Api for Client { 200 => { 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::<models::Changelogentry>(&buf)?; + let body = serde_json::from_str::<models::Changelogentries>(&buf)?; Ok(EditorUsernameChangelogGetResponse::FoundMergedChanges(body)) } diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index 3696a1e2..716781cb 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -118,8 +118,10 @@ pub enum EditgroupIdAcceptPostResponse { #[derive(Debug, PartialEq)] pub enum EditgroupIdGetResponse { - /// Found Editgroup - FoundEditgroup(models::Editgroup), + /// Found Entity + FoundEntity(models::Editgroup), + /// Bad Request + BadRequest(models::ErrorResponse), /// Not Found NotFound(models::ErrorResponse), /// Generic Error @@ -139,7 +141,7 @@ pub enum EditgroupPostResponse { #[derive(Debug, PartialEq)] pub enum EditorUsernameChangelogGetResponse { /// Found Merged Changes - FoundMergedChanges(models::Changelogentry), + FoundMergedChanges(models::Changelogentries), /// Not Found NotFound(models::ErrorResponse), /// Generic Error diff --git a/rust/fatcat-api/src/mimetypes.rs b/rust/fatcat-api/src/mimetypes.rs index 9d3d91a8..6b89f7bb 100644 --- a/rust/fatcat-api/src/mimetypes.rs +++ b/rust/fatcat-api/src/mimetypes.rs @@ -118,7 +118,11 @@ pub mod responses { } /// Create Mime objects for the response content types for EditgroupIdGet lazy_static! { - pub static ref EDITGROUP_ID_GET_FOUND_EDITGROUP: Mime = mime!(Application / Json); + pub static ref EDITGROUP_ID_GET_FOUND_ENTITY: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for EditgroupIdGet + lazy_static! { + pub static ref EDITGROUP_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdGet lazy_static! { diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 82fe7bad..0186f0a0 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -9,25 +9,84 @@ use std::collections::HashMap; use swagger; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Changelogentry { +pub struct Changelogentries(Vec<ChangelogentriesInner>); + +impl ::std::convert::From<Vec<ChangelogentriesInner>> for Changelogentries { + fn from(x: Vec<ChangelogentriesInner>) -> Self { + Changelogentries(x) + } +} + +impl ::std::convert::From<Changelogentries> for Vec<ChangelogentriesInner> { + fn from(x: Changelogentries) -> Self { + x.0 + } +} + +impl ::std::iter::FromIterator<ChangelogentriesInner> for Changelogentries { + fn from_iter<U: IntoIterator<Item = ChangelogentriesInner>>(u: U) -> Self { + Changelogentries(Vec::<ChangelogentriesInner>::from_iter(u)) + } +} + +impl ::std::iter::IntoIterator for Changelogentries { + type Item = ChangelogentriesInner; + type IntoIter = ::std::vec::IntoIter<ChangelogentriesInner>; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl<'a> ::std::iter::IntoIterator for &'a Changelogentries { + type Item = &'a ChangelogentriesInner; + type IntoIter = ::std::slice::Iter<'a, ChangelogentriesInner>; + + fn into_iter(self) -> Self::IntoIter { + (&self.0).into_iter() + } +} + +impl<'a> ::std::iter::IntoIterator for &'a mut Changelogentries { + type Item = &'a mut ChangelogentriesInner; + type IntoIter = ::std::slice::IterMut<'a, ChangelogentriesInner>; + + fn into_iter(self) -> Self::IntoIter { + (&mut self.0).into_iter() + } +} + +impl ::std::ops::Deref for Changelogentries { + type Target = Vec<ChangelogentriesInner>; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ::std::ops::DerefMut for Changelogentries { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct ChangelogentriesInner { #[serde(rename = "index")] pub index: isize, #[serde(rename = "editgroup_id")] - #[serde(skip_serializing_if = "Option::is_none")] - pub editgroup_id: Option<isize>, + pub editgroup_id: isize, #[serde(rename = "timestamp")] - #[serde(skip_serializing_if = "Option::is_none")] - pub timestamp: Option<chrono::DateTime<chrono::Utc>>, + pub timestamp: chrono::DateTime<chrono::Utc>, } -impl Changelogentry { - pub fn new(index: isize) -> Changelogentry { - Changelogentry { +impl ChangelogentriesInner { + pub fn new(index: isize, editgroup_id: isize, timestamp: chrono::DateTime<chrono::Utc>) -> ChangelogentriesInner { + ChangelogentriesInner { index: index, - editgroup_id: None, - timestamp: None, + editgroup_id: editgroup_id, + timestamp: timestamp, } } } @@ -135,11 +194,19 @@ pub struct Editgroup { #[serde(rename = "editor_id")] pub editor_id: isize, + + #[serde(rename = "description")] + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option<String>, } impl Editgroup { pub fn new(editor_id: isize) -> Editgroup { - Editgroup { id: None, editor_id: editor_id } + Editgroup { + id: None, + editor_id: editor_id, + description: None, + } } } diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index 090c45e3..902ebd6d 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -759,11 +759,21 @@ where match api.editgroup_id_get(param_id, context).wait() { Ok(rsp) => match rsp { - EditgroupIdGetResponse::FoundEditgroup(body) => { + EditgroupIdGetResponse::FoundEntity(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_GET_FOUND_EDITGROUP.clone())); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_FOUND_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + EditgroupIdGetResponse::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::EDITGROUP_ID_GET_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); |