diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/fatcat-api/README.md | 2 | ||||
| -rw-r--r-- | rust/fatcat-api/api.yaml | 6 | ||||
| -rw-r--r-- | rust/fatcat-api/api/swagger.yaml | 15 | ||||
| -rw-r--r-- | rust/fatcat-api/examples/client.rs | 11 | ||||
| -rw-r--r-- | rust/fatcat-api/examples/server_lib/server.rs | 4 | ||||
| -rw-r--r-- | rust/fatcat-api/src/client.rs | 7 | ||||
| -rw-r--r-- | rust/fatcat-api/src/lib.rs | 8 | ||||
| -rw-r--r-- | rust/fatcat-api/src/mimetypes.rs | 4 | ||||
| -rw-r--r-- | rust/fatcat-api/src/server.rs | 37 | ||||
| -rw-r--r-- | rust/fatcat-openapi2.yml | 6 | 
10 files changed, 81 insertions, 19 deletions
| diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md index 6247d176..94d9f29b 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-17T06:11:30.535Z +- Build date: 2018-05-17T06:58:26.208Z  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 4f8f1b3d..57902a56 100644 --- a/rust/fatcat-api/api.yaml +++ b/rust/fatcat-api/api.yaml @@ -407,6 +407,12 @@ paths:              $ref: "#/definitions/error_response"    /editgroup:      post: +      parameters: +        - name: body +          in: body +          required: true +          schema: +            $ref: "#/definitions/editgroup"        responses:          201:            description: Successfully Created diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml index 3fa3fa02..629e599b 100644 --- a/rust/fatcat-api/api/swagger.yaml +++ b/rust/fatcat-api/api/swagger.yaml @@ -849,7 +849,19 @@ paths:        httpmethod: "get"    /editgroup:      post: -      parameters: [] +      parameters: +      - in: "body" +        name: "body" +        required: true +        schema: +          $ref: "#/definitions/editgroup" +        uppercase_data_type: "EDITGROUP" +        refName: "editgroup" +        formatString: "{:?}" +        example: "???" +        model_key: "changelogentries_inner" +        uppercase_operation_id: "EDITGROUP_POST" +        consumesJson: true        responses:          201:            description: "Successfully Created" @@ -883,6 +895,7 @@ paths:        path: "/editgroup"        HttpMethod: "Post"        httpmethod: "post" +      noClientExample: true    /editgroup/{id}:      get:        parameters: diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs index 3302c0cd..b2edead6 100644 --- a/rust/fatcat-api/examples/client.rs +++ b/rust/fatcat-api/examples/client.rs @@ -29,7 +29,6 @@ fn main() {                      "CreatorLookupGet",                      "EditgroupIdAcceptPost",                      "EditgroupIdGet", -                    "EditgroupPost",                      "EditorUsernameChangelogGet",                      "EditorUsernameGet",                      "FileIdGet", @@ -105,11 +104,11 @@ fn main() {              println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));          } -        Some("EditgroupPost") => { -            let result = client.editgroup_post().wait(); -            println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); -        } - +        // Disabled because there's no example. +        // Some("EditgroupPost") => { +        //     let result = client.editgroup_post(???).wait(); +        //     println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); +        //  },          Some("EditorUsernameChangelogGet") => {              let result = client.editor_username_changelog_get("username_example".to_string()).wait();              println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); diff --git a/rust/fatcat-api/examples/server_lib/server.rs b/rust/fatcat-api/examples/server_lib/server.rs index 42b6384f..b81af0f8 100644 --- a/rust/fatcat-api/examples/server_lib/server.rs +++ b/rust/fatcat-api/examples/server_lib/server.rs @@ -66,9 +66,9 @@ impl Api for Server {          Box::new(futures::failed("Generic failure".into()))      } -    fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { +    fn editgroup_post(&self, body: models::Editgroup, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> {          let context = context.clone(); -        println!("editgroup_post() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("<none>")).clone()); +        println!("editgroup_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());          Box::new(futures::failed("Generic failure".into()))      } diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index 0c1345de..4fa084f9 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -657,13 +657,18 @@ impl Api for Client {          Box::new(futures::done(result))      } -    fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { +    fn editgroup_post(&self, param_body: models::Editgroup, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> {          let url = format!("{}/v0/editgroup", self.base_path); +        let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); +          let hyper_client = (self.hyper_client)();          let request = hyper_client.request(hyper::method::Method::Post, &url);          let mut custom_headers = hyper::header::Headers::new(); +        let request = request.body(&body); + +        custom_headers.set(ContentType(mimetypes::requests::EDITGROUP_POST.clone()));          context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));          let request = request.headers(custom_headers); diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index 716781cb..abd68f04 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -272,7 +272,7 @@ pub trait Api {      fn editgroup_id_get(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; -    fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>; +    fn editgroup_post(&self, body: models::Editgroup, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>;      fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; @@ -313,7 +313,7 @@ pub trait ApiNoContext {      fn editgroup_id_get(&self, id: i32) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; -    fn editgroup_post(&self) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>; +    fn editgroup_post(&self, body: models::Editgroup) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>;      fn editor_username_changelog_get(&self, username: String) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; @@ -384,8 +384,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {          self.api().editgroup_id_get(id, &self.context())      } -    fn editgroup_post(&self) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { -        self.api().editgroup_post(&self.context()) +    fn editgroup_post(&self, body: models::Editgroup) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { +        self.api().editgroup_post(body, &self.context())      }      fn editor_username_changelog_get(&self, username: String) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { diff --git a/rust/fatcat-api/src/mimetypes.rs b/rust/fatcat-api/src/mimetypes.rs index 6b89f7bb..5814890f 100644 --- a/rust/fatcat-api/src/mimetypes.rs +++ b/rust/fatcat-api/src/mimetypes.rs @@ -309,6 +309,10 @@ pub mod requests {      lazy_static! {          pub static ref CREATOR_POST: Mime = mime!(Application / Json);      } +    /// Create Mime objects for the request content types for EditgroupPost +    lazy_static! { +        pub static ref EDITGROUP_POST: Mime = mime!(Application / Json); +    }      /// Create Mime objects for the request content types for FilePost      lazy_static! {          pub static ref FILE_POST: Mime = mime!(Application / Json); diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index 902ebd6d..95829602 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -831,7 +831,30 @@ where                  context.auth_data = req.extensions.remove::<AuthData>();                  context.authorization = req.extensions.remove::<Authorization>(); -                match api.editgroup_post(context).wait() { +                // Body parameters (note that non-required body parameters will ignore garbage +                // values, rather than causing a 400 response). Produce warning header and logs for +                // any unused fields. + +                let param_body = req.get::<bodyparser::Raw>() +                    .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + +                let mut unused_elements = Vec::new(); + +                let param_body = if let Some(param_body_raw) = param_body { +                    let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + +                    let param_body: Option<models::Editgroup> = serde_ignored::deserialize(deserializer, |path| { +                        warn!("Ignoring unknown field in body: {}", path); +                        unused_elements.push(path.to_string()); +                    }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?; + +                    param_body +                } else { +                    None +                }; +                let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + +                match api.editgroup_post(param_body, context).wait() {                      Ok(rsp) => match rsp {                          EditgroupPostResponse::SuccessfullyCreated(body) => {                              let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -840,7 +863,9 @@ where                              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()))); - +                            if !unused_elements.is_empty() { +                                response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); +                            }                              Ok(response)                          }                          EditgroupPostResponse::BadRequest(body) => { @@ -850,7 +875,9 @@ where                              response.headers.set(ContentType(mimetypes::responses::EDITGROUP_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))); +                            }                              Ok(response)                          }                          EditgroupPostResponse::GenericError(body) => { @@ -860,7 +887,9 @@ where                              response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR.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)                          }                      }, diff --git a/rust/fatcat-openapi2.yml b/rust/fatcat-openapi2.yml index 4f8f1b3d..57902a56 100644 --- a/rust/fatcat-openapi2.yml +++ b/rust/fatcat-openapi2.yml @@ -407,6 +407,12 @@ paths:              $ref: "#/definitions/error_response"    /editgroup:      post: +      parameters: +        - name: body +          in: body +          required: true +          schema: +            $ref: "#/definitions/editgroup"        responses:          201:            description: Successfully Created | 
