From eff2aec9ff1f12d09f026d4c504ac219304bd05f Mon Sep 17 00:00:00 2001 From: Seb Renauld Date: Thu, 17 Oct 2019 19:54:34 +0200 Subject: [PATCH 1/4] Integrating reqwest's `async` module as a rust module This commit contains modifications to the Rust codegen module in order to be able to generate futures-aware, threadsafe `reqwest` bindings from an openAPI template, in order to be able to take advantage of non-blocking API calls. --- .../codegen/languages/RustClientCodegen.java | 8 +- .../src/main/resources/rust/Cargo.mustache | 4 + .../src/main/resources/rust/lib.mustache | 4 + .../rust/reqwestFutures/api.mustache | 233 ++++++++++++++++++ .../rust/reqwestFutures/api_mod.mustache | 47 ++++ .../rust/reqwestFutures/client.mustache | 52 ++++ .../reqwestFutures/configuration.mustache | 41 +++ 7 files changed, 388 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwestFutures/api_mod.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwestFutures/client.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwestFutures/configuration.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index cdac07896c1e..64d95e10b6ae 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -40,6 +40,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { public static final String HYPER_LIBRARY = "hyper"; public static final String REQWEST_LIBRARY = "reqwest"; + public static final String REQWEST_FUTURES_LIBRARY = "reqwestFutures"; protected String packageName = "openapi"; protected String packageVersion = "1.0.0"; @@ -136,11 +137,14 @@ public RustClientCodegen() { .defaultValue("openapi")); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Rust package version.") .defaultValue("1.0.0")); + cliOptions.add(new CliOption(CodegenConstants.INTERFACE_PREFIX, "Method prefix.") + .defaultValue("")); cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC) .defaultValue(Boolean.TRUE.toString())); supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper."); supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest."); + supportedLibraries.put(REQWEST_FUTURES_LIBRARY, "HTTP client: Reqwest (futures)."); CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); libraryOption.setEnum(supportedLibraries); @@ -221,6 +225,8 @@ public void processOpts() { additionalProperties.put(HYPER_LIBRARY, "true"); } else if (REQWEST_LIBRARY.equals(getLibrary())) { additionalProperties.put(REQWEST_LIBRARY, "true"); + } else if (REQWEST_FUTURES_LIBRARY.equals(getLibrary())) { + additionalProperties.put("reqwestFutures", "true"); } else { LOGGER.error("Unknown library option (-l/--library): {}", getLibrary()); } @@ -431,7 +437,7 @@ public Map postProcessOperationsWithModels(Map o // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put) if (HYPER_LIBRARY.equals(getLibrary())) { operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); - } else if (REQWEST_LIBRARY.equals(getLibrary())) { + } else if (REQWEST_LIBRARY.equals(getLibrary()) || REQWEST_FUTURES_LIBRARY.equals(getLibrary())) { operation.httpMethod = operation.httpMethod.toLowerCase(Locale.ROOT); } diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index e448a38c51c9..eb375fe8a003 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -17,6 +17,10 @@ futures = "0.1.23" {{#reqwest}} reqwest = "~0.9" {{/reqwest}} +{{#reqwestFutures}} +reqwest = "~0.9" +futures = "0.1.23" +{{/reqwestFutures}} [dev-dependencies] {{#hyper}} diff --git a/modules/openapi-generator/src/main/resources/rust/lib.mustache b/modules/openapi-generator/src/main/resources/rust/lib.mustache index cdc5287aae73..66add6f83a9f 100644 --- a/modules/openapi-generator/src/main/resources/rust/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust/lib.mustache @@ -11,6 +11,10 @@ extern crate futures; {{#reqwest}} extern crate reqwest; {{/reqwest}} +{{#reqwestFutures}} +extern crate reqwest; +extern crate futures; +{{/reqwestFutures}} pub mod apis; pub mod models; diff --git a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache new file mode 100644 index 000000000000..3098d523a146 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache @@ -0,0 +1,233 @@ +{{>partial_header}} +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct {{{classname}}}Client { + configuration: Arc, +} + +impl {{{classname}}}Client { + pub fn new(configuration: Arc) -> {{{classname}}}Client { + {{{classname}}}Client { + configuration, + } + } +} + +pub trait {{{classname}}} { +{{#operations}} +{{#operation}} + fn {{{interfacePrefix}}}{{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box + Send>; +{{/operation}} +{{/operations}} +} + +impl {{{classname}}} for {{{classname}}}Client { +{{#operations}} +{{#operation}} + fn {{{interfacePrefix}}}{{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}crate::apis::urlencode({{/isString}}{{{paramName}}}{{^required}}.unwrap(){{/required}}{{#required}}{{#isNullable}}.unwrap(){{/isNullable}}{{/required}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{#isString}}){{/isString}}{{/pathParams}}); + let mut req_builder = client.{{{httpMethod}}}(uri_str.as_str()); + + {{#queryParams}} + {{#required}} + req_builder = req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}{{#isListContainer}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isListContainer}}.to_string())]); + {{/required}} + {{^required}} + if let Some(ref s) = {{{paramName}}} { + req_builder = req_builder.query(&[("{{{baseName}}}", &s{{#isListContainer}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isListContainer}}.to_string())]); + } + {{/required}} + {{/queryParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInQuery}} + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.query(&[("{{{keyParamName}}}", val)]); + } + {{/isKeyInQuery}} + {{/isApiKey}} + {{/authMethods}} + {{/hasAuthMethods}} + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + {{#hasHeaderParams}} + {{#headerParams}} + {{#required}} + {{^isNullable}} + req_builder = req_builder.header("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { req_builder = req_builder.header("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { req_builder = req_builder.header("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + req_builder = req_builder.header("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/headerParams}} + {{/hasHeaderParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInHeader}} + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("{{{keyParamName}}}", val); + }; + {{/isKeyInHeader}} + {{/isApiKey}} + {{#isBasic}} + {{^isBasicBearer}} + if let Some(ref auth_conf) = configuration.basic_auth { + req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned()); + }; + {{/isBasicBearer}} + {{#isBasicBearer}} + if let Some(ref token) = configuration.bearer_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isBasicBearer}} + {{/isBasic}} + {{#isOAuth}} + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isOAuth}} + {{/authMethods}} + {{/hasAuthMethods}} + {{#isMultipart}} + {{#hasFormParams}} + let mut form = reqwest::multipart::Form::new(); + {{#formParams}} + {{#isFile}} + {{#required}} + {{^isNullable}} + form = form.file("{{{baseName}}}", {{{paramName}}})?; + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form = form.file("{{{baseName}}}", param_value)?; }, + None => { unimplemented!("Required nullable form file param not supported"); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form = form.file("{{{baseName}}}", param_value)?; + } + {{/required}} + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + form = form.text("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form = form.text("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { form = form.text("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form = form.text("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + req_builder = req_builder.multipart(form); + {{/hasFormParams}} + {{/isMultipart}} + {{^isMultipart}} + {{#hasFormParams}} + let mut form_params = std::collections::HashMap::new(); + {{#formParams}} + {{#isFile}} + {{#required}} + {{^isNullable}} + form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); }, + None => { unimplemented!("Required nullable file form param not supported with x-www-form-urlencoded content"); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + } + {{/required}} + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + form_params.insert("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form_params.insert("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { form_params.insert("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form_params.insert("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + req_builder = req_builder.form(&form_params); + {{/hasFormParams}} + {{/isMultipart}} + {{#hasBodyParam}} + {{#bodyParams}} + req_builder = req_builder.json(&{{{paramName}}}); + {{/bodyParams}} + {{/hasBodyParam}} + + // send request + Box::new(req_builder.send() + {{^returnType}} + .and_then(|i| i.error_for_status()) + .map(|_| ()) + {{/returnType}} + {{#returnType}} + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + {{/returnType}} + .from_err() + ) + } + +{{/operation}} +{{/operations}} +} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api_mod.mustache new file mode 100644 index 000000000000..93123e31facd --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api_mod.mustache @@ -0,0 +1,47 @@ +use reqwest; +use serde_json; + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +{{#apiInfo}} +{{#apis}} +mod {{{classFilename}}}; +{{#operations}} +{{#operation}} +{{#-last}} +pub use self::{{{classFilename}}}::{ {{{classname}}}, {{{classname}}}Client }; +{{/-last}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} + +pub mod configuration; +pub mod client; diff --git a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/client.mustache b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/client.mustache new file mode 100644 index 000000000000..8589665d956e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/client.mustache @@ -0,0 +1,52 @@ +use std::sync::Arc; + +use super::configuration::Configuration; + +pub struct APIClient { +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#operation}} + {{#-last}} + {{{classFilename}}}: Box, + {{/-last}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Arc::new(configuration); + + APIClient { +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#operation}} + {{#-last}} + {{{classFilename}}}: Box::new(crate::apis::{{{classname}}}Client::new(rc.clone())), + {{/-last}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} + } + } + +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#operation}} +{{#-last}} + pub fn {{{classFilename}}}(&self) -> &dyn crate::apis::{{{classname}}}{ + self.{{{classFilename}}}.as_ref() + } + +{{/-last}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} +} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/configuration.mustache b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/configuration.mustache new file mode 100644 index 000000000000..cc968afcf55c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/configuration.mustache @@ -0,0 +1,41 @@ +{{>partial_header}} + +use reqwest; + +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::async::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "{{{basePath}}}".to_owned(), + user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("OpenAPI-Generator/{{{version}}}/rust".to_owned()){{/httpUserAgent}}, + client: reqwest::async::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} From b7404f1a541b20ecdd805c1f7375e3819ac8bbac Mon Sep 17 00:00:00 2001 From: Seb Renauld Date: Tue, 22 Oct 2019 21:02:08 +0200 Subject: [PATCH 2/4] Samples have been generated --- bin/rust-petstore.sh | 2 +- bin/windows/rust-futures-petstore.bat | 10 + samples/client/petstore/rust/.gitignore | 3 +- .../petstore/rust/.openapi-generator-ignore | 23 ++ .../petstore/rust/.openapi-generator/VERSION | 2 +- samples/client/petstore/rust/.travis.yml | 1 + samples/client/petstore/rust/Cargo.toml | 16 +- samples/client/petstore/rust/README.md | 68 +++++ .../client/petstore/rust/docs/ApiResponse.md | 13 + samples/client/petstore/rust/docs/Category.md | 12 + samples/client/petstore/rust/docs/Order.md | 16 ++ samples/client/petstore/rust/docs/Pet.md | 16 ++ samples/client/petstore/rust/docs/PetApi.md | 251 ++++++++++++++++++ samples/client/petstore/rust/docs/StoreApi.md | 127 +++++++++ samples/client/petstore/rust/docs/Tag.md | 12 + samples/client/petstore/rust/docs/User.md | 18 ++ samples/client/petstore/rust/docs/UserApi.md | 245 +++++++++++++++++ samples/client/petstore/rust/git_push.sh | 58 ++++ .../client/petstore/rust/src/apis/client.rs | 34 +++ .../petstore/rust/src/apis/configuration.rs | 50 ++++ samples/client/petstore/rust/src/apis/mod.rs | 41 +++ .../client/petstore/rust/src/apis/pet_api.rs | 248 +++++++++++++++++ .../client/petstore/rust/src/apis/request.rs | 239 +++++++++++++++++ .../petstore/rust/src/apis/store_api.rs | 125 +++++++++ .../client/petstore/rust/src/apis/user_api.rs | 202 ++++++++++++++ samples/client/petstore/rust/src/lib.rs | 11 + .../petstore/rust/src/models/api_response.rs | 36 +++ .../petstore/rust/src/models/category.rs | 33 +++ .../client/petstore/rust/src/models/mod.rs | 12 + .../client/petstore/rust/src/models/order.rs | 56 ++++ .../client/petstore/rust/src/models/pet.rs | 56 ++++ .../client/petstore/rust/src/models/tag.rs | 33 +++ .../client/petstore/rust/src/models/user.rs | 52 ++++ 33 files changed, 2116 insertions(+), 5 deletions(-) create mode 100644 bin/windows/rust-futures-petstore.bat create mode 100644 samples/client/petstore/rust/.openapi-generator-ignore create mode 100644 samples/client/petstore/rust/.travis.yml create mode 100644 samples/client/petstore/rust/README.md create mode 100644 samples/client/petstore/rust/docs/ApiResponse.md create mode 100644 samples/client/petstore/rust/docs/Category.md create mode 100644 samples/client/petstore/rust/docs/Order.md create mode 100644 samples/client/petstore/rust/docs/Pet.md create mode 100644 samples/client/petstore/rust/docs/PetApi.md create mode 100644 samples/client/petstore/rust/docs/StoreApi.md create mode 100644 samples/client/petstore/rust/docs/Tag.md create mode 100644 samples/client/petstore/rust/docs/User.md create mode 100644 samples/client/petstore/rust/docs/UserApi.md create mode 100644 samples/client/petstore/rust/git_push.sh create mode 100644 samples/client/petstore/rust/src/apis/client.rs create mode 100644 samples/client/petstore/rust/src/apis/configuration.rs create mode 100644 samples/client/petstore/rust/src/apis/mod.rs create mode 100644 samples/client/petstore/rust/src/apis/pet_api.rs create mode 100644 samples/client/petstore/rust/src/apis/request.rs create mode 100644 samples/client/petstore/rust/src/apis/store_api.rs create mode 100644 samples/client/petstore/rust/src/apis/user_api.rs create mode 100644 samples/client/petstore/rust/src/lib.rs create mode 100644 samples/client/petstore/rust/src/models/api_response.rs create mode 100644 samples/client/petstore/rust/src/models/category.rs create mode 100644 samples/client/petstore/rust/src/models/mod.rs create mode 100644 samples/client/petstore/rust/src/models/order.rs create mode 100644 samples/client/petstore/rust/src/models/pet.rs create mode 100644 samples/client/petstore/rust/src/models/tag.rs create mode 100644 samples/client/petstore/rust/src/models/user.rs diff --git a/bin/rust-petstore.sh b/bin/rust-petstore.sh index d5aceb82af66..327b9cc3a8c5 100755 --- a/bin/rust-petstore.sh +++ b/bin/rust-petstore.sh @@ -35,7 +35,7 @@ for spec_path in \ ; do spec=$(basename "$spec_path" | sed 's/.yaml//' | sed 's/.json//' ) - for library in hyper reqwest; do + for library in hyper reqwest reqwestFutures; do args="generate --template-dir modules/openapi-generator/src/main/resources/rust --input-spec $spec_path --generator-name rust diff --git a/bin/windows/rust-futures-petstore.bat b/bin/windows/rust-futures-petstore.bat new file mode 100644 index 000000000000..7098cff6de46 --- /dev/null +++ b/bin/windows/rust-futures-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g rust --library reqwestFutures -o samples\client\petstore\rust + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/samples/client/petstore/rust/.gitignore b/samples/client/petstore/rust/.gitignore index a9d37c560c6a..6aa106405a4b 100644 --- a/samples/client/petstore/rust/.gitignore +++ b/samples/client/petstore/rust/.gitignore @@ -1,2 +1,3 @@ -target +/target/ +**/*.rs.bk Cargo.lock diff --git a/samples/client/petstore/rust/.openapi-generator-ignore b/samples/client/petstore/rust/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/rust/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/rust/.openapi-generator/VERSION b/samples/client/petstore/rust/.openapi-generator/VERSION index 479c313e87b9..c3a2c7076fa8 100644 --- a/samples/client/petstore/rust/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.3-SNAPSHOT \ No newline at end of file +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/.travis.yml b/samples/client/petstore/rust/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/petstore/rust/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/petstore/rust/Cargo.toml b/samples/client/petstore/rust/Cargo.toml index 46b06cf9bbe3..cb04bcf49bfa 100644 --- a/samples/client/petstore/rust/Cargo.toml +++ b/samples/client/petstore/rust/Cargo.toml @@ -1,2 +1,14 @@ -[workspace] -members = ["hyper/*", "reqwest/*"] +[package] +name = "openapi" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] + +[dependencies] +serde = "^1.0" +serde_derive = "^1.0" +serde_json = "^1.0" +url = "1.5" +reqwest = "~0.9" +futures = "0.1.23" + +[dev-dependencies] diff --git a/samples/client/petstore/rust/README.md b/samples/client/petstore/rust/README.md new file mode 100644 index 000000000000..8d3556dd568e --- /dev/null +++ b/samples/client/petstore/rust/README.md @@ -0,0 +1,68 @@ +# Rust API client for openapi + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Build package: org.openapitools.codegen.languages.RustClientCodegen + +## Installation + +Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`: + +``` + openapi = { path = "./generated" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **post** /pet | Add a new pet to the store +*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID +*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **put** /pet | Update an existing pet +*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **post** /store/order | Place an order for a pet +*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **post** /user | Create user +*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **delete** /user/{username} | Delete user +*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name +*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **get** /user/login | Logs user into the system +*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session +*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **put** /user/{username} | Updated user + + +## Documentation For Models + + - [ApiResponse](docs/ApiResponse.md) + - [Category](docs/Category.md) + - [Order](docs/Order.md) + - [Pet](docs/Pet.md) + - [Tag](docs/Tag.md) + - [User](docs/User.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/petstore/rust/docs/ApiResponse.md b/samples/client/petstore/rust/docs/ApiResponse.md new file mode 100644 index 000000000000..97128a87d97b --- /dev/null +++ b/samples/client/petstore/rust/docs/ApiResponse.md @@ -0,0 +1,13 @@ +# ApiResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**code** | Option<**i32**> | | [optional] +**_type** | Option<**String**> | | [optional] +**message** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/Category.md b/samples/client/petstore/rust/docs/Category.md new file mode 100644 index 000000000000..1cf67347c057 --- /dev/null +++ b/samples/client/petstore/rust/docs/Category.md @@ -0,0 +1,12 @@ +# Category + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**name** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/Order.md b/samples/client/petstore/rust/docs/Order.md new file mode 100644 index 000000000000..d9a09c397432 --- /dev/null +++ b/samples/client/petstore/rust/docs/Order.md @@ -0,0 +1,16 @@ +# Order + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**pet_id** | Option<**i64**> | | [optional] +**quantity** | Option<**i32**> | | [optional] +**ship_date** | Option<**String**> | | [optional] +**status** | Option<**String**> | Order Status | [optional] +**complete** | Option<**bool**> | | [optional][default to false] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/Pet.md b/samples/client/petstore/rust/docs/Pet.md new file mode 100644 index 000000000000..27886889d1d4 --- /dev/null +++ b/samples/client/petstore/rust/docs/Pet.md @@ -0,0 +1,16 @@ +# Pet + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**category** | Option<[**crate::models::Category**](Category.md)> | | [optional] +**name** | **String** | | +**photo_urls** | **Vec** | | +**tags** | Option<[**Vec**](Tag.md)> | | [optional] +**status** | Option<**String**> | pet status in the store | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/PetApi.md b/samples/client/petstore/rust/docs/PetApi.md new file mode 100644 index 000000000000..4716e752b666 --- /dev/null +++ b/samples/client/petstore/rust/docs/PetApi.md @@ -0,0 +1,251 @@ +# \PetApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**add_pet**](PetApi.md#add_pet) | **post** /pet | Add a new pet to the store +[**delete_pet**](PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status +[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags +[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID +[**update_pet**](PetApi.md#update_pet) | **put** /pet | Update an existing pet +[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data +[**upload_file**](PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image + + + +## add_pet + +> add_pet(body) +Add a new pet to the store + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## delete_pet + +> delete_pet(pet_id, api_key) +Deletes a pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | Pet id to delete | [required] | +**api_key** | Option<**String**> | | | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## find_pets_by_status + +> Vec find_pets_by_status(status) +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**status** | [**Vec**](String.md) | Status values that need to be considered for filter | [required] | + +### Return type + +[**Vec**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## find_pets_by_tags + +> Vec find_pets_by_tags(tags) +Finds Pets by tags + +Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**tags** | [**Vec**](String.md) | Tags to filter by | [required] | + +### Return type + +[**Vec**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_pet_by_id + +> crate::models::Pet get_pet_by_id(pet_id) +Find pet by ID + +Returns a single pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet to return | [required] | + +### Return type + +[**crate::models::Pet**](Pet.md) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_pet + +> update_pet(body) +Update an existing pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_pet_with_form + +> update_pet_with_form(pet_id, name, status) +Updates a pet in the store with form data + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet that needs to be updated | [required] | +**name** | Option<**String**> | Updated name of the pet | | +**status** | Option<**String**> | Updated status of the pet | | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/x-www-form-urlencoded +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## upload_file + +> crate::models::ApiResponse upload_file(pet_id, additional_metadata, file) +uploads an image + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet to update | [required] | +**additional_metadata** | Option<**String**> | Additional data to pass to server | | +**file** | Option<**std::path::PathBuf**> | file to upload | | + +### Return type + +[**crate::models::ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: multipart/form-data +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/docs/StoreApi.md b/samples/client/petstore/rust/docs/StoreApi.md new file mode 100644 index 000000000000..a310b5383154 --- /dev/null +++ b/samples/client/petstore/rust/docs/StoreApi.md @@ -0,0 +1,127 @@ +# \StoreApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**delete_order**](StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID +[**get_inventory**](StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status +[**get_order_by_id**](StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID +[**place_order**](StoreApi.md#place_order) | **post** /store/order | Place an order for a pet + + + +## delete_order + +> delete_order(order_id) +Delete purchase order by ID + +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order_id** | **String** | ID of the order that needs to be deleted | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_inventory + +> ::std::collections::HashMap get_inventory() +Returns pet inventories by status + +Returns a map of status codes to quantities + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +**::std::collections::HashMap** + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_order_by_id + +> crate::models::Order get_order_by_id(order_id) +Find purchase order by ID + +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order_id** | **i64** | ID of pet that needs to be fetched | [required] | + +### Return type + +[**crate::models::Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## place_order + +> crate::models::Order place_order(body) +Place an order for a pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Order**](Order.md) | order placed for purchasing the pet | [required] | + +### Return type + +[**crate::models::Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/docs/Tag.md b/samples/client/petstore/rust/docs/Tag.md new file mode 100644 index 000000000000..7bf71ab0e9d8 --- /dev/null +++ b/samples/client/petstore/rust/docs/Tag.md @@ -0,0 +1,12 @@ +# Tag + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**name** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/User.md b/samples/client/petstore/rust/docs/User.md new file mode 100644 index 000000000000..2e6abda42b32 --- /dev/null +++ b/samples/client/petstore/rust/docs/User.md @@ -0,0 +1,18 @@ +# User + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**username** | Option<**String**> | | [optional] +**first_name** | Option<**String**> | | [optional] +**last_name** | Option<**String**> | | [optional] +**email** | Option<**String**> | | [optional] +**password** | Option<**String**> | | [optional] +**phone** | Option<**String**> | | [optional] +**user_status** | Option<**i32**> | User Status | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/docs/UserApi.md b/samples/client/petstore/rust/docs/UserApi.md new file mode 100644 index 000000000000..a6268f251a64 --- /dev/null +++ b/samples/client/petstore/rust/docs/UserApi.md @@ -0,0 +1,245 @@ +# \UserApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**create_user**](UserApi.md#create_user) | **post** /user | Create user +[**create_users_with_array_input**](UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array +[**create_users_with_list_input**](UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array +[**delete_user**](UserApi.md#delete_user) | **delete** /user/{username} | Delete user +[**get_user_by_name**](UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name +[**login_user**](UserApi.md#login_user) | **get** /user/login | Logs user into the system +[**logout_user**](UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session +[**update_user**](UserApi.md#update_user) | **put** /user/{username} | Updated user + + + +## create_user + +> create_user(body) +Create user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**User**](User.md) | Created user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## create_users_with_array_input + +> create_users_with_array_input(body) +Creates list of users with given input array + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## create_users_with_list_input + +> create_users_with_list_input(body) +Creates list of users with given input array + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## delete_user + +> delete_user(username) +Delete user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be deleted | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_user_by_name + +> crate::models::User get_user_by_name(username) +Get user by user name + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | + +### Return type + +[**crate::models::User**](User.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## login_user + +> String login_user(username, password) +Logs user into the system + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The user name for login | [required] | +**password** | **String** | The password for login in clear text | [required] | + +### Return type + +**String** + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## logout_user + +> logout_user() +Logs out current logged in user session + +### Parameters + +This endpoint does not need any parameter. + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_user + +> update_user(username, body) +Updated user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | name that need to be deleted | [required] | +**body** | [**User**](User.md) | Updated user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/git_push.sh b/samples/client/petstore/rust/git_push.sh new file mode 100644 index 000000000000..ced3be2b0c7b --- /dev/null +++ b/samples/client/petstore/rust/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/rust/src/apis/client.rs b/samples/client/petstore/rust/src/apis/client.rs new file mode 100644 index 000000000000..260183d6ba80 --- /dev/null +++ b/samples/client/petstore/rust/src/apis/client.rs @@ -0,0 +1,34 @@ +use std::sync::Arc; + +use super::configuration::Configuration; + +pub struct APIClient { + pet_api: Box, + store_api: Box, + user_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Arc::new(configuration); + + APIClient { + pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), + store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), + user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), + } + } + + pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ + self.pet_api.as_ref() + } + + pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ + self.store_api.as_ref() + } + + pub fn user_api(&self) -> &dyn crate::apis::UserApi{ + self.user_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/src/apis/configuration.rs b/samples/client/petstore/rust/src/apis/configuration.rs new file mode 100644 index 000000000000..4442a66f0d25 --- /dev/null +++ b/samples/client/petstore/rust/src/apis/configuration.rs @@ -0,0 +1,50 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; + +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::async::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://petstore.swagger.io/v2".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::async::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/petstore/rust/src/apis/mod.rs b/samples/client/petstore/rust/src/apis/mod.rs new file mode 100644 index 000000000000..c14d751153a1 --- /dev/null +++ b/samples/client/petstore/rust/src/apis/mod.rs @@ -0,0 +1,41 @@ +use reqwest; +use serde_json; + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +mod pet_api; +pub use self::pet_api::{ PetApi, PetApiClient }; +mod store_api; +pub use self::store_api::{ StoreApi, StoreApiClient }; +mod user_api; +pub use self::user_api::{ UserApi, UserApiClient }; + +pub mod configuration; +pub mod client; diff --git a/samples/client/petstore/rust/src/apis/pet_api.rs b/samples/client/petstore/rust/src/apis/pet_api.rs new file mode 100644 index 000000000000..17c5da7b028a --- /dev/null +++ b/samples/client/petstore/rust/src/apis/pet_api.rs @@ -0,0 +1,248 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct PetApiClient { + configuration: Arc, +} + +impl PetApiClient { + pub fn new(configuration: Arc) -> PetApiClient { + PetApiClient { + configuration, + } + } +} + +pub trait PetApi { + fn add_pet(&self, body: crate::models::Pet) -> Box + Send>; + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send>; + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send>; + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send>; + fn get_pet_by_id(&self, pet_id: i64) -> Box + Send>; + fn update_pet(&self, body: crate::models::Pet) -> Box + Send>; + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send>; + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send>; +} + +impl PetApi for PetApiClient { + fn add_pet(&self, body: crate::models::Pet) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + let mut req_builder = client.delete(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(param_value) = api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); + } + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); + 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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); + 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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn get_pet_by_id(&self, pet_id: i64) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + 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 apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("api_key", val); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn update_pet(&self, body: crate::models::Pet) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = client.put(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + let mut form_params = std::collections::HashMap::new(); + if let Some(param_value) = name { + form_params.insert("name", param_value.to_string()); + } + if let Some(param_value) = status { + form_params.insert("status", param_value.to_string()); + } + req_builder = req_builder.form(&form_params); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=pet_id); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + let mut form = reqwest::multipart::Form::new(); + if let Some(param_value) = additional_metadata { + form = form.text("additionalMetadata", param_value.to_string()); + } + if let Some(param_value) = file { + form = form.file("file", param_value)?; + } + req_builder = req_builder.multipart(form); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/src/apis/request.rs b/samples/client/petstore/rust/src/apis/request.rs new file mode 100644 index 000000000000..f97b5277196a --- /dev/null +++ b/samples/client/petstore/rust/src/apis/request.rs @@ -0,0 +1,239 @@ +use std::borrow::Cow; +use std::collections::HashMap; + +use super::{configuration, Error}; +use futures; +use futures::{Future, Stream}; +use hyper; +use hyper::header::UserAgent; +use serde; +use serde_json; + +pub(crate) struct ApiKey { + pub in_header: bool, + pub in_query: bool, + pub param_name: String, +} + +impl ApiKey { + fn key(&self, prefix: &Option, key: &str) -> String { + match prefix { + None => key.to_owned(), + Some(ref prefix) => format!("{} {}", prefix, key), + } + } +} + +#[allow(dead_code)] +pub(crate) enum Auth { + None, + ApiKey(ApiKey), + Basic, + Oauth, +} + +pub(crate) struct Request { + auth: Auth, + method: hyper::Method, + path: String, + query_params: HashMap, + no_return_type: bool, + path_params: HashMap, + form_params: HashMap, + header_params: HashMap, + // TODO: multiple body params are possible technically, but not supported here. + serialized_body: Option, +} + +impl Request { + pub fn new(method: hyper::Method, path: String) -> Self { + Request { + auth: Auth::None, + method: method, + path: path, + query_params: HashMap::new(), + path_params: HashMap::new(), + form_params: HashMap::new(), + header_params: HashMap::new(), + serialized_body: None, + no_return_type: false, + } + } + + pub fn with_body_param(mut self, param: T) -> Self { + self.serialized_body = Some(serde_json::to_string(¶m).unwrap()); + self + } + + pub fn with_header_param(mut self, basename: String, param: String) -> Self { + self.header_params.insert(basename, param); + self + } + + pub fn with_query_param(mut self, basename: String, param: String) -> Self { + self.query_params.insert(basename, param); + self + } + + pub fn with_path_param(mut self, basename: String, param: String) -> Self { + self.path_params.insert(basename, param); + self + } + + pub fn with_form_param(mut self, basename: String, param: String) -> Self { + self.form_params.insert(basename, param); + self + } + + pub fn returns_nothing(mut self) -> Self { + self.no_return_type = true; + self + } + + pub fn with_auth(mut self, auth: Auth) -> Self { + self.auth = auth; + self + } + + pub fn execute<'a, C, U>( + self, + conf: &configuration::Configuration, + ) -> Box> + 'a> + where + C: hyper::client::Connect, + U: Sized + 'a, + for<'de> U: serde::Deserialize<'de>, + { + let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned()); + // raw_headers is for headers we don't know the proper type of (e.g. custom api key + // headers); headers is for ones we do know the type of. + let mut raw_headers = HashMap::new(); + let mut headers: hyper::header::Headers = hyper::header::Headers::new(); + + let mut path = self.path; + for (k, v) in self.path_params { + // replace {id} with the value of the id path param + path = path.replace(&format!("{{{}}}", k), &v); + } + + for (k, v) in self.header_params { + raw_headers.insert(k, v); + } + + for (key, val) in self.query_params { + query_string.append_pair(&key, &val); + } + + match self.auth { + Auth::ApiKey(apikey) => { + if let Some(ref key) = conf.api_key { + let val = apikey.key(&key.prefix, &key.key); + if apikey.in_query { + query_string.append_pair(&apikey.param_name, &val); + } + if apikey.in_header { + raw_headers.insert(apikey.param_name, val); + } + } + } + Auth::Basic => { + if let Some(ref auth_conf) = conf.basic_auth { + let auth = hyper::header::Authorization(hyper::header::Basic { + username: auth_conf.0.to_owned(), + password: auth_conf.1.to_owned(), + }); + headers.set(auth); + } + } + Auth::Oauth => { + if let Some(ref token) = conf.oauth_access_token { + let auth = hyper::header::Authorization(hyper::header::Bearer { + token: token.to_owned(), + }); + headers.set(auth); + } + } + Auth::None => {} + } + + let mut uri_str = format!("{}{}", conf.base_path, path); + + let query_string_str = query_string.finish(); + if query_string_str != "" { + uri_str += "?"; + uri_str += &query_string_str; + } + let uri: hyper::Uri = match uri_str.parse() { + Err(e) => { + return Box::new(futures::future::err(Error::UriError(e))); + } + Ok(u) => u, + }; + + let mut req = hyper::Request::new(self.method, uri); + { + let req_headers = req.headers_mut(); + if let Some(ref user_agent) = conf.user_agent { + req_headers.set(UserAgent::new(Cow::Owned(user_agent.clone()))); + } + + req_headers.extend(headers.iter()); + + for (key, val) in raw_headers { + req_headers.set_raw(key, val); + } + } + + if self.form_params.len() > 0 { + req.headers_mut().set(hyper::header::ContentType::form_url_encoded()); + let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned()); + for (k, v) in self.form_params { + enc.append_pair(&k, &v); + } + req.set_body(enc.finish()); + } + + if let Some(body) = self.serialized_body { + req.headers_mut().set(hyper::header::ContentType::json()); + req.headers_mut() + .set(hyper::header::ContentLength(body.len() as u64)); + req.set_body(body); + } + + let no_ret_type = self.no_return_type; + let res = conf.client + .request(req) + .map_err(|e| Error::from(e)) + .and_then(|resp| { + let status = resp.status(); + resp.body() + .concat2() + .and_then(move |body| Ok((status, body))) + .map_err(|e| Error::from(e)) + }) + .and_then(|(status, body)| { + if status.is_success() { + Ok(body) + } else { + Err(Error::from((status, &*body))) + } + }); + Box::new( + res + .and_then(move |body| { + let parsed: Result = if no_ret_type { + // This is a hack; if there's no_ret_type, U is (), but serde_json gives an + // error when deserializing "" into (), so deserialize 'null' into it + // instead. + // An alternate option would be to require U: Default, and then return + // U::default() here instead since () implements that, but then we'd + // need to impl default for all models. + serde_json::from_str("null") + } else { + serde_json::from_slice(&body) + }; + parsed.map_err(|e| Error::from(e)) + }) + ) + } +} diff --git a/samples/client/petstore/rust/src/apis/store_api.rs b/samples/client/petstore/rust/src/apis/store_api.rs new file mode 100644 index 000000000000..681a3c2b4d08 --- /dev/null +++ b/samples/client/petstore/rust/src/apis/store_api.rs @@ -0,0 +1,125 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct StoreApiClient { + configuration: Arc, +} + +impl StoreApiClient { + pub fn new(configuration: Arc) -> StoreApiClient { + StoreApiClient { + configuration, + } + } +} + +pub trait StoreApi { + fn delete_order(&self, order_id: &str) -> Box + Send>; + fn get_inventory(&self, ) -> Box, Error = Error> + Send>; + fn get_order_by_id(&self, order_id: i64) -> Box + Send>; + fn place_order(&self, body: crate::models::Order) -> Box + Send>; +} + +impl StoreApi for StoreApiClient { + fn delete_order(&self, order_id: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(order_id)); + let mut req_builder = client.delete(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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn get_inventory(&self, ) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/inventory", 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 apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("api_key", val); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn get_order_by_id(&self, order_id: i64) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id); + 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn place_order(&self, body: crate::models::Order) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/src/apis/user_api.rs b/samples/client/petstore/rust/src/apis/user_api.rs new file mode 100644 index 000000000000..c9c8acbc89c8 --- /dev/null +++ b/samples/client/petstore/rust/src/apis/user_api.rs @@ -0,0 +1,202 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct UserApiClient { + configuration: Arc, +} + +impl UserApiClient { + pub fn new(configuration: Arc) -> UserApiClient { + UserApiClient { + configuration, + } + } +} + +pub trait UserApi { + fn create_user(&self, body: crate::models::User) -> Box + Send>; + fn create_users_with_array_input(&self, body: Vec) -> Box + Send>; + fn create_users_with_list_input(&self, body: Vec) -> Box + Send>; + fn delete_user(&self, username: &str) -> Box + Send>; + fn get_user_by_name(&self, username: &str) -> Box + Send>; + fn login_user(&self, username: &str, password: &str) -> Box + Send>; + fn logout_user(&self, ) -> Box + Send>; + fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send>; +} + +impl UserApi for UserApiClient { + fn create_user(&self, body: crate::models::User) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn create_users_with_array_input(&self, body: Vec) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn create_users_with_list_input(&self, body: Vec) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn delete_user(&self, username: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + let mut req_builder = client.delete(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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn get_user_by_name(&self, username: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn login_user(&self, username: &str, password: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("username", &username.to_string())]); + req_builder = req_builder.query(&[("password", &password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn logout_user(&self, ) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/logout", 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + let mut req_builder = client.put(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/src/lib.rs b/samples/client/petstore/rust/src/lib.rs new file mode 100644 index 000000000000..f318efa89200 --- /dev/null +++ b/samples/client/petstore/rust/src/lib.rs @@ -0,0 +1,11 @@ +#[macro_use] +extern crate serde_derive; + +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; +extern crate futures; + +pub mod apis; +pub mod models; diff --git a/samples/client/petstore/rust/src/models/api_response.rs b/samples/client/petstore/rust/src/models/api_response.rs new file mode 100644 index 000000000000..f1286a5d1c84 --- /dev/null +++ b/samples/client/petstore/rust/src/models/api_response.rs @@ -0,0 +1,36 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// ApiResponse : Describes the result of uploading an image resource + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct ApiResponse { + #[serde(rename = "code", skip_serializing_if = "Option::is_none")] + pub code: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub _type: Option, + #[serde(rename = "message", skip_serializing_if = "Option::is_none")] + pub message: Option, +} + +impl ApiResponse { + /// Describes the result of uploading an image resource + pub fn new() -> ApiResponse { + ApiResponse { + code: None, + _type: None, + message: None, + } + } +} + + diff --git a/samples/client/petstore/rust/src/models/category.rs b/samples/client/petstore/rust/src/models/category.rs new file mode 100644 index 000000000000..dcd2dc386302 --- /dev/null +++ b/samples/client/petstore/rust/src/models/category.rs @@ -0,0 +1,33 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Category : A category for a pet + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Category { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +impl Category { + /// A category for a pet + pub fn new() -> Category { + Category { + id: None, + name: None, + } + } +} + + diff --git a/samples/client/petstore/rust/src/models/mod.rs b/samples/client/petstore/rust/src/models/mod.rs new file mode 100644 index 000000000000..1baf2f7528e2 --- /dev/null +++ b/samples/client/petstore/rust/src/models/mod.rs @@ -0,0 +1,12 @@ +pub mod api_response; +pub use self::api_response::ApiResponse; +pub mod category; +pub use self::category::Category; +pub mod order; +pub use self::order::Order; +pub mod pet; +pub use self::pet::Pet; +pub mod tag; +pub use self::tag::Tag; +pub mod user; +pub use self::user::User; diff --git a/samples/client/petstore/rust/src/models/order.rs b/samples/client/petstore/rust/src/models/order.rs new file mode 100644 index 000000000000..89cab91e62c1 --- /dev/null +++ b/samples/client/petstore/rust/src/models/order.rs @@ -0,0 +1,56 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Order : An order for a pets from the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Order { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "petId", skip_serializing_if = "Option::is_none")] + pub pet_id: Option, + #[serde(rename = "quantity", skip_serializing_if = "Option::is_none")] + pub quantity: Option, + #[serde(rename = "shipDate", skip_serializing_if = "Option::is_none")] + pub ship_date: Option, + /// Order Status + #[serde(rename = "status", skip_serializing_if = "Option::is_none")] + pub status: Option, + #[serde(rename = "complete", skip_serializing_if = "Option::is_none")] + pub complete: Option, +} + +impl Order { + /// An order for a pets from the pet store + pub fn new() -> Order { + Order { + id: None, + pet_id: None, + quantity: None, + ship_date: None, + status: None, + complete: None, + } + } +} + +/// Order Status +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "placed")] + Placed, + #[serde(rename = "approved")] + Approved, + #[serde(rename = "delivered")] + Delivered, +} + diff --git a/samples/client/petstore/rust/src/models/pet.rs b/samples/client/petstore/rust/src/models/pet.rs new file mode 100644 index 000000000000..ff8a32fee3ab --- /dev/null +++ b/samples/client/petstore/rust/src/models/pet.rs @@ -0,0 +1,56 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Pet : A pet for sale in the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Pet { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "category", skip_serializing_if = "Option::is_none")] + pub category: Option, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "photoUrls")] + pub photo_urls: Vec, + #[serde(rename = "tags", skip_serializing_if = "Option::is_none")] + pub tags: Option>, + /// pet status in the store + #[serde(rename = "status", skip_serializing_if = "Option::is_none")] + pub status: Option, +} + +impl Pet { + /// A pet for sale in the pet store + pub fn new(name: String, photo_urls: Vec) -> Pet { + Pet { + id: None, + category: None, + name, + photo_urls, + tags: None, + status: None, + } + } +} + +/// pet status in the store +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "available")] + Available, + #[serde(rename = "pending")] + Pending, + #[serde(rename = "sold")] + Sold, +} + diff --git a/samples/client/petstore/rust/src/models/tag.rs b/samples/client/petstore/rust/src/models/tag.rs new file mode 100644 index 000000000000..f6bcb5c78d6a --- /dev/null +++ b/samples/client/petstore/rust/src/models/tag.rs @@ -0,0 +1,33 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Tag : A tag for a pet + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Tag { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +impl Tag { + /// A tag for a pet + pub fn new() -> Tag { + Tag { + id: None, + name: None, + } + } +} + + diff --git a/samples/client/petstore/rust/src/models/user.rs b/samples/client/petstore/rust/src/models/user.rs new file mode 100644 index 000000000000..cf863af7b585 --- /dev/null +++ b/samples/client/petstore/rust/src/models/user.rs @@ -0,0 +1,52 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// User : A User who is purchasing from the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct User { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "username", skip_serializing_if = "Option::is_none")] + pub username: Option, + #[serde(rename = "firstName", skip_serializing_if = "Option::is_none")] + pub first_name: Option, + #[serde(rename = "lastName", skip_serializing_if = "Option::is_none")] + pub last_name: Option, + #[serde(rename = "email", skip_serializing_if = "Option::is_none")] + pub email: Option, + #[serde(rename = "password", skip_serializing_if = "Option::is_none")] + pub password: Option, + #[serde(rename = "phone", skip_serializing_if = "Option::is_none")] + pub phone: Option, + /// User Status + #[serde(rename = "userStatus", skip_serializing_if = "Option::is_none")] + pub user_status: Option, +} + +impl User { + /// A User who is purchasing from the pet store + pub fn new() -> User { + User { + id: None, + username: None, + first_name: None, + last_name: None, + email: None, + password: None, + phone: None, + user_status: None, + } + } +} + + From db03b20fbb98218aabb975e76c9815fd7009d0ce Mon Sep 17 00:00:00 2001 From: Seb Renauld Date: Tue, 22 Oct 2019 21:55:36 +0200 Subject: [PATCH 3/4] Forgot that one --- docs/generators/rust.md | 3 +- .../fileResponseTest/.gitignore | 3 + .../.openapi-generator-ignore | 23 ++ .../.openapi-generator/VERSION | 1 + .../fileResponseTest/.travis.yml | 1 + .../fileResponseTest/Cargo.toml | 14 + .../reqwestFutures/fileResponseTest/README.md | 43 +++ .../fileResponseTest/docs/DefaultApi.md | 34 +++ .../fileResponseTest/git_push.sh | 58 ++++ .../fileResponseTest/src/apis/client.rs | 22 ++ .../src/apis/configuration.rs | 50 ++++ .../fileResponseTest/src/apis/default_api.rs | 56 ++++ .../fileResponseTest/src/apis/mod.rs | 37 +++ .../fileResponseTest/src/lib.rs | 11 + .../fileResponseTest/src/models/mod.rs | 0 .../rust/reqwestFutures/petstore/.gitignore | 3 + .../petstore/.openapi-generator-ignore | 23 ++ .../petstore/.openapi-generator/VERSION | 1 + .../rust/reqwestFutures/petstore/.travis.yml | 1 + .../rust/reqwestFutures/petstore/Cargo.toml | 14 + .../rust/reqwestFutures/petstore/README.md | 68 +++++ .../petstore/docs/ApiResponse.md | 13 + .../reqwestFutures/petstore/docs/Category.md | 12 + .../reqwestFutures/petstore/docs/Order.md | 16 ++ .../rust/reqwestFutures/petstore/docs/Pet.md | 16 ++ .../reqwestFutures/petstore/docs/PetApi.md | 251 ++++++++++++++++++ .../reqwestFutures/petstore/docs/StoreApi.md | 127 +++++++++ .../rust/reqwestFutures/petstore/docs/Tag.md | 12 + .../rust/reqwestFutures/petstore/docs/User.md | 18 ++ .../reqwestFutures/petstore/docs/UserApi.md | 245 +++++++++++++++++ .../rust/reqwestFutures/petstore/git_push.sh | 58 ++++ .../petstore/src/apis/client.rs | 34 +++ .../petstore/src/apis/configuration.rs | 50 ++++ .../reqwestFutures/petstore/src/apis/mod.rs | 41 +++ .../petstore/src/apis/pet_api.rs | 248 +++++++++++++++++ .../petstore/src/apis/store_api.rs | 125 +++++++++ .../petstore/src/apis/user_api.rs | 202 ++++++++++++++ .../rust/reqwestFutures/petstore/src/lib.rs | 11 + .../petstore/src/models/api_response.rs | 36 +++ .../petstore/src/models/category.rs | 33 +++ .../reqwestFutures/petstore/src/models/mod.rs | 12 + .../petstore/src/models/order.rs | 56 ++++ .../reqwestFutures/petstore/src/models/pet.rs | 56 ++++ .../reqwestFutures/petstore/src/models/tag.rs | 33 +++ .../petstore/src/models/user.rs | 52 ++++ .../rust/reqwestFutures/rust-test/.gitignore | 3 + .../rust-test/.openapi-generator-ignore | 23 ++ .../rust-test/.openapi-generator/VERSION | 1 + .../rust/reqwestFutures/rust-test/.travis.yml | 1 + .../rust/reqwestFutures/rust-test/Cargo.toml | 14 + .../rust/reqwestFutures/rust-test/README.md | 44 +++ .../rust-test/docs/DefaultApi.md | 34 +++ .../rust-test/docs/TypeTesting.md | 16 ++ .../rust/reqwestFutures/rust-test/git_push.sh | 58 ++++ .../rust-test/src/apis/client.rs | 22 ++ .../rust-test/src/apis/configuration.rs | 50 ++++ .../rust-test/src/apis/default_api.rs | 56 ++++ .../reqwestFutures/rust-test/src/apis/mod.rs | 37 +++ .../rust/reqwestFutures/rust-test/src/lib.rs | 11 + .../rust-test/src/models/mod.rs | 2 + .../rust-test/src/models/type_testing.rs | 45 ++++ 61 files changed, 2639 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/.gitignore create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator-ignore create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator/VERSION create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/.travis.yml create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/README.md create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/docs/DefaultApi.md create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/git_push.sh create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/client.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/configuration.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/models/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/.gitignore create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator-ignore create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator/VERSION create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/.travis.yml create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/README.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/ApiResponse.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/Category.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/Order.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/Pet.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/PetApi.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/StoreApi.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/Tag.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/User.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/docs/UserApi.md create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/git_push.sh create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/client.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/configuration.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/api_response.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/category.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/order.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/pet.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/tag.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/petstore/src/models/user.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/.gitignore create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator-ignore create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator/VERSION create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/.travis.yml create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/README.md create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/docs/DefaultApi.md create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/docs/TypeTesting.md create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/git_push.sh create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/client.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/configuration.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/models/mod.rs create mode 100644 samples/client/petstore/rust/reqwestFutures/rust-test/src/models/type_testing.rs diff --git a/docs/generators/rust.md b/docs/generators/rust.md index 2f1aa5d74719..03cb6dfa20b6 100644 --- a/docs/generators/rust.md +++ b/docs/generators/rust.md @@ -7,5 +7,6 @@ sidebar_label: rust | ------ | ----------- | ------ | ------- | |packageName|Rust package name (convention: lowercase).| |openapi| |packageVersion|Rust package version.| |1.0.0| +|interfacePrefix|Method prefix.| || |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| -|library|library template (sub-template) to use.|
**hyper**
HTTP client: Hyper.
**reqwest**
HTTP client: Reqwest.
|hyper| +|library|library template (sub-template) to use.|
**hyper**
HTTP client: Hyper.
**reqwest**
HTTP client: Reqwest.
**reqwestFutures**
HTTP client: Reqwest (futures).
|hyper| diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.gitignore b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator-ignore b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator/VERSION new file mode 100644 index 000000000000..c3a2c7076fa8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.travis.yml b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml new file mode 100644 index 000000000000..1c700bf03833 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "fileResponseTest-reqwestFutures" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] + +[dependencies] +serde = "^1.0" +serde_derive = "^1.0" +serde_json = "^1.0" +url = "1.5" +reqwest = "~0.9" +futures = "0.1.23" + +[dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/README.md b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/README.md new file mode 100644 index 000000000000..bfd64293dda9 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/README.md @@ -0,0 +1,43 @@ +# Rust API client for fileResponseTest-reqwestFutures + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Build package: org.openapitools.codegen.languages.RustClientCodegen + +## Installation + +Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`: + +``` + openapi = { path = "./generated" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**fileresponsetest**](docs/DefaultApi.md#fileresponsetest) | **get** /tests/fileResponse | + + +## Documentation For Models + + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/docs/DefaultApi.md b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/docs/DefaultApi.md new file mode 100644 index 000000000000..0b0273e4346b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/docs/DefaultApi.md @@ -0,0 +1,34 @@ +# \DefaultApi + +All URIs are relative to *http://localhost/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**fileresponsetest**](DefaultApi.md#fileresponsetest) | **get** /tests/fileResponse | + + + +## fileresponsetest + +> std::path::PathBuf fileresponsetest() + + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**std::path::PathBuf**](std::path::PathBuf.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/octet-stream + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/git_push.sh b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/git_push.sh new file mode 100644 index 000000000000..ced3be2b0c7b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/client.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/client.rs new file mode 100644 index 000000000000..3f1438beaf1a --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/client.rs @@ -0,0 +1,22 @@ +use std::sync::Arc; + +use super::configuration::Configuration; + +pub struct APIClient { + default_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Arc::new(configuration); + + APIClient { + default_api: Box::new(crate::apis::DefaultApiClient::new(rc.clone())), + } + } + + pub fn default_api(&self) -> &dyn crate::apis::DefaultApi{ + self.default_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/configuration.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/configuration.rs new file mode 100644 index 000000000000..169b4bdcb6b8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/configuration.rs @@ -0,0 +1,50 @@ +/* + * File Response Test + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; + +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::async::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://localhost/v2".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::async::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs new file mode 100644 index 000000000000..1114367df043 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs @@ -0,0 +1,56 @@ +/* + * File Response Test + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct DefaultApiClient { + configuration: Arc, +} + +impl DefaultApiClient { + pub fn new(configuration: Arc) -> DefaultApiClient { + DefaultApiClient { + configuration, + } + } +} + +pub trait DefaultApi { + fn fileresponsetest(&self, ) -> Box + Send>; +} + +impl DefaultApi for DefaultApiClient { + fn fileresponsetest(&self, ) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/mod.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/mod.rs new file mode 100644 index 000000000000..3b70668f6fd9 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/mod.rs @@ -0,0 +1,37 @@ +use reqwest; +use serde_json; + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +mod default_api; +pub use self::default_api::{ DefaultApi, DefaultApiClient }; + +pub mod configuration; +pub mod client; diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs new file mode 100644 index 000000000000..f318efa89200 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs @@ -0,0 +1,11 @@ +#[macro_use] +extern crate serde_derive; + +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; +extern crate futures; + +pub mod apis; +pub mod models; diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/models/mod.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/models/mod.rs new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/.gitignore b/samples/client/petstore/rust/reqwestFutures/petstore/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator-ignore b/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator/VERSION new file mode 100644 index 000000000000..c3a2c7076fa8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/.travis.yml b/samples/client/petstore/rust/reqwestFutures/petstore/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml new file mode 100644 index 000000000000..8b980867ec3e --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "petstore-reqwestFutures" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] + +[dependencies] +serde = "^1.0" +serde_derive = "^1.0" +serde_json = "^1.0" +url = "1.5" +reqwest = "~0.9" +futures = "0.1.23" + +[dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/README.md b/samples/client/petstore/rust/reqwestFutures/petstore/README.md new file mode 100644 index 000000000000..4465b8519c81 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/README.md @@ -0,0 +1,68 @@ +# Rust API client for petstore-reqwestFutures + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Build package: org.openapitools.codegen.languages.RustClientCodegen + +## Installation + +Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`: + +``` + openapi = { path = "./generated" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **post** /pet | Add a new pet to the store +*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID +*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **put** /pet | Update an existing pet +*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **post** /store/order | Place an order for a pet +*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **post** /user | Create user +*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **delete** /user/{username} | Delete user +*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name +*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **get** /user/login | Logs user into the system +*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session +*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **put** /user/{username} | Updated user + + +## Documentation For Models + + - [ApiResponse](docs/ApiResponse.md) + - [Category](docs/Category.md) + - [Order](docs/Order.md) + - [Pet](docs/Pet.md) + - [Tag](docs/Tag.md) + - [User](docs/User.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/ApiResponse.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/ApiResponse.md new file mode 100644 index 000000000000..97128a87d97b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/ApiResponse.md @@ -0,0 +1,13 @@ +# ApiResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**code** | Option<**i32**> | | [optional] +**_type** | Option<**String**> | | [optional] +**message** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/Category.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Category.md new file mode 100644 index 000000000000..1cf67347c057 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Category.md @@ -0,0 +1,12 @@ +# Category + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**name** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/Order.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Order.md new file mode 100644 index 000000000000..d9a09c397432 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Order.md @@ -0,0 +1,16 @@ +# Order + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**pet_id** | Option<**i64**> | | [optional] +**quantity** | Option<**i32**> | | [optional] +**ship_date** | Option<**String**> | | [optional] +**status** | Option<**String**> | Order Status | [optional] +**complete** | Option<**bool**> | | [optional][default to false] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/Pet.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Pet.md new file mode 100644 index 000000000000..27886889d1d4 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Pet.md @@ -0,0 +1,16 @@ +# Pet + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**category** | Option<[**crate::models::Category**](Category.md)> | | [optional] +**name** | **String** | | +**photo_urls** | **Vec** | | +**tags** | Option<[**Vec**](Tag.md)> | | [optional] +**status** | Option<**String**> | pet status in the store | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/PetApi.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/PetApi.md new file mode 100644 index 000000000000..4716e752b666 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/PetApi.md @@ -0,0 +1,251 @@ +# \PetApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**add_pet**](PetApi.md#add_pet) | **post** /pet | Add a new pet to the store +[**delete_pet**](PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status +[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags +[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID +[**update_pet**](PetApi.md#update_pet) | **put** /pet | Update an existing pet +[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data +[**upload_file**](PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image + + + +## add_pet + +> add_pet(body) +Add a new pet to the store + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## delete_pet + +> delete_pet(pet_id, api_key) +Deletes a pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | Pet id to delete | [required] | +**api_key** | Option<**String**> | | | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## find_pets_by_status + +> Vec find_pets_by_status(status) +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**status** | [**Vec**](String.md) | Status values that need to be considered for filter | [required] | + +### Return type + +[**Vec**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## find_pets_by_tags + +> Vec find_pets_by_tags(tags) +Finds Pets by tags + +Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**tags** | [**Vec**](String.md) | Tags to filter by | [required] | + +### Return type + +[**Vec**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_pet_by_id + +> crate::models::Pet get_pet_by_id(pet_id) +Find pet by ID + +Returns a single pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet to return | [required] | + +### Return type + +[**crate::models::Pet**](Pet.md) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_pet + +> update_pet(body) +Update an existing pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_pet_with_form + +> update_pet_with_form(pet_id, name, status) +Updates a pet in the store with form data + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet that needs to be updated | [required] | +**name** | Option<**String**> | Updated name of the pet | | +**status** | Option<**String**> | Updated status of the pet | | + +### Return type + + (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/x-www-form-urlencoded +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## upload_file + +> crate::models::ApiResponse upload_file(pet_id, additional_metadata, file) +uploads an image + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet_id** | **i64** | ID of pet to update | [required] | +**additional_metadata** | Option<**String**> | Additional data to pass to server | | +**file** | Option<**std::path::PathBuf**> | file to upload | | + +### Return type + +[**crate::models::ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: multipart/form-data +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/StoreApi.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/StoreApi.md new file mode 100644 index 000000000000..a310b5383154 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/StoreApi.md @@ -0,0 +1,127 @@ +# \StoreApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**delete_order**](StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID +[**get_inventory**](StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status +[**get_order_by_id**](StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID +[**place_order**](StoreApi.md#place_order) | **post** /store/order | Place an order for a pet + + + +## delete_order + +> delete_order(order_id) +Delete purchase order by ID + +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order_id** | **String** | ID of the order that needs to be deleted | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_inventory + +> ::std::collections::HashMap get_inventory() +Returns pet inventories by status + +Returns a map of status codes to quantities + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +**::std::collections::HashMap** + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_order_by_id + +> crate::models::Order get_order_by_id(order_id) +Find purchase order by ID + +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order_id** | **i64** | ID of pet that needs to be fetched | [required] | + +### Return type + +[**crate::models::Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## place_order + +> crate::models::Order place_order(body) +Place an order for a pet + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Order**](Order.md) | order placed for purchasing the pet | [required] | + +### Return type + +[**crate::models::Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/Tag.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Tag.md new file mode 100644 index 000000000000..7bf71ab0e9d8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/Tag.md @@ -0,0 +1,12 @@ +# Tag + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**name** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/User.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/User.md new file mode 100644 index 000000000000..2e6abda42b32 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/User.md @@ -0,0 +1,18 @@ +# User + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**username** | Option<**String**> | | [optional] +**first_name** | Option<**String**> | | [optional] +**last_name** | Option<**String**> | | [optional] +**email** | Option<**String**> | | [optional] +**password** | Option<**String**> | | [optional] +**phone** | Option<**String**> | | [optional] +**user_status** | Option<**i32**> | User Status | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/docs/UserApi.md b/samples/client/petstore/rust/reqwestFutures/petstore/docs/UserApi.md new file mode 100644 index 000000000000..a6268f251a64 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/docs/UserApi.md @@ -0,0 +1,245 @@ +# \UserApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**create_user**](UserApi.md#create_user) | **post** /user | Create user +[**create_users_with_array_input**](UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array +[**create_users_with_list_input**](UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array +[**delete_user**](UserApi.md#delete_user) | **delete** /user/{username} | Delete user +[**get_user_by_name**](UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name +[**login_user**](UserApi.md#login_user) | **get** /user/login | Logs user into the system +[**logout_user**](UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session +[**update_user**](UserApi.md#update_user) | **put** /user/{username} | Updated user + + + +## create_user + +> create_user(body) +Create user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**User**](User.md) | Created user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## create_users_with_array_input + +> create_users_with_array_input(body) +Creates list of users with given input array + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## create_users_with_list_input + +> create_users_with_list_input(body) +Creates list of users with given input array + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**body** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## delete_user + +> delete_user(username) +Delete user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be deleted | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_user_by_name + +> crate::models::User get_user_by_name(username) +Get user by user name + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | + +### Return type + +[**crate::models::User**](User.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## login_user + +> String login_user(username, password) +Logs user into the system + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The user name for login | [required] | +**password** | **String** | The password for login in clear text | [required] | + +### Return type + +**String** + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## logout_user + +> logout_user() +Logs out current logged in user session + +### Parameters + +This endpoint does not need any parameter. + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## update_user + +> update_user(username, body) +Updated user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | name that need to be deleted | [required] | +**body** | [**User**](User.md) | Updated user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/git_push.sh b/samples/client/petstore/rust/reqwestFutures/petstore/git_push.sh new file mode 100644 index 000000000000..ced3be2b0c7b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/client.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/client.rs new file mode 100644 index 000000000000..260183d6ba80 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/client.rs @@ -0,0 +1,34 @@ +use std::sync::Arc; + +use super::configuration::Configuration; + +pub struct APIClient { + pet_api: Box, + store_api: Box, + user_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Arc::new(configuration); + + APIClient { + pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), + store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), + user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), + } + } + + pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ + self.pet_api.as_ref() + } + + pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ + self.store_api.as_ref() + } + + pub fn user_api(&self) -> &dyn crate::apis::UserApi{ + self.user_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/configuration.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/configuration.rs new file mode 100644 index 000000000000..4442a66f0d25 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/configuration.rs @@ -0,0 +1,50 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; + +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::async::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://petstore.swagger.io/v2".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::async::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/mod.rs new file mode 100644 index 000000000000..c14d751153a1 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/mod.rs @@ -0,0 +1,41 @@ +use reqwest; +use serde_json; + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +mod pet_api; +pub use self::pet_api::{ PetApi, PetApiClient }; +mod store_api; +pub use self::store_api::{ StoreApi, StoreApiClient }; +mod user_api; +pub use self::user_api::{ UserApi, UserApiClient }; + +pub mod configuration; +pub mod client; diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs new file mode 100644 index 000000000000..17c5da7b028a --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs @@ -0,0 +1,248 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct PetApiClient { + configuration: Arc, +} + +impl PetApiClient { + pub fn new(configuration: Arc) -> PetApiClient { + PetApiClient { + configuration, + } + } +} + +pub trait PetApi { + fn add_pet(&self, body: crate::models::Pet) -> Box + Send>; + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send>; + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send>; + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send>; + fn get_pet_by_id(&self, pet_id: i64) -> Box + Send>; + fn update_pet(&self, body: crate::models::Pet) -> Box + Send>; + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send>; + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send>; +} + +impl PetApi for PetApiClient { + fn add_pet(&self, body: crate::models::Pet) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + let mut req_builder = client.delete(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(param_value) = api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); + } + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); + 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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); + 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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn get_pet_by_id(&self, pet_id: i64) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + 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 apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("api_key", val); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn update_pet(&self, body: crate::models::Pet) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = client.put(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + let mut form_params = std::collections::HashMap::new(); + if let Some(param_value) = name { + form_params.insert("name", param_value.to_string()); + } + if let Some(param_value) = status { + form_params.insert("status", param_value.to_string()); + } + req_builder = req_builder.form(&form_params); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=pet_id); + let mut req_builder = client.post(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 token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + let mut form = reqwest::multipart::Form::new(); + if let Some(param_value) = additional_metadata { + form = form.text("additionalMetadata", param_value.to_string()); + } + if let Some(param_value) = file { + form = form.file("file", param_value)?; + } + req_builder = req_builder.multipart(form); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs new file mode 100644 index 000000000000..681a3c2b4d08 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs @@ -0,0 +1,125 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct StoreApiClient { + configuration: Arc, +} + +impl StoreApiClient { + pub fn new(configuration: Arc) -> StoreApiClient { + StoreApiClient { + configuration, + } + } +} + +pub trait StoreApi { + fn delete_order(&self, order_id: &str) -> Box + Send>; + fn get_inventory(&self, ) -> Box, Error = Error> + Send>; + fn get_order_by_id(&self, order_id: i64) -> Box + Send>; + fn place_order(&self, body: crate::models::Order) -> Box + Send>; +} + +impl StoreApi for StoreApiClient { + fn delete_order(&self, order_id: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(order_id)); + let mut req_builder = client.delete(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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn get_inventory(&self, ) -> Box, Error = Error> + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/inventory", 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 apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("api_key", val); + }; + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn get_order_by_id(&self, order_id: i64) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id); + 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn place_order(&self, body: crate::models::Order) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs new file mode 100644 index 000000000000..c9c8acbc89c8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs @@ -0,0 +1,202 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct UserApiClient { + configuration: Arc, +} + +impl UserApiClient { + pub fn new(configuration: Arc) -> UserApiClient { + UserApiClient { + configuration, + } + } +} + +pub trait UserApi { + fn create_user(&self, body: crate::models::User) -> Box + Send>; + fn create_users_with_array_input(&self, body: Vec) -> Box + Send>; + fn create_users_with_list_input(&self, body: Vec) -> Box + Send>; + fn delete_user(&self, username: &str) -> Box + Send>; + fn get_user_by_name(&self, username: &str) -> Box + Send>; + fn login_user(&self, username: &str, password: &str) -> Box + Send>; + fn logout_user(&self, ) -> Box + Send>; + fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send>; +} + +impl UserApi for UserApiClient { + fn create_user(&self, body: crate::models::User) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn create_users_with_array_input(&self, body: Vec) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn create_users_with_list_input(&self, body: Vec) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = client.post(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn delete_user(&self, username: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + let mut req_builder = client.delete(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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn get_user_by_name(&self, username: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn login_user(&self, username: &str, password: &str) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = client.get(uri_str.as_str()); + + req_builder = req_builder.query(&[("username", &username.to_string())]); + req_builder = req_builder.query(&[("password", &password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .and_then(|mut i| i.json()) + .from_err() + ) + } + + fn logout_user(&self, ) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/logout", 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + + fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); + let mut req_builder = client.put(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()); + } + req_builder = req_builder.json(&body); + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs new file mode 100644 index 000000000000..f318efa89200 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs @@ -0,0 +1,11 @@ +#[macro_use] +extern crate serde_derive; + +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; +extern crate futures; + +pub mod apis; +pub mod models; diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/api_response.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/api_response.rs new file mode 100644 index 000000000000..f1286a5d1c84 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/api_response.rs @@ -0,0 +1,36 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// ApiResponse : Describes the result of uploading an image resource + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct ApiResponse { + #[serde(rename = "code", skip_serializing_if = "Option::is_none")] + pub code: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub _type: Option, + #[serde(rename = "message", skip_serializing_if = "Option::is_none")] + pub message: Option, +} + +impl ApiResponse { + /// Describes the result of uploading an image resource + pub fn new() -> ApiResponse { + ApiResponse { + code: None, + _type: None, + message: None, + } + } +} + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/category.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/category.rs new file mode 100644 index 000000000000..dcd2dc386302 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/category.rs @@ -0,0 +1,33 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Category : A category for a pet + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Category { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +impl Category { + /// A category for a pet + pub fn new() -> Category { + Category { + id: None, + name: None, + } + } +} + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/mod.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/mod.rs new file mode 100644 index 000000000000..1baf2f7528e2 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/mod.rs @@ -0,0 +1,12 @@ +pub mod api_response; +pub use self::api_response::ApiResponse; +pub mod category; +pub use self::category::Category; +pub mod order; +pub use self::order::Order; +pub mod pet; +pub use self::pet::Pet; +pub mod tag; +pub use self::tag::Tag; +pub mod user; +pub use self::user::User; diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/order.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/order.rs new file mode 100644 index 000000000000..89cab91e62c1 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/order.rs @@ -0,0 +1,56 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Order : An order for a pets from the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Order { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "petId", skip_serializing_if = "Option::is_none")] + pub pet_id: Option, + #[serde(rename = "quantity", skip_serializing_if = "Option::is_none")] + pub quantity: Option, + #[serde(rename = "shipDate", skip_serializing_if = "Option::is_none")] + pub ship_date: Option, + /// Order Status + #[serde(rename = "status", skip_serializing_if = "Option::is_none")] + pub status: Option, + #[serde(rename = "complete", skip_serializing_if = "Option::is_none")] + pub complete: Option, +} + +impl Order { + /// An order for a pets from the pet store + pub fn new() -> Order { + Order { + id: None, + pet_id: None, + quantity: None, + ship_date: None, + status: None, + complete: None, + } + } +} + +/// Order Status +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "placed")] + Placed, + #[serde(rename = "approved")] + Approved, + #[serde(rename = "delivered")] + Delivered, +} + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/pet.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/pet.rs new file mode 100644 index 000000000000..ff8a32fee3ab --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/pet.rs @@ -0,0 +1,56 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Pet : A pet for sale in the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Pet { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "category", skip_serializing_if = "Option::is_none")] + pub category: Option, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "photoUrls")] + pub photo_urls: Vec, + #[serde(rename = "tags", skip_serializing_if = "Option::is_none")] + pub tags: Option>, + /// pet status in the store + #[serde(rename = "status", skip_serializing_if = "Option::is_none")] + pub status: Option, +} + +impl Pet { + /// A pet for sale in the pet store + pub fn new(name: String, photo_urls: Vec) -> Pet { + Pet { + id: None, + category: None, + name, + photo_urls, + tags: None, + status: None, + } + } +} + +/// pet status in the store +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "available")] + Available, + #[serde(rename = "pending")] + Pending, + #[serde(rename = "sold")] + Sold, +} + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/tag.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/tag.rs new file mode 100644 index 000000000000..f6bcb5c78d6a --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/tag.rs @@ -0,0 +1,33 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// Tag : A tag for a pet + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Tag { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +impl Tag { + /// A tag for a pet + pub fn new() -> Tag { + Tag { + id: None, + name: None, + } + } +} + + diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/models/user.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/user.rs new file mode 100644 index 000000000000..cf863af7b585 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/models/user.rs @@ -0,0 +1,52 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// User : A User who is purchasing from the pet store + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct User { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "username", skip_serializing_if = "Option::is_none")] + pub username: Option, + #[serde(rename = "firstName", skip_serializing_if = "Option::is_none")] + pub first_name: Option, + #[serde(rename = "lastName", skip_serializing_if = "Option::is_none")] + pub last_name: Option, + #[serde(rename = "email", skip_serializing_if = "Option::is_none")] + pub email: Option, + #[serde(rename = "password", skip_serializing_if = "Option::is_none")] + pub password: Option, + #[serde(rename = "phone", skip_serializing_if = "Option::is_none")] + pub phone: Option, + /// User Status + #[serde(rename = "userStatus", skip_serializing_if = "Option::is_none")] + pub user_status: Option, +} + +impl User { + /// A User who is purchasing from the pet store + pub fn new() -> User { + User { + id: None, + username: None, + first_name: None, + last_name: None, + email: None, + password: None, + phone: None, + user_status: None, + } + } +} + + diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/.gitignore b/samples/client/petstore/rust/reqwestFutures/rust-test/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator-ignore b/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator/VERSION new file mode 100644 index 000000000000..c3a2c7076fa8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/.travis.yml b/samples/client/petstore/rust/reqwestFutures/rust-test/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml new file mode 100644 index 000000000000..da82e969a171 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rust-test-reqwestFutures" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] + +[dependencies] +serde = "^1.0" +serde_derive = "^1.0" +serde_json = "^1.0" +url = "1.5" +reqwest = "~0.9" +futures = "0.1.23" + +[dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/README.md b/samples/client/petstore/rust/reqwestFutures/rust-test/README.md new file mode 100644 index 000000000000..9341aa94aa36 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/README.md @@ -0,0 +1,44 @@ +# Rust API client for rust-test-reqwestFutures + +Special testing for the Rust client generator + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.7 +- Package version: 1.0.0 +- Build package: org.openapitools.codegen.languages.RustClientCodegen + +## Installation + +Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`: + +``` + openapi = { path = "./generated" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**dummy_get**](docs/DefaultApi.md#dummy_get) | **get** /dummy | A dummy endpoint to make the spec valid. + + +## Documentation For Models + + - [TypeTesting](docs/TypeTesting.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/docs/DefaultApi.md b/samples/client/petstore/rust/reqwestFutures/rust-test/docs/DefaultApi.md new file mode 100644 index 000000000000..ea01d010f01f --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/docs/DefaultApi.md @@ -0,0 +1,34 @@ +# \DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**dummy_get**](DefaultApi.md#dummy_get) | **get** /dummy | A dummy endpoint to make the spec valid. + + + +## dummy_get + +> dummy_get() +A dummy endpoint to make the spec valid. + +### Parameters + +This endpoint does not need any parameter. + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/docs/TypeTesting.md b/samples/client/petstore/rust/reqwestFutures/rust-test/docs/TypeTesting.md new file mode 100644 index 000000000000..7b05cee280a8 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/docs/TypeTesting.md @@ -0,0 +1,16 @@ +# TypeTesting + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**integer** | Option<**i32**> | | [optional] +**long** | Option<**i64**> | | [optional] +**number** | Option<**f32**> | | [optional] +**float** | Option<**f32**> | | [optional] +**double** | Option<**f64**> | | [optional] +**uuid** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/git_push.sh b/samples/client/petstore/rust/reqwestFutures/rust-test/git_push.sh new file mode 100644 index 000000000000..ced3be2b0c7b --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/client.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/client.rs new file mode 100644 index 000000000000..3f1438beaf1a --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/client.rs @@ -0,0 +1,22 @@ +use std::sync::Arc; + +use super::configuration::Configuration; + +pub struct APIClient { + default_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Arc::new(configuration); + + APIClient { + default_api: Box::new(crate::apis::DefaultApiClient::new(rc.clone())), + } + } + + pub fn default_api(&self) -> &dyn crate::apis::DefaultApi{ + self.default_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/configuration.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/configuration.rs new file mode 100644 index 000000000000..a4307abb909e --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/configuration.rs @@ -0,0 +1,50 @@ +/* + * Rust client test spec + * + * Special testing for the Rust client generator + * + * The version of the OpenAPI document: 1.0.7 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; + +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::async::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +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.7/rust".to_owned()), + client: reqwest::async::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs new file mode 100644 index 000000000000..c66258bb46d1 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs @@ -0,0 +1,56 @@ +/* + * Rust client test spec + * + * Special testing for the Rust client generator + * + * The version of the OpenAPI document: 1.0.7 + * + * Generated by: https://openapi-generator.tech + */ + +use std::sync::Arc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; +use futures::{Future}; +use reqwest; + +use super::{Error, configuration}; + +pub struct DefaultApiClient { + configuration: Arc, +} + +impl DefaultApiClient { + pub fn new(configuration: Arc) -> DefaultApiClient { + DefaultApiClient { + configuration, + } + } +} + +pub trait DefaultApi { + fn dummy_get(&self, ) -> Box + Send>; +} + +impl DefaultApi for DefaultApiClient { + fn dummy_get(&self, ) -> Box + Send> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}/dummy", 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()); + } + + // send request + Box::new(req_builder.send() + .and_then(|i| i.error_for_status()) + .map(|_| ()) + .from_err() + ) + } + +} diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/mod.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/mod.rs new file mode 100644 index 000000000000..3b70668f6fd9 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/mod.rs @@ -0,0 +1,37 @@ +use reqwest; +use serde_json; + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +mod default_api; +pub use self::default_api::{ DefaultApi, DefaultApiClient }; + +pub mod configuration; +pub mod client; diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs new file mode 100644 index 000000000000..f318efa89200 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs @@ -0,0 +1,11 @@ +#[macro_use] +extern crate serde_derive; + +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; +extern crate futures; + +pub mod apis; +pub mod models; diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/mod.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/mod.rs new file mode 100644 index 000000000000..97887b5798ef --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/mod.rs @@ -0,0 +1,2 @@ +pub mod type_testing; +pub use self::type_testing::TypeTesting; diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/type_testing.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/type_testing.rs new file mode 100644 index 000000000000..57188e8ee7e4 --- /dev/null +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/models/type_testing.rs @@ -0,0 +1,45 @@ +/* + * Rust client test spec + * + * Special testing for the Rust client generator + * + * The version of the OpenAPI document: 1.0.7 + * + * Generated by: https://openapi-generator.tech + */ + +/// TypeTesting : Test handling of differing types (see \\#3463) + + + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct TypeTesting { + #[serde(rename = "integer", skip_serializing_if = "Option::is_none")] + pub integer: Option, + #[serde(rename = "long", skip_serializing_if = "Option::is_none")] + pub long: Option, + #[serde(rename = "number", skip_serializing_if = "Option::is_none")] + pub number: Option, + #[serde(rename = "float", skip_serializing_if = "Option::is_none")] + pub float: Option, + #[serde(rename = "double", skip_serializing_if = "Option::is_none")] + pub double: Option, + #[serde(rename = "uuid", skip_serializing_if = "Option::is_none")] + pub uuid: Option, +} + +impl TypeTesting { + /// Test handling of differing types (see \\#3463) + pub fn new() -> TypeTesting { + TypeTesting { + integer: None, + long: None, + number: None, + float: None, + double: None, + uuid: None, + } + } +} + + From 2884dbfa36b44b816ac40b100c697a0260578176 Mon Sep 17 00:00:00 2001 From: Seb Renauld Date: Tue, 22 Oct 2019 23:39:20 +0200 Subject: [PATCH 4/4] Added file uploads I was not aware that openapi-generator could generate multipart MIME bindings. Implementing them was complicated further by `reqwest::async::multipart::Form` having an entirely different API than the `sync` version of it, leading to two decisions: 1. The file is read in its entirety. This is the same behavior as on the sync version; if time allows, I will convert this into a chunked stream 2. The entire mime detection logic is taken from the `sync` version and added as a private function in the module --- .../src/main/resources/rust/Cargo.mustache | 1 + .../src/main/resources/rust/api.mustache | 231 +++++++++++++++ .../src/main/resources/rust/lib.mustache | 1 + .../rust/reqwestFutures/api.mustache | 51 +++- samples/client/petstore/rust/Cargo.toml | 5 +- samples/client/petstore/rust/README.md | 40 +-- samples/client/petstore/rust/docs/PetApi.md | 16 +- samples/client/petstore/rust/docs/StoreApi.md | 8 +- samples/client/petstore/rust/docs/UserApi.md | 16 +- .../fileResponseTest/Cargo.toml | 1 + .../fileResponseTest/src/apis/default_api.rs | 31 +- .../fileResponseTest/src/lib.rs | 1 + .../rust/reqwestFutures/petstore/Cargo.toml | 1 + .../petstore/src/apis/pet_api.rs | 38 ++- .../petstore/src/apis/store_api.rs | 31 +- .../petstore/src/apis/user_api.rs | 31 +- .../rust/reqwestFutures/petstore/src/lib.rs | 1 + .../rust/reqwestFutures/rust-test/Cargo.toml | 1 + .../rust-test/src/apis/default_api.rs | 31 +- .../rust/reqwestFutures/rust-test/src/lib.rs | 1 + .../client/petstore/rust/src/apis/client.rs | 7 +- .../petstore/rust/src/apis/configuration.rs | 21 +- samples/client/petstore/rust/src/apis/mod.rs | 53 +++- .../client/petstore/rust/src/apis/pet_api.rs | 274 ++++++------------ .../petstore/rust/src/apis/store_api.rs | 125 +++----- .../client/petstore/rust/src/apis/user_api.rs | 216 +++++--------- samples/client/petstore/rust/src/lib.rs | 2 +- 27 files changed, 716 insertions(+), 519 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/rust/api.mustache diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index eb375fe8a003..d51bf608e206 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -20,6 +20,7 @@ reqwest = "~0.9" {{#reqwestFutures}} reqwest = "~0.9" futures = "0.1.23" +mime_guess = "2.0.1" {{/reqwestFutures}} [dev-dependencies] diff --git a/modules/openapi-generator/src/main/resources/rust/api.mustache b/modules/openapi-generator/src/main/resources/rust/api.mustache new file mode 100644 index 000000000000..448f6c302c98 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/api.mustache @@ -0,0 +1,231 @@ +{{>partial_header}} +use std::rc::Rc; +use std::borrow::Borrow; +#[allow(unused_imports)] +use std::option::Option; + +use reqwest; + +use super::{Error, configuration}; + +pub struct {{{classname}}}Client { + configuration: Rc, +} + +impl {{{classname}}}Client { + pub fn new(configuration: Rc) -> {{{classname}}}Client { + {{{classname}}}Client { + configuration, + } + } +} + +pub trait {{{classname}}} { +{{#operations}} +{{#operation}} + fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}, Error>; +{{/operation}} +{{/operations}} +} + +impl {{{classname}}} for {{{classname}}}Client { +{{#operations}} +{{#operation}} + fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}, Error> { + let configuration: &configuration::Configuration = self.configuration.borrow(); + let client = &configuration.client; + + let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}crate::apis::urlencode({{/isString}}{{{paramName}}}{{^required}}.unwrap(){{/required}}{{#required}}{{#isNullable}}.unwrap(){{/isNullable}}{{/required}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{#isString}}){{/isString}}{{/pathParams}}); + let mut req_builder = client.{{{httpMethod}}}(uri_str.as_str()); + + {{#queryParams}} + {{#required}} + req_builder = req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}{{#isListContainer}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isListContainer}}.to_string())]); + {{/required}} + {{^required}} + if let Some(ref s) = {{{paramName}}} { + req_builder = req_builder.query(&[("{{{baseName}}}", &s{{#isListContainer}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isListContainer}}.to_string())]); + } + {{/required}} + {{/queryParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInQuery}} + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.query(&[("{{{keyParamName}}}", val)]); + } + {{/isKeyInQuery}} + {{/isApiKey}} + {{/authMethods}} + {{/hasAuthMethods}} + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + {{#hasHeaderParams}} + {{#headerParams}} + {{#required}} + {{^isNullable}} + req_builder = req_builder.header("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { req_builder = req_builder.header("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { req_builder = req_builder.header("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + req_builder = req_builder.header("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/headerParams}} + {{/hasHeaderParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInHeader}} + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let val = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, + }; + req_builder = req_builder.header("{{{keyParamName}}}", val); + }; + {{/isKeyInHeader}} + {{/isApiKey}} + {{#isBasic}} + {{^isBasicBearer}} + if let Some(ref auth_conf) = configuration.basic_auth { + req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned()); + }; + {{/isBasicBearer}} + {{#isBasicBearer}} + if let Some(ref token) = configuration.bearer_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isBasicBearer}} + {{/isBasic}} + {{#isOAuth}} + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isOAuth}} + {{/authMethods}} + {{/hasAuthMethods}} + {{#isMultipart}} + {{#hasFormParams}} + let mut form = reqwest::multipart::Form::new(); + {{#formParams}} + {{#isFile}} + {{#required}} + {{^isNullable}} + form = form.file("{{{baseName}}}", {{{paramName}}})?; + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form = form.file("{{{baseName}}}", param_value)?; }, + None => { unimplemented!("Required nullable form file param not supported"); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form = form.file("{{{baseName}}}", param_value)?; + } + {{/required}} + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + form = form.text("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form = form.text("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { form = form.text("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form = form.text("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + req_builder = req_builder.multipart(form); + {{/hasFormParams}} + {{/isMultipart}} + {{^isMultipart}} + {{#hasFormParams}} + let mut form_params = std::collections::HashMap::new(); + {{#formParams}} + {{#isFile}} + {{#required}} + {{^isNullable}} + form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); }, + None => { unimplemented!("Required nullable file form param not supported with x-www-form-urlencoded content"); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + } + {{/required}} + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + form_params.insert("{{{baseName}}}", {{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(param_value) => { form_params.insert("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); }, + None => { form_params.insert("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(param_value) = {{{paramName}}} { + form_params.insert("{{{baseName}}}", param_value{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + req_builder = req_builder.form(&form_params); + {{/hasFormParams}} + {{/isMultipart}} + {{#hasBodyParam}} + {{#bodyParams}} + req_builder = req_builder.json(&{{{paramName}}}); + {{/bodyParams}} + {{/hasBodyParam}} + + // send request + let req = req_builder.build()?; + + {{^returnType}} + client.execute(req)?.error_for_status()?; + Ok(()) + {{/returnType}} + {{#returnType}} + Ok(client.execute(req)?.error_for_status()?.json()?) + {{/returnType}} + } + +{{/operation}} +{{/operations}} +} diff --git a/modules/openapi-generator/src/main/resources/rust/lib.mustache b/modules/openapi-generator/src/main/resources/rust/lib.mustache index 66add6f83a9f..3f04e34aa552 100644 --- a/modules/openapi-generator/src/main/resources/rust/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust/lib.mustache @@ -14,6 +14,7 @@ extern crate reqwest; {{#reqwestFutures}} extern crate reqwest; extern crate futures; +extern crate mime_guess; {{/reqwestFutures}} pub mod apis; diff --git a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache index 3098d523a146..24424f42fdf6 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwestFutures/api.mustache @@ -3,10 +3,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct {{{classname}}}Client { configuration: Arc, @@ -122,23 +149,35 @@ impl {{{classname}}} for {{{classname}}}Client { {{/hasAuthMethods}} {{#isMultipart}} {{#hasFormParams}} - let mut form = reqwest::multipart::Form::new(); + let mut form = reqwest::async::multipart::Form::new(); {{#formParams}} {{#isFile}} {{#required}} {{^isNullable}} - form = form.file("{{{baseName}}}", {{{paramName}}})?; + match part_from_file({{{paramName}}}) { + Ok(part) => form = form.part("{{{baseName}}}", part), + Err(e) => return Box::new(future::err(e.into())) + } + // form = form.part("{{{baseName}}}", part_from_file({{{paramName}}})); {{/isNullable}} {{#isNullable}} match {{{paramName}}} { - Some(param_value) => { form = form.file("{{{baseName}}}", param_value)?; }, + Some(param_value) => { + match part_from_file(param_value) { + Ok(part) => { form = form.part("{{{baseName}}}", part); }, + Err(e) => { return Box::new(future::err(e.into())); } + } + }, None => { unimplemented!("Required nullable form file param not supported"); }, } {{/isNullable}} {{/required}} {{^required}} if let Some(param_value) = {{{paramName}}} { - form = form.file("{{{baseName}}}", param_value)?; + match part_from_file(param_value) { + Ok(part) => { form = form.part("{{{baseName}}}", part); }, + Err(e) => { return Box::new(future::err(e.into())); } + } } {{/required}} {{/isFile}} diff --git a/samples/client/petstore/rust/Cargo.toml b/samples/client/petstore/rust/Cargo.toml index cb04bcf49bfa..d2f23d92784d 100644 --- a/samples/client/petstore/rust/Cargo.toml +++ b/samples/client/petstore/rust/Cargo.toml @@ -8,7 +8,10 @@ serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" url = "1.5" -reqwest = "~0.9" +hyper = "~0.11" +serde_yaml = "0.7" +base64 = "~0.7.0" futures = "0.1.23" [dev-dependencies] +tokio-core = "*" diff --git a/samples/client/petstore/rust/README.md b/samples/client/petstore/rust/README.md index 8d3556dd568e..8c29b9199dff 100644 --- a/samples/client/petstore/rust/README.md +++ b/samples/client/petstore/rust/README.md @@ -24,26 +24,26 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **post** /pet | Add a new pet to the store -*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet -*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status -*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags -*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID -*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **put** /pet | Update an existing pet -*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID -*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status -*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID -*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **post** /store/order | Place an order for a pet -*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **post** /user | Create user -*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array -*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array -*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **delete** /user/{username} | Delete user -*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name -*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **get** /user/login | Logs user into the system -*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session -*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **put** /user/{username} | Updated user +*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **Post** /pet | Add a new pet to the store +*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **Get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **Get** /pet/{petId} | Find pet by ID +*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **Put** /pet | Update an existing pet +*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **Get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet +*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **Post** /user | Create user +*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **Post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **Post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **Delete** /user/{username} | Delete user +*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **Get** /user/{username} | Get user by user name +*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **Get** /user/login | Logs user into the system +*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **Get** /user/logout | Logs out current logged in user session +*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **Put** /user/{username} | Updated user ## Documentation For Models diff --git a/samples/client/petstore/rust/docs/PetApi.md b/samples/client/petstore/rust/docs/PetApi.md index 4716e752b666..6ac82abc9d4a 100644 --- a/samples/client/petstore/rust/docs/PetApi.md +++ b/samples/client/petstore/rust/docs/PetApi.md @@ -4,14 +4,14 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**add_pet**](PetApi.md#add_pet) | **post** /pet | Add a new pet to the store -[**delete_pet**](PetApi.md#delete_pet) | **delete** /pet/{petId} | Deletes a pet -[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **get** /pet/findByStatus | Finds Pets by status -[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **get** /pet/findByTags | Finds Pets by tags -[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **get** /pet/{petId} | Find pet by ID -[**update_pet**](PetApi.md#update_pet) | **put** /pet | Update an existing pet -[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **post** /pet/{petId} | Updates a pet in the store with form data -[**upload_file**](PetApi.md#upload_file) | **post** /pet/{petId}/uploadImage | uploads an image +[**add_pet**](PetApi.md#add_pet) | **Post** /pet | Add a new pet to the store +[**delete_pet**](PetApi.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status +[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **Get** /pet/findByTags | Finds Pets by tags +[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **Get** /pet/{petId} | Find pet by ID +[**update_pet**](PetApi.md#update_pet) | **Put** /pet | Update an existing pet +[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data +[**upload_file**](PetApi.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image diff --git a/samples/client/petstore/rust/docs/StoreApi.md b/samples/client/petstore/rust/docs/StoreApi.md index a310b5383154..7a7b9498d16a 100644 --- a/samples/client/petstore/rust/docs/StoreApi.md +++ b/samples/client/petstore/rust/docs/StoreApi.md @@ -4,10 +4,10 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**delete_order**](StoreApi.md#delete_order) | **delete** /store/order/{orderId} | Delete purchase order by ID -[**get_inventory**](StoreApi.md#get_inventory) | **get** /store/inventory | Returns pet inventories by status -[**get_order_by_id**](StoreApi.md#get_order_by_id) | **get** /store/order/{orderId} | Find purchase order by ID -[**place_order**](StoreApi.md#place_order) | **post** /store/order | Place an order for a pet +[**delete_order**](StoreApi.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID +[**get_inventory**](StoreApi.md#get_inventory) | **Get** /store/inventory | Returns pet inventories by status +[**get_order_by_id**](StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID +[**place_order**](StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet diff --git a/samples/client/petstore/rust/docs/UserApi.md b/samples/client/petstore/rust/docs/UserApi.md index a6268f251a64..f3fce53b66da 100644 --- a/samples/client/petstore/rust/docs/UserApi.md +++ b/samples/client/petstore/rust/docs/UserApi.md @@ -4,14 +4,14 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**create_user**](UserApi.md#create_user) | **post** /user | Create user -[**create_users_with_array_input**](UserApi.md#create_users_with_array_input) | **post** /user/createWithArray | Creates list of users with given input array -[**create_users_with_list_input**](UserApi.md#create_users_with_list_input) | **post** /user/createWithList | Creates list of users with given input array -[**delete_user**](UserApi.md#delete_user) | **delete** /user/{username} | Delete user -[**get_user_by_name**](UserApi.md#get_user_by_name) | **get** /user/{username} | Get user by user name -[**login_user**](UserApi.md#login_user) | **get** /user/login | Logs user into the system -[**logout_user**](UserApi.md#logout_user) | **get** /user/logout | Logs out current logged in user session -[**update_user**](UserApi.md#update_user) | **put** /user/{username} | Updated user +[**create_user**](UserApi.md#create_user) | **Post** /user | Create user +[**create_users_with_array_input**](UserApi.md#create_users_with_array_input) | **Post** /user/createWithArray | Creates list of users with given input array +[**create_users_with_list_input**](UserApi.md#create_users_with_list_input) | **Post** /user/createWithList | Creates list of users with given input array +[**delete_user**](UserApi.md#delete_user) | **Delete** /user/{username} | Delete user +[**get_user_by_name**](UserApi.md#get_user_by_name) | **Get** /user/{username} | Get user by user name +[**login_user**](UserApi.md#login_user) | **Get** /user/login | Logs user into the system +[**logout_user**](UserApi.md#logout_user) | **Get** /user/logout | Logs out current logged in user session +[**update_user**](UserApi.md#update_user) | **Put** /user/{username} | Updated user diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml index 1c700bf03833..59b2c48e826c 100644 --- a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/Cargo.toml @@ -10,5 +10,6 @@ serde_json = "^1.0" url = "1.5" reqwest = "~0.9" futures = "0.1.23" +mime_guess = "2.0.1" [dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs index 1114367df043..ec9fb623e9fc 100644 --- a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/apis/default_api.rs @@ -12,10 +12,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct DefaultApiClient { configuration: Arc, diff --git a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs index f318efa89200..6b40adb9e9f9 100644 --- a/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs +++ b/samples/client/petstore/rust/reqwestFutures/fileResponseTest/src/lib.rs @@ -6,6 +6,7 @@ extern crate serde_json; extern crate url; extern crate reqwest; extern crate futures; +extern crate mime_guess; pub mod apis; pub mod models; diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml index 8b980867ec3e..682ba5bb4f90 100644 --- a/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwestFutures/petstore/Cargo.toml @@ -10,5 +10,6 @@ serde_json = "^1.0" url = "1.5" reqwest = "~0.9" futures = "0.1.23" +mime_guess = "2.0.1" [dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs index 17c5da7b028a..e75e03528271 100644 --- a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/pet_api.rs @@ -12,10 +12,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct PetApiClient { configuration: Arc, @@ -228,12 +255,15 @@ impl PetApi for PetApiClient { if let Some(ref token) = configuration.oauth_access_token { req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut form = reqwest::multipart::Form::new(); + let mut form = reqwest::async::multipart::Form::new(); if let Some(param_value) = additional_metadata { form = form.text("additionalMetadata", param_value.to_string()); } if let Some(param_value) = file { - form = form.file("file", param_value)?; + match part_from_file(param_value) { + Ok(part) => { form = form.part("file", part); }, + Err(e) => { return Box::new(future::err(e.into())); } + } } req_builder = req_builder.multipart(form); diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs index 681a3c2b4d08..c2de90f4c088 100644 --- a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/store_api.rs @@ -12,10 +12,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct StoreApiClient { configuration: Arc, diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs index c9c8acbc89c8..ab7554dcbb1c 100644 --- a/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/apis/user_api.rs @@ -12,10 +12,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct UserApiClient { configuration: Arc, diff --git a/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs index f318efa89200..6b40adb9e9f9 100644 --- a/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs +++ b/samples/client/petstore/rust/reqwestFutures/petstore/src/lib.rs @@ -6,6 +6,7 @@ extern crate serde_json; extern crate url; extern crate reqwest; extern crate futures; +extern crate mime_guess; pub mod apis; pub mod models; diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml b/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml index da82e969a171..5a252229b72f 100644 --- a/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/Cargo.toml @@ -10,5 +10,6 @@ serde_json = "^1.0" url = "1.5" reqwest = "~0.9" futures = "0.1.23" +mime_guess = "2.0.1" [dev-dependencies] diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs index c66258bb46d1..f67aa7764d45 100644 --- a/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/apis/default_api.rs @@ -12,10 +12,37 @@ use std::sync::Arc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; +use futures::{Future, future}; use reqwest; - +use mime_guess::{self, Mime}; +use reqwest::async::multipart::Part; use super::{Error, configuration}; +use std::path::Path; +use std::io; +use std::io::Read; +use std::fs::{File}; + +fn part_from_file>(path: T) -> io::Result { + let path = path.as_ref(); + let file_name = path.file_name().and_then(|filename| { + Some(filename.to_string_lossy().into_owned()) + }); + let ext = path.extension() + .and_then(|ext| ext.to_str()) + .unwrap_or(""); + let mime = mime_guess::from_ext(ext).first_or_octet_stream(); + let mut file = File::open(path)?; + let mut buffer = vec![]; + let bytes_read = file.read_to_end(&mut buffer)?; + let field = Part::bytes(buffer) + .mime_str(&mime.to_string()) + .map_err(|e| io::Error::new(io::ErrorKind::NotFound, "Invalid/unknown mime type"))?; + Ok(if let Some(file_name) = file_name { + field.file_name(file_name) + } else { + field + }) +} pub struct DefaultApiClient { configuration: Arc, diff --git a/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs b/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs index f318efa89200..6b40adb9e9f9 100644 --- a/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs +++ b/samples/client/petstore/rust/reqwestFutures/rust-test/src/lib.rs @@ -6,6 +6,7 @@ extern crate serde_json; extern crate url; extern crate reqwest; extern crate futures; +extern crate mime_guess; pub mod apis; pub mod models; diff --git a/samples/client/petstore/rust/src/apis/client.rs b/samples/client/petstore/rust/src/apis/client.rs index 260183d6ba80..34953d4a0631 100644 --- a/samples/client/petstore/rust/src/apis/client.rs +++ b/samples/client/petstore/rust/src/apis/client.rs @@ -1,5 +1,6 @@ -use std::sync::Arc; +use std::rc::Rc; +use hyper; use super::configuration::Configuration; pub struct APIClient { @@ -9,8 +10,8 @@ pub struct APIClient { } impl APIClient { - pub fn new(configuration: Configuration) -> APIClient { - let rc = Arc::new(configuration); + pub fn new(configuration: Configuration) -> APIClient { + let rc = Rc::new(configuration); APIClient { pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), diff --git a/samples/client/petstore/rust/src/apis/configuration.rs b/samples/client/petstore/rust/src/apis/configuration.rs index 4442a66f0d25..83d5f1c3d0cc 100644 --- a/samples/client/petstore/rust/src/apis/configuration.rs +++ b/samples/client/petstore/rust/src/apis/configuration.rs @@ -8,16 +8,14 @@ * Generated by: https://openapi-generator.tech */ +use hyper; -use reqwest; - -pub struct Configuration { +pub struct Configuration { pub base_path: String, pub user_agent: Option, - pub client: reqwest::async::Client, + pub client: hyper::client::Client, pub basic_auth: Option, pub oauth_access_token: Option, - pub bearer_access_token: Option, pub api_key: Option, // TODO: take an oauth2 token source, similar to the go one } @@ -29,21 +27,14 @@ pub struct ApiKey { pub key: String, } -impl Configuration { - pub fn new() -> Configuration { - Configuration::default() - } -} - -impl Default for Configuration { - fn default() -> Self { +impl Configuration { + pub fn new(client: hyper::client::Client) -> Configuration { Configuration { base_path: "http://petstore.swagger.io/v2".to_owned(), user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), - client: reqwest::async::Client::new(), + client: client, basic_auth: None, oauth_access_token: None, - bearer_access_token: None, api_key: None, } } diff --git a/samples/client/petstore/rust/src/apis/mod.rs b/samples/client/petstore/rust/src/apis/mod.rs index c14d751153a1..8e1f9cc2adb5 100644 --- a/samples/client/petstore/rust/src/apis/mod.rs +++ b/samples/client/petstore/rust/src/apis/mod.rs @@ -1,35 +1,56 @@ -use reqwest; +use hyper; +use serde; use serde_json; #[derive(Debug)] -pub enum Error { - Reqwest(reqwest::Error), +pub enum Error { + UriError(hyper::error::UriError), + Hyper(hyper::Error), Serde(serde_json::Error), - Io(std::io::Error), + ApiError(ApiError), } -impl From for Error { - fn from(e: reqwest::Error) -> Self { - Error::Reqwest(e) - } +#[derive(Debug)] +pub struct ApiError { + pub code: hyper::StatusCode, + pub content: Option, } -impl From for Error { - fn from(e: serde_json::Error) -> Self { - Error::Serde(e) +impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error + 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::(e.1) { + Ok(t) => Error::ApiError(ApiError{ + code: e.0, + content: Some(t), + }), + Err(e) => { + Error::from(e) + } + } } } -impl From for Error { - fn from(e: std::io::Error) -> Self { - Error::Io(e) +impl From for Error { + fn from(e: hyper::Error) -> Self { + return Error::Hyper(e) } } -pub fn urlencode>(s: T) -> String { - ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +impl From for Error { + fn from(e: serde_json::Error) -> Self { + return Error::Serde(e) + } } +mod request; + mod pet_api; pub use self::pet_api::{ PetApi, PetApiClient }; mod store_api; diff --git a/samples/client/petstore/rust/src/apis/pet_api.rs b/samples/client/petstore/rust/src/apis/pet_api.rs index 17c5da7b028a..6ecaee91037f 100644 --- a/samples/client/petstore/rust/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/src/apis/pet_api.rs @@ -8,21 +8,24 @@ * Generated by: https://openapi-generator.tech */ -use std::sync::Arc; +use std::rc::Rc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; -use reqwest; + +use hyper; +use serde_json; +use futures::Future; use super::{Error, configuration}; +use super::request as __internal_request; -pub struct PetApiClient { - configuration: Arc, +pub struct PetApiClient { + configuration: Rc>, } -impl PetApiClient { - pub fn new(configuration: Arc) -> PetApiClient { +impl PetApiClient { + pub fn new(configuration: Rc>) -> PetApiClient { PetApiClient { configuration, } @@ -30,219 +33,110 @@ impl PetApiClient { } pub trait PetApi { - fn add_pet(&self, body: crate::models::Pet) -> Box + Send>; - fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send>; - fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send>; - fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send>; - fn get_pet_by_id(&self, pet_id: i64) -> Box + Send>; - fn update_pet(&self, body: crate::models::Pet) -> Box + Send>; - fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send>; - fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send>; + fn add_pet(&self, body: crate::models::Pet) -> Box>>; + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box>>; + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>>; + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>>; + fn get_pet_by_id(&self, pet_id: i64) -> Box>>; + fn update_pet(&self, body: crate::models::Pet) -> Box>>; + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box>>; + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box>>; } -impl PetApi for PetApiClient { - fn add_pet(&self, body: crate::models::Pet) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/pet", configuration.base_path); - let mut req_builder = client.post(uri_str.as_str()); +implPetApi for PetApiClient { + fn add_pet(&self, body: crate::models::Pet) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_body_param(body); + req = req.returns_nothing(); - 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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); - let mut req_builder = client.delete(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()); - } + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Delete, "/pet/{petId}".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_path_param("petId".to_string(), pet_id.to_string()); if let Some(param_value) = api_key { - req_builder = req_builder.header("api_key", param_value.to_string()); + req = req.with_header_param("api_key".to_string(), param_value.to_string()); } - if let Some(ref token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) - } - - fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error> + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/pet/findByStatus", configuration.base_path); - let mut req_builder = client.get(uri_str.as_str()); + req = req.returns_nothing(); - req_builder = req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); - 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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error> + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/pet/findByTags", configuration.base_path); - let mut req_builder = client.get(uri_str.as_str()); + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/findByStatus".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_query_param("status".to_string(), status.join(",").to_string()); - req_builder = req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]); - 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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn get_pet_by_id(&self, pet_id: i64) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/findByTags".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_query_param("tags".to_string(), tags.join(",").to_string()); - let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); - 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 apikey) = configuration.api_key { - let key = apikey.key.clone(); - let val = match apikey.prefix { - Some(ref prefix) => format!("{} {}", prefix, key), - None => key, - }; - req_builder = req_builder.header("api_key", val); - }; - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn update_pet(&self, body: crate::models::Pet) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/pet", configuration.base_path); - let mut req_builder = client.put(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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + fn get_pet_by_id(&self, pet_id: i64) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/{petId}".to_string()) + .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ + in_header: true, + in_query: false, + param_name: "api_key".to_owned(), + })) + ; + req = req.with_path_param("petId".to_string(), pet_id.to_string()); + + req.execute(self.configuration.borrow()) } - fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn update_pet(&self, body: crate::models::Pet) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Put, "/pet".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_body_param(body); + req = req.returns_nothing(); - let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); - let mut req_builder = client.post(uri_str.as_str()); + req.execute(self.configuration.borrow()) + } - 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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - let mut form_params = std::collections::HashMap::new(); + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet/{petId}".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_path_param("petId".to_string(), pet_id.to_string()); if let Some(param_value) = name { - form_params.insert("name", param_value.to_string()); + req = req.with_form_param("name".to_string(), param_value.to_string()); } if let Some(param_value) = status { - form_params.insert("status", param_value.to_string()); + req = req.with_form_param("status".to_string(), param_value.to_string()); } - req_builder = req_builder.form(&form_params); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) - } - - fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + req = req.returns_nothing(); - let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=pet_id); - let mut req_builder = client.post(uri_str.as_str()); + req.execute(self.configuration.borrow()) + } - 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 token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - let mut form = reqwest::multipart::Form::new(); + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet/{petId}/uploadImage".to_string()) + .with_auth(__internal_request::Auth::Oauth) + ; + req = req.with_path_param("petId".to_string(), pet_id.to_string()); if let Some(param_value) = additional_metadata { - form = form.text("additionalMetadata", param_value.to_string()); + req = req.with_form_param("additionalMetadata".to_string(), param_value.to_string()); } if let Some(param_value) = file { - form = form.file("file", param_value)?; + req = req.with_form_param("file".to_string(), unimplemented!()); } - req_builder = req_builder.multipart(form); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + + req.execute(self.configuration.borrow()) } } diff --git a/samples/client/petstore/rust/src/apis/store_api.rs b/samples/client/petstore/rust/src/apis/store_api.rs index 681a3c2b4d08..a72554307e15 100644 --- a/samples/client/petstore/rust/src/apis/store_api.rs +++ b/samples/client/petstore/rust/src/apis/store_api.rs @@ -8,21 +8,24 @@ * Generated by: https://openapi-generator.tech */ -use std::sync::Arc; +use std::rc::Rc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; -use reqwest; + +use hyper; +use serde_json; +use futures::Future; use super::{Error, configuration}; +use super::request as __internal_request; -pub struct StoreApiClient { - configuration: Arc, +pub struct StoreApiClient { + configuration: Rc>, } -impl StoreApiClient { - pub fn new(configuration: Arc) -> StoreApiClient { +impl StoreApiClient { + pub fn new(configuration: Rc>) -> StoreApiClient { StoreApiClient { configuration, } @@ -30,96 +33,48 @@ impl StoreApiClient { } pub trait StoreApi { - fn delete_order(&self, order_id: &str) -> Box + Send>; - fn get_inventory(&self, ) -> Box, Error = Error> + Send>; - fn get_order_by_id(&self, order_id: i64) -> Box + Send>; - fn place_order(&self, body: crate::models::Order) -> Box + Send>; + fn delete_order(&self, order_id: &str) -> Box>>; + fn get_inventory(&self, ) -> Box, Error = Error>>; + fn get_order_by_id(&self, order_id: i64) -> Box>>; + fn place_order(&self, body: crate::models::Order) -> Box>>; } -impl StoreApi for StoreApiClient { - fn delete_order(&self, order_id: &str) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut req_builder = client.delete(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()); - } +implStoreApi for StoreApiClient { + fn delete_order(&self, order_id: &str) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Delete, "/store/order/{orderId}".to_string()) + ; + req = req.with_path_param("orderId".to_string(), order_id.to_string()); + req = req.returns_nothing(); - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn get_inventory(&self, ) -> Box, Error = Error> + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/store/inventory", 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 apikey) = configuration.api_key { - let key = apikey.key.clone(); - let val = match apikey.prefix { - Some(ref prefix) => format!("{} {}", prefix, key), - None => key, - }; - req_builder = req_builder.header("api_key", val); - }; + fn get_inventory(&self, ) -> Box, Error = Error>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/store/inventory".to_string()) + .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ + in_header: true, + in_query: false, + param_name: "api_key".to_owned(), + })) + ; - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn get_order_by_id(&self, order_id: i64) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn get_order_by_id(&self, order_id: i64) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/store/order/{orderId}".to_string()) + ; + req = req.with_path_param("orderId".to_string(), order_id.to_string()); - let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id); - 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()); - } - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn place_order(&self, body: crate::models::Order) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/store/order", configuration.base_path); - let mut req_builder = client.post(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()); - } - req_builder = req_builder.json(&body); + fn place_order(&self, body: crate::models::Order) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/store/order".to_string()) + ; + req = req.with_body_param(body); - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } } diff --git a/samples/client/petstore/rust/src/apis/user_api.rs b/samples/client/petstore/rust/src/apis/user_api.rs index c9c8acbc89c8..70f2ab5ae3e9 100644 --- a/samples/client/petstore/rust/src/apis/user_api.rs +++ b/samples/client/petstore/rust/src/apis/user_api.rs @@ -8,21 +8,24 @@ * Generated by: https://openapi-generator.tech */ -use std::sync::Arc; +use std::rc::Rc; use std::borrow::Borrow; #[allow(unused_imports)] use std::option::Option; -use futures::{Future}; -use reqwest; + +use hyper; +use serde_json; +use futures::Future; use super::{Error, configuration}; +use super::request as __internal_request; -pub struct UserApiClient { - configuration: Arc, +pub struct UserApiClient { + configuration: Rc>, } -impl UserApiClient { - pub fn new(configuration: Arc) -> UserApiClient { +impl UserApiClient { + pub fn new(configuration: Rc>) -> UserApiClient { UserApiClient { configuration, } @@ -30,173 +33,86 @@ impl UserApiClient { } pub trait UserApi { - fn create_user(&self, body: crate::models::User) -> Box + Send>; - fn create_users_with_array_input(&self, body: Vec) -> Box + Send>; - fn create_users_with_list_input(&self, body: Vec) -> Box + Send>; - fn delete_user(&self, username: &str) -> Box + Send>; - fn get_user_by_name(&self, username: &str) -> Box + Send>; - fn login_user(&self, username: &str, password: &str) -> Box + Send>; - fn logout_user(&self, ) -> Box + Send>; - fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send>; + fn create_user(&self, body: crate::models::User) -> Box>>; + fn create_users_with_array_input(&self, body: Vec) -> Box>>; + fn create_users_with_list_input(&self, body: Vec) -> Box>>; + fn delete_user(&self, username: &str) -> Box>>; + fn get_user_by_name(&self, username: &str) -> Box>>; + fn login_user(&self, username: &str, password: &str) -> Box>>; + fn logout_user(&self, ) -> Box>>; + fn update_user(&self, username: &str, body: crate::models::User) -> Box>>; } -impl UserApi for UserApiClient { - fn create_user(&self, body: crate::models::User) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/user", configuration.base_path); - let mut req_builder = client.post(uri_str.as_str()); +implUserApi for UserApiClient { + fn create_user(&self, body: crate::models::User) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/user".to_string()) + ; + req = req.with_body_param(body); + req = req.returns_nothing(); - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn create_users_with_array_input(&self, body: Vec) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn create_users_with_array_input(&self, body: Vec) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/user/createWithArray".to_string()) + ; + req = req.with_body_param(body); + req = req.returns_nothing(); - let uri_str = format!("{}/user/createWithArray", configuration.base_path); - let mut req_builder = client.post(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()); - } - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn create_users_with_list_input(&self, body: Vec) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/user/createWithList", configuration.base_path); - let mut req_builder = client.post(uri_str.as_str()); + fn create_users_with_list_input(&self, body: Vec) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Post, "/user/createWithList".to_string()) + ; + req = req.with_body_param(body); + req = req.returns_nothing(); - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn delete_user(&self, username: &str) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); - let mut req_builder = client.delete(uri_str.as_str()); + fn delete_user(&self, username: &str) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Delete, "/user/{username}".to_string()) + ; + req = req.with_path_param("username".to_string(), username.to_string()); + req = req.returns_nothing(); - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn get_user_by_name(&self, username: &str) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); - let mut req_builder = client.get(uri_str.as_str()); + fn get_user_by_name(&self, username: &str) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/{username}".to_string()) + ; + req = req.with_path_param("username".to_string(), username.to_string()); - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn login_user(&self, username: &str, password: &str) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; - - let uri_str = format!("{}/user/login", configuration.base_path); - let mut req_builder = client.get(uri_str.as_str()); - - req_builder = req_builder.query(&[("username", &username.to_string())]); - req_builder = req_builder.query(&[("password", &password.to_string())]); - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } + fn login_user(&self, username: &str, password: &str) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/login".to_string()) + ; + req = req.with_query_param("username".to_string(), username.to_string()); + req = req.with_query_param("password".to_string(), password.to_string()); - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .and_then(|mut i| i.json()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn logout_user(&self, ) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn logout_user(&self, ) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/logout".to_string()) + ; + req = req.returns_nothing(); - let uri_str = format!("{}/user/logout", 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()); - } - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } - fn update_user(&self, username: &str, body: crate::models::User) -> Box + Send> { - let configuration: &configuration::Configuration = self.configuration.borrow(); - let client = &configuration.client; + fn update_user(&self, username: &str, body: crate::models::User) -> Box>> { + let mut req = __internal_request::Request::new(hyper::Method::Put, "/user/{username}".to_string()) + ; + req = req.with_path_param("username".to_string(), username.to_string()); + req = req.with_body_param(body); + req = req.returns_nothing(); - let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); - let mut req_builder = client.put(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()); - } - req_builder = req_builder.json(&body); - - // send request - Box::new(req_builder.send() - .and_then(|i| i.error_for_status()) - .map(|_| ()) - .from_err() - ) + req.execute(self.configuration.borrow()) } } diff --git a/samples/client/petstore/rust/src/lib.rs b/samples/client/petstore/rust/src/lib.rs index f318efa89200..a76d822525da 100644 --- a/samples/client/petstore/rust/src/lib.rs +++ b/samples/client/petstore/rust/src/lib.rs @@ -4,7 +4,7 @@ extern crate serde_derive; extern crate serde; extern crate serde_json; extern crate url; -extern crate reqwest; +extern crate hyper; extern crate futures; pub mod apis;