diff --git a/bin/rust-petstore.sh b/bin/rust-petstore.sh index 1e08b616a11d..6ccfa708269a 100755 --- a/bin/rust-petstore.sh +++ b/bin/rust-petstore.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/swagger-codegen/src/main/resources/rust -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l rust -o samples/client/petstore/rust $@" +ags="generate -t modules/swagger-codegen/src/main/resources/rust -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l rust -o samples/client/petstore/rust -DpackageName=petstore_client $@" java ${JAVA_OPTS} -jar ${executable} ${ags} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustClientCodegen.java index 5ac612111ac5..01dd7dff24da 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustClientCodegen.java @@ -325,11 +325,11 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(sanitizedOperationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize("call_" + operationId)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } - return camelize(sanitizedOperationId); + return underscore(sanitizedOperationId); } @Override diff --git a/modules/swagger-codegen/src/main/resources/rust/model.mustache b/modules/swagger-codegen/src/main/resources/rust/model.mustache index d841f482c01a..5774bbaffa6a 100644 --- a/modules/swagger-codegen/src/main/resources/rust/model.mustache +++ b/modules/swagger-codegen/src/main/resources/rust/model.mustache @@ -11,7 +11,8 @@ pub struct {{classname}} { {{#description}} /// {{{description}}} {{/description}} - #[serde(rename = "{{baseName}}")] {{name}}: {{^required}}Option<{{/required}}{{{datatype}}}{{^required}}>{{/required}}{{#hasMore}},{{/hasMore}} + #[serde(rename = "{{baseName}}")] + {{name}}: {{^required}}Option<{{/required}}{{{datatype}}}{{^required}}>{{/required}}{{#hasMore}},{{/hasMore}} {{/vars}} } @@ -37,10 +38,16 @@ impl {{classname}} { self } - pub fn {{name}}(&self) -> &{{datatype}} { - &self.{{name}} + pub fn {{name}}(&self) -> {{^required}}Option<{{/required}}&{{{datatype}}}{{^required}}>{{/required}} { + {{#required}}&{{/required}}self.{{name}}{{^required}}.as_ref(){{/required}} } + {{^required}} + pub fn reset_{{name}}(&mut self) { + self.{{name}} = None; + } + {{/required}} + {{/vars}} } diff --git a/samples/client/petstore/rust/Cargo.toml b/samples/client/petstore/rust/Cargo.toml index ad18ef787813..8fe01ecd0229 100644 --- a/samples/client/petstore/rust/Cargo.toml +++ b/samples/client/petstore/rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "swagger" +name = "petstore_client" version = "1.0.0" authors = ["Swagger Codegen team and contributors"] diff --git a/samples/client/petstore/rust/README.md b/samples/client/petstore/rust/README.md index ee5f2426813e..248d02349b62 100644 --- a/samples/client/petstore/rust/README.md +++ b/samples/client/petstore/rust/README.md @@ -1,4 +1,4 @@ -# Rust API client for swagger +# Rust API client for petstore_client This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. @@ -12,7 +12,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge ## Installation Put the package under your project folder and add the following in import: ``` - "./swagger" + "./petstore_client" ``` ## Documentation for API Endpoints @@ -21,26 +21,26 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **Post** /pet | Add a new pet to the store -*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **Delete** /pet/{petId} | Deletes a pet -*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **Get** /pet/findByStatus | Finds Pets by status -*PetApi* | [**FindPetsByTags**](docs/PetApi.md#findpetsbytags) | **Get** /pet/findByTags | Finds Pets by tags -*PetApi* | [**GetPetById**](docs/PetApi.md#getpetbyid) | **Get** /pet/{petId} | Find pet by ID -*PetApi* | [**UpdatePet**](docs/PetApi.md#updatepet) | **Put** /pet | Update an existing pet -*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **Post** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **Post** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **Delete** /store/order/{orderId} | Delete purchase order by ID -*StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **Get** /store/inventory | Returns pet inventories by status -*StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **Get** /store/order/{orderId} | Find purchase order by ID -*StoreApi* | [**PlaceOrder**](docs/StoreApi.md#placeorder) | **Post** /store/order | Place an order for a pet -*UserApi* | [**CreateUser**](docs/UserApi.md#createuser) | **Post** /user | Create user -*UserApi* | [**CreateUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **Post** /user/createWithArray | Creates list of users with given input array -*UserApi* | [**CreateUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **Post** /user/createWithList | Creates list of users with given input array -*UserApi* | [**DeleteUser**](docs/UserApi.md#deleteuser) | **Delete** /user/{username} | Delete user -*UserApi* | [**GetUserByName**](docs/UserApi.md#getuserbyname) | **Get** /user/{username} | Get user by user name -*UserApi* | [**LoginUser**](docs/UserApi.md#loginuser) | **Get** /user/login | Logs user into the system -*UserApi* | [**LogoutUser**](docs/UserApi.md#logoutuser) | **Get** /user/logout | Logs out current logged in user session -*UserApi* | [**UpdateUser**](docs/UserApi.md#updateuser) | **Put** /user/{username} | Updated user +*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **Post** /pet | Add a new pet to the store +*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet +*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **Get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **Get** /pet/{petId} | Find pet by ID +*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **Put** /pet | Update an existing pet +*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **Get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet +*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **Post** /user | Create user +*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **Post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **Post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **Delete** /user/{username} | Delete user +*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **Get** /user/{username} | Get user by user name +*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **Get** /user/login | Logs user into the system +*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **Get** /user/logout | Logs out current logged in user session +*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **Put** /user/{username} | Updated user ## Documentation For Models diff --git a/samples/client/petstore/rust/docs/PetApi.md b/samples/client/petstore/rust/docs/PetApi.md index 82e8a231c37a..c225d46d739c 100644 --- a/samples/client/petstore/rust/docs/PetApi.md +++ b/samples/client/petstore/rust/docs/PetApi.md @@ -4,18 +4,18 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**AddPet**](PetApi.md#AddPet) | **Post** /pet | Add a new pet to the store -[**DeletePet**](PetApi.md#DeletePet) | **Delete** /pet/{petId} | Deletes a pet -[**FindPetsByStatus**](PetApi.md#FindPetsByStatus) | **Get** /pet/findByStatus | Finds Pets by status -[**FindPetsByTags**](PetApi.md#FindPetsByTags) | **Get** /pet/findByTags | Finds Pets by tags -[**GetPetById**](PetApi.md#GetPetById) | **Get** /pet/{petId} | Find pet by ID -[**UpdatePet**](PetApi.md#UpdatePet) | **Put** /pet | Update an existing pet -[**UpdatePetWithForm**](PetApi.md#UpdatePetWithForm) | **Post** /pet/{petId} | Updates a pet in the store with form data -[**UploadFile**](PetApi.md#UploadFile) | **Post** /pet/{petId}/uploadImage | uploads an image +[**add_pet**](PetApi.md#add_pet) | **Post** /pet | Add a new pet to the store +[**delete_pet**](PetApi.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet +[**find_pets_by_status**](PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status +[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **Get** /pet/findByTags | Finds Pets by tags +[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **Get** /pet/{petId} | Find pet by ID +[**update_pet**](PetApi.md#update_pet) | **Put** /pet | Update an existing pet +[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data +[**upload_file**](PetApi.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image -# **AddPet** -> AddPet(ctx, body) +# **add_pet** +> add_pet(ctx, body) Add a new pet to the store @@ -42,8 +42,8 @@ Name | Type | Description | Notes [[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) -# **DeletePet** -> DeletePet(ctx, pet_id, optional) +# **delete_pet** +> delete_pet(ctx, pet_id, optional) Deletes a pet @@ -79,8 +79,8 @@ Name | Type | Description | Notes [[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) -# **FindPetsByStatus** -> Vec<::models::Pet> FindPetsByStatus(ctx, status) +# **find_pets_by_status** +> Vec<::models::Pet> find_pets_by_status(ctx, status) Finds Pets by status Multiple status values can be provided with comma separated strings @@ -107,8 +107,8 @@ Name | Type | Description | Notes [[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) -# **FindPetsByTags** -> Vec<::models::Pet> FindPetsByTags(ctx, tags) +# **find_pets_by_tags** +> Vec<::models::Pet> find_pets_by_tags(ctx, tags) Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -135,8 +135,8 @@ Name | Type | Description | Notes [[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) -# **GetPetById** -> ::models::Pet GetPetById(ctx, pet_id) +# **get_pet_by_id** +> ::models::Pet get_pet_by_id(ctx, pet_id) Find pet by ID Returns a single pet @@ -163,8 +163,8 @@ Name | Type | Description | Notes [[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) -# **UpdatePet** -> UpdatePet(ctx, body) +# **update_pet** +> update_pet(ctx, body) Update an existing pet @@ -191,8 +191,8 @@ Name | Type | Description | Notes [[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) -# **UpdatePetWithForm** -> UpdatePetWithForm(ctx, pet_id, optional) +# **update_pet_with_form** +> update_pet_with_form(ctx, pet_id, optional) Updates a pet in the store with form data @@ -229,8 +229,8 @@ Name | Type | Description | Notes [[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) -# **UploadFile** -> ::models::ApiResponse UploadFile(ctx, pet_id, optional) +# **upload_file** +> ::models::ApiResponse upload_file(ctx, pet_id, optional) uploads an image diff --git a/samples/client/petstore/rust/docs/StoreApi.md b/samples/client/petstore/rust/docs/StoreApi.md index f2c523db474f..7da85fb64706 100644 --- a/samples/client/petstore/rust/docs/StoreApi.md +++ b/samples/client/petstore/rust/docs/StoreApi.md @@ -4,14 +4,14 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**DeleteOrder**](StoreApi.md#DeleteOrder) | **Delete** /store/order/{orderId} | Delete purchase order by ID -[**GetInventory**](StoreApi.md#GetInventory) | **Get** /store/inventory | Returns pet inventories by status -[**GetOrderById**](StoreApi.md#GetOrderById) | **Get** /store/order/{orderId} | Find purchase order by ID -[**PlaceOrder**](StoreApi.md#PlaceOrder) | **Post** /store/order | Place an order for a pet +[**delete_order**](StoreApi.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID +[**get_inventory**](StoreApi.md#get_inventory) | **Get** /store/inventory | Returns pet inventories by status +[**get_order_by_id**](StoreApi.md#get_order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID +[**place_order**](StoreApi.md#place_order) | **Post** /store/order | Place an order for a pet -# **DeleteOrder** -> DeleteOrder(order_id) +# **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 @@ -37,8 +37,8 @@ No authorization required [[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) -# **GetInventory** -> ::std::collections::HashMap GetInventory(ctx, ) +# **get_inventory** +> ::std::collections::HashMap get_inventory(ctx, ) Returns pet inventories by status Returns a map of status codes to quantities @@ -61,8 +61,8 @@ This endpoint does not need any parameter. [[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) -# **GetOrderById** -> ::models::Order GetOrderById(order_id) +# **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 generated exceptions @@ -88,8 +88,8 @@ No authorization required [[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) -# **PlaceOrder** -> ::models::Order PlaceOrder(body) +# **place_order** +> ::models::Order place_order(body) Place an order for a pet diff --git a/samples/client/petstore/rust/docs/UserApi.md b/samples/client/petstore/rust/docs/UserApi.md index 1ae4ba43937d..80ae627c3b4d 100644 --- a/samples/client/petstore/rust/docs/UserApi.md +++ b/samples/client/petstore/rust/docs/UserApi.md @@ -4,18 +4,18 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**CreateUser**](UserApi.md#CreateUser) | **Post** /user | Create user -[**CreateUsersWithArrayInput**](UserApi.md#CreateUsersWithArrayInput) | **Post** /user/createWithArray | Creates list of users with given input array -[**CreateUsersWithListInput**](UserApi.md#CreateUsersWithListInput) | **Post** /user/createWithList | Creates list of users with given input array -[**DeleteUser**](UserApi.md#DeleteUser) | **Delete** /user/{username} | Delete user -[**GetUserByName**](UserApi.md#GetUserByName) | **Get** /user/{username} | Get user by user name -[**LoginUser**](UserApi.md#LoginUser) | **Get** /user/login | Logs user into the system -[**LogoutUser**](UserApi.md#LogoutUser) | **Get** /user/logout | Logs out current logged in user session -[**UpdateUser**](UserApi.md#UpdateUser) | **Put** /user/{username} | Updated user +[**create_user**](UserApi.md#create_user) | **Post** /user | Create user +[**create_users_with_array_input**](UserApi.md#create_users_with_array_input) | **Post** /user/createWithArray | Creates list of users with given input array +[**create_users_with_list_input**](UserApi.md#create_users_with_list_input) | **Post** /user/createWithList | Creates list of users with given input array +[**delete_user**](UserApi.md#delete_user) | **Delete** /user/{username} | Delete user +[**get_user_by_name**](UserApi.md#get_user_by_name) | **Get** /user/{username} | Get user by user name +[**login_user**](UserApi.md#login_user) | **Get** /user/login | Logs user into the system +[**logout_user**](UserApi.md#logout_user) | **Get** /user/logout | Logs out current logged in user session +[**update_user**](UserApi.md#update_user) | **Put** /user/{username} | Updated user -# **CreateUser** -> CreateUser(body) +# **create_user** +> create_user(body) Create user This can only be done by the logged in user. @@ -41,8 +41,8 @@ No authorization required [[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) -# **CreateUsersWithArrayInput** -> CreateUsersWithArrayInput(body) +# **create_users_with_array_input** +> create_users_with_array_input(body) Creates list of users with given input array @@ -68,8 +68,8 @@ No authorization required [[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) -# **CreateUsersWithListInput** -> CreateUsersWithListInput(body) +# **create_users_with_list_input** +> create_users_with_list_input(body) Creates list of users with given input array @@ -95,8 +95,8 @@ No authorization required [[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) -# **DeleteUser** -> DeleteUser(username) +# **delete_user** +> delete_user(username) Delete user This can only be done by the logged in user. @@ -122,8 +122,8 @@ No authorization required [[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) -# **GetUserByName** -> ::models::User GetUserByName(username) +# **get_user_by_name** +> ::models::User get_user_by_name(username) Get user by user name @@ -149,8 +149,8 @@ No authorization required [[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) -# **LoginUser** -> String LoginUser(username, password) +# **login_user** +> String login_user(username, password) Logs user into the system @@ -177,8 +177,8 @@ No authorization required [[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) -# **LogoutUser** -> LogoutUser() +# **logout_user** +> logout_user() Logs out current logged in user session @@ -201,8 +201,8 @@ No authorization required [[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) -# **UpdateUser** -> UpdateUser(username, body) +# **update_user** +> update_user(username, body) Updated user This can only be done by the logged in user. diff --git a/samples/client/petstore/rust/examples/client.rs b/samples/client/petstore/rust/examples/client.rs index f690146421f7..0b0e73c2c3d7 100644 --- a/samples/client/petstore/rust/examples/client.rs +++ b/samples/client/petstore/rust/examples/client.rs @@ -12,32 +12,19 @@ fn main() { let mut core = Core::new().expect("failed to init core"); let handle = core.handle(); - let http_connector = HttpConnector::new(4, &handle); - - let client = Client::configure().connector(http_connector).build(&handle); - let api = "http://petstore.swagger.io:80/v2"; - let new_pet = petstore_client::models::Pet::new("barker".to_owned(), vec![]).with_id(1337); let apicli = petstore_client::apis::client::APIClient::new( petstore_client::apis::configuration::Configuration::new( Client::configure().connector(HttpConnector::new(4, &handle)).build(&handle))); - let work = apicli.pet_api().add_pet(&new_pet) + let work = apicli.pet_api().add_pet(new_pet) // petstore_client::apis::add_pet(api, &client, &new_pet) .and_then(|_| { - petstore_client::apis::update_pet_with_form( - api, - &client, - 1337, - "barko", - "escaped") + apicli.pet_api().update_pet_with_form(1337, "barko", "escaped") }) .and_then(|_| { - petstore_client::apis::get_pet_by_id( - api, - &client, - 1337) + apicli.pet_api().get_pet_by_id(1337) }) .and_then(|pet| { println!("pet: {:?}", pet); diff --git a/samples/client/petstore/rust/src/apis/add_pet_api.rs b/samples/client/petstore/rust/src/apis/add_pet_api.rs deleted file mode 100644 index 2d43880ce2de..000000000000 --- a/samples/client/petstore/rust/src/apis/add_pet_api.rs +++ /dev/null @@ -1,27 +0,0 @@ -use hyper; -use serde_json; -use futures::{Future, Stream}; -use futures; - -use super::models; -use super::Error; - -pub fn add_pet( - prefix: &str, - cli: &hyper::client::Client, - pet: &models::Pet, - ) -> Box> { - let mut req = hyper::Request::new( - hyper::Method::Post, - format!("{}/pet", prefix).parse().unwrap()); - let serialized = serde_json::to_string(pet).unwrap(); - req.headers_mut().set(hyper::header::ContentType::json()); - req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64)); - req.set_body(serialized); - - Box::new( - cli.request(req).and_then(|res| { res.body().concat2() }) - .map_err(|e| Error::from(e)) - .and_then(|_| futures::future::ok(())) - ) -} diff --git a/samples/client/petstore/rust/src/apis/api.rs b/samples/client/petstore/rust/src/apis/api.rs deleted file mode 100644 index e0429480fd1f..000000000000 --- a/samples/client/petstore/rust/src/apis/api.rs +++ /dev/null @@ -1,95 +0,0 @@ -use hyper; -use serde_json; - -#[derive(Debug)] -pub enum Error { - Hyper(hyper::Error), - Serde(serde_json::Error), -} - -impl From for Error { - fn from(e: hyper::Error) -> Self { - return Error::Hyper(e) - } -} - -impl From for Error { - fn from(e: serde_json::Error) -> Self { - return Error::Serde(e) - } -} - -use super::models; - -//Add a new pet to the store -mod pet_api_func; -pub use self::pet_api::AddPet; -//Deletes a pet -mod pet_api_func; -pub use self::pet_api::DeletePet; -//Finds Pets by status -mod pet_api_func; -pub use self::pet_api::FindPetsByStatus; -//Finds Pets by tags -mod pet_api_func; -pub use self::pet_api::FindPetsByTags; -//Find pet by ID -mod pet_api_func; -pub use self::pet_api::GetPetById; -//Update an existing pet -mod pet_api_func; -pub use self::pet_api::UpdatePet; -//Updates a pet in the store with form data -mod pet_api_func; -pub use self::pet_api::UpdatePetWithForm; -//uploads an image -mod pet_api_func; -pub use self::pet_api::UploadFile; - -mod pet_api_api; -pub use self::pet_api::PetApi; -//Delete purchase order by ID -mod store_api_func; -pub use self::store_api::DeleteOrder; -//Returns pet inventories by status -mod store_api_func; -pub use self::store_api::GetInventory; -//Find purchase order by ID -mod store_api_func; -pub use self::store_api::GetOrderById; -//Place an order for a pet -mod store_api_func; -pub use self::store_api::PlaceOrder; - -mod store_api_api; -pub use self::store_api::StoreApi; -//Create user -mod user_api_func; -pub use self::user_api::CreateUser; -//Creates list of users with given input array -mod user_api_func; -pub use self::user_api::CreateUsersWithArrayInput; -//Creates list of users with given input array -mod user_api_func; -pub use self::user_api::CreateUsersWithListInput; -//Delete user -mod user_api_func; -pub use self::user_api::DeleteUser; -//Get user by user name -mod user_api_func; -pub use self::user_api::GetUserByName; -//Logs user into the system -mod user_api_func; -pub use self::user_api::LoginUser; -//Logs out current logged in user session -mod user_api_func; -pub use self::user_api::LogoutUser; -//Updated user -mod user_api_func; -pub use self::user_api::UpdateUser; - -mod user_api_api; -pub use self::user_api::UserApi; - -pub mod configuration; -pub mod client; diff --git a/samples/client/petstore/rust/src/apis/get_pet_by_id_api.rs b/samples/client/petstore/rust/src/apis/get_pet_by_id_api.rs deleted file mode 100644 index 74ae95dc7da9..000000000000 --- a/samples/client/petstore/rust/src/apis/get_pet_by_id_api.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper; -use serde_json; -use futures::{Future, Stream}; - -use super::models; -use super::Error; - -pub fn get_pet_by_id( - prefix: &str, - cli: &hyper::client::Client, - pet_id: i64, - ) -> Box> { - Box::new( - cli.get(format!("{}/pet/{}", prefix, pet_id).parse().unwrap()) - - .and_then(|res| { res.body().concat2() }).map_err(|e| Error::from(e)) - - .and_then(|body| { - let parsed: Result = serde_json::from_slice(&body); - parsed.map_err(|e| Error::from(e)) - }).map_err(|e| Error::from(e)) - ) -} diff --git a/samples/client/petstore/rust/src/apis/pet_api.rs b/samples/client/petstore/rust/src/apis/pet_api.rs index 7c8249585cf0..246f7b0ed13a 100644 --- a/samples/client/petstore/rust/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/src/apis/pet_api.rs @@ -31,19 +31,19 @@ impl PetApiClient { } pub trait PetApi { - fn AddPet(&self, body: ::models::Pet) -> Box>; - fn DeletePet(&self, pet_id: i64, api_key: &str) -> Box>; - fn FindPetsByStatus(&self, status: Vec) -> Box, Error = Error>>; - fn FindPetsByTags(&self, tags: Vec) -> Box, Error = Error>>; - fn GetPetById(&self, pet_id: i64) -> Box>; - fn UpdatePet(&self, body: ::models::Pet) -> Box>; - fn UpdatePetWithForm(&self, pet_id: i64, name: &str, status: &str) -> Box>; - fn UploadFile(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box>; + fn add_pet(&self, body: ::models::Pet) -> Box>; + fn delete_pet(&self, pet_id: i64, api_key: &str) -> Box>; + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>>; + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>>; + fn get_pet_by_id(&self, pet_id: i64) -> Box>; + fn update_pet(&self, body: ::models::Pet) -> Box>; + fn update_pet_with_form(&self, pet_id: i64, name: &str, status: &str) -> Box>; + fn upload_file(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box>; } implPetApi for PetApiClient { - fn AddPet(&self, body: ::models::Pet) -> Box> { + fn add_pet(&self, body: ::models::Pet) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; @@ -71,7 +71,7 @@ implPetApi for PetApiClient { ) } - fn DeletePet(&self, pet_id: i64, api_key: &str) -> Box> { + fn delete_pet(&self, pet_id: i64, api_key: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Delete; @@ -99,7 +99,7 @@ implPetApi for PetApiClient { ) } - fn FindPetsByStatus(&self, status: Vec) -> Box, Error = Error>> { + fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -129,7 +129,7 @@ implPetApi for PetApiClient { ) } - fn FindPetsByTags(&self, tags: Vec) -> Box, Error = Error>> { + fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -159,7 +159,7 @@ implPetApi for PetApiClient { ) } - fn GetPetById(&self, pet_id: i64) -> Box> { + fn get_pet_by_id(&self, pet_id: i64) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -186,7 +186,7 @@ implPetApi for PetApiClient { ) } - fn UpdatePet(&self, body: ::models::Pet) -> Box> { + fn update_pet(&self, body: ::models::Pet) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Put; @@ -214,7 +214,7 @@ implPetApi for PetApiClient { ) } - fn UpdatePetWithForm(&self, pet_id: i64, name: &str, status: &str) -> Box> { + fn update_pet_with_form(&self, pet_id: i64, name: &str, status: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; @@ -238,7 +238,7 @@ implPetApi for PetApiClient { ) } - fn UploadFile(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box> { + fn upload_file(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; diff --git a/samples/client/petstore/rust/src/apis/store_api.rs b/samples/client/petstore/rust/src/apis/store_api.rs index f6165a22d453..fbae7a25883c 100644 --- a/samples/client/petstore/rust/src/apis/store_api.rs +++ b/samples/client/petstore/rust/src/apis/store_api.rs @@ -31,15 +31,15 @@ impl StoreApiClient { } pub trait StoreApi { - fn DeleteOrder(&self, order_id: &str) -> Box>; - fn GetInventory(&self, ) -> Box, Error = Error>>; - fn GetOrderById(&self, order_id: i64) -> Box>; - fn PlaceOrder(&self, body: ::models::Order) -> Box>; + fn delete_order(&self, order_id: &str) -> Box>; + fn get_inventory(&self, ) -> Box, Error = Error>>; + fn get_order_by_id(&self, order_id: i64) -> Box>; + fn place_order(&self, body: ::models::Order) -> Box>; } implStoreApi for StoreApiClient { - fn DeleteOrder(&self, order_id: &str) -> Box> { + fn delete_order(&self, order_id: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Delete; @@ -63,7 +63,7 @@ implStoreApi for StoreApiClient { ) } - fn GetInventory(&self, ) -> Box, Error = Error>> { + fn get_inventory(&self, ) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -90,7 +90,7 @@ implStoreApi for StoreApiClient { ) } - fn GetOrderById(&self, order_id: i64) -> Box> { + fn get_order_by_id(&self, order_id: i64) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -117,7 +117,7 @@ implStoreApi for StoreApiClient { ) } - fn PlaceOrder(&self, body: ::models::Order) -> Box> { + fn place_order(&self, body: ::models::Order) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; diff --git a/samples/client/petstore/rust/src/apis/update_pet_with_form_api.rs b/samples/client/petstore/rust/src/apis/update_pet_with_form_api.rs deleted file mode 100644 index a721d362179e..000000000000 --- a/samples/client/petstore/rust/src/apis/update_pet_with_form_api.rs +++ /dev/null @@ -1,31 +0,0 @@ -use hyper; -use futures::{Future, Stream}; -use url; -use futures; - -use super::Error; - -pub fn update_pet_with_form( - prefix: &str, - cli: &hyper::client::Client, - pet_id: i64, - name: &str, - status: &str, - ) -> Box> { - let mut req = hyper::Request::new( - hyper::Method::Post, - format!("{}/pet/{}", prefix, pet_id).parse().unwrap()); - let body = url::form_urlencoded::Serializer::new(String::new()) - .append_pair("name", name) - .append_pair("status", status) - .finish(); - req.headers_mut().set(hyper::header::ContentType::form_url_encoded()); - req.headers_mut().set(hyper::header::ContentLength(body.len() as u64)); - req.set_body(body); - - Box::new( - cli.request(req).and_then(|res| { res.body().concat2() }) - .map_err(|e| Error::from(e)) - .and_then(|_| futures::future::ok(())) - ) -} diff --git a/samples/client/petstore/rust/src/apis/user_api.rs b/samples/client/petstore/rust/src/apis/user_api.rs index 49925d7b3369..6a96c86d5c2e 100644 --- a/samples/client/petstore/rust/src/apis/user_api.rs +++ b/samples/client/petstore/rust/src/apis/user_api.rs @@ -31,19 +31,19 @@ impl UserApiClient { } pub trait UserApi { - fn CreateUser(&self, body: ::models::User) -> Box>; - fn CreateUsersWithArrayInput(&self, body: Vec<::models::User>) -> Box>; - fn CreateUsersWithListInput(&self, body: Vec<::models::User>) -> Box>; - fn DeleteUser(&self, username: &str) -> Box>; - fn GetUserByName(&self, username: &str) -> Box>; - fn LoginUser(&self, username: &str, password: &str) -> Box>; - fn LogoutUser(&self, ) -> Box>; - fn UpdateUser(&self, username: &str, body: ::models::User) -> Box>; + fn create_user(&self, body: ::models::User) -> Box>; + fn create_users_with_array_input(&self, body: Vec<::models::User>) -> Box>; + fn create_users_with_list_input(&self, body: Vec<::models::User>) -> Box>; + fn delete_user(&self, username: &str) -> Box>; + fn get_user_by_name(&self, username: &str) -> Box>; + fn login_user(&self, username: &str, password: &str) -> Box>; + fn logout_user(&self, ) -> Box>; + fn update_user(&self, username: &str, body: ::models::User) -> Box>; } implUserApi for UserApiClient { - fn CreateUser(&self, body: ::models::User) -> Box> { + fn create_user(&self, body: ::models::User) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; @@ -71,7 +71,7 @@ implUserApi for UserApiClient { ) } - fn CreateUsersWithArrayInput(&self, body: Vec<::models::User>) -> Box> { + fn create_users_with_array_input(&self, body: Vec<::models::User>) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; @@ -99,7 +99,7 @@ implUserApi for UserApiClient { ) } - fn CreateUsersWithListInput(&self, body: Vec<::models::User>) -> Box> { + fn create_users_with_list_input(&self, body: Vec<::models::User>) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Post; @@ -127,7 +127,7 @@ implUserApi for UserApiClient { ) } - fn DeleteUser(&self, username: &str) -> Box> { + fn delete_user(&self, username: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Delete; @@ -151,7 +151,7 @@ implUserApi for UserApiClient { ) } - fn GetUserByName(&self, username: &str) -> Box> { + fn get_user_by_name(&self, username: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -178,7 +178,7 @@ implUserApi for UserApiClient { ) } - fn LoginUser(&self, username: &str, password: &str) -> Box> { + fn login_user(&self, username: &str, password: &str) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -209,7 +209,7 @@ implUserApi for UserApiClient { ) } - fn LogoutUser(&self, ) -> Box> { + fn logout_user(&self, ) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Get; @@ -233,7 +233,7 @@ implUserApi for UserApiClient { ) } - fn UpdateUser(&self, username: &str, body: ::models::User) -> Box> { + fn update_user(&self, username: &str, body: ::models::User) -> Box> { let configuration: &configuration::Configuration = self.configuration.borrow(); let method = hyper::Method::Put; diff --git a/samples/client/petstore/rust/src/models/api_response.rs b/samples/client/petstore/rust/src/models/api_response.rs index 8597a1a4df55..91cbb74f7f27 100644 --- a/samples/client/petstore/rust/src/models/api_response.rs +++ b/samples/client/petstore/rust/src/models/api_response.rs @@ -12,9 +12,12 @@ #[derive(Debug, Serialize, Deserialize)] pub struct ApiResponse { - #[serde(rename = "code")] code: Option, - #[serde(rename = "type")] _type: Option, - #[serde(rename = "message")] message: Option + #[serde(rename = "code")] + code: Option, + #[serde(rename = "type")] + _type: Option, + #[serde(rename = "message")] + message: Option } impl ApiResponse { @@ -36,8 +39,12 @@ impl ApiResponse { self } - pub fn code(&self) -> &i32 { - &self.code + pub fn code(&self) -> Option<&i32> { + self.code.as_ref() + } + + pub fn reset_code(&mut self) { + self.code = None; } pub fn set__type(&mut self, _type: String) { @@ -49,8 +56,12 @@ impl ApiResponse { self } - pub fn _type(&self) -> &String { - &self._type + pub fn _type(&self) -> Option<&String> { + self._type.as_ref() + } + + pub fn reset__type(&mut self) { + self._type = None; } pub fn set_message(&mut self, message: String) { @@ -62,8 +73,12 @@ impl ApiResponse { self } - pub fn message(&self) -> &String { - &self.message + pub fn message(&self) -> Option<&String> { + self.message.as_ref() + } + + pub fn reset_message(&mut self) { + self.message = None; } } diff --git a/samples/client/petstore/rust/src/models/category.rs b/samples/client/petstore/rust/src/models/category.rs index 109d67aec795..c7c9265e14c5 100644 --- a/samples/client/petstore/rust/src/models/category.rs +++ b/samples/client/petstore/rust/src/models/category.rs @@ -12,8 +12,10 @@ #[derive(Debug, Serialize, Deserialize)] pub struct Category { - #[serde(rename = "id")] id: Option, - #[serde(rename = "name")] name: Option + #[serde(rename = "id")] + id: Option, + #[serde(rename = "name")] + name: Option } impl Category { @@ -34,8 +36,12 @@ impl Category { self } - pub fn id(&self) -> &i64 { - &self.id + pub fn id(&self) -> Option<&i64> { + self.id.as_ref() + } + + pub fn reset_id(&mut self) { + self.id = None; } pub fn set_name(&mut self, name: String) { @@ -47,8 +53,12 @@ impl Category { self } - pub fn name(&self) -> &String { - &self.name + pub fn name(&self) -> Option<&String> { + self.name.as_ref() + } + + pub fn reset_name(&mut self) { + self.name = None; } } diff --git a/samples/client/petstore/rust/src/models/order.rs b/samples/client/petstore/rust/src/models/order.rs index 5b6a40bea88d..75fce8840855 100644 --- a/samples/client/petstore/rust/src/models/order.rs +++ b/samples/client/petstore/rust/src/models/order.rs @@ -12,13 +12,19 @@ #[derive(Debug, Serialize, Deserialize)] pub struct Order { - #[serde(rename = "id")] id: Option, - #[serde(rename = "petId")] pet_id: Option, - #[serde(rename = "quantity")] quantity: Option, - #[serde(rename = "shipDate")] ship_date: Option, + #[serde(rename = "id")] + id: Option, + #[serde(rename = "petId")] + pet_id: Option, + #[serde(rename = "quantity")] + quantity: Option, + #[serde(rename = "shipDate")] + ship_date: Option, /// Order Status - #[serde(rename = "status")] status: Option, - #[serde(rename = "complete")] complete: Option + #[serde(rename = "status")] + status: Option, + #[serde(rename = "complete")] + complete: Option } impl Order { @@ -43,8 +49,12 @@ impl Order { self } - pub fn id(&self) -> &i64 { - &self.id + pub fn id(&self) -> Option<&i64> { + self.id.as_ref() + } + + pub fn reset_id(&mut self) { + self.id = None; } pub fn set_pet_id(&mut self, pet_id: i64) { @@ -56,8 +66,12 @@ impl Order { self } - pub fn pet_id(&self) -> &i64 { - &self.pet_id + pub fn pet_id(&self) -> Option<&i64> { + self.pet_id.as_ref() + } + + pub fn reset_pet_id(&mut self) { + self.pet_id = None; } pub fn set_quantity(&mut self, quantity: i32) { @@ -69,8 +83,12 @@ impl Order { self } - pub fn quantity(&self) -> &i32 { - &self.quantity + pub fn quantity(&self) -> Option<&i32> { + self.quantity.as_ref() + } + + pub fn reset_quantity(&mut self) { + self.quantity = None; } pub fn set_ship_date(&mut self, ship_date: String) { @@ -82,8 +100,12 @@ impl Order { self } - pub fn ship_date(&self) -> &String { - &self.ship_date + pub fn ship_date(&self) -> Option<&String> { + self.ship_date.as_ref() + } + + pub fn reset_ship_date(&mut self) { + self.ship_date = None; } pub fn set_status(&mut self, status: String) { @@ -95,8 +117,12 @@ impl Order { self } - pub fn status(&self) -> &String { - &self.status + pub fn status(&self) -> Option<&String> { + self.status.as_ref() + } + + pub fn reset_status(&mut self) { + self.status = None; } pub fn set_complete(&mut self, complete: bool) { @@ -108,8 +134,12 @@ impl Order { self } - pub fn complete(&self) -> &bool { - &self.complete + pub fn complete(&self) -> Option<&bool> { + self.complete.as_ref() + } + + pub fn reset_complete(&mut self) { + self.complete = None; } } diff --git a/samples/client/petstore/rust/src/models/pet.rs b/samples/client/petstore/rust/src/models/pet.rs index e1d04e749fdd..837358a3f3eb 100644 --- a/samples/client/petstore/rust/src/models/pet.rs +++ b/samples/client/petstore/rust/src/models/pet.rs @@ -12,13 +12,19 @@ #[derive(Debug, Serialize, Deserialize)] pub struct Pet { - #[serde(rename = "id")] id: Option, - #[serde(rename = "category")] category: Option<::models::Category>, - #[serde(rename = "name")] name: String, - #[serde(rename = "photoUrls")] photo_urls: Vec, - #[serde(rename = "tags")] tags: Option>, + #[serde(rename = "id")] + id: Option, + #[serde(rename = "category")] + category: Option<::models::Category>, + #[serde(rename = "name")] + name: String, + #[serde(rename = "photoUrls")] + photo_urls: Vec, + #[serde(rename = "tags")] + tags: Option>, /// pet status in the store - #[serde(rename = "status")] status: Option + #[serde(rename = "status")] + status: Option } impl Pet { @@ -43,8 +49,12 @@ impl Pet { self } - pub fn id(&self) -> &i64 { - &self.id + pub fn id(&self) -> Option<&i64> { + self.id.as_ref() + } + + pub fn reset_id(&mut self) { + self.id = None; } pub fn set_category(&mut self, category: ::models::Category) { @@ -56,8 +66,12 @@ impl Pet { self } - pub fn category(&self) -> &::models::Category { - &self.category + pub fn category(&self) -> Option<&::models::Category> { + self.category.as_ref() + } + + pub fn reset_category(&mut self) { + self.category = None; } pub fn set_name(&mut self, name: String) { @@ -73,6 +87,7 @@ impl Pet { &self.name } + pub fn set_photo_urls(&mut self, photo_urls: Vec) { self.photo_urls = photo_urls; } @@ -82,10 +97,11 @@ impl Pet { self } - pub fn photo_urls(&self) -> &Vec<String> { + pub fn photo_urls(&self) -> &Vec { &self.photo_urls } + pub fn set_tags(&mut self, tags: Vec<::models::Tag>) { self.tags = Some(tags); } @@ -95,8 +111,12 @@ impl Pet { self } - pub fn tags(&self) -> &Vec<::models::Tag> { - &self.tags + pub fn tags(&self) -> Option<&Vec<::models::Tag>> { + self.tags.as_ref() + } + + pub fn reset_tags(&mut self) { + self.tags = None; } pub fn set_status(&mut self, status: String) { @@ -108,8 +128,12 @@ impl Pet { self } - pub fn status(&self) -> &String { - &self.status + pub fn status(&self) -> Option<&String> { + self.status.as_ref() + } + + pub fn reset_status(&mut self) { + self.status = None; } } diff --git a/samples/client/petstore/rust/src/models/tag.rs b/samples/client/petstore/rust/src/models/tag.rs index 59dcd8c1cce4..2f328870a6cb 100644 --- a/samples/client/petstore/rust/src/models/tag.rs +++ b/samples/client/petstore/rust/src/models/tag.rs @@ -12,8 +12,10 @@ #[derive(Debug, Serialize, Deserialize)] pub struct Tag { - #[serde(rename = "id")] id: Option, - #[serde(rename = "name")] name: Option + #[serde(rename = "id")] + id: Option, + #[serde(rename = "name")] + name: Option } impl Tag { @@ -34,8 +36,12 @@ impl Tag { self } - pub fn id(&self) -> &i64 { - &self.id + pub fn id(&self) -> Option<&i64> { + self.id.as_ref() + } + + pub fn reset_id(&mut self) { + self.id = None; } pub fn set_name(&mut self, name: String) { @@ -47,8 +53,12 @@ impl Tag { self } - pub fn name(&self) -> &String { - &self.name + pub fn name(&self) -> Option<&String> { + self.name.as_ref() + } + + pub fn reset_name(&mut self) { + self.name = None; } } diff --git a/samples/client/petstore/rust/src/models/user.rs b/samples/client/petstore/rust/src/models/user.rs index fb5d417eeb4b..095131307a60 100644 --- a/samples/client/petstore/rust/src/models/user.rs +++ b/samples/client/petstore/rust/src/models/user.rs @@ -12,15 +12,23 @@ #[derive(Debug, Serialize, Deserialize)] pub struct User { - #[serde(rename = "id")] id: Option, - #[serde(rename = "username")] username: Option, - #[serde(rename = "firstName")] first_name: Option, - #[serde(rename = "lastName")] last_name: Option, - #[serde(rename = "email")] email: Option, - #[serde(rename = "password")] password: Option, - #[serde(rename = "phone")] phone: Option, + #[serde(rename = "id")] + id: Option, + #[serde(rename = "username")] + username: Option, + #[serde(rename = "firstName")] + first_name: Option, + #[serde(rename = "lastName")] + last_name: Option, + #[serde(rename = "email")] + email: Option, + #[serde(rename = "password")] + password: Option, + #[serde(rename = "phone")] + phone: Option, /// User Status - #[serde(rename = "userStatus")] user_status: Option + #[serde(rename = "userStatus")] + user_status: Option } impl User { @@ -47,8 +55,12 @@ impl User { self } - pub fn id(&self) -> &i64 { - &self.id + pub fn id(&self) -> Option<&i64> { + self.id.as_ref() + } + + pub fn reset_id(&mut self) { + self.id = None; } pub fn set_username(&mut self, username: String) { @@ -60,8 +72,12 @@ impl User { self } - pub fn username(&self) -> &String { - &self.username + pub fn username(&self) -> Option<&String> { + self.username.as_ref() + } + + pub fn reset_username(&mut self) { + self.username = None; } pub fn set_first_name(&mut self, first_name: String) { @@ -73,8 +89,12 @@ impl User { self } - pub fn first_name(&self) -> &String { - &self.first_name + pub fn first_name(&self) -> Option<&String> { + self.first_name.as_ref() + } + + pub fn reset_first_name(&mut self) { + self.first_name = None; } pub fn set_last_name(&mut self, last_name: String) { @@ -86,8 +106,12 @@ impl User { self } - pub fn last_name(&self) -> &String { - &self.last_name + pub fn last_name(&self) -> Option<&String> { + self.last_name.as_ref() + } + + pub fn reset_last_name(&mut self) { + self.last_name = None; } pub fn set_email(&mut self, email: String) { @@ -99,8 +123,12 @@ impl User { self } - pub fn email(&self) -> &String { - &self.email + pub fn email(&self) -> Option<&String> { + self.email.as_ref() + } + + pub fn reset_email(&mut self) { + self.email = None; } pub fn set_password(&mut self, password: String) { @@ -112,8 +140,12 @@ impl User { self } - pub fn password(&self) -> &String { - &self.password + pub fn password(&self) -> Option<&String> { + self.password.as_ref() + } + + pub fn reset_password(&mut self) { + self.password = None; } pub fn set_phone(&mut self, phone: String) { @@ -125,8 +157,12 @@ impl User { self } - pub fn phone(&self) -> &String { - &self.phone + pub fn phone(&self) -> Option<&String> { + self.phone.as_ref() + } + + pub fn reset_phone(&mut self) { + self.phone = None; } pub fn set_user_status(&mut self, user_status: i32) { @@ -138,8 +174,12 @@ impl User { self } - pub fn user_status(&self) -> &i32 { - &self.user_status + pub fn user_status(&self) -> Option<&i32> { + self.user_status.as_ref() + } + + pub fn reset_user_status(&mut self) { + self.user_status = None; } }