From b88666b87acab1d59f5a1502c2445bf390ae8dfe Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 19 Jul 2022 11:22:29 +0800 Subject: [PATCH] add uuid test, better hyper test (#12916) --- bin/configs/rust-hyper-petstore.yaml | 2 +- .../src/test/resources/3_0/rust/petstore.yaml | 8 +++ .../hyper/petstore/.openapi-generator/FILES | 4 ++ .../petstore/rust/hyper/petstore/README.md | 2 + .../rust/hyper/petstore/docs/FakeApi.md | 41 +++++++++++++ .../rust/hyper/petstore/docs/PropertyTest.md | 11 ++++ .../petstore/rust/hyper/petstore/pom.xml | 46 ++++++++++++++ .../rust/hyper/petstore/src/apis/client.rs | 6 ++ .../rust/hyper/petstore/src/apis/fake_api.rs | 60 +++++++++++++++++++ .../rust/hyper/petstore/src/apis/mod.rs | 2 + .../rust/hyper/petstore/src/models/mod.rs | 2 + .../petstore/src/models/property_test.rs | 30 ++++++++++ .../reqwest/petstore/.openapi-generator/FILES | 2 + .../petstore/rust/reqwest/petstore/README.md | 1 + .../reqwest/petstore/docs/PropertyTest.md | 11 ++++ .../rust/reqwest/petstore/src/models/mod.rs | 2 + .../petstore/src/models/property_test.rs | 30 ++++++++++ 17 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md create mode 100644 samples/client/petstore/rust/hyper/petstore/docs/PropertyTest.md create mode 100644 samples/client/petstore/rust/hyper/petstore/pom.xml create mode 100644 samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs create mode 100644 samples/client/petstore/rust/hyper/petstore/src/models/property_test.rs create mode 100644 samples/client/petstore/rust/reqwest/petstore/docs/PropertyTest.md create mode 100644 samples/client/petstore/rust/reqwest/petstore/src/models/property_test.rs diff --git a/bin/configs/rust-hyper-petstore.yaml b/bin/configs/rust-hyper-petstore.yaml index c1a2520faa3..0d8ab210f77 100644 --- a/bin/configs/rust-hyper-petstore.yaml +++ b/bin/configs/rust-hyper-petstore.yaml @@ -1,7 +1,7 @@ generatorName: rust outputDir: samples/client/petstore/rust/hyper/petstore library: hyper -inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: supportAsync: "false" diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml index fd902c55160..a22fbc7896c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml @@ -769,3 +769,11 @@ components: type: string message: type: string + property_test: + title: A model to test various formats, e.g. UUID + description: A model to test various formats, e.g. UUID + type: object + properties: + uuid: + type: string + format: uuid diff --git a/samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES b/samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES index a670589b33e..5345a60cd98 100644 --- a/samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES +++ b/samples/client/petstore/rust/hyper/petstore/.openapi-generator/FILES @@ -4,9 +4,11 @@ Cargo.toml README.md docs/ApiResponse.md docs/Category.md +docs/FakeApi.md docs/Order.md docs/Pet.md docs/PetApi.md +docs/PropertyTest.md docs/StoreApi.md docs/Tag.md docs/User.md @@ -14,6 +16,7 @@ docs/UserApi.md git_push.sh src/apis/client.rs src/apis/configuration.rs +src/apis/fake_api.rs src/apis/mod.rs src/apis/pet_api.rs src/apis/request.rs @@ -25,5 +28,6 @@ src/models/category.rs src/models/mod.rs src/models/order.rs src/models/pet.rs +src/models/property_test.rs src/models/tag.rs src/models/user.rs diff --git a/samples/client/petstore/rust/hyper/petstore/README.md b/samples/client/petstore/rust/hyper/petstore/README.md index 3e4d0401e5e..2fe69e24cc8 100644 --- a/samples/client/petstore/rust/hyper/petstore/README.md +++ b/samples/client/petstore/rust/hyper/petstore/README.md @@ -25,6 +25,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **Get** /fake/user/{username} | To test nullable required parameters *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **Post** /pet | Add a new pet to the store *PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet *PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status @@ -53,6 +54,7 @@ Class | Method | HTTP request | Description - [Category](docs/Category.md) - [Order](docs/Order.md) - [Pet](docs/Pet.md) + - [PropertyTest](docs/PropertyTest.md) - [Tag](docs/Tag.md) - [User](docs/User.md) diff --git a/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md b/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md new file mode 100644 index 00000000000..df993a82f4b --- /dev/null +++ b/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md @@ -0,0 +1,41 @@ +# \FakeApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**test_nullable_required_param**](FakeApi.md#test_nullable_required_param) | **Get** /fake/user/{username} | To test nullable required parameters + + + +## test_nullable_required_param + +> test_nullable_required_param(username, dummy_required_nullable_param, uppercase) +To test nullable required parameters + + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**username** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | +**dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | +**uppercase** | Option<**String**> | To test parameter names in upper case | | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/rust/hyper/petstore/docs/PropertyTest.md b/samples/client/petstore/rust/hyper/petstore/docs/PropertyTest.md new file mode 100644 index 00000000000..3f36c163de0 --- /dev/null +++ b/samples/client/petstore/rust/hyper/petstore/docs/PropertyTest.md @@ -0,0 +1,11 @@ +# PropertyTest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**uuid** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/hyper/petstore/pom.xml b/samples/client/petstore/rust/hyper/petstore/pom.xml new file mode 100644 index 00000000000..bf771956527 --- /dev/null +++ b/samples/client/petstore/rust/hyper/petstore/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + org.openapitools + RustHyperClientTests + pom + 1.0-SNAPSHOT + Rust Hyper Petstore Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + bundle-test + integration-test + + exec + + + cargo + + test + + + + + + + + diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs index 290b99e86f3..e209050c597 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs @@ -4,6 +4,7 @@ use hyper; use super::configuration::Configuration; pub struct APIClient { + fake_api: Box, pet_api: Box, store_api: Box, user_api: Box, @@ -15,12 +16,17 @@ impl APIClient { let rc = Rc::new(configuration); APIClient { + fake_api: Box::new(crate::apis::FakeApiClient::new(rc.clone())), 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 fake_api(&self) -> &dyn crate::apis::FakeApi{ + self.fake_api.as_ref() + } + pub fn pet_api(&self) -> &dyn crate::apis::PetApi{ self.pet_api.as_ref() } diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs new file mode 100644 index 00000000000..49ffc5a3bce --- /dev/null +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs @@ -0,0 +1,60 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use std::rc::Rc; +use std::borrow::Borrow; +use std::pin::Pin; +#[allow(unused_imports)] +use std::option::Option; + +use hyper; +use futures::Future; + +use super::{Error, configuration}; +use super::request as __internal_request; + +pub struct FakeApiClient + where C: Clone + std::marker::Send + Sync + 'static { + configuration: Rc>, +} + +impl FakeApiClient + where C: Clone + std::marker::Send + Sync { + pub fn new(configuration: Rc>) -> FakeApiClient { + FakeApiClient { + configuration, + } + } +} + +pub trait FakeApi { + fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin>>>; +} + +implFakeApi for FakeApiClient + where C: Clone + std::marker::Send + Sync { + #[allow(unused_mut)] + fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/fake/user/{username}".to_string()) + ; + req = req.with_path_param("username".to_string(), username.to_string()); + match dummy_required_nullable_param { + Some(param_value) => { req = req.with_header_param("dummy_required_nullable_param".to_string(), param_value.to_string()); }, + None => { req = req.with_header_param("dummy_required_nullable_param".to_string(), "".to_string()); }, + } + if let Some(param_value) = uppercase { + req = req.with_header_param("UPPERCASE".to_string(), param_value.to_string()); + } + req = req.returns_nothing(); + + req.execute(self.configuration.borrow()) + } + +} diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs index 1245257e5d8..e2ccc5d6a38 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs @@ -47,6 +47,8 @@ impl From for Error { mod request; +mod fake_api; +pub use self::fake_api::{ FakeApi, FakeApiClient }; mod pet_api; pub use self::pet_api::{ PetApi, PetApiClient }; mod store_api; diff --git a/samples/client/petstore/rust/hyper/petstore/src/models/mod.rs b/samples/client/petstore/rust/hyper/petstore/src/models/mod.rs index 1baf2f7528e..37334443da2 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/models/mod.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/models/mod.rs @@ -6,6 +6,8 @@ pub mod order; pub use self::order::Order; pub mod pet; pub use self::pet::Pet; +pub mod property_test; +pub use self::property_test::PropertyTest; pub mod tag; pub use self::tag::Tag; pub mod user; diff --git a/samples/client/petstore/rust/hyper/petstore/src/models/property_test.rs b/samples/client/petstore/rust/hyper/petstore/src/models/property_test.rs new file mode 100644 index 00000000000..1c3c4f3f3fc --- /dev/null +++ b/samples/client/petstore/rust/hyper/petstore/src/models/property_test.rs @@ -0,0 +1,30 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// PropertyTest : A model to test various formats, e.g. UUID + + + +#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] +pub struct PropertyTest { + #[serde(rename = "uuid", skip_serializing_if = "Option::is_none")] + pub uuid: Option, +} + +impl PropertyTest { + /// A model to test various formats, e.g. UUID + pub fn new() -> PropertyTest { + PropertyTest { + uuid: None, + } + } +} + + diff --git a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/FILES b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/FILES index 9ad23161e6f..75bd989a45f 100644 --- a/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/FILES +++ b/samples/client/petstore/rust/reqwest/petstore/.openapi-generator/FILES @@ -8,6 +8,7 @@ docs/FakeApi.md docs/Order.md docs/Pet.md docs/PetApi.md +docs/PropertyTest.md docs/StoreApi.md docs/Tag.md docs/User.md @@ -25,5 +26,6 @@ src/models/category.rs src/models/mod.rs src/models/order.rs src/models/pet.rs +src/models/property_test.rs src/models/tag.rs src/models/user.rs diff --git a/samples/client/petstore/rust/reqwest/petstore/README.md b/samples/client/petstore/rust/reqwest/petstore/README.md index c2d345f9ef9..af68b013a2d 100644 --- a/samples/client/petstore/rust/reqwest/petstore/README.md +++ b/samples/client/petstore/rust/reqwest/petstore/README.md @@ -54,6 +54,7 @@ Class | Method | HTTP request | Description - [Category](docs/Category.md) - [Order](docs/Order.md) - [Pet](docs/Pet.md) + - [PropertyTest](docs/PropertyTest.md) - [Tag](docs/Tag.md) - [User](docs/User.md) diff --git a/samples/client/petstore/rust/reqwest/petstore/docs/PropertyTest.md b/samples/client/petstore/rust/reqwest/petstore/docs/PropertyTest.md new file mode 100644 index 00000000000..3f36c163de0 --- /dev/null +++ b/samples/client/petstore/rust/reqwest/petstore/docs/PropertyTest.md @@ -0,0 +1,11 @@ +# PropertyTest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**uuid** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/rust/reqwest/petstore/src/models/mod.rs b/samples/client/petstore/rust/reqwest/petstore/src/models/mod.rs index 1baf2f7528e..37334443da2 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/models/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/models/mod.rs @@ -6,6 +6,8 @@ pub mod order; pub use self::order::Order; pub mod pet; pub use self::pet::Pet; +pub mod property_test; +pub use self::property_test::PropertyTest; pub mod tag; pub use self::tag::Tag; pub mod user; diff --git a/samples/client/petstore/rust/reqwest/petstore/src/models/property_test.rs b/samples/client/petstore/rust/reqwest/petstore/src/models/property_test.rs new file mode 100644 index 00000000000..1c3c4f3f3fc --- /dev/null +++ b/samples/client/petstore/rust/reqwest/petstore/src/models/property_test.rs @@ -0,0 +1,30 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +/// PropertyTest : A model to test various formats, e.g. UUID + + + +#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] +pub struct PropertyTest { + #[serde(rename = "uuid", skip_serializing_if = "Option::is_none")] + pub uuid: Option, +} + +impl PropertyTest { + /// A model to test various formats, e.g. UUID + pub fn new() -> PropertyTest { + PropertyTest { + uuid: None, + } + } +} + +