Skip to content

Commit

Permalink
[rust] Make it easier to test rust client generator (OpenAPITools#3543)
Browse files Browse the repository at this point in the history
As we discovered in OpenAPITools#3463, there are various bits of the rust client generator that are currently untested. This PR adds tests for various generator-specific types, and also files.

Follows the example of the rust-server generator for making it easy to add new test specs. This should make it easier for future contributors to make sure that their contributions are tested
  • Loading branch information
bjgill authored and Jesse Michael committed Oct 3, 2019
1 parent 44116b3 commit 4fcf05c
Show file tree
Hide file tree
Showing 134 changed files with 2,064 additions and 174 deletions.
19 changes: 17 additions & 2 deletions bin/rust-petstore.sh
Expand Up @@ -27,6 +27,21 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/rust -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g rust -o samples/client/petstore/rust --additional-properties packageName=petstore_client --library=hyper $@"

java ${JAVA_OPTS} -jar ${executable} ${ags}
for spec_path in \
modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
modules/openapi-generator/src/test/resources/3_0/rust/rust-test.yaml \
modules/openapi-generator/src/test/resources/2_0/fileResponseTest.json\
; do
spec=$(basename "$spec_path" | sed 's/.yaml//' | sed 's/.json//' )

for library in hyper reqwest; do
args="generate --template-dir modules/openapi-generator/src/main/resources/rust
--input-spec $spec_path
--generator-name rust
--output samples/client/petstore/rust/$library/$spec
--additional-properties packageName=${spec}-${library}
--library=$library $@"
java ${JAVA_OPTS} -jar ${executable} ${args} || exit 1
done
done
32 changes: 0 additions & 32 deletions bin/rust-reqwest-petstore.sh

This file was deleted.

@@ -0,0 +1,31 @@
openapi: 3.0.1
info:
title: Rust client test spec
description: Special testing for the Rust client generator
version: 1.0.7
paths:
/dummy:
get:
summary: A dummy endpoint to make the spec valid.
responses:
'200':
description: Success
components:
schemas:
TypeTesting:
description: Test handling of differing types (see \#3463)
type: object
properties:
integer:
type: integer
long:
type: long
number:
type: number
float:
type: float
double:
type: double
uuid:
type: string
format: uuid
1 change: 0 additions & 1 deletion pom.xml
Expand Up @@ -1039,7 +1039,6 @@
<!-- <module>samples/client/petstore/cpp-qt5</module> -->
<module>samples/client/petstore/elm-0.18</module>
<module>samples/client/petstore/rust</module>
<module>samples/client/petstore/rust-reqwest</module>
<!--<module>samples/client/petstore/perl</module>-->
<module>samples/client/petstore/php/OpenAPIClient-php</module>
<module>samples/openapi3/client/petstore/php/OpenAPIClient-php</module>
Expand Down

This file was deleted.

46 changes: 0 additions & 46 deletions samples/client/petstore/rust-reqwest/pom.xml

This file was deleted.

34 changes: 0 additions & 34 deletions samples/client/petstore/rust-reqwest/src/apis/client.rs.orig

This file was deleted.

3 changes: 1 addition & 2 deletions samples/client/petstore/rust/.gitignore
@@ -1,3 +1,2 @@
/target/
**/*.rs.bk
target
Cargo.lock

This file was deleted.

19 changes: 2 additions & 17 deletions samples/client/petstore/rust/Cargo.toml
@@ -1,17 +1,2 @@
[package]
name = "petstore_client"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
url = "1.5"
hyper = "~0.11"
serde_yaml = "0.7"
base64 = "~0.7.0"
futures = "0.1.23"

[dev-dependencies]
tokio-core = "*"
[workspace]
members = ["hyper/*", "reqwest/*"]
17 changes: 17 additions & 0 deletions samples/client/petstore/rust/hyper/fileResponseTest/Cargo.toml
@@ -0,0 +1,17 @@
[package]
name = "fileResponseTest-hyper"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
url = "1.5"
hyper = "~0.11"
serde_yaml = "0.7"
base64 = "~0.7.0"
futures = "0.1.23"

[dev-dependencies]
tokio-core = "*"
43 changes: 43 additions & 0 deletions samples/client/petstore/rust/hyper/fileResponseTest/README.md
@@ -0,0 +1,43 @@
# Rust API client for fileResponseTest-hyper

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

## Overview

This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.RustClientCodegen

## Installation

Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`:

```
openapi = { path = "./generated" }
```

## Documentation for API Endpoints

All URIs are relative to *http://localhost/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DefaultApi* | [**fileresponsetest**](docs/DefaultApi.md#fileresponsetest) | **Get** /tests/fileResponse |


## Documentation For Models



To get access to the crate's generated documentation, use:

```
cargo doc --open
```

## Author



@@ -0,0 +1,34 @@
# \DefaultApi

All URIs are relative to *http://localhost/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**fileresponsetest**](DefaultApi.md#fileresponsetest) | **Get** /tests/fileResponse |



## fileresponsetest

> std::path::PathBuf fileresponsetest()

### Parameters

This endpoint does not need any parameter.

### Return type

[**std::path::PathBuf**](std::path::PathBuf.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/octet-stream

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

@@ -0,0 +1,23 @@
use std::rc::Rc;

use hyper;
use super::configuration::Configuration;

pub struct APIClient {
default_api: Box<crate::apis::DefaultApi>,
}

impl APIClient {
pub fn new<C: hyper::client::Connect>(configuration: Configuration<C>) -> APIClient {
let rc = Rc::new(configuration);

APIClient {
default_api: Box::new(crate::apis::DefaultApiClient::new(rc.clone())),
}
}

pub fn default_api(&self) -> &crate::apis::DefaultApi{
self.default_api.as_ref()
}

}
@@ -0,0 +1,41 @@
/*
* File Response Test
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

use hyper;

pub struct Configuration<C: hyper::client::Connect> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub api_key: Option<ApiKey>,
// TODO: take an oauth2 token source, similar to the go one
}

pub type BasicAuth = (String, Option<String>);

pub struct ApiKey {
pub prefix: Option<String>,
pub key: String,
}

impl<C: hyper::client::Connect> Configuration<C> {
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
Configuration {
base_path: "http://localhost/v2".to_owned(),
user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()),
client: client,
basic_auth: None,
oauth_access_token: None,
api_key: None,
}
}
}

0 comments on commit 4fcf05c

Please sign in to comment.