add uuid test, better hyper test (#12916)

This commit is contained in:
William Cheng 2022-07-19 11:22:29 +08:00 committed by GitHub
parent 4ee336a9da
commit b88666b87a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 259 additions and 1 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,46 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>RustHyperClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Rust Hyper Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>bundle-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cargo</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -4,6 +4,7 @@ use hyper;
use super::configuration::Configuration;
pub struct APIClient {
fake_api: Box<dyn crate::apis::FakeApi>,
pet_api: Box<dyn crate::apis::PetApi>,
store_api: Box<dyn crate::apis::StoreApi>,
user_api: Box<dyn crate::apis::UserApi>,
@ -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()
}

View File

@ -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<C: hyper::client::connect::Connect>
where C: Clone + std::marker::Send + Sync + 'static {
configuration: Rc<configuration::Configuration<C>>,
}
impl<C: hyper::client::connect::Connect> FakeApiClient<C>
where C: Clone + std::marker::Send + Sync {
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> FakeApiClient<C> {
FakeApiClient {
configuration,
}
}
}
pub trait FakeApi {
fn test_nullable_required_param(&self, username: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
}
impl<C: hyper::client::connect::Connect>FakeApi for FakeApiClient<C>
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<Box<dyn Future<Output = Result<(), Error>>>> {
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())
}
}

View File

@ -47,6 +47,8 @@ impl From<serde_json::Error> 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;

View File

@ -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;

View File

@ -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<uuid::Uuid>,
}
impl PropertyTest {
/// A model to test various formats, e.g. UUID
pub fn new() -> PropertyTest {
PropertyTest {
uuid: None,
}
}
}

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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<uuid::Uuid>,
}
impl PropertyTest {
/// A model to test various formats, e.g. UUID
pub fn new() -> PropertyTest {
PropertyTest {
uuid: None,
}
}
}