Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rust][Client] Unify sync/async client structure #6753

Merged
merged 3 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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