Skip to content

Commit

Permalink
Regenerated using OpenAPI Generator Version 5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DazWilkin committed Feb 23, 2021
1 parent c97250b commit 60a9ba6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 308 deletions.
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
name = "openapi"
version = "1.1.0"
authors = ["OpenAPI Generator team and contributors"]
edition = "2018"

[dependencies]
reqwest = { version = "^0.11", default-features = false, features = ["json","multipart"] }
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
url = "1.5"
hyper = "0.13.10"
serde_yaml = "0.8"
base64 = "~0.7.0"
futures = "0.1.23"

[dev-dependencies]
tokio-core = "*"
17 changes: 0 additions & 17 deletions src/apis/client.rs

This file was deleted.

21 changes: 15 additions & 6 deletions src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
* Generated by: https://openapi-generator.tech
*/

use hyper;

pub struct Configuration<C: hyper::client::Connect> {
use reqwest;

pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>,
pub client: reqwest::Client,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
pub api_key: Option<ApiKey>,
// TODO: take an oauth2 token source, similar to the go one
}
Expand All @@ -27,14 +29,21 @@ pub struct ApiKey {
pub key: String,
}

impl<C: hyper::client::Connect> Configuration<C> {
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
}
}

impl Default for Configuration {
fn default() -> Self {
Configuration {
base_path: "http://localhost".to_owned(),
user_agent: Some("OpenAPI-Generator/1.0/rust".to_owned()),
client: client,
client: reqwest::Client::new(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
api_key: None,
}
}
Expand Down
83 changes: 46 additions & 37 deletions src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,65 @@
use hyper;
use serde;
use serde_json;
use std::error;
use std::fmt;

#[derive(Debug, Clone)]
pub struct ResponseContent<T> {
pub status: reqwest::StatusCode,
pub content: String,
pub entity: Option<T>,
}

#[derive(Debug)]
pub enum Error<T> {
UriError(hyper::error::UriError),
Hyper(hyper::Error),
Reqwest(reqwest::Error),
Serde(serde_json::Error),
ApiError(ApiError<T>),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
}

#[derive(Debug)]
pub struct ApiError<T> {
pub code: hyper::StatusCode,
pub content: Option<T>,
}

impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error<T>
where T: serde::Deserialize<'de> {
fn from(e: (hyper::StatusCode, &'de [u8])) -> Self {
if e.1.len() == 0 {
return Error::ApiError(ApiError{
code: e.0,
content: None,
});
}
match serde_json::from_slice::<T>(e.1) {
Ok(t) => Error::ApiError(ApiError{
code: e.0,
content: Some(t),
}),
Err(e) => {
Error::from(e)
}
}
impl <T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
};
write!(f, "error in {}: {}", module, e)
}
}

impl <T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Error::Serde(e) => e,
Error::Io(e) => e,
Error::ResponseError(_) => return None,
})
}
}

impl<T> From<hyper::Error> for Error<T> {
fn from(e: hyper::Error) -> Self {
return Error::Hyper(e)
impl <T> From<reqwest::Error> for Error<T> {
fn from(e: reqwest::Error) -> Self {
Error::Reqwest(e)
}
}

impl<T> From<serde_json::Error> for Error<T> {
impl <T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
return Error::Serde(e)
Error::Serde(e)
}
}

mod request;
impl <T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}

pub fn urlencode<T: AsRef<str>>(s: T) -> String {
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}


pub mod configuration;
pub mod client;
Loading

0 comments on commit 60a9ba6

Please sign in to comment.