Skip to content

Commit

Permalink
[Rust][Client] Unify sync/async client structure (#6753)
Browse files Browse the repository at this point in the history
* Unify sync/async client structure (configuration as first param instead of a struct).

* Fix: Hyper client requires the client.rs file.

Co-authored-by: Henning Holm <git@henningholm.de>

* Add API method comments (description and/or notes when available).

Co-authored-by: Henning Holm <git@henningholm.de>
  • Loading branch information
bcourtine and HenningHolmDE authored Jul 1, 2020
1 parent 6224f5e commit fa72c63
Show file tree
Hide file tree
Showing 20 changed files with 1,300 additions and 1,534 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ public void processOpts() {
supportingFiles.add(new SupportingFile(getLibrary() + "/configuration.mustache", apiFolder, "configuration.rs"));
if (HYPER_LIBRARY.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("request.rs", apiFolder, "request.rs"));
}
if (!getSupportAsync()) { // for sync only
supportingFiles.add(new SupportingFile(getLibrary() + "/client.mustache", apiFolder, "client.rs"));
}
}
Expand Down
471 changes: 219 additions & 252 deletions modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ pub mod {{{classFilename}}};
{{/apis}}
{{/apiInfo}}

{{^supportAsync}}
pub mod client;
{{/supportAsync}}
pub mod configuration;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Cargo.toml
README.md
docs/DefaultApi.md
git_push.sh
src/apis/client.rs
src/apis/configuration.rs
src/apis/default_api.rs
src/apis/mod.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,12 @@
* Generated by: https://openapi-generator.tech
*/

#[allow(unused_imports)]
use std::rc::Rc;
use std::borrow::Borrow;
use std::option::Option;

use reqwest;

use crate::apis::ResponseContent;
use super::{Error, configuration};

pub struct DefaultApiClient {
configuration: Rc<configuration::Configuration>,
}

impl DefaultApiClient {
pub fn new(configuration: Rc<configuration::Configuration>) -> DefaultApiClient {
DefaultApiClient {
configuration,
}
}
}


/// struct for typed errors of method `fileresponsetest`
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -39,35 +23,29 @@ pub enum FileresponsetestError {
}


pub trait DefaultApi {
fn fileresponsetest(&self, ) -> Result<std::path::PathBuf, Error<FileresponsetestError>>;
}
pub fn fileresponsetest(configuration: &configuration::Configuration, ) -> Result<std::path::PathBuf, Error<FileresponsetestError>> {

impl DefaultApi for DefaultApiClient {
fn fileresponsetest(&self, ) -> Result<std::path::PathBuf, Error<FileresponsetestError>> {
let configuration: &configuration::Configuration = self.configuration.borrow();
let client = &configuration.client;
let client = &configuration.client;

let uri_str = format!("{}/tests/fileResponse", configuration.base_path);
let mut req_builder = client.get(uri_str.as_str());
let uri_str = format!("{}/tests/fileResponse", configuration.base_path);
let mut req_builder = client.get(uri_str.as_str());

if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}

let req = req_builder.build()?;
let mut resp = client.execute(req)?;
let req = req_builder.build()?;
let mut resp = client.execute(req)?;

let status = resp.status();
let content = resp.text()?;
let status = resp.status();
let content = resp.text()?;

if status.is_success() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<FileresponsetestError> = serde_json::from_str(&content).ok();
let error = ResponseContent { status, content, entity };
Err(Error::ResponseError(error))
}
if status.is_success() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<FileresponsetestError> = serde_json::from_str(&content).ok();
let error = ResponseContent { status, content, entity };
Err(Error::ResponseError(error))
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ pub fn urlencode<T: AsRef<str>>(s: T) -> String {

pub mod default_api;

pub mod client;
pub mod configuration;
Loading

0 comments on commit fa72c63

Please sign in to comment.