Skip to content

Commit c3a8599

Browse files
committed
Add test of rust's file handling
1 parent ede2180 commit c3a8599

File tree

30 files changed

+933
-1
lines changed

30 files changed

+933
-1
lines changed

bin/rust-petstore.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
3131
for spec_path in \
3232
modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
3333
modules/openapi-generator/src/test/resources/3_0/rust/rust-test.yaml \
34+
modules/openapi-generator/src/test/resources/2_0/fileResponseTest.json\
3435
; do
35-
spec=$(basename "$spec_path" | sed 's/.yaml//')
36+
spec=$(basename "$spec_path" | sed 's/.yaml//' | sed 's/.json//' )
3637

3738
for library in hyper reqwest; do
3839
ags="generate --template-dir modules/openapi-generator/src/main/resources/rust
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
**/*.rs.bk
3+
Cargo.lock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.1.0-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: rust
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "fileResponseTest-hyper"
3+
version = "1.0.0"
4+
authors = ["OpenAPI Generator team and contributors"]
5+
6+
[dependencies]
7+
serde = "^1.0"
8+
serde_derive = "^1.0"
9+
serde_json = "^1.0"
10+
url = "1.5"
11+
hyper = "~0.11"
12+
serde_yaml = "0.7"
13+
base64 = "~0.7.0"
14+
futures = "0.1.23"
15+
16+
[dev-dependencies]
17+
tokio-core = "*"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Rust API client for fileResponseTest-hyper
2+
3+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4+
5+
## Overview
6+
7+
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.
8+
9+
- API version: 1.0.0
10+
- Package version: 1.0.0
11+
- Build package: org.openapitools.codegen.languages.RustClientCodegen
12+
13+
## Installation
14+
15+
Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`:
16+
17+
```
18+
openapi = { path = "./generated" }
19+
```
20+
21+
## Documentation for API Endpoints
22+
23+
All URIs are relative to *http://localhost/v2*
24+
25+
Class | Method | HTTP request | Description
26+
------------ | ------------- | ------------- | -------------
27+
*DefaultApi* | [**fileresponsetest**](docs/DefaultApi.md#fileresponsetest) | **Get** /tests/fileResponse |
28+
29+
30+
## Documentation For Models
31+
32+
33+
34+
To get access to the crate's generated documentation, use:
35+
36+
```
37+
cargo doc --open
38+
```
39+
40+
## Author
41+
42+
43+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# \DefaultApi
2+
3+
All URIs are relative to *http://localhost/v2*
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**fileresponsetest**](DefaultApi.md#fileresponsetest) | **Get** /tests/fileResponse |
8+
9+
10+
11+
## fileresponsetest
12+
13+
> std::path::PathBuf fileresponsetest()
14+
15+
16+
### Parameters
17+
18+
This endpoint does not need any parameter.
19+
20+
### Return type
21+
22+
[**std::path::PathBuf**](std::path::PathBuf.md)
23+
24+
### Authorization
25+
26+
No authorization required
27+
28+
### HTTP request headers
29+
30+
- **Content-Type**: Not defined
31+
- **Accept**: application/octet-stream
32+
33+
[[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)
34+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
10+
if [ "$git_user_id" = "" ]; then
11+
git_user_id="GIT_USER_ID"
12+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13+
fi
14+
15+
if [ "$git_repo_id" = "" ]; then
16+
git_repo_id="GIT_REPO_ID"
17+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18+
fi
19+
20+
if [ "$release_note" = "" ]; then
21+
release_note="Minor update"
22+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23+
fi
24+
25+
# Initialize the local directory as a Git repository
26+
git init
27+
28+
# Adds the files in the local repository and stages them for commit.
29+
git add .
30+
31+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
32+
git commit -m "$release_note"
33+
34+
# Sets the new remote
35+
git_remote=`git remote`
36+
if [ "$git_remote" = "" ]; then # git remote not defined
37+
38+
if [ "$GIT_TOKEN" = "" ]; then
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
40+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41+
else
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43+
fi
44+
45+
fi
46+
47+
git pull origin master
48+
49+
# Pushes (Forces) the changes in the local repository up to the remote repository
50+
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
51+
git push origin master 2>&1 | grep -v 'To https'
52+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::rc::Rc;
2+
3+
use hyper;
4+
use super::configuration::Configuration;
5+
6+
pub struct APIClient {
7+
default_api: Box<crate::apis::DefaultApi>,
8+
}
9+
10+
impl APIClient {
11+
pub fn new<C: hyper::client::Connect>(configuration: Configuration<C>) -> APIClient {
12+
let rc = Rc::new(configuration);
13+
14+
APIClient {
15+
default_api: Box::new(crate::apis::DefaultApiClient::new(rc.clone())),
16+
}
17+
}
18+
19+
pub fn default_api(&self) -> &crate::apis::DefaultApi{
20+
self.default_api.as_ref()
21+
}
22+
23+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* File Response Test
3+
*
4+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5+
*
6+
* The version of the OpenAPI document: 1.0.0
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
use hyper;
12+
13+
pub struct Configuration<C: hyper::client::Connect> {
14+
pub base_path: String,
15+
pub user_agent: Option<String>,
16+
pub client: hyper::client::Client<C>,
17+
pub basic_auth: Option<BasicAuth>,
18+
pub oauth_access_token: Option<String>,
19+
pub api_key: Option<ApiKey>,
20+
// TODO: take an oauth2 token source, similar to the go one
21+
}
22+
23+
pub type BasicAuth = (String, Option<String>);
24+
25+
pub struct ApiKey {
26+
pub prefix: Option<String>,
27+
pub key: String,
28+
}
29+
30+
impl<C: hyper::client::Connect> Configuration<C> {
31+
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
32+
Configuration {
33+
base_path: "http://localhost/v2".to_owned(),
34+
user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()),
35+
client: client,
36+
basic_auth: None,
37+
oauth_access_token: None,
38+
api_key: None,
39+
}
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* File Response Test
3+
*
4+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5+
*
6+
* The version of the OpenAPI document: 1.0.0
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
use std::rc::Rc;
12+
use std::borrow::Borrow;
13+
14+
use hyper;
15+
use serde_json;
16+
use futures::Future;
17+
18+
use super::{Error, configuration};
19+
use super::request as __internal_request;
20+
21+
pub struct DefaultApiClient<C: hyper::client::Connect> {
22+
configuration: Rc<configuration::Configuration<C>>,
23+
}
24+
25+
impl<C: hyper::client::Connect> DefaultApiClient<C> {
26+
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> DefaultApiClient<C> {
27+
DefaultApiClient {
28+
configuration: configuration,
29+
}
30+
}
31+
}
32+
33+
pub trait DefaultApi {
34+
fn fileresponsetest(&self, ) -> Box<Future<Item = std::path::PathBuf, Error = Error<serde_json::Value>>>;
35+
}
36+
37+
38+
impl<C: hyper::client::Connect>DefaultApi for DefaultApiClient<C> {
39+
fn fileresponsetest(&self, ) -> Box<Future<Item = std::path::PathBuf, Error = Error<serde_json::Value>>> {
40+
__internal_request::Request::new(hyper::Method::Get, "/tests/fileResponse".to_string())
41+
.execute(self.configuration.borrow())
42+
}
43+
44+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use hyper;
2+
use serde;
3+
use serde_json;
4+
5+
#[derive(Debug)]
6+
pub enum Error<T> {
7+
UriError(hyper::error::UriError),
8+
Hyper(hyper::Error),
9+
Serde(serde_json::Error),
10+
ApiError(ApiError<T>),
11+
}
12+
13+
#[derive(Debug)]
14+
pub struct ApiError<T> {
15+
pub code: hyper::StatusCode,
16+
pub content: Option<T>,
17+
}
18+
19+
impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error<T>
20+
where T: serde::Deserialize<'de> {
21+
fn from(e: (hyper::StatusCode, &'de [u8])) -> Self {
22+
if e.1.len() == 0 {
23+
return Error::ApiError(ApiError{
24+
code: e.0,
25+
content: None,
26+
});
27+
}
28+
match serde_json::from_slice::<T>(e.1) {
29+
Ok(t) => Error::ApiError(ApiError{
30+
code: e.0,
31+
content: Some(t),
32+
}),
33+
Err(e) => {
34+
Error::from(e)
35+
}
36+
}
37+
}
38+
}
39+
40+
impl<T> From<hyper::Error> for Error<T> {
41+
fn from(e: hyper::Error) -> Self {
42+
return Error::Hyper(e)
43+
}
44+
}
45+
46+
impl<T> From<serde_json::Error> for Error<T> {
47+
fn from(e: serde_json::Error) -> Self {
48+
return Error::Serde(e)
49+
}
50+
}
51+
52+
mod request;
53+
54+
mod default_api;
55+
pub use self::default_api::{ DefaultApi, DefaultApiClient };
56+
57+
pub mod configuration;
58+
pub mod client;

0 commit comments

Comments
 (0)