From e45600f4a54da26e5232ca998badee0d63ac553b Mon Sep 17 00:00:00 2001 From: JR Andreassen Date: Sat, 25 Jul 2020 16:43:34 -0500 Subject: [PATCH 1/6] Rust reqwest/api_mustache Missing api Vec in parameter Not using #isListContainer in parameters --- .../src/main/resources/rust/reqwest/api.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index 62d63e1b9b14..e6850f92a4ce 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -17,7 +17,7 @@ pub struct {{{operationIdCamelCase}}}Params { {{#description}} /// {{{.}}} {{/description}} - pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}String{{/isString}}{{#isUuid}}String{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}},{{/hasMore}} + pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isListContainer}}Vec<{{/isListContainer}}{{#isString}}String{{/isString}}{{#isUuid}}String{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{#isListContainer}}>{{/isListContainer}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}},{{/hasMore}} {{#-last}} } @@ -88,7 +88,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/vendorExtensions.x-group-parameters}} {{^vendorExtensions.x-group-parameters}} -pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { +pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isListContainer}}Vec<{{/isListContainer}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#isListContainer}}>{{/isListContainer}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { {{/vendorExtensions.x-group-parameters}} let client = &configuration.client; From d104118a72268a1bc09a68ae9c600bb6eb476cbf Mon Sep 17 00:00:00 2001 From: JR Andreassen Date: Sun, 26 Jul 2020 07:26:23 -0500 Subject: [PATCH 2/6] incorrect value for supportAsync supportAsync set to "false" should be false --- bin/configs/rust-reqwest-petstore.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/configs/rust-reqwest-petstore.yaml b/bin/configs/rust-reqwest-petstore.yaml index 1bc1d4c8667f..a3cb1b61abae 100644 --- a/bin/configs/rust-reqwest-petstore.yaml +++ b/bin/configs/rust-reqwest-petstore.yaml @@ -4,5 +4,5 @@ library: reqwest inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: - supportAsync: "false" + supportAsync: false packageName: petstore-reqwest From 1f3b602c0b76d80256bdab01cdb76dd53c83dd47 Mon Sep 17 00:00:00 2001 From: JR Andreassen Date: Sun, 26 Jul 2020 07:27:05 -0500 Subject: [PATCH 3/6] Sample updates for CI --- .../petstore-async/.openapi-generator/VERSION | 2 +- .../reqwest/petstore-async/src/apis/client.rs | 34 +++++ .../petstore-async/src/apis/pet_api.rs | 128 ++---------------- .../petstore-async/src/apis/store_api.rs | 51 +------ .../petstore-async/src/apis/user_api.rs | 105 ++------------ .../petstore/.openapi-generator/VERSION | 2 +- .../rust/reqwest/petstore/src/apis/client.rs | 34 +++++ .../rust/reqwest/petstore/src/apis/pet_api.rs | 14 +- .../reqwest/petstore/src/apis/store_api.rs | 8 +- .../reqwest/petstore/src/apis/user_api.rs | 9 +- 10 files changed, 108 insertions(+), 279 deletions(-) create mode 100644 samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs create mode 100644 samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs diff --git a/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION index d99e7162d01f..58592f031f65 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-SNAPSHOT \ No newline at end of file +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs new file mode 100644 index 000000000000..8a3963dcc539 --- /dev/null +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs @@ -0,0 +1,34 @@ +use std::rc::Rc; + +use super::configuration::Configuration; + +pub struct APIClient { + pet_api: Box, + store_api: Box, + user_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Rc::new(configuration); + + APIClient { + pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), + store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), + user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), + } + } + + pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ + self.pet_api.as_ref() + } + + pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ + self.store_api.as_ref() + } + + pub fn user_api(&self) -> &dyn crate::apis::UserApi{ + self.user_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index d2d1b7c37a94..959a0b9e20a6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -14,71 +14,6 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; -/// struct for passing parameters to the method `add_pet` -#[derive(Clone, Debug)] -pub struct AddPetParams { - /// Pet object that needs to be added to the store - pub body: crate::models::Pet -} - -/// struct for passing parameters to the method `delete_pet` -#[derive(Clone, Debug)] -pub struct DeletePetParams { - /// Pet id to delete - pub pet_id: i64, - pub api_key: Option -} - -/// struct for passing parameters to the method `find_pets_by_status` -#[derive(Clone, Debug)] -pub struct FindPetsByStatusParams { - /// Status values that need to be considered for filter - pub status: Vec -} - -/// struct for passing parameters to the method `find_pets_by_tags` -#[derive(Clone, Debug)] -pub struct FindPetsByTagsParams { - /// Tags to filter by - pub tags: Vec -} - -/// struct for passing parameters to the method `get_pet_by_id` -#[derive(Clone, Debug)] -pub struct GetPetByIdParams { - /// ID of pet to return - pub pet_id: i64 -} - -/// struct for passing parameters to the method `update_pet` -#[derive(Clone, Debug)] -pub struct UpdatePetParams { - /// Pet object that needs to be added to the store - pub body: crate::models::Pet -} - -/// struct for passing parameters to the method `update_pet_with_form` -#[derive(Clone, Debug)] -pub struct UpdatePetWithFormParams { - /// ID of pet that needs to be updated - pub pet_id: i64, - /// Updated name of the pet - pub name: Option, - /// Updated status of the pet - pub status: Option -} - -/// struct for passing parameters to the method `upload_file` -#[derive(Clone, Debug)] -pub struct UploadFileParams { - /// ID of pet to update - pub pet_id: i64, - /// Additional data to pass to server - pub additional_metadata: Option, - /// file to upload - pub file: Option -} - /// struct for typed successes of method `add_pet` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -98,7 +33,6 @@ pub enum DeletePetSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusSuccess { - Status200(Vec), UnknownValue(serde_json::Value), } @@ -106,7 +40,6 @@ pub enum FindPetsByStatusSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsSuccess { - Status200(Vec), UnknownValue(serde_json::Value), } @@ -114,7 +47,6 @@ pub enum FindPetsByTagsSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdSuccess { - Status200(crate::models::Pet), UnknownValue(serde_json::Value), } @@ -136,7 +68,6 @@ pub enum UpdatePetWithFormSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileSuccess { - Status200(crate::models::ApiResponse), UnknownValue(serde_json::Value), } @@ -144,7 +75,6 @@ pub enum UploadFileSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AddPetError { - Status405(), UnknownValue(serde_json::Value), } @@ -152,7 +82,6 @@ pub enum AddPetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeletePetError { - Status400(), UnknownValue(serde_json::Value), } @@ -160,7 +89,7 @@ pub enum DeletePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusError { - Status400(), + DefaultResponse(Vec), UnknownValue(serde_json::Value), } @@ -168,7 +97,7 @@ pub enum FindPetsByStatusError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsError { - Status400(), + DefaultResponse(Vec), UnknownValue(serde_json::Value), } @@ -176,8 +105,7 @@ pub enum FindPetsByTagsError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdError { - Status400(), - Status404(), + DefaultResponse(crate::models::Pet), UnknownValue(serde_json::Value), } @@ -185,9 +113,6 @@ pub enum GetPetByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetError { - Status400(), - Status404(), - Status405(), UnknownValue(serde_json::Value), } @@ -195,7 +120,6 @@ pub enum UpdatePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetWithFormError { - Status405(), UnknownValue(serde_json::Value), } @@ -203,14 +127,12 @@ pub enum UpdatePetWithFormError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileError { + DefaultResponse(crate::models::ApiResponse), UnknownValue(serde_json::Value), } -pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn add_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result, Error> { let client = &configuration.client; @@ -242,11 +164,7 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe } } -pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { - // unbox the parameters - let pet_id = params.pet_id; - let api_key = params.api_key; - +pub async fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result, Error> { let client = &configuration.client; @@ -281,10 +199,7 @@ pub async fn delete_pet(configuration: &configuration::Configuration, params: De } /// Multiple status values can be provided with comma separated strings -pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { - // unbox the parameters - let status = params.status; - +pub async fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec) -> Result, Error> { let client = &configuration.client; @@ -317,10 +232,7 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. -pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { - // unbox the parameters - let tags = params.tags; - +pub async fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { let client = &configuration.client; @@ -353,10 +265,7 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par } /// Returns a single pet -pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { - // unbox the parameters - let pet_id = params.pet_id; - +pub async fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result, Error> { let client = &configuration.client; @@ -392,10 +301,7 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: } } -pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn update_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result, Error> { let client = &configuration.client; @@ -427,12 +333,7 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up } } -pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { - // unbox the parameters - let pet_id = params.pet_id; - let name = params.name; - let status = params.status; - +pub async fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result, Error> { let client = &configuration.client; @@ -471,12 +372,7 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, } } -pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { - // unbox the parameters - let pet_id = params.pet_id; - let additional_metadata = params.additional_metadata; - let file = params.file; - +pub async fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result, Error> { let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index 52f40c9ad5c2..f27149f841f5 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -14,27 +14,6 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; -/// struct for passing parameters to the method `delete_order` -#[derive(Clone, Debug)] -pub struct DeleteOrderParams { - /// ID of the order that needs to be deleted - pub order_id: String -} - -/// struct for passing parameters to the method `get_order_by_id` -#[derive(Clone, Debug)] -pub struct GetOrderByIdParams { - /// ID of pet that needs to be fetched - pub order_id: i64 -} - -/// struct for passing parameters to the method `place_order` -#[derive(Clone, Debug)] -pub struct PlaceOrderParams { - /// order placed for purchasing the pet - pub body: crate::models::Order -} - /// struct for typed successes of method `delete_order` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -47,7 +26,6 @@ pub enum DeleteOrderSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventorySuccess { - Status200(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -55,7 +33,6 @@ pub enum GetInventorySuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdSuccess { - Status200(crate::models::Order), UnknownValue(serde_json::Value), } @@ -63,7 +40,6 @@ pub enum GetOrderByIdSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderSuccess { - Status200(crate::models::Order), UnknownValue(serde_json::Value), } @@ -71,8 +47,6 @@ pub enum PlaceOrderSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteOrderError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } @@ -80,6 +54,7 @@ pub enum DeleteOrderError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventoryError { + DefaultResponse(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -87,8 +62,7 @@ pub enum GetInventoryError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdError { - Status400(), - Status404(), + DefaultResponse(crate::models::Order), UnknownValue(serde_json::Value), } @@ -96,16 +70,13 @@ pub enum GetOrderByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderError { - Status400(), + DefaultResponse(crate::models::Order), UnknownValue(serde_json::Value), } /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors -pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { - // unbox the parameters - let order_id = params.order_id; - +pub async fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result, Error> { let client = &configuration.client; @@ -134,9 +105,7 @@ pub async fn delete_order(configuration: &configuration::Configuration, params: } /// Returns a map of status codes to quantities -pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { - // unbox the parameters - +pub async fn get_inventory(configuration: &configuration::Configuration, ) -> Result, Error> { let client = &configuration.client; @@ -173,10 +142,7 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions -pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { - // unbox the parameters - let order_id = params.order_id; - +pub async fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result, Error> { let client = &configuration.client; @@ -204,10 +170,7 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param } } -pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn place_order(configuration: &configuration::Configuration, body: crate::models::Order) -> Result, Error> { let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 6678d1ec8d0e..4e187515805f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -14,59 +14,6 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; -/// struct for passing parameters to the method `create_user` -#[derive(Clone, Debug)] -pub struct CreateUserParams { - /// Created user object - pub body: crate::models::User -} - -/// struct for passing parameters to the method `create_users_with_array_input` -#[derive(Clone, Debug)] -pub struct CreateUsersWithArrayInputParams { - /// List of user object - pub body: Vec -} - -/// struct for passing parameters to the method `create_users_with_list_input` -#[derive(Clone, Debug)] -pub struct CreateUsersWithListInputParams { - /// List of user object - pub body: Vec -} - -/// struct for passing parameters to the method `delete_user` -#[derive(Clone, Debug)] -pub struct DeleteUserParams { - /// The name that needs to be deleted - pub username: String -} - -/// struct for passing parameters to the method `get_user_by_name` -#[derive(Clone, Debug)] -pub struct GetUserByNameParams { - /// The name that needs to be fetched. Use user1 for testing. - pub username: String -} - -/// struct for passing parameters to the method `login_user` -#[derive(Clone, Debug)] -pub struct LoginUserParams { - /// The user name for login - pub username: String, - /// The password for login in clear text - pub password: String -} - -/// struct for passing parameters to the method `update_user` -#[derive(Clone, Debug)] -pub struct UpdateUserParams { - /// name that need to be deleted - pub username: String, - /// Updated user object - pub body: crate::models::User -} - /// struct for typed successes of method `create_user` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -100,7 +47,6 @@ pub enum DeleteUserSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameSuccess { - Status200(crate::models::User), UnknownValue(serde_json::Value), } @@ -108,7 +54,6 @@ pub enum GetUserByNameSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserSuccess { - Status200(String), UnknownValue(serde_json::Value), } @@ -154,8 +99,6 @@ pub enum CreateUsersWithListInputError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteUserError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } @@ -163,8 +106,7 @@ pub enum DeleteUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameError { - Status400(), - Status404(), + DefaultResponse(crate::models::User), UnknownValue(serde_json::Value), } @@ -172,7 +114,7 @@ pub enum GetUserByNameError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserError { - Status400(), + DefaultResponse(String), UnknownValue(serde_json::Value), } @@ -188,17 +130,12 @@ pub enum LogoutUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdateUserError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } /// This can only be done by the logged in user. -pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn create_user(configuration: &configuration::Configuration, body: crate::models::User) -> Result, Error> { let client = &configuration.client; @@ -227,10 +164,7 @@ pub async fn create_user(configuration: &configuration::Configuration, params: C } } -pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn create_users_with_array_input(configuration: &configuration::Configuration, body: Vec) -> Result, Error> { let client = &configuration.client; @@ -259,10 +193,7 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config } } -pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { - // unbox the parameters - let body = params.body; - +pub async fn create_users_with_list_input(configuration: &configuration::Configuration, body: Vec) -> Result, Error> { let client = &configuration.client; @@ -292,10 +223,7 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu } /// This can only be done by the logged in user. -pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { - // unbox the parameters - let username = params.username; - +pub async fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result, Error> { let client = &configuration.client; @@ -323,10 +251,7 @@ pub async fn delete_user(configuration: &configuration::Configuration, params: D } } -pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { - // unbox the parameters - let username = params.username; - +pub async fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result, Error> { let client = &configuration.client; @@ -354,11 +279,7 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para } } -pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { - // unbox the parameters - let username = params.username; - let password = params.password; - +pub async fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result, Error> { let client = &configuration.client; @@ -388,9 +309,7 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo } } -pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { - // unbox the parameters - +pub async fn logout_user(configuration: &configuration::Configuration, ) -> Result, Error> { let client = &configuration.client; @@ -419,11 +338,7 @@ pub async fn logout_user(configuration: &configuration::Configuration) -> Result } /// This can only be done by the logged in user. -pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { - // unbox the parameters - let username = params.username; - let body = params.body; - +pub async fn update_user(configuration: &configuration::Configuration, username: &str, body: crate::models::User) -> Result, Error> { let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION index d99e7162d01f..58592f031f65 100644 --- a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-SNAPSHOT \ No newline at end of file +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs new file mode 100644 index 000000000000..8a3963dcc539 --- /dev/null +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs @@ -0,0 +1,34 @@ +use std::rc::Rc; + +use super::configuration::Configuration; + +pub struct APIClient { + pet_api: Box, + store_api: Box, + user_api: Box, +} + +impl APIClient { + pub fn new(configuration: Configuration) -> APIClient { + let rc = Rc::new(configuration); + + APIClient { + pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), + store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), + user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), + } + } + + pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ + self.pet_api.as_ref() + } + + pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ + self.store_api.as_ref() + } + + pub fn user_api(&self) -> &dyn crate::apis::UserApi{ + self.user_api.as_ref() + } + +} diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs index c6715740fc47..530b6415dad6 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs @@ -19,7 +19,6 @@ use super::{Error, configuration}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AddPetError { - Status405(), UnknownValue(serde_json::Value), } @@ -27,7 +26,6 @@ pub enum AddPetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeletePetError { - Status400(), UnknownValue(serde_json::Value), } @@ -35,7 +33,7 @@ pub enum DeletePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusError { - Status400(), + DefaultResponse(Vec), UnknownValue(serde_json::Value), } @@ -43,7 +41,7 @@ pub enum FindPetsByStatusError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsError { - Status400(), + DefaultResponse(Vec), UnknownValue(serde_json::Value), } @@ -51,8 +49,7 @@ pub enum FindPetsByTagsError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdError { - Status400(), - Status404(), + DefaultResponse(crate::models::Pet), UnknownValue(serde_json::Value), } @@ -60,9 +57,6 @@ pub enum GetPetByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetError { - Status400(), - Status404(), - Status405(), UnknownValue(serde_json::Value), } @@ -70,7 +64,6 @@ pub enum UpdatePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetWithFormError { - Status405(), UnknownValue(serde_json::Value), } @@ -78,6 +71,7 @@ pub enum UpdatePetWithFormError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileError { + DefaultResponse(crate::models::ApiResponse), UnknownValue(serde_json::Value), } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs index 2474d591dbc1..273e09236224 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs @@ -19,8 +19,6 @@ use super::{Error, configuration}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteOrderError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } @@ -28,6 +26,7 @@ pub enum DeleteOrderError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventoryError { + DefaultResponse(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -35,8 +34,7 @@ pub enum GetInventoryError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdError { - Status400(), - Status404(), + DefaultResponse(crate::models::Order), UnknownValue(serde_json::Value), } @@ -44,7 +42,7 @@ pub enum GetOrderByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderError { - Status400(), + DefaultResponse(crate::models::Order), UnknownValue(serde_json::Value), } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs index de5fc2cc4f4e..12e1e61bee99 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs @@ -43,8 +43,6 @@ pub enum CreateUsersWithListInputError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteUserError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } @@ -52,8 +50,7 @@ pub enum DeleteUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameError { - Status400(), - Status404(), + DefaultResponse(crate::models::User), UnknownValue(serde_json::Value), } @@ -61,7 +58,7 @@ pub enum GetUserByNameError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserError { - Status400(), + DefaultResponse(String), UnknownValue(serde_json::Value), } @@ -77,8 +74,6 @@ pub enum LogoutUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdateUserError { - Status400(), - Status404(), UnknownValue(serde_json::Value), } From 85a9d2309651103015c1a936c829a2dda5af3b12 Mon Sep 17 00:00:00 2001 From: JR Andreassen Date: Sun, 26 Jul 2020 09:04:01 -0500 Subject: [PATCH 4/6] Fixed Double Vec Only check for special case... "dataType" case includes Vec --- .../src/main/resources/rust/reqwest/api.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index e6850f92a4ce..287b5b8db81c 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -17,7 +17,7 @@ pub struct {{{operationIdCamelCase}}}Params { {{#description}} /// {{{.}}} {{/description}} - pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isListContainer}}Vec<{{/isListContainer}}{{#isString}}String{{/isString}}{{#isUuid}}String{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{#isListContainer}}>{{/isListContainer}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}},{{/hasMore}} + pub {{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isListContainer}}Vec<{{/isListContainer}}String{{#isListContainer}}>{{/isListContainer}}{{/isString}}{{#isUuid}}{{#isListContainer}}Vec<{{/isListContainer}}String{{#isListContainer}}>{{/isListContainer}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}},{{/hasMore}} {{#-last}} } @@ -88,7 +88,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/vendorExtensions.x-group-parameters}} {{^vendorExtensions.x-group-parameters}} -pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isListContainer}}Vec<{{/isListContainer}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#isListContainer}}>{{/isListContainer}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { +pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isListContainer}}Vec<{{/isListContainer}}&str{{#isListContainer}}>{{/isListContainer}}{{/isString}}{{#isUuid}}{{#isListContainer}}Vec<{{/isListContainer}}&str{{#isListContainer}}>{{/isListContainer}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { {{/vendorExtensions.x-group-parameters}} let client = &configuration.client; From 60ec574bfd0149a7c0767392c7f04769bb9e6a5f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 27 Jul 2020 11:00:27 +0800 Subject: [PATCH 5/6] update samples --- .../petstore-async/.openapi-generator/VERSION | 2 +- .../petstore-async/src/apis/pet_api.rs | 128 ++++++++++++++++-- .../petstore-async/src/apis/store_api.rs | 51 ++++++- .../petstore-async/src/apis/user_api.rs | 105 ++++++++++++-- .../petstore/.openapi-generator/VERSION | 2 +- .../rust/reqwest/petstore/src/apis/pet_api.rs | 14 +- .../reqwest/petstore/src/apis/store_api.rs | 8 +- .../reqwest/petstore/src/apis/user_api.rs | 9 +- 8 files changed, 279 insertions(+), 40 deletions(-) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION index 58592f031f65..d99e7162d01f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/reqwest/petstore-async/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.3-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index 959a0b9e20a6..d2d1b7c37a94 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -14,6 +14,71 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; +/// struct for passing parameters to the method `add_pet` +#[derive(Clone, Debug)] +pub struct AddPetParams { + /// Pet object that needs to be added to the store + pub body: crate::models::Pet +} + +/// struct for passing parameters to the method `delete_pet` +#[derive(Clone, Debug)] +pub struct DeletePetParams { + /// Pet id to delete + pub pet_id: i64, + pub api_key: Option +} + +/// struct for passing parameters to the method `find_pets_by_status` +#[derive(Clone, Debug)] +pub struct FindPetsByStatusParams { + /// Status values that need to be considered for filter + pub status: Vec +} + +/// struct for passing parameters to the method `find_pets_by_tags` +#[derive(Clone, Debug)] +pub struct FindPetsByTagsParams { + /// Tags to filter by + pub tags: Vec +} + +/// struct for passing parameters to the method `get_pet_by_id` +#[derive(Clone, Debug)] +pub struct GetPetByIdParams { + /// ID of pet to return + pub pet_id: i64 +} + +/// struct for passing parameters to the method `update_pet` +#[derive(Clone, Debug)] +pub struct UpdatePetParams { + /// Pet object that needs to be added to the store + pub body: crate::models::Pet +} + +/// struct for passing parameters to the method `update_pet_with_form` +#[derive(Clone, Debug)] +pub struct UpdatePetWithFormParams { + /// ID of pet that needs to be updated + pub pet_id: i64, + /// Updated name of the pet + pub name: Option, + /// Updated status of the pet + pub status: Option +} + +/// struct for passing parameters to the method `upload_file` +#[derive(Clone, Debug)] +pub struct UploadFileParams { + /// ID of pet to update + pub pet_id: i64, + /// Additional data to pass to server + pub additional_metadata: Option, + /// file to upload + pub file: Option +} + /// struct for typed successes of method `add_pet` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -33,6 +98,7 @@ pub enum DeletePetSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusSuccess { + Status200(Vec), UnknownValue(serde_json::Value), } @@ -40,6 +106,7 @@ pub enum FindPetsByStatusSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsSuccess { + Status200(Vec), UnknownValue(serde_json::Value), } @@ -47,6 +114,7 @@ pub enum FindPetsByTagsSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdSuccess { + Status200(crate::models::Pet), UnknownValue(serde_json::Value), } @@ -68,6 +136,7 @@ pub enum UpdatePetWithFormSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileSuccess { + Status200(crate::models::ApiResponse), UnknownValue(serde_json::Value), } @@ -75,6 +144,7 @@ pub enum UploadFileSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AddPetError { + Status405(), UnknownValue(serde_json::Value), } @@ -82,6 +152,7 @@ pub enum AddPetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeletePetError { + Status400(), UnknownValue(serde_json::Value), } @@ -89,7 +160,7 @@ pub enum DeletePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusError { - DefaultResponse(Vec), + Status400(), UnknownValue(serde_json::Value), } @@ -97,7 +168,7 @@ pub enum FindPetsByStatusError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsError { - DefaultResponse(Vec), + Status400(), UnknownValue(serde_json::Value), } @@ -105,7 +176,8 @@ pub enum FindPetsByTagsError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdError { - DefaultResponse(crate::models::Pet), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -113,6 +185,9 @@ pub enum GetPetByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetError { + Status400(), + Status404(), + Status405(), UnknownValue(serde_json::Value), } @@ -120,6 +195,7 @@ pub enum UpdatePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetWithFormError { + Status405(), UnknownValue(serde_json::Value), } @@ -127,12 +203,14 @@ pub enum UpdatePetWithFormError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileError { - DefaultResponse(crate::models::ApiResponse), UnknownValue(serde_json::Value), } -pub async fn add_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result, Error> { +pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; @@ -164,7 +242,11 @@ pub async fn add_pet(configuration: &configuration::Configuration, body: crate:: } } -pub async fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result, Error> { +pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { + // unbox the parameters + let pet_id = params.pet_id; + let api_key = params.api_key; + let client = &configuration.client; @@ -199,7 +281,10 @@ pub async fn delete_pet(configuration: &configuration::Configuration, pet_id: i6 } /// Multiple status values can be provided with comma separated strings -pub async fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec) -> Result, Error> { +pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { + // unbox the parameters + let status = params.status; + let client = &configuration.client; @@ -232,7 +317,10 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, s } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. -pub async fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { +pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { + // unbox the parameters + let tags = params.tags; + let client = &configuration.client; @@ -265,7 +353,10 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, tag } /// Returns a single pet -pub async fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result, Error> { +pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { + // unbox the parameters + let pet_id = params.pet_id; + let client = &configuration.client; @@ -301,7 +392,10 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: } } -pub async fn update_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result, Error> { +pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; @@ -333,7 +427,12 @@ pub async fn update_pet(configuration: &configuration::Configuration, body: crat } } -pub async fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result, Error> { +pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { + // unbox the parameters + let pet_id = params.pet_id; + let name = params.name; + let status = params.status; + let client = &configuration.client; @@ -372,7 +471,12 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, } } -pub async fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result, Error> { +pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { + // unbox the parameters + let pet_id = params.pet_id; + let additional_metadata = params.additional_metadata; + let file = params.file; + let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index f27149f841f5..52f40c9ad5c2 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -14,6 +14,27 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; +/// struct for passing parameters to the method `delete_order` +#[derive(Clone, Debug)] +pub struct DeleteOrderParams { + /// ID of the order that needs to be deleted + pub order_id: String +} + +/// struct for passing parameters to the method `get_order_by_id` +#[derive(Clone, Debug)] +pub struct GetOrderByIdParams { + /// ID of pet that needs to be fetched + pub order_id: i64 +} + +/// struct for passing parameters to the method `place_order` +#[derive(Clone, Debug)] +pub struct PlaceOrderParams { + /// order placed for purchasing the pet + pub body: crate::models::Order +} + /// struct for typed successes of method `delete_order` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -26,6 +47,7 @@ pub enum DeleteOrderSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventorySuccess { + Status200(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -33,6 +55,7 @@ pub enum GetInventorySuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdSuccess { + Status200(crate::models::Order), UnknownValue(serde_json::Value), } @@ -40,6 +63,7 @@ pub enum GetOrderByIdSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderSuccess { + Status200(crate::models::Order), UnknownValue(serde_json::Value), } @@ -47,6 +71,8 @@ pub enum PlaceOrderSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteOrderError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -54,7 +80,6 @@ pub enum DeleteOrderError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventoryError { - DefaultResponse(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -62,7 +87,8 @@ pub enum GetInventoryError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdError { - DefaultResponse(crate::models::Order), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -70,13 +96,16 @@ pub enum GetOrderByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderError { - DefaultResponse(crate::models::Order), + Status400(), UnknownValue(serde_json::Value), } /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors -pub async fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result, Error> { +pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { + // unbox the parameters + let order_id = params.order_id; + let client = &configuration.client; @@ -105,7 +134,9 @@ pub async fn delete_order(configuration: &configuration::Configuration, order_id } /// Returns a map of status codes to quantities -pub async fn get_inventory(configuration: &configuration::Configuration, ) -> Result, Error> { +pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { + // unbox the parameters + let client = &configuration.client; @@ -142,7 +173,10 @@ pub async fn get_inventory(configuration: &configuration::Configuration, ) -> Re } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions -pub async fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result, Error> { +pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { + // unbox the parameters + let order_id = params.order_id; + let client = &configuration.client; @@ -170,7 +204,10 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, order } } -pub async fn place_order(configuration: &configuration::Configuration, body: crate::models::Order) -> Result, Error> { +pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 4e187515805f..6678d1ec8d0e 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -14,6 +14,59 @@ use reqwest; use crate::apis::ResponseContent; use super::{Error, configuration}; +/// struct for passing parameters to the method `create_user` +#[derive(Clone, Debug)] +pub struct CreateUserParams { + /// Created user object + pub body: crate::models::User +} + +/// struct for passing parameters to the method `create_users_with_array_input` +#[derive(Clone, Debug)] +pub struct CreateUsersWithArrayInputParams { + /// List of user object + pub body: Vec +} + +/// struct for passing parameters to the method `create_users_with_list_input` +#[derive(Clone, Debug)] +pub struct CreateUsersWithListInputParams { + /// List of user object + pub body: Vec +} + +/// struct for passing parameters to the method `delete_user` +#[derive(Clone, Debug)] +pub struct DeleteUserParams { + /// The name that needs to be deleted + pub username: String +} + +/// struct for passing parameters to the method `get_user_by_name` +#[derive(Clone, Debug)] +pub struct GetUserByNameParams { + /// The name that needs to be fetched. Use user1 for testing. + pub username: String +} + +/// struct for passing parameters to the method `login_user` +#[derive(Clone, Debug)] +pub struct LoginUserParams { + /// The user name for login + pub username: String, + /// The password for login in clear text + pub password: String +} + +/// struct for passing parameters to the method `update_user` +#[derive(Clone, Debug)] +pub struct UpdateUserParams { + /// name that need to be deleted + pub username: String, + /// Updated user object + pub body: crate::models::User +} + /// struct for typed successes of method `create_user` #[derive(Debug, Clone, Serialize, Deserialize)] @@ -47,6 +100,7 @@ pub enum DeleteUserSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameSuccess { + Status200(crate::models::User), UnknownValue(serde_json::Value), } @@ -54,6 +108,7 @@ pub enum GetUserByNameSuccess { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserSuccess { + Status200(String), UnknownValue(serde_json::Value), } @@ -99,6 +154,8 @@ pub enum CreateUsersWithListInputError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteUserError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -106,7 +163,8 @@ pub enum DeleteUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameError { - DefaultResponse(crate::models::User), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -114,7 +172,7 @@ pub enum GetUserByNameError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserError { - DefaultResponse(String), + Status400(), UnknownValue(serde_json::Value), } @@ -130,12 +188,17 @@ pub enum LogoutUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdateUserError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } /// This can only be done by the logged in user. -pub async fn create_user(configuration: &configuration::Configuration, body: crate::models::User) -> Result, Error> { +pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; @@ -164,7 +227,10 @@ pub async fn create_user(configuration: &configuration::Configuration, body: cra } } -pub async fn create_users_with_array_input(configuration: &configuration::Configuration, body: Vec) -> Result, Error> { +pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; @@ -193,7 +259,10 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config } } -pub async fn create_users_with_list_input(configuration: &configuration::Configuration, body: Vec) -> Result, Error> { +pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; @@ -223,7 +292,10 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu } /// This can only be done by the logged in user. -pub async fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result, Error> { +pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { + // unbox the parameters + let username = params.username; + let client = &configuration.client; @@ -251,7 +323,10 @@ pub async fn delete_user(configuration: &configuration::Configuration, username: } } -pub async fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result, Error> { +pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { + // unbox the parameters + let username = params.username; + let client = &configuration.client; @@ -279,7 +354,11 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, user } } -pub async fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result, Error> { +pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { + // unbox the parameters + let username = params.username; + let password = params.password; + let client = &configuration.client; @@ -309,7 +388,9 @@ pub async fn login_user(configuration: &configuration::Configuration, username: } } -pub async fn logout_user(configuration: &configuration::Configuration, ) -> Result, Error> { +pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { + // unbox the parameters + let client = &configuration.client; @@ -338,7 +419,11 @@ pub async fn logout_user(configuration: &configuration::Configuration, ) -> Resu } /// This can only be done by the logged in user. -pub async fn update_user(configuration: &configuration::Configuration, username: &str, body: crate::models::User) -> Result, Error> { +pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { + // unbox the parameters + let username = params.username; + let body = params.body; + let client = &configuration.client; diff --git a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION index 58592f031f65..d99e7162d01f 100644 --- a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION +++ b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.3-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs index 530b6415dad6..c6715740fc47 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs @@ -19,6 +19,7 @@ use super::{Error, configuration}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AddPetError { + Status405(), UnknownValue(serde_json::Value), } @@ -26,6 +27,7 @@ pub enum AddPetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeletePetError { + Status400(), UnknownValue(serde_json::Value), } @@ -33,7 +35,7 @@ pub enum DeletePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByStatusError { - DefaultResponse(Vec), + Status400(), UnknownValue(serde_json::Value), } @@ -41,7 +43,7 @@ pub enum FindPetsByStatusError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum FindPetsByTagsError { - DefaultResponse(Vec), + Status400(), UnknownValue(serde_json::Value), } @@ -49,7 +51,8 @@ pub enum FindPetsByTagsError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetPetByIdError { - DefaultResponse(crate::models::Pet), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -57,6 +60,9 @@ pub enum GetPetByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetError { + Status400(), + Status404(), + Status405(), UnknownValue(serde_json::Value), } @@ -64,6 +70,7 @@ pub enum UpdatePetError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdatePetWithFormError { + Status405(), UnknownValue(serde_json::Value), } @@ -71,7 +78,6 @@ pub enum UpdatePetWithFormError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UploadFileError { - DefaultResponse(crate::models::ApiResponse), UnknownValue(serde_json::Value), } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs index 273e09236224..2474d591dbc1 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs @@ -19,6 +19,8 @@ use super::{Error, configuration}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteOrderError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -26,7 +28,6 @@ pub enum DeleteOrderError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetInventoryError { - DefaultResponse(::std::collections::HashMap), UnknownValue(serde_json::Value), } @@ -34,7 +35,8 @@ pub enum GetInventoryError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetOrderByIdError { - DefaultResponse(crate::models::Order), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -42,7 +44,7 @@ pub enum GetOrderByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PlaceOrderError { - DefaultResponse(crate::models::Order), + Status400(), UnknownValue(serde_json::Value), } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs index 12e1e61bee99..de5fc2cc4f4e 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs @@ -43,6 +43,8 @@ pub enum CreateUsersWithListInputError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DeleteUserError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -50,7 +52,8 @@ pub enum DeleteUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetUserByNameError { - DefaultResponse(crate::models::User), + Status400(), + Status404(), UnknownValue(serde_json::Value), } @@ -58,7 +61,7 @@ pub enum GetUserByNameError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LoginUserError { - DefaultResponse(String), + Status400(), UnknownValue(serde_json::Value), } @@ -74,6 +77,8 @@ pub enum LogoutUserError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UpdateUserError { + Status400(), + Status404(), UnknownValue(serde_json::Value), } From 8d5a4cb97f22578e00812a25b8816a97392531fb Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 31 Jul 2020 11:08:44 +0800 Subject: [PATCH 6/6] remove old files --- .../reqwest/petstore-async/src/apis/client.rs | 34 ------------------- .../rust/reqwest/petstore/src/apis/client.rs | 34 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs delete mode 100644 samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs deleted file mode 100644 index 8a3963dcc539..000000000000 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/client.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::rc::Rc; - -use super::configuration::Configuration; - -pub struct APIClient { - pet_api: Box, - store_api: Box, - user_api: Box, -} - -impl APIClient { - pub fn new(configuration: Configuration) -> APIClient { - let rc = Rc::new(configuration); - - APIClient { - pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), - store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), - user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), - } - } - - pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ - self.pet_api.as_ref() - } - - pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ - self.store_api.as_ref() - } - - pub fn user_api(&self) -> &dyn crate::apis::UserApi{ - self.user_api.as_ref() - } - -} diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs deleted file mode 100644 index 8a3963dcc539..000000000000 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/client.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::rc::Rc; - -use super::configuration::Configuration; - -pub struct APIClient { - pet_api: Box, - store_api: Box, - user_api: Box, -} - -impl APIClient { - pub fn new(configuration: Configuration) -> APIClient { - let rc = Rc::new(configuration); - - APIClient { - pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())), - store_api: Box::new(crate::apis::StoreApiClient::new(rc.clone())), - user_api: Box::new(crate::apis::UserApiClient::new(rc.clone())), - } - } - - pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ - self.pet_api.as_ref() - } - - pub fn store_api(&self) -> &dyn crate::apis::StoreApi{ - self.store_api.as_ref() - } - - pub fn user_api(&self) -> &dyn crate::apis::UserApi{ - self.user_api.as_ref() - } - -}