From 891b541a8bb7b4a32400e48fb0bebdad6236a2bc Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 6 Oct 2024 00:46:18 +0900 Subject: [PATCH 1/7] Added Rust Reqwest trait based client --- bin/configs/rust-reqwest-trait-petstore.yaml | 10 + .../codegen/languages/RustClientCodegen.java | 9 +- .../src/main/resources/rust/Cargo.mustache | 5 + .../resources/rust/reqwest-trait/api.mustache | 386 +++++++++++++++++ .../rust/reqwest-trait/api_mod.mustache | 181 ++++++++ .../rust/reqwest-trait/configuration.mustache | 120 ++++++ .../rust/reqwest-trait/petstore/.gitignore | 3 + .../petstore/.openapi-generator-ignore | 23 + .../petstore/.openapi-generator/FILES | 55 +++ .../petstore/.openapi-generator/VERSION | 1 + .../rust/reqwest-trait/petstore/.travis.yml | 1 + .../rust/reqwest-trait/petstore/Cargo.toml | 16 + .../rust/reqwest-trait/petstore/README.md | 85 ++++ .../petstore/docs/ActionContainer.md | 11 + .../petstore/docs/ApiResponse.md | 13 + .../petstore/docs/ArrayItemRefTest.md | 12 + .../rust/reqwest-trait/petstore/docs/Baz.md | 14 + .../reqwest-trait/petstore/docs/Category.md | 12 + .../petstore/docs/EnumArrayTesting.md | 11 + .../reqwest-trait/petstore/docs/FakeApi.md | 41 ++ .../petstore/docs/NullableArray.md | 14 + .../petstore/docs/NumericEnumTesting.md | 15 + .../petstore/docs/OptionalTesting.md | 14 + .../rust/reqwest-trait/petstore/docs/Order.md | 16 + .../rust/reqwest-trait/petstore/docs/Pet.md | 16 + .../reqwest-trait/petstore/docs/PetApi.md | 261 ++++++++++++ .../petstore/docs/PropertyTest.md | 11 + .../rust/reqwest-trait/petstore/docs/Ref.md | 11 + .../reqwest-trait/petstore/docs/Return.md | 13 + .../reqwest-trait/petstore/docs/StoreApi.md | 129 ++++++ .../rust/reqwest-trait/petstore/docs/Tag.md | 12 + .../reqwest-trait/petstore/docs/TestingApi.md | 60 +++ .../petstore/docs/TypeTesting.md | 18 + .../petstore/docs/UniqueItemArrayTesting.md | 11 + .../rust/reqwest-trait/petstore/docs/User.md | 18 + .../reqwest-trait/petstore/docs/UserApi.md | 255 ++++++++++++ .../rust/reqwest-trait/petstore/git_push.sh | 57 +++ .../petstore/src/apis/configuration.rs | 51 +++ .../petstore/src/apis/fake_api.rs | 83 ++++ .../reqwest-trait/petstore/src/apis/mod.rs | 149 +++++++ .../petstore/src/apis/pet_api.rs | 392 ++++++++++++++++++ .../petstore/src/apis/store_api.rs | 196 +++++++++ .../petstore/src/apis/testing_api.rs | 108 +++++ .../petstore/src/apis/user_api.rs | 391 +++++++++++++++++ .../rust/reqwest-trait/petstore/src/lib.rs | 10 + .../petstore/src/models/action_container.rs | 27 ++ .../petstore/src/models/api_response.rs | 35 ++ .../src/models/array_item_ref_test.rs | 32 ++ .../reqwest-trait/petstore/src/models/baz.rs | 42 ++ .../petstore/src/models/category.rs | 32 ++ .../petstore/src/models/enum_array_testing.rs | 45 ++ .../reqwest-trait/petstore/src/models/mod.rs | 36 ++ .../petstore/src/models/model_ref.rs | 29 ++ .../petstore/src/models/model_return.rs | 35 ++ .../petstore/src/models/nullable_array.rs | 36 ++ .../src/models/numeric_enum_testing.rs | 42 ++ .../petstore/src/models/optional_testing.rs | 38 ++ .../petstore/src/models/order.rs | 61 +++ .../reqwest-trait/petstore/src/models/pet.rs | 61 +++ .../petstore/src/models/property_test.rs | 29 ++ .../reqwest-trait/petstore/src/models/tag.rs | 32 ++ .../petstore/src/models/type_testing.rs | 54 +++ .../src/models/unique_item_array_testing.rs | 46 ++ .../reqwest-trait/petstore/src/models/user.rs | 51 +++ 64 files changed, 4081 insertions(+), 2 deletions(-) create mode 100644 bin/configs/rust-reqwest-trait-petstore.yaml create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust/reqwest-trait/configuration.mustache create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/.gitignore create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator-ignore create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/FILES create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/.travis.yml create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/README.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/ActionContainer.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/ApiResponse.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/ArrayItemRefTest.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Baz.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Category.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/EnumArrayTesting.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/NullableArray.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/NumericEnumTesting.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/OptionalTesting.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Order.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Pet.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/PetApi.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/PropertyTest.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Ref.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Return.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/StoreApi.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/Tag.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/TestingApi.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/TypeTesting.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/UniqueItemArrayTesting.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/User.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/docs/UserApi.md create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/git_push.sh create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/configuration.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/lib.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/action_container.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/api_response.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/array_item_ref_test.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/baz.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/category.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/enum_array_testing.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/mod.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_ref.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_return.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/nullable_array.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/numeric_enum_testing.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/optional_testing.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/order.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/pet.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/property_test.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/tag.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/type_testing.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/unique_item_array_testing.rs create mode 100644 samples/client/petstore/rust/reqwest-trait/petstore/src/models/user.rs diff --git a/bin/configs/rust-reqwest-trait-petstore.yaml b/bin/configs/rust-reqwest-trait-petstore.yaml new file mode 100644 index 000000000000..1aef6449ccb3 --- /dev/null +++ b/bin/configs/rust-reqwest-trait-petstore.yaml @@ -0,0 +1,10 @@ +generatorName: rust +outputDir: samples/client/petstore/rust/reqwest-trait/petstore +library: reqwest-trait +inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/rust +additionalProperties: + topLevelApiClient: true + packageName: petstore-reqwest +enumNameMappings: + delivered: shipped 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 9fb5b8f3ef5b..f2763248247f 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 @@ -61,6 +61,8 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon public static final String HYPER_LIBRARY = "hyper"; public static final String HYPER0X_LIBRARY = "hyper0x"; public static final String REQWEST_LIBRARY = "reqwest"; + public static final String REQWEST_TRAIT_LIBRARY = "reqwest-trait"; + public static final String REQWEST_TRAIT_LIBRARY_ATTR = "reqwestTrait"; public static final String SUPPORT_ASYNC = "supportAsync"; public static final String SUPPORT_MIDDLEWARE = "supportMiddleware"; public static final String SUPPORT_TOKEN_SOURCE = "supportTokenSource"; @@ -211,6 +213,7 @@ public RustClientCodegen() { supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x)."); supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x)."); supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest."); + supportedLibraries.put(REQWEST_TRAIT_LIBRARY, "HTTP client: Reqwest (trait based)."); CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); libraryOption.setEnum(supportedLibraries); @@ -389,6 +392,8 @@ public void processOpts() { additionalProperties.put(HYPER0X_LIBRARY, "true"); } else if (REQWEST_LIBRARY.equals(getLibrary())) { additionalProperties.put(REQWEST_LIBRARY, "true"); + } else if (REQWEST_TRAIT_LIBRARY.equals(getLibrary())) { + additionalProperties.put(REQWEST_TRAIT_LIBRARY_ATTR, "true"); } else { LOGGER.error("Unknown library option (-l/--library): {}", getLibrary()); } @@ -446,7 +451,7 @@ private boolean getSupportAsync() { private boolean getSupportMiddleware() { return supportMiddleware; } - + private boolean getSupportTokenSource() { return supportTokenSource; } @@ -566,7 +571,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List 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_TRAIT_LIBRARY.equals(getLibrary())) { operation.httpMethod = operation.httpMethod.toUpperCase(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 1bac4f8128d7..02fd09bd1b31 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -72,9 +72,14 @@ reqwest = { version = "^0.12", features = ["json", "multipart"] } reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } {{/supportMiddleware}} {{#supportTokenSource}} +{{^reqwestTrait}} async-trait = "^0.1" +{{/reqwestTrait}} # TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. google-cloud-token = "^0.1" {{/supportTokenSource}} {{/supportAsync}} {{/reqwest}} +{{#reqwestTrait}} +async-trait = "^0.1" +{{/reqwestTrait}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache new file mode 100644 index 000000000000..4997f1e2800f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache @@ -0,0 +1,386 @@ +{{>partial_header}} + +use async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait {{{classname}}}: Send + Sync { +{{#operations}} +{{#operation}} + async fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>; +{{/operation}} +{{/operations}} +} + +pub struct {{{classname}}}Client { + configuration: Arc +} + +impl {{classname}}Client { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl {{classname}} for {{classname}}Client { + {{#operations}} + {{#operation}} + {{#description}} + /// {{{.}}} + {{/description}} + {{#notes}} + /// {{{.}}} + {{/notes}} + {{#vendorExtensions.x-group-parameters}} + async fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { + let local_var_configuration = configuration; + + // unbox the parameters + {{#allParams}} + let {{paramName}} = params.{{paramName}}; + {{/allParams}} + + {{/vendorExtensions.x-group-parameters}} + {{^vendorExtensions.x-group-parameters}} + async fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { + let local_var_configuration = &self.configuration; + {{/vendorExtensions.x-group-parameters}} + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}{{{path}}}", local_var_configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}crate::apis::urlencode({{/isString}}{{{paramName}}}{{^required}}.unwrap(){{/required}}{{#required}}{{#isNullable}}.unwrap(){{/isNullable}}{{/required}}{{#isArray}}.join(",").as_ref(){{/isArray}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}.to_string(){{/isContainer}}{{/isPrimitiveType}}{{/isUuid}}{{/isString}}{{#isString}}){{/isString}}{{/pathParams}}); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::{{{httpMethod}}}, local_var_uri_str.as_str()); + + {{#queryParams}} + {{#required}} + {{#isArray}} + local_var_req_builder = match "{{collectionFormat}}" { + "multi" => local_var_req_builder.query(&{{{paramName}}}.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), + _ => local_var_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + }; + {{/isArray}} + {{^isArray}} + {{^isNullable}} + local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.to_string())]); + {{/isNullable}} + {{#isNullable}} + {{#isDeepObject}} + if let Some(ref local_var_str) = {{{paramName}}} { + let params = crate::apis::parse_deep_object("{{{baseName}}}", local_var_str); + local_var_req_builder = local_var_req_builder.query(¶ms); + }; + {{/isDeepObject}} + {{^isDeepObject}} + if let Some(ref local_var_str) = {{{paramName}}} { + local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.to_string())]); + }; + {{/isDeepObject}} + {{/isNullable}} + {{/isArray}} + {{/required}} + {{^required}} + if let Some(ref local_var_str) = {{{paramName}}} { + {{#isArray}} + local_var_req_builder = match "{{collectionFormat}}" { + "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), + _ => local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + }; + {{/isArray}} + {{^isArray}} + {{#isDeepObject}} + let params = crate::apis::parse_deep_object("{{{baseName}}}", local_var_str); + local_var_req_builder = local_var_req_builder.query(¶ms); + {{/isDeepObject}} + {{^isDeepObject}} + local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.to_string())]); + {{/isDeepObject}} + {{/isArray}} + } + {{/required}} + {{/queryParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInQuery}} + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.query(&[("{{{keyParamName}}}", local_var_value)]); + } + {{/isKeyInQuery}} + {{/isApiKey}} + {{/authMethods}} + {{/hasAuthMethods}} + {{#hasAuthMethods}} + {{#withAWSV4Signature}} + if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { + let local_var_new_headers = match local_var_aws_v4_key.sign( + &local_var_uri_str, + "{{{httpMethod}}}", + {{#hasBodyParam}} + {{#bodyParams}} + &serde_json::to_string(&{{{paramName}}}).expect("param should serialize to string"), + {{/bodyParams}} + {{/hasBodyParam}} + {{^hasBodyParam}} + "", + {{/hasBodyParam}} + ) { + Ok(new_headers) => new_headers, + Err(err) => return Err(Error::AWSV4SignatureError(err)), + }; + for (local_var_name, local_var_value) in local_var_new_headers.iter() { + local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + } + } + {{/withAWSV4Signature}} + {{/hasAuthMethods}} + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + {{#hasHeaderParams}} + {{#headerParams}} + {{#required}} + {{^isNullable}} + local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", {{{paramName}}}{{#isArray}}.join(","){{/isArray}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", local_var_param_value{{#isArray}}.join(","){{/isArray}}.to_string()); }, + None => { local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(local_var_param_value) = {{{paramName}}} { + local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", local_var_param_value{{#isArray}}.join(","){{/isArray}}.to_string()); + } + {{/required}} + {{/headerParams}} + {{/hasHeaderParams}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#supportTokenSource}} + // Obtain a token from source provider. + // Tokens can be Id or access tokens depending on the provider type and configuration. + let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. + local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + {{/supportTokenSource}} + {{^supportTokenSource}} + {{#isApiKey}} + {{#isKeyInHeader}} + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("{{{keyParamName}}}", local_var_value); + }; + {{/isKeyInHeader}} + {{/isApiKey}} + {{#isBasic}} + {{#isBasicBasic}} + if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { + local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); + }; + {{/isBasicBasic}} + {{#isBasicBearer}} + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + {{/isBasicBearer}} + {{/isBasic}} + {{#isOAuth}} + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + {{/isOAuth}} + {{/supportTokenSource}} + {{/authMethods}} + {{/hasAuthMethods}} + {{#isMultipart}} + {{#hasFormParams}} + let mut local_var_form = reqwest::multipart::Form::new(); + {{#formParams}} + {{#isFile}} + // TODO: support file upload for '{{{baseName}}}' parameter + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + local_var_form = local_var_form.text("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(local_var_param_value) => { local_var_form = local_var_form.text("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, + None => { local_var_form = local_var_form.text("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(local_var_param_value) = {{{paramName}}} { + local_var_form = local_var_form.text("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + local_var_req_builder = local_var_req_builder.multipart(local_var_form); + {{/hasFormParams}} + {{/isMultipart}} + {{^isMultipart}} + {{#hasFormParams}} + let mut local_var_form_params = std::collections::HashMap::new(); + {{#formParams}} + {{#isFile}} + {{#required}} + {{^isNullable}} + local_var_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(local_var_param_value) => { local_var_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(local_var_param_value) = {{{paramName}}} { + local_var_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + } + {{/required}} + {{/isFile}} + {{^isFile}} + {{#required}} + {{^isNullable}} + local_var_form_params.insert("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + {{/isNullable}} + {{#isNullable}} + match {{{paramName}}} { + Some(local_var_param_value) => { local_var_form_params.insert("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, + None => { local_var_form_params.insert("{{{baseName}}}", ""); }, + } + {{/isNullable}} + {{/required}} + {{^required}} + if let Some(local_var_param_value) = {{{paramName}}} { + local_var_form_params.insert("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + } + {{/required}} + {{/isFile}} + {{/formParams}} + local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + {{/hasFormParams}} + {{/isMultipart}} + {{#hasBodyParam}} + {{#bodyParams}} + local_var_req_builder = local_var_req_builder.json(&{{{paramName}}}); + {{/bodyParams}} + {{/hasBodyParam}} + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + {{^supportMultipleResponses}} + {{^returnType}} + Ok(()) + {{/returnType}} + {{#returnType}} + serde_json::from_str(&local_var_content).map_err(Error::from) + {{/returnType}} + {{/supportMultipleResponses}} + {{#supportMultipleResponses}} + let local_var_entity: Option<{{{operationIdCamelCase}}}Success> = serde_json::from_str(&local_var_content).ok(); + let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Ok(local_var_result) + {{/supportMultipleResponses}} + } else { + let local_var_entity: Option<{{{operationIdCamelCase}}}Error> = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + {{/operation}} + {{/operations}} +} + + +{{#operations}} +{{#operation}} +{{#vendorExtensions.x-group-parameters}} +{{#allParams}} +{{#-first}} +/// struct for passing parameters to the method [`{{operationId}}`] +#[derive(Clone, Debug)] +pub struct {{{operationIdCamelCase}}}Params { +{{/-first}} + {{#description}} + /// {{{.}}} + {{/description}} + pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^isUuid}}{{#isString}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isString}}{{/isUuid}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}},{{/-last}} +{{#-last}} +} + +{{/-last}} +{{/allParams}} +{{/vendorExtensions.x-group-parameters}} +{{/operation}} +{{/operations}} + +{{#supportMultipleResponses}} +{{#operations}} +{{#operation}} +/// struct for typed successes of method [`{{operationId}}`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum {{{operationIdCamelCase}}}Success { + {{#responses}} + {{#is2xx}} + Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}), + {{/is2xx}} + {{#is3xx}} + Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}), + {{/is3xx}} + {{/responses}} + UnknownValue(serde_json::Value), +} + +{{/operation}} +{{/operations}} +{{/supportMultipleResponses}} +{{#operations}} +{{#operation}} +/// struct for typed errors of method [`{{operationId}}`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum {{{operationIdCamelCase}}}Error { + {{#responses}} + {{#is4xx}} + Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}), + {{/is4xx}} + {{#is5xx}} + Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}), + {{/is5xx}} + {{#isDefault}} + DefaultResponse({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}), + {{/isDefault}} + {{/responses}} + UnknownValue(serde_json::Value), +} + +{{/operation}} +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache new file mode 100644 index 000000000000..6089916916b8 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache @@ -0,0 +1,181 @@ +use std::error; +use std::fmt; +{{#withAWSV4Signature}} +use aws_sigv4; +{{/withAWSV4Signature}} + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + {{#supportMiddleware}} + ReqwestMiddleware(reqwest_middleware::Error), + {{/supportMiddleware}} + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), + {{#withAWSV4Signature}} + AWSV4SignatureError(aws_sigv4::http_request::Error), + {{/withAWSV4Signature}} + {{#supportTokenSource}} + TokenSource(Box), + {{/supportTokenSource}} +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + {{#supportMiddleware}} + Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()), + {{/supportMiddleware}} + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + {{#withAWSV4Signature}} + Error::AWSV4SignatureError(e) => ("aws v4 signature", e.to_string()), + {{/withAWSV4Signature}} + {{#supportTokenSource}} + Error::TokenSource(e) => ("token source failure", e.to_string()), + {{/supportTokenSource}} + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + {{#supportMiddleware}} + Error::ReqwestMiddleware(e) => e, + {{/supportMiddleware}} + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + {{#withAWSV4Signature}} + Error::AWSV4SignatureError(_) => return None, + {{/withAWSV4Signature}} + {{#supportTokenSource}} + Error::TokenSource(e) => &**e, + {{/supportTokenSource}} + }) + } +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +{{#supportMiddleware}} +impl From for Error { + fn from(e: reqwest_middleware::Error) -> Self { + Error::ReqwestMiddleware(e) + } +} + +{{/supportMiddleware}} +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() +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +{{#apiInfo}} +{{#apis}} +pub mod {{{classFilename}}}; +{{/apis}} +{{/apiInfo}} + +pub mod configuration; + +{{#topLevelApiClient}} +use std::sync::Arc; + +pub trait Api { + {{#apiInfo}} + {{#apis}} + fn {{{classFilename}}}(&self) -> &dyn {{{classFilename}}}::{{classname}}; + {{/apis}} + {{/apiInfo}} +} + +pub struct ApiClient { + {{#apiInfo}} + {{#apis}} + {{{classFilename}}}: Box, + {{/apis}} + {{/apiInfo}} +} + +impl ApiClient { + pub fn new(configuration: Arc) -> Self { + Self { + {{#apiInfo}} + {{#apis}} + {{{classFilename}}}: Box::new({{{classFilename}}}::{{classname}}Client::new(configuration.clone())), + {{/apis}} + {{/apiInfo}} + } + } +} + +impl Api for ApiClient { + {{#apiInfo}} + {{#apis}} + fn {{{classFilename}}}(&self) -> &dyn {{{classFilename}}}::{{classname}} { + self.{{{classFilename}}}.as_ref() + } + {{/apis}} + {{/apiInfo}} + +} + +{{/topLevelApiClient}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/configuration.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/configuration.mustache new file mode 100644 index 000000000000..25360691a835 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/configuration.mustache @@ -0,0 +1,120 @@ +{{>partial_header}} + +{{#withAWSV4Signature}} +use std::time::SystemTime; +use aws_sigv4::http_request::{sign, SigningSettings, SigningParams, SignableRequest}; +use http; +use secrecy::{SecretString, ExposeSecret}; +{{/withAWSV4Signature}} +{{#supportTokenSource}} +use std::sync::Arc; +use google_cloud_token::TokenSource; +use async_trait::async_trait; +{{/supportTokenSource}} + +#[derive(Debug, Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: {{#supportMiddleware}}reqwest_middleware::ClientWithMiddleware{{/supportMiddleware}}{{^supportMiddleware}}reqwest::Client{{/supportMiddleware}}, + {{^supportTokenSource}} + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, + {{/supportTokenSource}} + {{#withAWSV4Signature}} + pub aws_v4_key: Option, + {{/withAWSV4Signature}} + {{#supportTokenSource}} + pub token_source: Arc, + {{/supportTokenSource}} +} +{{^supportTokenSource}} + +pub type BasicAuth = (String, Option); + +#[derive(Debug, Clone)] +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} +{{/supportTokenSource}} + +{{#withAWSV4Signature}} +#[derive(Debug, Clone)] +pub struct AWSv4Key { + pub access_key: String, + pub secret_key: SecretString, + pub region: String, + pub service: String, +} + +impl AWSv4Key { + pub fn sign(&self, uri: &str, method: &str, body: &str) -> Result, aws_sigv4::http_request::Error> { + let request = http::Request::builder() + .uri(uri) + .method(method) + .body(body).unwrap(); + let signing_settings = SigningSettings::default(); + let signing_params = SigningParams::builder() + .access_key(self.access_key.as_str()) + .secret_key(self.secret_key.expose_secret().as_str()) + .region(self.region.as_str()) + .service_name(self.service.as_str()) + .time(SystemTime::now()) + .settings(signing_settings) + .build() + .unwrap(); + let signable_request = SignableRequest::from(&request); + let (mut signing_instructions, _signature) = sign(signable_request, &signing_params)?.into_parts(); + let mut additional_headers = Vec::<(String, String)>::new(); + if let Some(new_headers) = signing_instructions.take_headers() { + for (name, value) in new_headers.into_iter() { + additional_headers.push((name.expect("header should have name").to_string(), + value.to_str().expect("header value should be a string").to_string())); + } + } + Ok(additional_headers) + } +} +{{/withAWSV4Signature}} + +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: {{#supportMiddleware}}reqwest_middleware::ClientBuilder::new(reqwest::Client::new()).build(){{/supportMiddleware}}{{^supportMiddleware}}reqwest::Client::new(){{/supportMiddleware}}, + {{^supportTokenSource}} + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + {{/supportTokenSource}} + {{#withAWSV4Signature}} + aws_v4_key: None, + {{/withAWSV4Signature}} + {{#supportTokenSource}} + token_source: Arc::new(NoopTokenSource{}), + {{/supportTokenSource}} + } + } +} +{{#supportTokenSource}} +#[derive(Debug)] +struct NoopTokenSource{} + +#[async_trait] +impl TokenSource for NoopTokenSource { + async fn token(&self) -> Result> { + panic!("This is dummy token source. You can use TokenSourceProvider from 'google_cloud_auth' crate, or any other compatible crate.") + } +} +{{/supportTokenSource}} diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/.gitignore b/samples/client/petstore/rust/reqwest-trait/petstore/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator-ignore b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/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/reqwest-trait/petstore/.openapi-generator/FILES b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/FILES new file mode 100644 index 000000000000..6d5eacd5c073 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/FILES @@ -0,0 +1,55 @@ +.gitignore +.travis.yml +Cargo.toml +README.md +docs/ActionContainer.md +docs/ApiResponse.md +docs/ArrayItemRefTest.md +docs/Baz.md +docs/Category.md +docs/EnumArrayTesting.md +docs/FakeApi.md +docs/NullableArray.md +docs/NumericEnumTesting.md +docs/OptionalTesting.md +docs/Order.md +docs/Pet.md +docs/PetApi.md +docs/PropertyTest.md +docs/Ref.md +docs/Return.md +docs/StoreApi.md +docs/Tag.md +docs/TestingApi.md +docs/TypeTesting.md +docs/UniqueItemArrayTesting.md +docs/User.md +docs/UserApi.md +git_push.sh +src/apis/configuration.rs +src/apis/fake_api.rs +src/apis/mod.rs +src/apis/pet_api.rs +src/apis/store_api.rs +src/apis/testing_api.rs +src/apis/user_api.rs +src/lib.rs +src/models/action_container.rs +src/models/api_response.rs +src/models/array_item_ref_test.rs +src/models/baz.rs +src/models/category.rs +src/models/enum_array_testing.rs +src/models/mod.rs +src/models/model_ref.rs +src/models/model_return.rs +src/models/nullable_array.rs +src/models/numeric_enum_testing.rs +src/models/optional_testing.rs +src/models/order.rs +src/models/pet.rs +src/models/property_test.rs +src/models/tag.rs +src/models/type_testing.rs +src/models/unique_item_array_testing.rs +src/models/user.rs diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION new file mode 100644 index 000000000000..17f2442ff3bc --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.9.0-SNAPSHOT diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/.travis.yml b/samples/client/petstore/rust/reqwest-trait/petstore/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml new file mode 100644 index 000000000000..f129252521bc --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "petstore-reqwest" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] +description = "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters." +license = "Apache-2.0" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +uuid = { version = "^1.8", features = ["serde", "v4"] } +async-trait = "^0.1" diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/README.md b/samples/client/petstore/rust/reqwest-trait/petstore/README.md new file mode 100644 index 000000000000..43c026e7687d --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/README.md @@ -0,0 +1,85 @@ +# Rust API client for petstore-reqwest + +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 +- Generator version: 7.9.0-SNAPSHOT +- Build package: `org.openapitools.codegen.languages.RustClientCodegen` + +## Installation + +Put the package under your project folder in a directory named `petstore-reqwest` and add the following to `Cargo.toml` under `[dependencies]`: + +``` +petstore-reqwest = { path = "./petstore-reqwest" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{username} | To test nullable required parameters +*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 +*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file +*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema +*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 + + - [ActionContainer](docs/ActionContainer.md) + - [ApiResponse](docs/ApiResponse.md) + - [ArrayItemRefTest](docs/ArrayItemRefTest.md) + - [Baz](docs/Baz.md) + - [Category](docs/Category.md) + - [EnumArrayTesting](docs/EnumArrayTesting.md) + - [NullableArray](docs/NullableArray.md) + - [NumericEnumTesting](docs/NumericEnumTesting.md) + - [OptionalTesting](docs/OptionalTesting.md) + - [Order](docs/Order.md) + - [Pet](docs/Pet.md) + - [PropertyTest](docs/PropertyTest.md) + - [Ref](docs/Ref.md) + - [Return](docs/Return.md) + - [Tag](docs/Tag.md) + - [TypeTesting](docs/TypeTesting.md) + - [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.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/reqwest-trait/petstore/docs/ActionContainer.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ActionContainer.md new file mode 100644 index 000000000000..4e0a0ba49615 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ActionContainer.md @@ -0,0 +1,11 @@ +# ActionContainer + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**action** | [**models::Baz**](Baz.md) | | + +[[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/reqwest-trait/petstore/docs/ApiResponse.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ApiResponse.md new file mode 100644 index 000000000000..b5125ba685b1 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ApiResponse.md @@ -0,0 +1,13 @@ +# ApiResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**code** | Option<**i32**> | | [optional] +**r#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/reqwest-trait/petstore/docs/ArrayItemRefTest.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ArrayItemRefTest.md new file mode 100644 index 000000000000..616deda7c4b5 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/ArrayItemRefTest.md @@ -0,0 +1,12 @@ +# ArrayItemRefTest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**list_with_array_ref** | [**Vec>**](Vec.md) | | +**list_with_object_ref** | [**Vec>**](std::collections::HashMap.md) | | + +[[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/reqwest-trait/petstore/docs/Baz.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Baz.md new file mode 100644 index 000000000000..e9c4c693d898 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Baz.md @@ -0,0 +1,14 @@ +# Baz + +## Enum Variants + +| Name | Value | +|---- | -----| +| A | A | +| B | B | +| Empty | | + + +[[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/reqwest-trait/petstore/docs/Category.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Category.md new file mode 100644 index 000000000000..1cf67347c057 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/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/reqwest-trait/petstore/docs/EnumArrayTesting.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/EnumArrayTesting.md new file mode 100644 index 000000000000..fb4c54df47d5 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/EnumArrayTesting.md @@ -0,0 +1,11 @@ +# EnumArrayTesting + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**required_enums** | **Vec** | | + +[[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/reqwest-trait/petstore/docs/FakeApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md new file mode 100644 index 000000000000..55bf612aa216 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md @@ -0,0 +1,41 @@ +# \FakeApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**test_nullable_required_param**](FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{username} | To test nullable required parameters + + + +## test_nullable_required_param + +> test_nullable_required_param(username, dummy_required_nullable_param, uppercase) +To test nullable required parameters + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | +**dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | +**uppercase** | Option<**String**> | To test parameter names in upper case | | + +### 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/reqwest-trait/petstore/docs/NullableArray.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/NullableArray.md new file mode 100644 index 000000000000..3b4aaa9668fc --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/NullableArray.md @@ -0,0 +1,14 @@ +# NullableArray + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array_nullable** | Option<**Vec**> | | [optional] +**just_array** | Option<**Vec**> | | [optional] +**nullable_string** | Option<**String**> | | [optional] +**just_string** | 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/reqwest-trait/petstore/docs/NumericEnumTesting.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/NumericEnumTesting.md new file mode 100644 index 000000000000..6e99038d397e --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/NumericEnumTesting.md @@ -0,0 +1,15 @@ +# NumericEnumTesting + +## Enum Variants + +| Name | Value | +|---- | -----| +| Variant0 | 0 | +| Variant1 | 1 | +| Variant2 | 2 | +| Variant3 | 3 | + + +[[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/reqwest-trait/petstore/docs/OptionalTesting.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/OptionalTesting.md new file mode 100644 index 000000000000..029e38eb9772 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/OptionalTesting.md @@ -0,0 +1,14 @@ +# OptionalTesting + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**optional_nonnull** | Option<**String**> | | [optional] +**required_nonnull** | **String** | | +**optional_nullable** | Option<**String**> | | [optional] +**required_nullable** | Option<**String**> | | + +[[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/reqwest-trait/petstore/docs/Order.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Order.md new file mode 100644 index 000000000000..d9a09c397432 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/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/reqwest-trait/petstore/docs/Pet.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Pet.md new file mode 100644 index 000000000000..e7a72caa16e9 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Pet.md @@ -0,0 +1,16 @@ +# Pet + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**category** | Option<[**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/reqwest-trait/petstore/docs/PetApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/PetApi.md new file mode 100644 index 000000000000..d503facb903c --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/PetApi.md @@ -0,0 +1,261 @@ +# \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 + +> models::Pet add_pet(pet) +Add a new pet to the store + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + +[**models::Pet**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **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) + + +## 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 + +> 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 + +[**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 + +> models::Pet update_pet(pet) +Update an existing pet + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**pet** | [**Pet**](Pet.md) | Pet object that needs to be added to the store | [required] | + +### Return type + +[**models::Pet**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **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_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 + +> 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 + +[**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/reqwest-trait/petstore/docs/PropertyTest.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/PropertyTest.md new file mode 100644 index 000000000000..3f36c163de0b --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/PropertyTest.md @@ -0,0 +1,11 @@ +# PropertyTest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**uuid** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [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/reqwest-trait/petstore/docs/Ref.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Ref.md new file mode 100644 index 000000000000..04f9d0aa55a2 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Ref.md @@ -0,0 +1,11 @@ +# Ref + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**dummy** | 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/reqwest-trait/petstore/docs/Return.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Return.md new file mode 100644 index 000000000000..04710a019db2 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Return.md @@ -0,0 +1,13 @@ +# Return + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**r#match** | Option<**i32**> | | [optional] +**r#async** | Option<**bool**> | | [optional] +**param_super** | Option<**bool**> | | [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/reqwest-trait/petstore/docs/StoreApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/StoreApi.md new file mode 100644 index 000000000000..a513dfa1b5fa --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/StoreApi.md @@ -0,0 +1,129 @@ +# \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 + +> 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 generate exceptions + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order_id** | **i64** | ID of pet that needs to be fetched | [required] | + +### Return type + +[**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 + +> models::Order place_order(order) +Place an order for a pet + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**order** | [**Order**](Order.md) | order placed for purchasing the pet | [required] | + +### Return type + +[**models::Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **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/reqwest-trait/petstore/docs/Tag.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/Tag.md new file mode 100644 index 000000000000..7bf71ab0e9d8 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/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/reqwest-trait/petstore/docs/TestingApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/TestingApi.md new file mode 100644 index 000000000000..9c26af249127 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/TestingApi.md @@ -0,0 +1,60 @@ +# \TestingApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**tests_file_response_get**](TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file +[**tests_type_testing_get**](TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema + + + +## tests_file_response_get + +> std::path::PathBuf tests_file_response_get() +Returns an image file + +### 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**: image/jpeg + +[[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) + + +## tests_type_testing_get + +> models::TypeTesting tests_type_testing_get() +Route to test the TypeTesting schema + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**models::TypeTesting**](TypeTesting.md) + +### Authorization + +No authorization required + +### 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) + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/docs/TypeTesting.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/TypeTesting.md new file mode 100644 index 000000000000..4f650eb1aa29 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/TypeTesting.md @@ -0,0 +1,18 @@ +# TypeTesting + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**int32** | **i32** | | +**int64** | **i64** | | +**float** | **f32** | | +**double** | **f64** | | +**string** | **String** | | +**boolean** | **bool** | | +**uuid** | [**uuid::Uuid**](uuid::Uuid.md) | | +**bytes** | **String** | | + +[[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/reqwest-trait/petstore/docs/UniqueItemArrayTesting.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/UniqueItemArrayTesting.md new file mode 100644 index 000000000000..6e103e2bb28d --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/UniqueItemArrayTesting.md @@ -0,0 +1,11 @@ +# UniqueItemArrayTesting + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**unique_item_array** | **Vec** | Helper object for the unique item array test | + +[[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/reqwest-trait/petstore/docs/User.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/User.md new file mode 100644 index 000000000000..19d813622ede --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/User.md @@ -0,0 +1,18 @@ +# User + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**i64**> | | [optional] +**username** | **String** | | +**first_name** | Option<**String**> | | [optional] +**last_name** | **String** | | +**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/reqwest-trait/petstore/docs/UserApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/UserApi.md new file mode 100644 index 000000000000..d536057ae15a --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/UserApi.md @@ -0,0 +1,255 @@ +# \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(user) +Create user + +This can only be done by the logged in user. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**user** | [**User**](User.md) | Created user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: application/json +- **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(user) +Creates list of users with given input array + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**user** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: application/json +- **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(user) +Creates list of users with given input array + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**user** | [**Vec**](User.md) | List of user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: application/json +- **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 + +[api_key](../README.md#api_key) + +### 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 + +> 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 + +[**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 + +[api_key](../README.md#api_key) + +### 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, user) +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] | +**user** | [**User**](User.md) | Updated user object | [required] | + +### Return type + + (empty response body) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: application/json +- **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/reqwest-trait/petstore/git_push.sh b/samples/client/petstore/rust/reqwest-trait/petstore/git_push.sh new file mode 100644 index 000000000000..f53a75d4fabe --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/git_push.sh @@ -0,0 +1,57 @@ +#!/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-petstore-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/reqwest-trait/petstore/src/apis/configuration.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/configuration.rs new file mode 100644 index 000000000000..761172249baa --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/configuration.rs @@ -0,0 +1,51 @@ +/* + * 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 + */ + + + +#[derive(Debug, Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, +} + +pub type BasicAuth = (String, Option); + +#[derive(Debug, Clone)] +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::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs new file mode 100644 index 000000000000..201860b2f72d --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -0,0 +1,83 @@ +/* + * 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 async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait FakeApi: Send + Sync { + async fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error>; +} + +pub struct FakeApiClient { + configuration: Arc +} + +impl FakeApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl FakeApi for FakeApiClient { + /// + async fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/fake/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + match dummy_required_nullable_param { + Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, + None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + } + if let Some(local_var_param_value) = uppercase { + local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + + + +/// struct for typed errors of method [`test_nullable_required_param`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum TestNullableRequiredParamError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs new file mode 100644 index 000000000000..698ecf95b91f --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -0,0 +1,149 @@ +use std::error; +use std::fmt; + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + }) + } +} + +impl 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() +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +pub mod fake_api; +pub mod pet_api; +pub mod store_api; +pub mod testing_api; +pub mod user_api; + +pub mod configuration; + +use std::sync::Arc; + +trait Api { + fn fake_api(&self) -> &dyn fake_api::FakeApi; + fn pet_api(&self) -> &dyn pet_api::PetApi; + fn store_api(&self) -> &dyn store_api::StoreApi; + fn testing_api(&self) -> &dyn testing_api::TestingApi; + fn user_api(&self) -> &dyn user_api::UserApi; +} + +pub struct ApiClient { + fake_api: Box, + pet_api: Box, + store_api: Box, + testing_api: Box, + user_api: Box, +} + +impl ApiClient { + pub fn new(configuration: Arc) -> Self { + Self { + fake_api: Box::new(fake_api::FakeApiClient::new(configuration.clone())), + pet_api: Box::new(pet_api::PetApiClient::new(configuration.clone())), + store_api: Box::new(store_api::StoreApiClient::new(configuration.clone())), + testing_api: Box::new(testing_api::TestingApiClient::new(configuration.clone())), + user_api: Box::new(user_api::UserApiClient::new(configuration.clone())), + } + } +} + +impl Api for ApiClient { + fn fake_api(&self) -> &dyn fake_api::FakeApi { + self.fake_api.as_ref() + } + fn pet_api(&self) -> &dyn pet_api::PetApi { + self.pet_api.as_ref() + } + fn store_api(&self) -> &dyn store_api::StoreApi { + self.store_api.as_ref() + } + fn testing_api(&self) -> &dyn testing_api::TestingApi { + self.testing_api.as_ref() + } + fn user_api(&self) -> &dyn user_api::UserApi { + self.user_api.as_ref() + } + +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs new file mode 100644 index 000000000000..cc52f67e429d --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs @@ -0,0 +1,392 @@ +/* + * 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 async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait PetApi: Send + Sync { + async fn add_pet(&self, pet: models::Pet) -> Result>; + async fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Result<(), Error>; + async fn find_pets_by_status(&self, status: Vec) -> Result, Error>; + async fn find_pets_by_tags(&self, tags: Vec) -> Result, Error>; + async fn get_pet_by_id(&self, pet_id: i64) -> Result>; + async fn update_pet(&self, pet: models::Pet) -> Result>; + async fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error>; + async fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result>; +} + +pub struct PetApiClient { + configuration: Arc +} + +impl PetApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl PetApi for PetApiClient { + /// + async fn add_pet(&self, pet: models::Pet) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&pet); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(local_var_param_value) = api_key { + local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Multiple status values can be provided with comma separated strings + async fn find_pets_by_status(&self, status: Vec) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + local_var_req_builder = match "csv" { + "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + }; + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + async fn find_pets_by_tags(&self, tags: Vec) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + local_var_req_builder = match "csv" { + "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + }; + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Returns a single pet + async fn get_pet_by_id(&self, pet_id: i64) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn update_pet(&self, pet: models::Pet) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&pet); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + let mut local_var_form_params = std::collections::HashMap::new(); + if let Some(local_var_param_value) = name { + local_var_form_params.insert("name", local_var_param_value.to_string()); + } + if let Some(local_var_param_value) = status { + local_var_form_params.insert("status", local_var_param_value.to_string()); + } + local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + let mut local_var_form = reqwest::multipart::Form::new(); + if let Some(local_var_param_value) = additional_metadata { + local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + } + // TODO: support file upload for 'file' parameter + local_var_req_builder = local_var_req_builder.multipart(local_var_form); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + + + +/// struct for typed errors of method [`add_pet`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum AddPetError { + Status405(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`delete_pet`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeletePetError { + Status400(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`find_pets_by_status`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum FindPetsByStatusError { + Status400(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`find_pets_by_tags`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum FindPetsByTagsError { + Status400(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`get_pet_by_id`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetPetByIdError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`update_pet`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdatePetError { + Status400(), + Status404(), + Status405(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`update_pet_with_form`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdatePetWithFormError { + Status405(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`upload_file`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UploadFileError { + UnknownValue(serde_json::Value), +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs new file mode 100644 index 000000000000..943d1026d721 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs @@ -0,0 +1,196 @@ +/* + * 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 async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait StoreApi: Send + Sync { + async fn delete_order(&self, order_id: &str) -> Result<(), Error>; + async fn get_inventory(&self, ) -> Result, Error>; + async fn get_order_by_id(&self, order_id: i64) -> Result>; + async fn place_order(&self, order: models::Order) -> Result>; +} + +pub struct StoreApiClient { + configuration: Arc +} + +impl StoreApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl StoreApi for StoreApiClient { + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + async fn delete_order(&self, order_id: &str) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Returns a map of status codes to quantities + async fn get_inventory(&self, ) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + async fn get_order_by_id(&self, order_id: i64) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn place_order(&self, order: models::Order) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + local_var_req_builder = local_var_req_builder.json(&order); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + + + +/// struct for typed errors of method [`delete_order`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteOrderError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`get_inventory`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetInventoryError { + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`get_order_by_id`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetOrderByIdError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`place_order`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PlaceOrderError { + Status400(), + UnknownValue(serde_json::Value), +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs new file mode 100644 index 000000000000..dad8b66ec7c7 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs @@ -0,0 +1,108 @@ +/* + * 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 async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait TestingApi: Send + Sync { + async fn tests_file_response_get(&self, ) -> Result>; + async fn tests_type_testing_get(&self, ) -> Result>; +} + +pub struct TestingApiClient { + configuration: Arc +} + +impl TestingApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl TestingApi for TestingApiClient { + async fn tests_file_response_get(&self, ) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn tests_type_testing_get(&self, ) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + + + +/// struct for typed errors of method [`tests_file_response_get`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum TestsFileResponseGetError { + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`tests_type_testing_get`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum TestsTypeTestingGetError { + UnknownValue(serde_json::Value), +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs new file mode 100644 index 000000000000..12ff8089d649 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs @@ -0,0 +1,391 @@ +/* + * 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 async_trait::async_trait; +use reqwest; +use std::sync::Arc; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + +#[async_trait] +pub trait UserApi: Send + Sync { + async fn create_user(&self, user: models::User) -> Result<(), Error>; + async fn create_users_with_array_input(&self, user: Vec) -> Result<(), Error>; + async fn create_users_with_list_input(&self, user: Vec) -> Result<(), Error>; + async fn delete_user(&self, username: &str) -> Result<(), Error>; + async fn get_user_by_name(&self, username: &str) -> Result>; + async fn login_user(&self, username: &str, password: &str) -> Result>; + async fn logout_user(&self, ) -> Result<(), Error>; + async fn update_user(&self, username: &str, user: models::User) -> Result<(), Error>; +} + +pub struct UserApiClient { + configuration: Arc +} + +impl UserApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} + +#[async_trait] +impl UserApi for UserApiClient { + /// This can only be done by the logged in user. + async fn create_user(&self, user: models::User) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + local_var_req_builder = local_var_req_builder.json(&user); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn create_users_with_array_input(&self, user: Vec) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + local_var_req_builder = local_var_req_builder.json(&user); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn create_users_with_list_input(&self, user: Vec) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + local_var_req_builder = local_var_req_builder.json(&user); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// This can only be done by the logged in user. + async fn delete_user(&self, username: &str) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn get_user_by_name(&self, username: &str) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn login_user(&self, username: &str, password: &str) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); + local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// + async fn logout_user(&self, ) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// This can only be done by the logged in user. + async fn update_user(&self, username: &str, user: models::User) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_apikey) = local_var_configuration.api_key { + let local_var_key = local_var_apikey.key.clone(); + let local_var_value = match local_var_apikey.prefix { + Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), + None => local_var_key, + }; + local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + }; + local_var_req_builder = local_var_req_builder.json(&user); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + + + +/// struct for typed errors of method [`create_user`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateUserError { + DefaultResponse(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`create_users_with_array_input`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateUsersWithArrayInputError { + DefaultResponse(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`create_users_with_list_input`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateUsersWithListInputError { + DefaultResponse(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`delete_user`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteUserError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`get_user_by_name`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetUserByNameError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`login_user`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum LoginUserError { + Status400(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`logout_user`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum LogoutUserError { + DefaultResponse(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`update_user`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateUserError { + Status400(), + Status404(), + UnknownValue(serde_json::Value), +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/lib.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/lib.rs new file mode 100644 index 000000000000..edc482e8f2b7 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/lib.rs @@ -0,0 +1,10 @@ +#![allow(unused_imports)] +#![allow(clippy::too_many_arguments)] + +extern crate serde_repr; +extern crate serde; +extern crate serde_json; +extern crate url; + +pub mod apis; +pub mod models; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/action_container.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/action_container.rs new file mode 100644 index 000000000000..11d2f0b87124 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/action_container.rs @@ -0,0 +1,27 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ActionContainer { + #[serde(rename = "action")] + pub action: Box, +} + +impl ActionContainer { + pub fn new(action: models::Baz) -> ActionContainer { + ActionContainer { + action: Box::new(action), + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/api_response.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/api_response.rs new file mode 100644 index 000000000000..0a60da0f4773 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/api_response.rs @@ -0,0 +1,35 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// ApiResponse : Describes the result of uploading an image resource +#[derive(Clone, Default, 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 r#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, + r#type: None, + message: None, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/array_item_ref_test.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/array_item_ref_test.rs new file mode 100644 index 000000000000..4ac1e8a2fe9c --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/array_item_ref_test.rs @@ -0,0 +1,32 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// ArrayItemRefTest : Test handling of object reference in arrays +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ArrayItemRefTest { + #[serde(rename = "list_with_array_ref")] + pub list_with_array_ref: Vec>, + #[serde(rename = "list_with_object_ref")] + pub list_with_object_ref: Vec>, +} + +impl ArrayItemRefTest { + /// Test handling of object reference in arrays + pub fn new(list_with_array_ref: Vec>, list_with_object_ref: Vec>) -> ArrayItemRefTest { + ArrayItemRefTest { + list_with_array_ref, + list_with_object_ref, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/baz.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/baz.rs new file mode 100644 index 000000000000..17b42c0bd4f0 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/baz.rs @@ -0,0 +1,42 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Baz : Test handling of empty variants +/// Test handling of empty variants +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum Baz { + #[serde(rename = "A")] + A, + #[serde(rename = "B")] + B, + #[serde(rename = "")] + Empty, + +} + +impl std::fmt::Display for Baz { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::A => write!(f, "A"), + Self::B => write!(f, "B"), + Self::Empty => write!(f, ""), + } + } +} + +impl Default for Baz { + fn default() -> Baz { + Self::A + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/category.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/category.rs new file mode 100644 index 000000000000..9ecf89d354d6 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/category.rs @@ -0,0 +1,32 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Category : A category for a pet +#[derive(Clone, Default, 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/reqwest-trait/petstore/src/models/enum_array_testing.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/enum_array_testing.rs new file mode 100644 index 000000000000..2ac40c307756 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/enum_array_testing.rs @@ -0,0 +1,45 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// EnumArrayTesting : Test of enum array +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct EnumArrayTesting { + #[serde(rename = "required_enums")] + pub required_enums: Vec, +} + +impl EnumArrayTesting { + /// Test of enum array + pub fn new(required_enums: Vec) -> EnumArrayTesting { + EnumArrayTesting { + required_enums, + } + } +} +/// +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum RequiredEnums { + #[serde(rename = "A")] + A, + #[serde(rename = "B")] + B, + #[serde(rename = "C")] + C, +} + +impl Default for RequiredEnums { + fn default() -> RequiredEnums { + Self::A + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/mod.rs new file mode 100644 index 000000000000..b7e684d8071d --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/mod.rs @@ -0,0 +1,36 @@ +pub mod action_container; +pub use self::action_container::ActionContainer; +pub mod api_response; +pub use self::api_response::ApiResponse; +pub mod array_item_ref_test; +pub use self::array_item_ref_test::ArrayItemRefTest; +pub mod baz; +pub use self::baz::Baz; +pub mod category; +pub use self::category::Category; +pub mod enum_array_testing; +pub use self::enum_array_testing::EnumArrayTesting; +pub mod nullable_array; +pub use self::nullable_array::NullableArray; +pub mod numeric_enum_testing; +pub use self::numeric_enum_testing::NumericEnumTesting; +pub mod optional_testing; +pub use self::optional_testing::OptionalTesting; +pub mod order; +pub use self::order::Order; +pub mod pet; +pub use self::pet::Pet; +pub mod property_test; +pub use self::property_test::PropertyTest; +pub mod model_ref; +pub use self::model_ref::Ref; +pub mod model_return; +pub use self::model_return::Return; +pub mod tag; +pub use self::tag::Tag; +pub mod type_testing; +pub use self::type_testing::TypeTesting; +pub mod unique_item_array_testing; +pub use self::unique_item_array_testing::UniqueItemArrayTesting; +pub mod user; +pub use self::user::User; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_ref.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_ref.rs new file mode 100644 index 000000000000..9862cb1a48ef --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_ref.rs @@ -0,0 +1,29 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Ref : using reserved word as model name +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Ref { + #[serde(rename = "dummy", skip_serializing_if = "Option::is_none")] + pub dummy: Option, +} + +impl Ref { + /// using reserved word as model name + pub fn new() -> Ref { + Ref { + dummy: None, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_return.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_return.rs new file mode 100644 index 000000000000..07d9268e6e68 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/model_return.rs @@ -0,0 +1,35 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Return : Test using keywords +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Return { + #[serde(rename = "match", skip_serializing_if = "Option::is_none")] + pub r#match: Option, + #[serde(rename = "async", skip_serializing_if = "Option::is_none")] + pub r#async: Option, + #[serde(rename = "super", skip_serializing_if = "Option::is_none")] + pub param_super: Option, +} + +impl Return { + /// Test using keywords + pub fn new() -> Return { + Return { + r#match: None, + r#async: None, + param_super: None, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/nullable_array.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/nullable_array.rs new file mode 100644 index 000000000000..a155ea1176ab --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/nullable_array.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 + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct NullableArray { + #[serde(rename = "array_nullable", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub array_nullable: Option>>, + #[serde(rename = "just_array", skip_serializing_if = "Option::is_none")] + pub just_array: Option>, + #[serde(rename = "nullable_string", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub nullable_string: Option>, + #[serde(rename = "just_string", skip_serializing_if = "Option::is_none")] + pub just_string: Option, +} + +impl NullableArray { + pub fn new() -> NullableArray { + NullableArray { + array_nullable: None, + just_array: None, + nullable_string: None, + just_string: None, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/numeric_enum_testing.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/numeric_enum_testing.rs new file mode 100644 index 000000000000..e3681aa61778 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/numeric_enum_testing.rs @@ -0,0 +1,42 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +use serde_repr::{Serialize_repr,Deserialize_repr}; +/// NumericEnumTesting : testing that numeric enums are converted correctly +/// testing that numeric enums are converted correctly +#[repr(i64)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)] +pub enum NumericEnumTesting { + Variant0 = 0, + Variant1 = 1, + Variant2 = 2, + Variant3 = 3, + +} + +impl std::fmt::Display for NumericEnumTesting { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Variant0 => "0", + Self::Variant1 => "1", + Self::Variant2 => "2", + Self::Variant3 => "3", + }) + } +} +impl Default for NumericEnumTesting { + fn default() -> NumericEnumTesting { + Self::Variant0 + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/optional_testing.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/optional_testing.rs new file mode 100644 index 000000000000..72e5a009a623 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/optional_testing.rs @@ -0,0 +1,38 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// OptionalTesting : Test handling of optional and nullable fields +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct OptionalTesting { + #[serde(rename = "optional_nonnull", skip_serializing_if = "Option::is_none")] + pub optional_nonnull: Option, + #[serde(rename = "required_nonnull")] + pub required_nonnull: String, + #[serde(rename = "optional_nullable", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub optional_nullable: Option>, + #[serde(rename = "required_nullable", deserialize_with = "Option::deserialize")] + pub required_nullable: Option, +} + +impl OptionalTesting { + /// Test handling of optional and nullable fields + pub fn new(required_nonnull: String, required_nullable: Option) -> OptionalTesting { + OptionalTesting { + optional_nonnull: None, + required_nonnull, + optional_nullable: None, + required_nullable, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/order.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/order.rs new file mode 100644 index 000000000000..a66e7dbb5689 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/order.rs @@ -0,0 +1,61 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Order : An order for a pets from the pet store +#[derive(Clone, Default, 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(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "placed")] + Placed, + #[serde(rename = "approved")] + Approved, + #[serde(rename = "delivered")] + shipped, +} + +impl Default for Status { + fn default() -> Status { + Self::Placed + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/pet.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/pet.rs new file mode 100644 index 000000000000..785fb5390bed --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/pet.rs @@ -0,0 +1,61 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Pet : A pet for sale in the pet store +#[derive(Clone, Default, 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(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "available")] + Available, + #[serde(rename = "pending")] + Pending, + #[serde(rename = "sold")] + Sold, +} + +impl Default for Status { + fn default() -> Status { + Self::Available + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/property_test.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/property_test.rs new file mode 100644 index 000000000000..c98e7c762b58 --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/property_test.rs @@ -0,0 +1,29 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// PropertyTest : A model to test various formats, e.g. UUID +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct PropertyTest { + #[serde(rename = "uuid", skip_serializing_if = "Option::is_none")] + pub uuid: Option, +} + +impl PropertyTest { + /// A model to test various formats, e.g. UUID + pub fn new() -> PropertyTest { + PropertyTest { + uuid: None, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/tag.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/tag.rs new file mode 100644 index 000000000000..8fe4eebd723b --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/tag.rs @@ -0,0 +1,32 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// Tag : A tag for a pet +#[derive(Clone, Default, 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/reqwest-trait/petstore/src/models/type_testing.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/type_testing.rs new file mode 100644 index 000000000000..dba87bdb3cfd --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/type_testing.rs @@ -0,0 +1,54 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +use serde_with::serde_as; + +/// TypeTesting : Test handling of different field data types +#[serde_as] +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct TypeTesting { + #[serde(rename = "int32")] + pub int32: i32, + #[serde(rename = "int64")] + pub int64: i64, + #[serde(rename = "float")] + pub float: f32, + #[serde(rename = "double")] + pub double: f64, + #[serde(rename = "string")] + pub string: String, + #[serde(rename = "boolean")] + pub boolean: bool, + #[serde(rename = "uuid")] + pub uuid: uuid::Uuid, + #[serde_as(as = "serde_with::base64::Base64")] + #[serde(rename = "bytes")] + pub bytes: Vec, +} + +impl TypeTesting { + /// Test handling of different field data types + pub fn new(int32: i32, int64: i64, float: f32, double: f64, string: String, boolean: bool, uuid: uuid::Uuid, bytes: Vec) -> TypeTesting { + TypeTesting { + int32, + int64, + float, + double, + string, + boolean, + uuid, + bytes, + } + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/unique_item_array_testing.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/unique_item_array_testing.rs new file mode 100644 index 000000000000..2a1f18ca9cee --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/unique_item_array_testing.rs @@ -0,0 +1,46 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// UniqueItemArrayTesting : Test handling of enum array with unique items +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct UniqueItemArrayTesting { + /// Helper object for the unique item array test + #[serde(rename = "unique_item_array")] + pub unique_item_array: std::collections::HashSet, +} + +impl UniqueItemArrayTesting { + /// Test handling of enum array with unique items + pub fn new(unique_item_array: std::collections::HashSet) -> UniqueItemArrayTesting { + UniqueItemArrayTesting { + unique_item_array, + } + } +} +/// Helper object for the unique item array test +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum UniqueItemArray { + #[serde(rename = "unique_item_1")] + Variant1, + #[serde(rename = "unique_item_2")] + Variant2, + #[serde(rename = "unique_item_3")] + Variant3, +} + +impl Default for UniqueItemArray { + fn default() -> UniqueItemArray { + Self::Variant1 + } +} + diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/models/user.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/user.rs new file mode 100644 index 000000000000..c88c469a4ebe --- /dev/null +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/models/user.rs @@ -0,0 +1,51 @@ +/* + * 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 crate::models; +use serde::{Deserialize, Serialize}; + +/// User : A User who is purchasing from the pet store +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct User { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "username")] + pub username: String, + #[serde(rename = "firstName", skip_serializing_if = "Option::is_none")] + pub first_name: Option, + #[serde(rename = "lastName")] + pub last_name: String, + #[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(username: String, last_name: String) -> User { + User { + id: None, + username, + first_name: None, + last_name, + email: None, + password: None, + phone: None, + user_status: None, + } + } +} + From 25026763f50f2615d94fc914485d221347897e1a Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Sun, 6 Oct 2024 14:37:54 +0900 Subject: [PATCH 2/7] Fixed Cargo imports for reqwest trait template --- .../src/main/resources/rust/Cargo.mustache | 10 ++++++++-- .../petstore/rust/reqwest-trait/petstore/Cargo.toml | 1 + .../rust/reqwest-trait/petstore/src/apis/mod.rs | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 02fd09bd1b31..093113661c14 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -72,9 +72,7 @@ reqwest = { version = "^0.12", features = ["json", "multipart"] } reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } {{/supportMiddleware}} {{#supportTokenSource}} -{{^reqwestTrait}} async-trait = "^0.1" -{{/reqwestTrait}} # TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. google-cloud-token = "^0.1" {{/supportTokenSource}} @@ -82,4 +80,12 @@ google-cloud-token = "^0.1" {{/reqwest}} {{#reqwestTrait}} async-trait = "^0.1" +reqwest = { version = "^0.12", features = ["json", "multipart"] } +{{#supportMiddleware}} +reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } +{{/supportMiddleware}} +{{#supportTokenSource}} +# TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. +google-cloud-token = "^0.1" +{{/supportTokenSource}} {{/reqwestTrait}} diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml index f129252521bc..c3b2ea616cdd 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml @@ -14,3 +14,4 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } async-trait = "^0.1" +reqwest = { version = "^0.12", features = ["json", "multipart"] } diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs index 698ecf95b91f..3e523e7e9ded 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -100,7 +100,7 @@ pub mod configuration; use std::sync::Arc; -trait Api { +pub trait Api { fn fake_api(&self) -> &dyn fake_api::FakeApi; fn pet_api(&self) -> &dyn pet_api::PetApi; fn store_api(&self) -> &dyn store_api::StoreApi; From 0d29c47a140a87924151837c1b416e99dae33483 Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Sun, 6 Oct 2024 16:33:48 +0900 Subject: [PATCH 3/7] Added support for mockall to Rust reqwest trait library --- bin/configs/rust-reqwest-trait-petstore.yaml | 1 + docs/generators/rust.md | 9 +-- .../codegen/languages/RustClientCodegen.java | 65 +++++++++++++------ .../src/main/resources/rust/Cargo.mustache | 8 +++ .../resources/rust/reqwest-trait/api.mustache | 23 +++---- .../rust/hyper/api-with-ref-param/Cargo.toml | 2 + .../rust/hyper/composed-oneof/Cargo.toml | 2 + .../others/rust/hyper/emptyObject/Cargo.toml | 2 + .../rust/hyper/oneOf-array-map/Cargo.toml | 2 + .../rust/hyper/oneOf-reuseRef/Cargo.toml | 2 + .../client/others/rust/hyper/oneOf/Cargo.toml | 2 + .../rust/reqwest-regression-16119/Cargo.toml | 2 + .../reqwest/api-with-ref-param/Cargo.toml | 2 + .../rust/reqwest/composed-oneof/Cargo.toml | 2 + .../rust/reqwest/emptyObject/Cargo.toml | 2 + .../rust/reqwest/oneOf-array-map/Cargo.toml | 2 + .../rust/reqwest/oneOf-reuseRef/Cargo.toml | 2 + .../others/rust/reqwest/oneOf/Cargo.toml | 2 + .../petstore/rust/hyper/petstore/Cargo.toml | 2 + .../petstore/rust/hyper0x/petstore/Cargo.toml | 2 + .../rust/reqwest-trait/petstore/Cargo.toml | 4 ++ .../petstore/src/apis/fake_api.rs | 7 +- .../petstore/src/apis/pet_api.rs | 35 +++++----- .../petstore/src/apis/store_api.rs | 19 +++--- .../petstore/src/apis/testing_api.rs | 11 ++-- .../petstore/src/apis/user_api.rs | 35 +++++----- .../rust/reqwest/name-mapping/Cargo.toml | 2 + .../petstore-async-middleware/Cargo.toml | 2 + .../petstore-async-tokensource/Cargo.toml | 2 + .../rust/reqwest/petstore-async/Cargo.toml | 2 + .../reqwest/petstore-avoid-box/Cargo.toml | 2 + .../petstore-awsv4signature/Cargo.toml | 2 + .../petstore/rust/reqwest/petstore/Cargo.toml | 2 + 33 files changed, 178 insertions(+), 83 deletions(-) diff --git a/bin/configs/rust-reqwest-trait-petstore.yaml b/bin/configs/rust-reqwest-trait-petstore.yaml index 1aef6449ccb3..30190bf0c46e 100644 --- a/bin/configs/rust-reqwest-trait-petstore.yaml +++ b/bin/configs/rust-reqwest-trait-petstore.yaml @@ -6,5 +6,6 @@ templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: topLevelApiClient: true packageName: petstore-reqwest + mockall: true enumNameMappings: delivered: shipped diff --git a/docs/generators/rust.md b/docs/generators/rust.md index ccd1e9ce4134..3b72bcbadb40 100644 --- a/docs/generators/rust.md +++ b/docs/generators/rust.md @@ -22,14 +22,15 @@ These options may be applied as additional-properties (cli) or configOptions (pl |bestFitInt|Use best fitting integer type where minimum or maximum is set| |false| |enumNameSuffix|Suffix that will be appended to all enum names.| || |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| -|library|library template (sub-template) to use.|
**hyper**
HTTP client: Hyper (v1.x).
**hyper0x**
HTTP client: Hyper (v0.x).
**reqwest**
HTTP client: Reqwest.
|reqwest| +|library|library template (sub-template) to use.|
**hyper**
HTTP client: Hyper (v1.x).
**hyper0x**
HTTP client: Hyper (v0.x).
**reqwest**
HTTP client: Reqwest.
**reqwest-trait**
HTTP client: Reqwest (trait based).
|reqwest| +|mockall|Adds `#[automock]` from the mockall crate to api traits. This option is for 'reqwest-trait' library only| |false| |packageName|Rust package name (convention: lowercase).| |openapi| |packageVersion|Rust package version.| |1.0.0| |preferUnsignedInt|Prefer unsigned integers where minimum value is >= 0| |false| |supportAsync|If set, generate async function call instead. This option is for 'reqwest' library only| |true| -|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' library only| |false| -|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' library only| |false| -|supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' library only and requires the 'supportAsync' option| |false| +|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only| |false| +|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false| +|supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option| |false| |useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false| |withAWSV4Signature|whether to include AWS v4 signature support| |false| 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 f2763248247f..5ec7c7e5fc8c 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 @@ -17,15 +17,37 @@ package org.openapitools.codegen.languages; -import com.samskivert.mustache.Mustache; -import com.samskivert.mustache.Template; -import io.swagger.v3.oas.models.media.*; -import io.swagger.v3.parser.util.SchemaTypeUtil; -import joptsimple.internal.Strings; -import lombok.AccessLevel; -import lombok.Setter; -import org.openapitools.codegen.*; -import org.openapitools.codegen.meta.features.*; +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConfig; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.CodegenType; +import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.meta.features.ClientModificationFeature; +import org.openapitools.codegen.meta.features.DocumentationFeature; +import org.openapitools.codegen.meta.features.GlobalFeature; +import org.openapitools.codegen.meta.features.ParameterFeature; +import org.openapitools.codegen.meta.features.SchemaSupportFeature; +import org.openapitools.codegen.meta.features.SecurityFeature; +import org.openapitools.codegen.meta.features.WireFormatFeature; import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.OperationMap; @@ -35,13 +57,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import java.util.stream.Collectors; +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; + +import io.swagger.v3.oas.models.media.Discriminator; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.parser.util.SchemaTypeUtil; +import joptsimple.internal.Strings; +import lombok.AccessLevel; +import lombok.Setter; public class RustClientCodegen extends AbstractRustCodegen implements CodegenConfig { private final Logger LOGGER = LoggerFactory.getLogger(RustClientCodegen.class); @@ -70,6 +94,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon public static final String PREFER_UNSIGNED_INT = "preferUnsignedInt"; public static final String BEST_FIT_INT = "bestFitInt"; public static final String AVOID_BOXED_MODELS = "avoidBoxedModels"; + public static final String MOCKALL = "mockall"; @Setter protected String packageName = "openapi"; @Setter protected String packageVersion = "1.0.0"; @@ -194,11 +219,11 @@ public RustClientCodegen() { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(SUPPORT_ASYNC, "If set, generate async function call instead. This option is for 'reqwest' library only", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.TRUE.toString())); - cliOptions.add(new CliOption(SUPPORT_MIDDLEWARE, "If set, add support for reqwest-middleware. This option is for 'reqwest' library only", SchemaTypeUtil.BOOLEAN_TYPE) + cliOptions.add(new CliOption(SUPPORT_MIDDLEWARE, "If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); - cliOptions.add(new CliOption(SUPPORT_TOKEN_SOURCE, "If set, add support for google-cloud-token. This option is for 'reqwest' library only and requires the 'supportAsync' option", SchemaTypeUtil.BOOLEAN_TYPE) + cliOptions.add(new CliOption(SUPPORT_TOKEN_SOURCE, "If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); - cliOptions.add(new CliOption(SUPPORT_MULTIPLE_RESPONSES, "If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' library only", SchemaTypeUtil.BOOLEAN_TYPE) + cliOptions.add(new CliOption(SUPPORT_MULTIPLE_RESPONSES, "If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, CodegenConstants.ENUM_NAME_SUFFIX_DESC).defaultValue(this.enumSuffix)); cliOptions.add(new CliOption(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT, CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT_DESC, SchemaTypeUtil.BOOLEAN_TYPE) @@ -209,6 +234,8 @@ public RustClientCodegen() { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(AVOID_BOXED_MODELS, "If set, `Box` will not be used for models", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); + cliOptions.add(new CliOption(MOCKALL, "Adds `#[automock]` from the mockall crate to api traits. This option is for 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) + .defaultValue(Boolean.FALSE.toString())); supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x)."); supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x)."); diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 093113661c14..64bb630b1f0b 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -88,4 +88,12 @@ reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } # TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. google-cloud-token = "^0.1" {{/supportTokenSource}} +{{#mockall}} +mockall = { version = "^0.13", optional = true} +{{/mockall}} {{/reqwestTrait}} + +[features] +{{#mockall}} +mockall = ["dep:mockall"] +{{/mockall}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache index 4997f1e2800f..aa4bc7ab1d98 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache @@ -1,17 +1,24 @@ {{>partial_header}} use async_trait::async_trait; +{{#mockall}} +#[cfg(feature = "mockall")] +use mockall::automock; +{{/mockall}} use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +{{#mockall}} +#[cfg_attr(feature = "mockall", automock)] +{{/mockall}} #[async_trait] pub trait {{{classname}}}: Send + Sync { {{#operations}} {{#operation}} - async fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>; + async fn {{{operationId}}}<{{#allParams}}'{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}>(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{{paramName}}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>; {{/operation}} {{/operations}} } @@ -36,20 +43,8 @@ impl {{classname}} for {{classname}}Client { {{#notes}} /// {{{.}}} {{/notes}} - {{#vendorExtensions.x-group-parameters}} - async fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { - let local_var_configuration = configuration; - - // unbox the parameters - {{#allParams}} - let {{paramName}} = params.{{paramName}}; - {{/allParams}} - - {{/vendorExtensions.x-group-parameters}} - {{^vendorExtensions.x-group-parameters}} - async fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { + async fn {{{operationId}}}<{{#allParams}}'{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}>(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{{paramName}}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { let local_var_configuration = &self.configuration; - {{/vendorExtensions.x-group-parameters}} let local_var_client = &local_var_configuration.client; diff --git a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml index 00f46b1c7d3c..313daabf9e4a 100644 --- a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml index 4c0a00557c55..5f901d74f958 100644 --- a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/hyper/emptyObject/Cargo.toml b/samples/client/others/rust/hyper/emptyObject/Cargo.toml index 1efb624b65df..ae06393da67d 100644 --- a/samples/client/others/rust/hyper/emptyObject/Cargo.toml +++ b/samples/client/others/rust/hyper/emptyObject/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml index 1bb7aa7bb54d..037e0075253d 100644 --- a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml index 07b8f6cf6d8c..e2c446ec876d 100644 --- a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml @@ -18,3 +18,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/hyper/oneOf/Cargo.toml b/samples/client/others/rust/hyper/oneOf/Cargo.toml index fb78d69e9100..911c62903d07 100644 --- a/samples/client/others/rust/hyper/oneOf/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml index a1e41446d882..f1d92fa4707a 100644 --- a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml +++ b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml index e4edc99b719c..349ff48f768f 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml index f06effdcb109..e9e4276a4006 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml index d35bad9e88dd..acd996e1773c 100644 --- a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml +++ b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml index 5f2d99d18047..b38ed2cfd053 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml index 64b0d4bf92f2..36f06c25a75c 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml @@ -13,3 +13,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/others/rust/reqwest/oneOf/Cargo.toml b/samples/client/others/rust/reqwest/oneOf/Cargo.toml index 8966bd1292c5..b855ad7e95ed 100644 --- a/samples/client/others/rust/reqwest/oneOf/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/hyper/petstore/Cargo.toml b/samples/client/petstore/rust/hyper/petstore/Cargo.toml index a9eedf18dea5..d6a59606c646 100644 --- a/samples/client/petstore/rust/hyper/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper/petstore/Cargo.toml @@ -19,3 +19,5 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml b/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml index a1b39ea2340f..cb8e5dda9b45 100644 --- a/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml @@ -18,3 +18,5 @@ hyper-tls = "~0.5" http = "~0.2" base64 = "~0.7.0" futures = "^0.3" + +[features] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml index c3b2ea616cdd..02321d0a144b 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml @@ -15,3 +15,7 @@ url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } async-trait = "^0.1" reqwest = { version = "^0.12", features = ["json", "multipart"] } +mockall = { version = "^0.13", optional = true} + +[features] +mockall = ["dep:mockall"] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs index 201860b2f72d..04f4462b3c0b 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -10,15 +10,18 @@ use async_trait::async_trait; +#[cfg(feature = "mockall")] +use mockall::automock; use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +#[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait FakeApi: Send + Sync { - async fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error>; + async fn test_nullable_required_param<'username, 'dummy_required_nullable_param, 'uppercase>(&self, username: &'username str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>) -> Result<(), Error>; } pub struct FakeApiClient { @@ -34,7 +37,7 @@ impl FakeApiClient { #[async_trait] impl FakeApi for FakeApiClient { /// - async fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error> { + async fn test_nullable_required_param<'username, 'dummy_required_nullable_param, 'uppercase>(&self, username: &'username str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs index cc52f67e429d..ada787a79b8a 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs @@ -10,22 +10,25 @@ use async_trait::async_trait; +#[cfg(feature = "mockall")] +use mockall::automock; use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +#[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait PetApi: Send + Sync { - async fn add_pet(&self, pet: models::Pet) -> Result>; - async fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Result<(), Error>; - async fn find_pets_by_status(&self, status: Vec) -> Result, Error>; - async fn find_pets_by_tags(&self, tags: Vec) -> Result, Error>; - async fn get_pet_by_id(&self, pet_id: i64) -> Result>; - async fn update_pet(&self, pet: models::Pet) -> Result>; - async fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error>; - async fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result>; + async fn add_pet<'pet>(&self, pet: models::Pet) -> Result>; + async fn delete_pet<'pet_id, 'api_key>(&self, pet_id: i64, api_key: Option<&'api_key str>) -> Result<(), Error>; + async fn find_pets_by_status<'status>(&self, status: Vec) -> Result, Error>; + async fn find_pets_by_tags<'tags>(&self, tags: Vec) -> Result, Error>; + async fn get_pet_by_id<'pet_id>(&self, pet_id: i64) -> Result>; + async fn update_pet<'pet>(&self, pet: models::Pet) -> Result>; + async fn update_pet_with_form<'pet_id, 'name, 'status>(&self, pet_id: i64, name: Option<&'name str>, status: Option<&'status str>) -> Result<(), Error>; + async fn upload_file<'pet_id, 'additional_metadata, 'file>(&self, pet_id: i64, additional_metadata: Option<&'additional_metadata str>, file: Option) -> Result>; } pub struct PetApiClient { @@ -41,7 +44,7 @@ impl PetApiClient { #[async_trait] impl PetApi for PetApiClient { /// - async fn add_pet(&self, pet: models::Pet) -> Result> { + async fn add_pet<'pet>(&self, pet: models::Pet) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -73,7 +76,7 @@ impl PetApi for PetApiClient { } /// - async fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { + async fn delete_pet<'pet_id, 'api_key>(&self, pet_id: i64, api_key: Option<&'api_key str>) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -107,7 +110,7 @@ impl PetApi for PetApiClient { } /// Multiple status values can be provided with comma separated strings - async fn find_pets_by_status(&self, status: Vec) -> Result, Error> { + async fn find_pets_by_status<'status>(&self, status: Vec) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -142,7 +145,7 @@ impl PetApi for PetApiClient { } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - async fn find_pets_by_tags(&self, tags: Vec) -> Result, Error> { + async fn find_pets_by_tags<'tags>(&self, tags: Vec) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -177,7 +180,7 @@ impl PetApi for PetApiClient { } /// Returns a single pet - async fn get_pet_by_id(&self, pet_id: i64) -> Result> { + async fn get_pet_by_id<'pet_id>(&self, pet_id: i64) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -213,7 +216,7 @@ impl PetApi for PetApiClient { } /// - async fn update_pet(&self, pet: models::Pet) -> Result> { + async fn update_pet<'pet>(&self, pet: models::Pet) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -245,7 +248,7 @@ impl PetApi for PetApiClient { } /// - async fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { + async fn update_pet_with_form<'pet_id, 'name, 'status>(&self, pet_id: i64, name: Option<&'name str>, status: Option<&'status str>) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -284,7 +287,7 @@ impl PetApi for PetApiClient { } /// - async fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result> { + async fn upload_file<'pet_id, 'additional_metadata, 'file>(&self, pet_id: i64, additional_metadata: Option<&'additional_metadata str>, file: Option) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs index 943d1026d721..ed86d9d7e422 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs @@ -10,18 +10,21 @@ use async_trait::async_trait; +#[cfg(feature = "mockall")] +use mockall::automock; use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +#[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait StoreApi: Send + Sync { - async fn delete_order(&self, order_id: &str) -> Result<(), Error>; - async fn get_inventory(&self, ) -> Result, Error>; - async fn get_order_by_id(&self, order_id: i64) -> Result>; - async fn place_order(&self, order: models::Order) -> Result>; + async fn delete_order<'order_id>(&self, order_id: &'order_id str) -> Result<(), Error>; + async fn get_inventory<>(&self, ) -> Result, Error>; + async fn get_order_by_id<'order_id>(&self, order_id: i64) -> Result>; + async fn place_order<'order>(&self, order: models::Order) -> Result>; } pub struct StoreApiClient { @@ -37,7 +40,7 @@ impl StoreApiClient { #[async_trait] impl StoreApi for StoreApiClient { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - async fn delete_order(&self, order_id: &str) -> Result<(), Error> { + async fn delete_order<'order_id>(&self, order_id: &'order_id str) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -65,7 +68,7 @@ impl StoreApi for StoreApiClient { } /// Returns a map of status codes to quantities - async fn get_inventory(&self, ) -> Result, Error> { + async fn get_inventory<>(&self, ) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -101,7 +104,7 @@ impl StoreApi for StoreApiClient { } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions - async fn get_order_by_id(&self, order_id: i64) -> Result> { + async fn get_order_by_id<'order_id>(&self, order_id: i64) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -129,7 +132,7 @@ impl StoreApi for StoreApiClient { } /// - async fn place_order(&self, order: models::Order) -> Result> { + async fn place_order<'order>(&self, order: models::Order) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs index dad8b66ec7c7..603bea112cf0 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs @@ -10,16 +10,19 @@ use async_trait::async_trait; +#[cfg(feature = "mockall")] +use mockall::automock; use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +#[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait TestingApi: Send + Sync { - async fn tests_file_response_get(&self, ) -> Result>; - async fn tests_type_testing_get(&self, ) -> Result>; + async fn tests_file_response_get<>(&self, ) -> Result>; + async fn tests_type_testing_get<>(&self, ) -> Result>; } pub struct TestingApiClient { @@ -34,7 +37,7 @@ impl TestingApiClient { #[async_trait] impl TestingApi for TestingApiClient { - async fn tests_file_response_get(&self, ) -> Result> { + async fn tests_file_response_get<>(&self, ) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -61,7 +64,7 @@ impl TestingApi for TestingApiClient { } } - async fn tests_type_testing_get(&self, ) -> Result> { + async fn tests_type_testing_get<>(&self, ) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs index 12ff8089d649..a93bd6185565 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs @@ -10,22 +10,25 @@ use async_trait::async_trait; +#[cfg(feature = "mockall")] +use mockall::automock; use reqwest; use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +#[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait UserApi: Send + Sync { - async fn create_user(&self, user: models::User) -> Result<(), Error>; - async fn create_users_with_array_input(&self, user: Vec) -> Result<(), Error>; - async fn create_users_with_list_input(&self, user: Vec) -> Result<(), Error>; - async fn delete_user(&self, username: &str) -> Result<(), Error>; - async fn get_user_by_name(&self, username: &str) -> Result>; - async fn login_user(&self, username: &str, password: &str) -> Result>; - async fn logout_user(&self, ) -> Result<(), Error>; - async fn update_user(&self, username: &str, user: models::User) -> Result<(), Error>; + async fn create_user<'user>(&self, user: models::User) -> Result<(), Error>; + async fn create_users_with_array_input<'user>(&self, user: Vec) -> Result<(), Error>; + async fn create_users_with_list_input<'user>(&self, user: Vec) -> Result<(), Error>; + async fn delete_user<'username>(&self, username: &'username str) -> Result<(), Error>; + async fn get_user_by_name<'username>(&self, username: &'username str) -> Result>; + async fn login_user<'username, 'password>(&self, username: &'username str, password: &'password str) -> Result>; + async fn logout_user<>(&self, ) -> Result<(), Error>; + async fn update_user<'username, 'user>(&self, username: &'username str, user: models::User) -> Result<(), Error>; } pub struct UserApiClient { @@ -41,7 +44,7 @@ impl UserApiClient { #[async_trait] impl UserApi for UserApiClient { /// This can only be done by the logged in user. - async fn create_user(&self, user: models::User) -> Result<(), Error> { + async fn create_user<'user>(&self, user: models::User) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -78,7 +81,7 @@ impl UserApi for UserApiClient { } /// - async fn create_users_with_array_input(&self, user: Vec) -> Result<(), Error> { + async fn create_users_with_array_input<'user>(&self, user: Vec) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -115,7 +118,7 @@ impl UserApi for UserApiClient { } /// - async fn create_users_with_list_input(&self, user: Vec) -> Result<(), Error> { + async fn create_users_with_list_input<'user>(&self, user: Vec) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -152,7 +155,7 @@ impl UserApi for UserApiClient { } /// This can only be done by the logged in user. - async fn delete_user(&self, username: &str) -> Result<(), Error> { + async fn delete_user<'username>(&self, username: &'username str) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -188,7 +191,7 @@ impl UserApi for UserApiClient { } /// - async fn get_user_by_name(&self, username: &str) -> Result> { + async fn get_user_by_name<'username>(&self, username: &'username str) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -216,7 +219,7 @@ impl UserApi for UserApiClient { } /// - async fn login_user(&self, username: &str, password: &str) -> Result> { + async fn login_user<'username, 'password>(&self, username: &'username str, password: &'password str) -> Result> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -246,7 +249,7 @@ impl UserApi for UserApiClient { } /// - async fn logout_user(&self, ) -> Result<(), Error> { + async fn logout_user<>(&self, ) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -282,7 +285,7 @@ impl UserApi for UserApiClient { } /// This can only be done by the logged in user. - async fn update_user(&self, username: &str, user: models::User) -> Result<(), Error> { + async fn update_user<'username, 'user>(&self, username: &'username str, user: models::User) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; diff --git a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml index 172f74f4e1ff..9110c4e12a44 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml @@ -13,3 +13,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml index 2bbf314d7e82..9afd6b9fe452 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml @@ -15,3 +15,5 @@ url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml index 811475c96e17..018384a55fa4 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml @@ -17,3 +17,5 @@ reqwest = { version = "^0.12", features = ["json", "multipart"] } async-trait = "^0.1" # TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. google-cloud-token = "^0.1" + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml index 3803423fe927..19ecb7012106 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml index a3312a3a7eef..170654ea06f9 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml index d5a2bac56a2a..95bd36547b0d 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml @@ -17,3 +17,5 @@ aws-sigv4 = "0.3.0" http = "0.2.5" secrecy = "0.8.0" reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] diff --git a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml index 0dd7e9149413..a0e486ff4f4a 100644 --- a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml @@ -14,3 +14,5 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } + +[features] From 7e2f2d7433f6f40faed3d660837e00c12be7382a Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Sun, 6 Oct 2024 16:57:22 +0900 Subject: [PATCH 4/7] Added MockApiClient when mockall and topLevelClient are enabled --- .../rust/reqwest-trait/api_mod.mustache | 34 ++++++++++++++++ .../reqwest-trait/petstore/src/apis/mod.rs | 40 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache index 6089916916b8..c693585870fb 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache @@ -175,7 +175,41 @@ impl Api for ApiClient { } {{/apis}} {{/apiInfo}} +} + +{{#mockall}} +#[cfg(feature = "mockall")] +pub struct MockApiClient { + {{#apiInfo}} + {{#apis}} + pub {{{classFilename}}}_mock: {{{classFilename}}}::Mock{{classname}}, + {{/apis}} + {{/apiInfo}} +} + +#[cfg(feature = "mockall")] +impl MockApiClient { + pub fn new() -> Self { + Self { + {{#apiInfo}} + {{#apis}} + {{{classFilename}}}_mock: {{{classFilename}}}::Mock{{classname}}::new(), + {{/apis}} + {{/apiInfo}} + } + } +} +#[cfg(feature = "mockall")] +impl Api for MockApiClient { + {{#apiInfo}} + {{#apis}} + fn {{{classFilename}}}(&self) -> &dyn {{{classFilename}}}::{{classname}} { + &self.{{{classFilename}}}_mock + } + {{/apis}} + {{/apiInfo}} } +{{/mockall}} {{/topLevelApiClient}} diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs index 3e523e7e9ded..ba670264380c 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -144,6 +144,46 @@ impl Api for ApiClient { fn user_api(&self) -> &dyn user_api::UserApi { self.user_api.as_ref() } +} + +#[cfg(feature = "mockall")] +pub struct MockApiClient { + pub fake_api_mock: fake_api::MockFakeApi, + pub pet_api_mock: pet_api::MockPetApi, + pub store_api_mock: store_api::MockStoreApi, + pub testing_api_mock: testing_api::MockTestingApi, + pub user_api_mock: user_api::MockUserApi, +} +#[cfg(feature = "mockall")] +impl MockApiClient { + pub fn new() -> Self { + Self { + fake_api_mock: fake_api::MockFakeApi::new(), + pet_api_mock: pet_api::MockPetApi::new(), + store_api_mock: store_api::MockStoreApi::new(), + testing_api_mock: testing_api::MockTestingApi::new(), + user_api_mock: user_api::MockUserApi::new(), + } + } +} + +#[cfg(feature = "mockall")] +impl Api for MockApiClient { + fn fake_api(&self) -> &dyn fake_api::FakeApi { + &self.fake_api_mock + } + fn pet_api(&self) -> &dyn pet_api::PetApi { + &self.pet_api_mock + } + fn store_api(&self) -> &dyn store_api::StoreApi { + &self.store_api_mock + } + fn testing_api(&self) -> &dyn testing_api::TestingApi { + &self.testing_api_mock + } + fn user_api(&self) -> &dyn user_api::UserApi { + &self.user_api_mock + } } From f96453ee54169f737f899cc770c8053d72f51490 Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Sun, 6 Oct 2024 17:18:37 +0900 Subject: [PATCH 5/7] Added missing flags to Rust generator documentation --- docs/generators/rust.md | 1 + .../org/openapitools/codegen/languages/RustClientCodegen.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/generators/rust.md b/docs/generators/rust.md index 3b72bcbadb40..96170e2bc0f5 100644 --- a/docs/generators/rust.md +++ b/docs/generators/rust.md @@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only| |false| |supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false| |supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option| |false| +|topLevelApiClient|Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only| |false| |useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false| |withAWSV4Signature|whether to include AWS v4 signature support| |false| 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 5ec7c7e5fc8c..fc3ecfdc9998 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 @@ -94,6 +94,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon public static final String PREFER_UNSIGNED_INT = "preferUnsignedInt"; public static final String BEST_FIT_INT = "bestFitInt"; public static final String AVOID_BOXED_MODELS = "avoidBoxedModels"; + public static final String TOP_LEVEL_API_CLIENT = "topLevelApiClient"; public static final String MOCKALL = "mockall"; @Setter protected String packageName = "openapi"; @@ -236,6 +237,8 @@ public RustClientCodegen() { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(MOCKALL, "Adds `#[automock]` from the mockall crate to api traits. This option is for 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); + cliOptions.add(new CliOption(TOP_LEVEL_API_CLIENT, "Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) + .defaultValue(Boolean.FALSE.toString())); supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x)."); supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x)."); From e244ec68259ef5f494163052556c39d88f51d6fe Mon Sep 17 00:00:00 2001 From: Troy Benson Date: Fri, 18 Oct 2024 18:28:26 +0000 Subject: [PATCH 6/7] feat: add support for single argument and bon builder Adds support for single argument and bon building for the new reqwest-trait generator --- .../codegen/languages/RustClientCodegen.java | 3 + .../src/main/resources/rust/Cargo.mustache | 11 ++- .../resources/rust/reqwest-trait/api.mustache | 67 ++++++++++++------- 3 files changed, 55 insertions(+), 26 deletions(-) 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 fc3ecfdc9998..7cac8cecbde8 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 @@ -96,6 +96,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon public static final String AVOID_BOXED_MODELS = "avoidBoxedModels"; public static final String TOP_LEVEL_API_CLIENT = "topLevelApiClient"; public static final String MOCKALL = "mockall"; + public static final String BON_BUILDER = "useBonBuilder"; @Setter protected String packageName = "openapi"; @Setter protected String packageVersion = "1.0.0"; @@ -239,6 +240,8 @@ public RustClientCodegen() { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(TOP_LEVEL_API_CLIENT, "Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) .defaultValue(Boolean.FALSE.toString())); + cliOptions.add(new CliOption(BON_BUILDER, "Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE) + .defaultValue(Boolean.FALSE.toString())); supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x)."); supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x)."); diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 64bb630b1f0b..17fb2735a998 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -91,9 +91,14 @@ google-cloud-token = "^0.1" {{#mockall}} mockall = { version = "^0.13", optional = true} {{/mockall}} -{{/reqwestTrait}} - +{{#useBonBuilder}} +bon = { version = "2.3", optional = true } +{{/useBonBuilder}} [features] {{#mockall}} mockall = ["dep:mockall"] -{{/mockall}} \ No newline at end of file +{{/mockall}} +{{#useBonBuilder}} +bon = ["dep:bon"] +{{/useBonBuilder}} +{{/reqwestTrait}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache index aa4bc7ab1d98..d3569d622b43 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache @@ -18,7 +18,12 @@ use super::{Error, configuration}; pub trait {{{classname}}}: Send + Sync { {{#operations}} {{#operation}} +{{#vendorExtensions.x-group-parameters}} + async fn {{{operationId}}}(&self, {{#allParams}}{{#-first}} params: {{{operationIdCamelCase}}}Params {{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>; +{{/vendorExtensions.x-group-parameters}} +{{^vendorExtensions.x-group-parameters}} async fn {{{operationId}}}<{{#allParams}}'{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}>(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{{paramName}}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>>; +{{/vendorExtensions.x-group-parameters}} {{/operation}} {{/operations}} } @@ -33,6 +38,32 @@ impl {{classname}}Client { } } + +{{#operations}} +{{#operation}} +{{#vendorExtensions.x-group-parameters}} +{{#allParams}} +{{#-first}} +/// struct for passing parameters to the method [`{{operationId}}`] +#[derive(Clone, Debug)] +{{#useBonBuilder}} +#[cfg_attr(feature = "bon", derive(::bon::Builder))] +{{/useBonBuilder}} +pub struct {{{operationIdCamelCase}}}Params { +{{/-first}} + {{#description}} + /// {{{.}}} + {{/description}} + pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^isUuid}}{{#isString}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isString}}{{/isUuid}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}},{{/-last}} +{{#-last}} +} + +{{/-last}} +{{/allParams}} +{{/vendorExtensions.x-group-parameters}} +{{/operation}} +{{/operations}} + #[async_trait] impl {{classname}} for {{classname}}Client { {{#operations}} @@ -43,7 +74,20 @@ impl {{classname}} for {{classname}}Client { {{#notes}} /// {{{.}}} {{/notes}} + {{#vendorExtensions.x-group-parameters}} + async fn {{{operationId}}}(&self, {{#allParams}}{{#-first}} params: {{{operationIdCamelCase}}}Params {{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { + {{#allParams}}{{#-first}} + let {{{operationIdCamelCase}}}Params { + {{#allParams}} + {{{paramName}}}, + {{/allParams}} + } = params; + {{/-first}}{{/allParams}} + + {{/vendorExtensions.x-group-parameters}} + {{^vendorExtensions.x-group-parameters}} async fn {{{operationId}}}<{{#allParams}}'{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}>(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{{paramName}}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { + {{/vendorExtensions.x-group-parameters}} let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -313,29 +357,6 @@ impl {{classname}} for {{classname}}Client { {{/operations}} } - -{{#operations}} -{{#operation}} -{{#vendorExtensions.x-group-parameters}} -{{#allParams}} -{{#-first}} -/// struct for passing parameters to the method [`{{operationId}}`] -#[derive(Clone, Debug)] -pub struct {{{operationIdCamelCase}}}Params { -{{/-first}} - {{#description}} - /// {{{.}}} - {{/description}} - pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^isUuid}}{{#isString}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isString}}{{/isUuid}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}String{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}},{{/-last}} -{{#-last}} -} - -{{/-last}} -{{/allParams}} -{{/vendorExtensions.x-group-parameters}} -{{/operation}} -{{/operations}} - {{#supportMultipleResponses}} {{#operations}} {{#operation}} From 0bcfd678161f1a60796e78843bc6d027628f2ec5 Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Tue, 22 Oct 2024 19:25:29 +0900 Subject: [PATCH 7/7] Rebuilt rust samples --- docs/generators/rust.md | 1 + .../client/others/rust/hyper/api-with-ref-param/Cargo.toml | 2 -- samples/client/others/rust/hyper/composed-oneof/Cargo.toml | 2 -- samples/client/others/rust/hyper/emptyObject/Cargo.toml | 2 -- samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml | 2 -- samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml | 2 -- samples/client/others/rust/hyper/oneOf/Cargo.toml | 2 -- .../client/others/rust/reqwest-regression-16119/Cargo.toml | 2 -- .../client/others/rust/reqwest/api-with-ref-param/Cargo.toml | 2 -- samples/client/others/rust/reqwest/composed-oneof/Cargo.toml | 2 -- samples/client/others/rust/reqwest/emptyObject/Cargo.toml | 2 -- samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml | 2 -- samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml | 2 -- samples/client/others/rust/reqwest/oneOf/Cargo.toml | 2 -- samples/client/petstore/rust/hyper/petstore/Cargo.toml | 2 -- samples/client/petstore/rust/hyper0x/petstore/Cargo.toml | 2 -- .../rust/reqwest-trait/petstore/.openapi-generator/VERSION | 2 +- .../client/petstore/rust/reqwest-trait/petstore/Cargo.toml | 1 - samples/client/petstore/rust/reqwest-trait/petstore/README.md | 2 +- .../petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs | 4 ++-- .../petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs | 4 ++-- .../rust/reqwest-trait/petstore/src/apis/store_api.rs | 4 ++-- .../rust/reqwest-trait/petstore/src/apis/testing_api.rs | 4 ++-- .../petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs | 4 ++-- samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml | 2 -- .../rust/reqwest/petstore-async-middleware/Cargo.toml | 2 -- .../rust/reqwest/petstore-async-tokensource/Cargo.toml | 2 -- .../client/petstore/rust/reqwest/petstore-async/Cargo.toml | 2 -- .../petstore/rust/reqwest/petstore-avoid-box/Cargo.toml | 2 -- .../petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml | 2 -- samples/client/petstore/rust/reqwest/petstore/Cargo.toml | 2 -- 31 files changed, 13 insertions(+), 57 deletions(-) diff --git a/docs/generators/rust.md b/docs/generators/rust.md index 96170e2bc0f5..d3bf78829333 100644 --- a/docs/generators/rust.md +++ b/docs/generators/rust.md @@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false| |supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option| |false| |topLevelApiClient|Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only| |false| +|useBonBuilder|Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only| |false| |useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false| |withAWSV4Signature|whether to include AWS v4 signature support| |false| diff --git a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml index 313daabf9e4a..00f46b1c7d3c 100644 --- a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml index 5f901d74f958..4c0a00557c55 100644 --- a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/hyper/emptyObject/Cargo.toml b/samples/client/others/rust/hyper/emptyObject/Cargo.toml index ae06393da67d..1efb624b65df 100644 --- a/samples/client/others/rust/hyper/emptyObject/Cargo.toml +++ b/samples/client/others/rust/hyper/emptyObject/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml index 037e0075253d..1bb7aa7bb54d 100644 --- a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml index e2c446ec876d..07b8f6cf6d8c 100644 --- a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml @@ -18,5 +18,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/hyper/oneOf/Cargo.toml b/samples/client/others/rust/hyper/oneOf/Cargo.toml index 911c62903d07..fb78d69e9100 100644 --- a/samples/client/others/rust/hyper/oneOf/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml index f1d92fa4707a..a1e41446d882 100644 --- a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml +++ b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml index 349ff48f768f..e4edc99b719c 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml index e9e4276a4006..f06effdcb109 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml index acd996e1773c..d35bad9e88dd 100644 --- a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml +++ b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml index b38ed2cfd053..5f2d99d18047 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml index 36f06c25a75c..64b0d4bf92f2 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml @@ -13,5 +13,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/others/rust/reqwest/oneOf/Cargo.toml b/samples/client/others/rust/reqwest/oneOf/Cargo.toml index b855ad7e95ed..8966bd1292c5 100644 --- a/samples/client/others/rust/reqwest/oneOf/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/hyper/petstore/Cargo.toml b/samples/client/petstore/rust/hyper/petstore/Cargo.toml index d6a59606c646..a9eedf18dea5 100644 --- a/samples/client/petstore/rust/hyper/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper/petstore/Cargo.toml @@ -19,5 +19,3 @@ http-body-util = { version = "0.1.2" } http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml b/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml index cb8e5dda9b45..a1b39ea2340f 100644 --- a/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper0x/petstore/Cargo.toml @@ -18,5 +18,3 @@ hyper-tls = "~0.5" http = "~0.2" base64 = "~0.7.0" futures = "^0.3" - -[features] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION index 17f2442ff3bc..6935482704c1 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/reqwest-trait/petstore/.openapi-generator/VERSION @@ -1 +1 @@ -7.9.0-SNAPSHOT +7.10.0-SNAPSHOT diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml index 02321d0a144b..d7680f4dfa7f 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest-trait/petstore/Cargo.toml @@ -16,6 +16,5 @@ uuid = { version = "^1.8", features = ["serde", "v4"] } async-trait = "^0.1" reqwest = { version = "^0.12", features = ["json", "multipart"] } mockall = { version = "^0.13", optional = true} - [features] mockall = ["dep:mockall"] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/README.md b/samples/client/petstore/rust/reqwest-trait/petstore/README.md index 43c026e7687d..f75316b07e24 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/README.md +++ b/samples/client/petstore/rust/reqwest-trait/petstore/README.md @@ -9,7 +9,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat - API version: 1.0.0 - Package version: 1.0.0 -- Generator version: 7.9.0-SNAPSHOT +- Generator version: 7.10.0-SNAPSHOT - Build package: `org.openapitools.codegen.languages.RustClientCodegen` ## Installation diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs index 04f4462b3c0b..72b79b1d60ec 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -34,6 +34,8 @@ impl FakeApiClient { } } + + #[async_trait] impl FakeApi for FakeApiClient { /// @@ -73,8 +75,6 @@ impl FakeApi for FakeApiClient { } - - /// struct for typed errors of method [`test_nullable_required_param`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs index ada787a79b8a..2f937c1719fd 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs @@ -41,6 +41,8 @@ impl PetApiClient { } } + + #[async_trait] impl PetApi for PetApiClient { /// @@ -325,8 +327,6 @@ impl PetApi for PetApiClient { } - - /// struct for typed errors of method [`add_pet`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs index ed86d9d7e422..b9d14b0811cf 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs @@ -37,6 +37,8 @@ impl StoreApiClient { } } + + #[async_trait] impl StoreApi for StoreApiClient { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -162,8 +164,6 @@ impl StoreApi for StoreApiClient { } - - /// struct for typed errors of method [`delete_order`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs index 603bea112cf0..07f192529442 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs @@ -35,6 +35,8 @@ impl TestingApiClient { } } + + #[async_trait] impl TestingApi for TestingApiClient { async fn tests_file_response_get<>(&self, ) -> Result> { @@ -93,8 +95,6 @@ impl TestingApi for TestingApiClient { } - - /// struct for typed errors of method [`tests_file_response_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs index a93bd6185565..b5a02a344869 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs @@ -41,6 +41,8 @@ impl UserApiClient { } } + + #[async_trait] impl UserApi for UserApiClient { /// This can only be done by the logged in user. @@ -323,8 +325,6 @@ impl UserApi for UserApiClient { } - - /// struct for typed errors of method [`create_user`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml index 9110c4e12a44..172f74f4e1ff 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml @@ -13,5 +13,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml index 9afd6b9fe452..2bbf314d7e82 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/Cargo.toml @@ -15,5 +15,3 @@ url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml index 018384a55fa4..811475c96e17 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/Cargo.toml @@ -17,5 +17,3 @@ reqwest = { version = "^0.12", features = ["json", "multipart"] } async-trait = "^0.1" # TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers. google-cloud-token = "^0.1" - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml index 19ecb7012106..3803423fe927 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-async/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml index 170654ea06f9..a3312a3a7eef 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml index 95bd36547b0d..d5a2bac56a2a 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/Cargo.toml @@ -17,5 +17,3 @@ aws-sigv4 = "0.3.0" http = "0.2.5" secrecy = "0.8.0" reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features] diff --git a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml index a0e486ff4f4a..0dd7e9149413 100644 --- a/samples/client/petstore/rust/reqwest/petstore/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/petstore/Cargo.toml @@ -14,5 +14,3 @@ serde_repr = "^0.1" url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } - -[features]