Merge remote-tracking branch 'origin/4.2.x' into 5.0.x

This commit is contained in:
William Cheng
2019-08-12 00:22:19 +08:00
2707 changed files with 105802 additions and 13266 deletions

View File

@@ -0,0 +1,18 @@
[build]
rustflags = [
"-W", "missing_docs", # detects missing documentation for public members
"-W", "trivial_casts", # detects trivial casts which could be removed
"-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed
"-W", "unsafe_code", # usage of `unsafe` code
"-W", "unused_qualifications", # detects unnecessarily qualified names
"-W", "unused_extern_crates", # extern crates that are never used
"-W", "unused_import_braces", # unnecessary braces around an imported item
"-D", "warnings", # all warnings should be denied
]

View File

@@ -0,0 +1,2 @@
target
Cargo.lock

View File

@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@@ -0,0 +1 @@
5.0.0-SNAPSHOT

View File

@@ -0,0 +1,48 @@
[package]
name = "multipart-v3"
version = "1.0.7"
authors = []
description = "API under test"
license = "Unlicense"
[features]
default = ["client", "server"]
client = ["serde_json", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"]
server = ["serde_json", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"]
[dependencies]
# Required by example server.
#
chrono = { version = "0.4", features = ["serde"] }
futures = "0.1"
hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true}
swagger = "2"
# Not required by example server.
#
lazy_static = "0.2"
log = "0.3.0"
mime = "0.2.6"
multipart = {version = "0.13.3"}
native-tls = {version = "0.1.4", optional = true}
openssl = {version = "0.9.14", optional = true}
percent-encoding = {version = "1.0.0", optional = true}
regex = {version = "0.2", optional = true}
serde = "1.0"
serde_derive = "1.0"
serde_ignored = {version = "0.0.4", optional = true}
serde_json = {version = "1.0", optional = true}
serde_urlencoded = {version = "0.5.1", optional = true}
tokio-core = {version = "0.1.6", optional = true}
tokio-proto = {version = "0.1.1", optional = true}
tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]}
url = {version = "1.5", optional = true}
uuid = {version = "0.5", optional = true, features = ["serde", "v4"]}
# ToDo: this should be updated to point at the official crate once
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
[dev-dependencies]
clap = "2.25"
error-chain = "0.12"

View File

@@ -0,0 +1,128 @@
# Rust API for multipart-v3
API under test
## Overview
This client/server was generated by the [openapi-generator]
(https://openapi-generator.tech) project.
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
-
To see how to make this your own, look here:
[README]((https://openapi-generator.tech))
- API version: 1.0.7
This autogenerated project defines an API crate `multipart-v3` which contains:
* An `Api` trait defining the API in Rust.
* Data types representing the underlying data model.
* A `Client` type which implements `Api` and issues HTTP requests for each operation.
* A router which accepts HTTP requests and invokes the appropriate `Api` method for each operation.
It also contains an example server and client which make use of `multipart-v3`:
* The example server starts up a web server using the `multipart-v3` router,
and supplies a trivial implementation of `Api` which returns failure for every operation.
* The example client provides a CLI which lets you invoke any single operation on the
`multipart-v3` client by passing appropriate arguments on the command line.
You can use the example server and client as a basis for your own code.
See below for [more detail on implementing a server](#writing-a-server).
## Examples
Run examples with:
```
cargo run --example <example-name>
```
To pass in arguments to the examples, put them after `--`, for example:
```
cargo run --example client -- --help
```
### Running the server
To run the server, follow these simple steps:
```
cargo run --example server
```
### Running a client
To run a client, follow one of the following simple steps:
```
cargo run --example client MultipartRequestPost
```
### HTTPS
The examples can be run in HTTPS mode by passing in the flag `--https`, for example:
```
cargo run --example server -- --https
```
This will use the keys/certificates from the examples directory. Note that the server chain is signed with
`CN=localhost`.
## Writing a server
The server example is designed to form the basis for implementing your own server. Simply follow these steps.
* Set up a new Rust project, e.g., with `cargo init --bin`.
* Insert `multipart-v3` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "multipart-v3" ]`.
* Add `multipart-v3 = {version = "1.0.7", path = "multipart-v3"}` under `[dependencies]` in the root `Cargo.toml`.
* Copy the `[dependencies]` and `[dev-dependencies]` from `multipart-v3/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section.
* Copy all of the `[dev-dependencies]`, but only the `[dependencies]` that are required by the example server. These should be clearly indicated by comments.
* Remove `"optional = true"` from each of these lines if present.
Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time:
```
cp multipart-v3/examples/server.rs src/main.rs
cp multipart-v3/examples/server_lib/mod.rs src/lib.rs
cp multipart-v3/examples/server_lib/server.rs src/server.rs
```
Now
* From `src/main.rs`, remove the `mod server_lib;` line, and uncomment and fill in the `extern crate` line with the name of this server crate.
* Move the block of imports "required by the service library" from `src/main.rs` to `src/lib.rs` and uncomment.
* Change the `let server = server::Server {};` line to `let server = SERVICE_NAME::server().unwrap();` where `SERVICE_NAME` is the name of the server crate.
* Run `cargo build` to check it builds.
* Run `cargo fmt` to reformat the code.
* Commit the result before making any further changes (lest format changes get confused with your own updates).
Now replace the implementations in `src/server.rs` with your own code as required.
## Updating your server to track API changes
Later, if the API changes, you can copy new sections from the autogenerated API stub into your implementation.
Alternatively, implement the now-missing methods based on the compiler's error messages.
## Documentation for API Endpoints
All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
[****](docs/default_api.md#) | **POST** /multipart_request |
## Documentation For Models
- [MultipartRequest](docs/MultipartRequest.md)
- [MultipartRequestObjectField](docs/MultipartRequestObjectField.md)
## Documentation For Authorization
Endpoints do not require authorization.
## Author

View File

@@ -0,0 +1,47 @@
openapi: 3.0.1
info:
description: API under test
title: Multipart OpenAPI V3 Rust Server Test
version: 1.0.7
servers:
- url: /
paths:
/multipart_request:
post:
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/multipart_request'
required: true
responses:
201:
description: OK
components:
schemas:
multipart_request:
properties:
string_field:
type: string
optional_string_field:
type: string
object_field:
$ref: '#/components/schemas/multipart_request_object_field'
binary_field:
format: byte
type: string
required:
- binary_field
- string_field
type: object
multipart_request_object_field:
properties:
field_a:
type: string
field_b:
items:
type: string
type: array
required:
- field_a

View File

@@ -0,0 +1,13 @@
# MultipartRequest
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**string_field** | **String** | |
**optional_string_field** | **String** | | [optional] [default to None]
**object_field** | [***models::MultipartRequestObjectField**](multipart_request_object_field.md) | | [optional] [default to None]
**binary_field** | [***swagger::ByteArray**](ByteArray.md) | |
[[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,11 @@
# MultipartRequestObjectField
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**field_a** | **String** | |
**field_b** | **Vec<String>** | | [optional] [default to None]
[[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 @@
# default_api
All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
****](default_api.md#) | **POST** /multipart_request |
# ****
> (string_field, binary_field, optional)
### Required Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**string_field** | **String**| |
**binary_field** | **swagger::ByteArray**| |
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
### Optional Parameters
Optional parameters are passed through a map[string]interface{}.
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**string_field** | **String**| |
**binary_field** | **swagger::ByteArray**| |
**optional_string_field** | **String**| |
**object_field** | [**multipart_request_object_field**](multipart_request_object_field.md)| |
### Return type
(empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **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,17 @@
-----BEGIN CERTIFICATE-----
MIICtjCCAZ4CCQDpKecRERZ0xDANBgkqhkiG9w0BAQsFADAdMQswCQYDVQQGEwJV
UzEOMAwGA1UEAxMFTXkgQ0EwHhcNMTcwNTIzMTYwMDIzWhcNMTcwNjIyMTYwMDIz
WjAdMQswCQYDVQQGEwJVUzEOMAwGA1UEAxMFTXkgQ0EwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCt66py3x7sCSASRF2D05L5wkNDxAUjQKYx23W8Gbwv
GMGykk89BIdU5LX1JB1cKiUOkoIxfwAYuWc2V/wzTvVV7+11besnk3uX1c9KiqUF
LIX7kn/z5hzS4aelhKvH+MJlSZCSlp1ytpZbwo5GB5Pi2SGH56jDBiBoDRNBVdWL
z4wH7TdrQjqWwNxIZumD5OGMtcfJyuX08iPiEOaslOeoMqzObhvjc9aUgjVjhqyA
FkJGTXsi0oaD7oml+NE+mTNfEeZvEJQpLSjBY0OvQHzuHkyGBShBnfu/9x7/NRwd
WaqsLiF7/re9KDGYdJwP7Cu6uxYfKAyWarp6h2mG/GIdAgMBAAEwDQYJKoZIhvcN
AQELBQADggEBAGIl/VVIafeq/AJOQ9r7TzzB2ABJYr7NZa6bTu5O1jSp1Fonac15
SZ8gvRxODgH22ZYSqghPG4xzq4J3hkytlQqm57ZEt2I2M3OqIp17Ndcc1xDYzpLl
tA0FrVn6crQTM8vQkTDtGesaCWX+7Fir5dK7HnYWzfpSmsOpST07PfbNisEXKOxG
Dj4lBL1OnhTjsJeymVS1pFvkKkrcEJO+IxFiHL3CDsWjcXB0Z+E1zBtPoYyYsNsO
rBrjUxcZewF4xqWZhpW90Mt61fY2nRgU0uUwHcvDQUqvmzKcsqYa4mPKzfBI5mxo
01Ta96cDD6pS5Y1hOflZ0g84f2g/7xBLLDA=
-----END CERTIFICATE-----

View File

@@ -0,0 +1,82 @@
#![allow(missing_docs, unused_variables, trivial_casts)]
extern crate multipart_v3;
#[allow(unused_extern_crates)]
extern crate futures;
#[allow(unused_extern_crates)]
#[macro_use]
extern crate swagger;
#[allow(unused_extern_crates)]
extern crate uuid;
extern crate clap;
extern crate tokio_core;
use swagger::{ContextBuilder, EmptyContext, XSpanIdString, Has, Push, AuthData};
#[allow(unused_imports)]
use futures::{Future, future, Stream, stream};
use tokio_core::reactor;
#[allow(unused_imports)]
use multipart_v3::{ApiNoContext, ContextWrapperExt,
ApiError,
MultipartRequestPostResponse
};
use clap::{App, Arg};
fn main() {
let matches = App::new("client")
.arg(Arg::with_name("operation")
.help("Sets the operation to run")
.possible_values(&[
"MultipartRequestPost",
])
.required(true)
.index(1))
.arg(Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"))
.arg(Arg::with_name("host")
.long("host")
.takes_value(true)
.default_value("localhost")
.help("Hostname to contact"))
.arg(Arg::with_name("port")
.long("port")
.takes_value(true)
.default_value("80")
.help("Port to contact"))
.get_matches();
let mut core = reactor::Core::new().unwrap();
let is_https = matches.is_present("https");
let base_url = format!("{}://{}:{}",
if is_https { "https" } else { "http" },
matches.value_of("host").unwrap(),
matches.value_of("port").unwrap());
let client = if matches.is_present("https") {
// Using Simple HTTPS
multipart_v3::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
.expect("Failed to create HTTPS client")
} else {
// Using HTTP
multipart_v3::Client::try_new_http(core.handle(), &base_url)
.expect("Failed to create HTTP client")
};
let context: make_context_ty!(ContextBuilder, EmptyContext, Option<AuthData>, XSpanIdString) =
make_context!(ContextBuilder, EmptyContext, None as Option<AuthData>, XSpanIdString(self::uuid::Uuid::new_v4().to_string()));
let client = client.with_context(context);
match matches.value_of("operation") {
Some("MultipartRequestPost") => {
let result = core.run(client.multipart_request_post("string_field_example".to_string(), swagger::ByteArray(Vec::from("BYTE_ARRAY_DATA_HERE")), Some("optional_string_field_example".to_string()), None));
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
_ => {
panic!("Invalid operation provided")
}
}
}

View File

@@ -0,0 +1,66 @@
Certificate:
Data:
Version: 1 (0x0)
Serial Number: 4096 (0x1000)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=US, CN=My CA
Validity
Not Before: May 23 16:00:23 2017 GMT
Not After : Apr 29 16:00:23 2117 GMT
Subject: CN=localhost, C=US
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:c9:d4:43:60:50:fc:d6:0f:38:4d:5d:5e:aa:7c:
c0:5e:a9:ec:d9:93:78:d3:93:72:28:41:f5:08:a5:
ea:ac:67:07:d7:1f:f7:7d:74:69:7e:46:89:20:4b:
7a:2d:9b:02:08:e7:6f:0f:1d:0c:0f:c7:60:69:19:
4b:df:7e:ca:75:94:0b:49:71:e3:6d:f2:e8:79:fd:
ed:0a:94:67:55:f3:ca:6b:61:ba:58:b7:2e:dd:7b:
ca:b9:02:9f:24:36:ac:26:8f:04:8f:81:c8:35:10:
f4:aa:33:b2:24:16:f8:f7:1e:ea:f7:16:fe:fa:34:
c3:dd:bb:2c:ba:7a:df:4d:e2:da:1e:e5:d2:28:44:
6e:c8:96:e0:fd:09:0c:14:0c:31:dc:e0:ca:c1:a7:
9b:bf:16:8c:f7:36:3f:1b:2e:dd:90:eb:45:78:51:
bf:59:22:1e:c6:8c:0a:69:88:e5:03:5e:73:b7:fc:
93:7f:1b:46:1b:97:68:c5:c0:8b:35:1f:bb:1e:67:
7f:55:b7:3b:55:3f:ea:f2:ca:db:cc:52:cd:16:89:
db:15:47:bd:f2:cd:6c:7a:d7:b4:1a:ac:c8:15:6c:
6a:fb:77:c4:e9:f2:30:e0:14:24:66:65:6f:2a:e5:
2d:cc:f6:81:ae:57:c8:d1:9b:38:90:dc:60:93:02:
5e:cb
Exponent: 65537 (0x10001)
Signature Algorithm: sha256WithRSAEncryption
1c:7c:39:e8:3d:49:b2:09:1e:68:5a:2f:74:18:f4:63:b5:8c:
f6:e6:a1:e3:4d:95:90:99:ef:32:5c:34:40:e8:55:13:0e:e0:
1c:be:cd:ab:3f:64:38:99:5e:2b:c1:81:53:a0:18:a8:f6:ee:
6a:33:73:6c:9a:73:9d:86:08:5d:c7:11:38:46:4c:cd:a0:47:
37:8f:fe:a6:50:a9:02:21:99:42:86:5e:47:fe:65:56:60:1d:
16:53:86:bd:e4:63:c5:69:cf:fa:30:51:ab:a1:c3:50:53:cc:
66:1c:4c:ff:3f:2a:39:4d:a2:8f:9d:d1:a7:8b:22:e4:78:69:
24:06:83:4d:cc:0a:c0:87:69:9b:bc:80:a9:d2:b7:a5:23:84:
7e:a2:32:26:7c:78:0e:bd:db:cd:3b:69:18:33:b8:44:ef:96:
b4:99:86:ee:06:bd:51:1c:c7:a1:a4:0c:c4:4c:51:a0:df:ac:
14:07:88:8e:d7:39:45:fe:52:e0:a3:4c:db:5d:7a:ab:4d:e4:
ca:06:e8:bd:74:6f:46:e7:93:4a:4f:1b:67:e7:a5:9f:ef:9c:
02:49:d1:f2:d5:e9:53:ee:09:21:ac:08:c8:15:f7:af:35:b9:
4f:11:0f:43:ae:46:8e:fd:5b:8d:a3:4e:a7:2c:b7:25:ed:e4:
e5:94:1d:e3
-----BEGIN CERTIFICATE-----
MIICtTCCAZ0CAhAAMA0GCSqGSIb3DQEBCwUAMB0xCzAJBgNVBAYTAlVTMQ4wDAYD
VQQDEwVNeSBDQTAgFw0xNzA1MjMxNjAwMjNaGA8yMTE3MDQyOTE2MDAyM1owITES
MBAGA1UEAxMJbG9jYWxob3N0MQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBAMnUQ2BQ/NYPOE1dXqp8wF6p7NmTeNOTcihB9Qil6qxn
B9cf9310aX5GiSBLei2bAgjnbw8dDA/HYGkZS99+ynWUC0lx423y6Hn97QqUZ1Xz
ymthuli3Lt17yrkCnyQ2rCaPBI+ByDUQ9KozsiQW+Pce6vcW/vo0w927LLp6303i
2h7l0ihEbsiW4P0JDBQMMdzgysGnm78WjPc2Pxsu3ZDrRXhRv1kiHsaMCmmI5QNe
c7f8k38bRhuXaMXAizUfux5nf1W3O1U/6vLK28xSzRaJ2xVHvfLNbHrXtBqsyBVs
avt3xOnyMOAUJGZlbyrlLcz2ga5XyNGbOJDcYJMCXssCAwEAATANBgkqhkiG9w0B
AQsFAAOCAQEAHHw56D1JsgkeaFovdBj0Y7WM9uah402VkJnvMlw0QOhVEw7gHL7N
qz9kOJleK8GBU6AYqPbuajNzbJpznYYIXccROEZMzaBHN4/+plCpAiGZQoZeR/5l
VmAdFlOGveRjxWnP+jBRq6HDUFPMZhxM/z8qOU2ij53Rp4si5HhpJAaDTcwKwIdp
m7yAqdK3pSOEfqIyJnx4Dr3bzTtpGDO4RO+WtJmG7ga9URzHoaQMxExRoN+sFAeI
jtc5Rf5S4KNM2116q03kygbovXRvRueTSk8bZ+eln++cAknR8tXpU+4JIawIyBX3
rzW5TxEPQ65Gjv1bjaNOpyy3Je3k5ZQd4w==
-----END CERTIFICATE-----

View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJ1ENgUPzWDzhN
XV6qfMBeqezZk3jTk3IoQfUIpeqsZwfXH/d9dGl+RokgS3otmwII528PHQwPx2Bp
GUvffsp1lAtJceNt8uh5/e0KlGdV88prYbpYty7de8q5Ap8kNqwmjwSPgcg1EPSq
M7IkFvj3Hur3Fv76NMPduyy6et9N4toe5dIoRG7IluD9CQwUDDHc4MrBp5u/Foz3
Nj8bLt2Q60V4Ub9ZIh7GjAppiOUDXnO3/JN/G0Ybl2jFwIs1H7seZ39VtztVP+ry
ytvMUs0WidsVR73yzWx617QarMgVbGr7d8Tp8jDgFCRmZW8q5S3M9oGuV8jRmziQ
3GCTAl7LAgMBAAECggEBAKEd1q9j14KWYc64s6KLthGbutyxsinMMbxbct11fdIk
6YhdF3fJ35ETg9IJDr6rWEN9ZRX+jStncNpVfFEs6ThVd3Eo/nI+EEGaaIkikR93
X2a7fEPn7/yVHu70XdBN6L1bPDvHUeiy4W2hmRrgT90OjGm1rNRWHOm7yugOwIZu
HclzbR9Ca7EInFnotUiDQm9sw9VKHbJHqWx6OORdZrxR2ytYs0Qkq0XpGMvti2HW
7WAmKTg5QM8myXW7+/4iqb/u68wVBR2BBalShKmIf7lim9O3W2a1RjDdsvm/wNe9
I+D+Iq825vpqkKXcrxYlpVg7hYiaQaW/MNsEb7lQRjECgYEA/RJYby0POW+/k0Jn
jO8UmJVEMiuGa8WIUu/JJWMOmzRCukjSRNQOkt7niQrZPJYE8W6clM6RJTolWf9L
IL6mIb+mRaoudUk8SHGDq7ho1iMg9GK8lhYxvKh1Q6uv8EyVSkgLknAEY0NANKC1
zNdU5Dhven9aRX2gq9vP4XwMz2MCgYEAzCogQ7IFk+gkp3k491dOZnrGRoRCfuzo
4CJtyKFgOSd7BjmpcKkj0IPfVBjw6GjMIxfQRMTQmxAjjWevH45vG8l0Iiwz/gSp
81b5nsDEX5uv2Olcmcz5zxRFy36jOZ9ihMWinxcIlT2oDbyCdbruDKZq9ieJ9S8g
4qGx0OkwE3kCgYEA7CmAiU89U9YqqttfEq/RQoqY91CSwmO10d+ej9seuEtOsdRf
FIfnibulycdr7hP5TOxyBpO1802NqayJiWcgVYIpQf2MGTtcnCYCP+95NcvWZvj1
EAJqK6nwtFO1fcOZ1ZXh5qfOEGujsPkAbsXLnKXlsiTCMvMHSxl3pu5Cbg0CgYBf
JjbZNctRrjv+7Qj2hPLd4dQsIxGWc7ToWENP4J2mpVa5hQAJqFovoHXhjKohtk2F
AWEn243Y5oGbMjo0e74edhmwn2cvuF64MM2vBem/ISCn98IXT6cQskMA3qkVfsl8
VVs/x41ReGWs2TD3y0GMFbb9t1mdMfSiincDhNnKCQKBgGfeT4jKyYeCoCw4OLI1
G75Gd0METt/IkppwODPpNwj3Rp9I5jctWZFA/3wCX/zk0HgBeou5AFNS4nQZ/X/L
L9axbSdR7UJTGkT1r4gu3rLkPV4Tk+8XM03/JT2cofMlzQBuhvl1Pn4SgKowz7hl
lS76ECw4Av3T0S34VW9Z5oye
-----END PRIVATE KEY-----

View File

@@ -0,0 +1,75 @@
//! Main binary entry point for multipart_v3 implementation.
#![allow(missing_docs)]
// Imports required by this file.
// extern crate <name of this crate>;
extern crate multipart_v3;
extern crate swagger;
extern crate hyper;
extern crate openssl;
extern crate native_tls;
extern crate tokio_proto;
extern crate tokio_tls;
extern crate clap;
// Imports required by server library.
// extern crate multipart_v3;
// extern crate swagger;
extern crate futures;
extern crate chrono;
#[macro_use]
extern crate error_chain;
use openssl::x509::X509_FILETYPE_PEM;
use openssl::ssl::{SslAcceptorBuilder, SslMethod};
use openssl::error::ErrorStack;
use hyper::server::Http;
use tokio_proto::TcpServer;
use clap::{App, Arg};
use swagger::auth::AllowAllAuthenticator;
use swagger::EmptyContext;
mod server_lib;
// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
fn ssl() -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ssl = SslAcceptorBuilder::mozilla_intermediate_raw(SslMethod::tls())?;
// Server authentication
ssl.set_private_key_file("examples/server-key.pem", X509_FILETYPE_PEM)?;
ssl.set_certificate_chain_file("examples/server-chain.pem")?;
ssl.check_private_key()?;
Ok(ssl)
}
/// Create custom server, wire it to the autogenerated router,
/// and pass it to the web server.
fn main() {
let matches = App::new("server")
.arg(Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"))
.get_matches();
let service_fn =
multipart_v3::server::context::NewAddContext::<_, EmptyContext>::new(
AllowAllAuthenticator::new(
server_lib::NewService::new(),
"cosmo"
)
);
let addr = "127.0.0.1:80".parse().expect("Failed to parse bind address");
if matches.is_present("https") {
let ssl = ssl().expect("Failed to load SSL keys");
let builder: native_tls::TlsAcceptorBuilder = native_tls::backend::openssl::TlsAcceptorBuilderExt::from_openssl(ssl);
let tls_acceptor = builder.build().expect("Failed to build TLS acceptor");
TcpServer::new(tokio_tls::proto::Server::new(Http::new(), tls_acceptor), addr).serve(service_fn);
} else {
// Using HTTP
TcpServer::new(Http::new(), addr).serve(service_fn);
}
}

View File

@@ -0,0 +1,37 @@
//! Main library entry point for multipart_v3 implementation.
mod server;
mod errors {
error_chain!{}
}
pub use self::errors::*;
use std::io;
use std::clone::Clone;
use std::marker::PhantomData;
use hyper;
use multipart_v3;
use swagger::{Has, XSpanIdString};
pub struct NewService<C>{
marker: PhantomData<C>
}
impl<C> NewService<C>{
pub fn new() -> Self {
NewService{marker:PhantomData}
}
}
impl<C> hyper::server::NewService for NewService<C> where C: Has<XSpanIdString> + Clone + 'static {
type Request = (hyper::Request, C);
type Response = hyper::Response;
type Error = hyper::Error;
type Instance = multipart_v3::server::Service<server::Server<C>, C>;
/// Instantiate a new server.
fn new_service(&self) -> io::Result<Self::Instance> {
Ok(multipart_v3::server::Service::new(server::Server::new()))
}
}

View File

@@ -0,0 +1,38 @@
//! Server implementation of multipart_v3.
#![allow(unused_imports)]
use futures::{self, Future};
use chrono;
use std::collections::HashMap;
use std::marker::PhantomData;
use swagger;
use swagger::{Has, XSpanIdString};
use multipart_v3::{Api, ApiError,
MultipartRequestPostResponse
};
use multipart_v3::models;
#[derive(Copy, Clone)]
pub struct Server<C> {
marker: PhantomData<C>,
}
impl<C> Server<C> {
pub fn new() -> Self {
Server{marker: PhantomData}
}
}
impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
fn multipart_request_post(&self, string_field: String, binary_field: swagger::ByteArray, optional_string_field: Option<String>, object_field: Option<models::MultipartRequestObjectField>, context: &C) -> Box<Future<Item=MultipartRequestPostResponse, Error=ApiError>> {
let context = context.clone();
println!("multipart_request_post(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", string_field, binary_field, optional_string_field, object_field, context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
}

View File

@@ -0,0 +1,417 @@
#![allow(unused_extern_crates)]
extern crate tokio_core;
extern crate native_tls;
extern crate hyper_tls;
extern crate openssl;
extern crate mime;
extern crate chrono;
extern crate url;
extern crate multipart;
use hyper;
use hyper::header::{Headers, ContentType};
use hyper::Uri;
use self::url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET};
use futures;
use futures::{Future, Stream};
use futures::{future, stream};
use self::tokio_core::reactor::Handle;
use std::borrow::Cow;
use std::io::{Read, Error, ErrorKind};
use std::error;
use std::fmt;
use std::path::Path;
use std::sync::Arc;
use std::str;
use std::str::FromStr;
use std::string::ToString;
use hyper::mime::Mime;
use std::io::Cursor;
use client::multipart::client::lazy::Multipart;
use mimetypes;
use serde_json;
#[allow(unused_imports)]
use std::collections::{HashMap, BTreeMap};
#[allow(unused_imports)]
use swagger;
use swagger::{ApiError, XSpanId, XSpanIdString, Has, AuthData};
use {Api,
MultipartRequestPostResponse
};
use models;
define_encode_set! {
/// This encode set is used for object IDs
///
/// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`,
/// the vertical bar (|) is encoded.
pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'}
}
/// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.
fn into_base_path(input: &str, correct_scheme: Option<&'static str>) -> Result<String, ClientInitError> {
// First convert to Uri, since a base path is a subset of Uri.
let uri = Uri::from_str(input)?;
let scheme = uri.scheme().ok_or(ClientInitError::InvalidScheme)?;
// Check the scheme if necessary
if let Some(correct_scheme) = correct_scheme {
if scheme != correct_scheme {
return Err(ClientInitError::InvalidScheme);
}
}
let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?;
let port = uri.port().map(|x| format!(":{}", x)).unwrap_or_default();
Ok(format!("{}://{}{}", scheme, host, port))
}
/// A client that implements the API by making HTTP calls out to a server.
pub struct Client<F> where
F: Future<Item=hyper::Response, Error=hyper::Error> + 'static {
client_service: Arc<Box<hyper::client::Service<Request=hyper::Request<hyper::Body>, Response=hyper::Response, Error=hyper::Error, Future=F>>>,
base_path: String,
}
impl<F> fmt::Debug for Client<F> where
F: Future<Item=hyper::Response, Error=hyper::Error> + 'static {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Client {{ base_path: {} }}", self.base_path)
}
}
impl<F> Clone for Client<F> where
F: Future<Item=hyper::Response, Error=hyper::Error> + 'static {
fn clone(&self) -> Self {
Client {
client_service: self.client_service.clone(),
base_path: self.base_path.clone()
}
}
}
impl Client<hyper::client::FutureResponse> {
/// Create an HTTP client.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
pub fn try_new_http(handle: Handle, base_path: &str) -> Result<Client<hyper::client::FutureResponse>, ClientInitError> {
let http_connector = swagger::http_connector();
Self::try_new_with_connector::<hyper::client::HttpConnector>(
handle,
base_path,
Some("http"),
http_connector,
)
}
/// Create a client with a TLS connection to the server.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
/// * `ca_certificate` - Path to CA certificate used to authenticate the server
pub fn try_new_https<CA>(
handle: Handle,
base_path: &str,
ca_certificate: CA,
) -> Result<Client<hyper::client::FutureResponse>, ClientInitError>
where
CA: AsRef<Path>,
{
let https_connector = swagger::https_connector(ca_certificate);
Self::try_new_with_connector::<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>(
handle,
base_path,
Some("https"),
https_connector,
)
}
/// Create a client with a mutually authenticated TLS connection to the server.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
/// * `ca_certificate` - Path to CA certificate used to authenticate the server
/// * `client_key` - Path to the client private key
/// * `client_certificate` - Path to the client's public certificate associated with the private key
pub fn try_new_https_mutual<CA, K, C>(
handle: Handle,
base_path: &str,
ca_certificate: CA,
client_key: K,
client_certificate: C,
) -> Result<Client<hyper::client::FutureResponse>, ClientInitError>
where
CA: AsRef<Path>,
K: AsRef<Path>,
C: AsRef<Path>,
{
let https_connector =
swagger::https_mutual_connector(ca_certificate, client_key, client_certificate);
Self::try_new_with_connector::<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>(
handle,
base_path,
Some("https"),
https_connector,
)
}
/// Create a client with a custom implementation of hyper::client::Connect.
///
/// Intended for use with custom implementations of connect for e.g. protocol logging
/// or similar functionality which requires wrapping the transport layer. When wrapping a TCP connection,
/// this function should be used in conjunction with
/// `swagger::{http_connector, https_connector, https_mutual_connector}`.
///
/// For ordinary tcp connections, prefer the use of `try_new_http`, `try_new_https`
/// and `try_new_https_mutual`, to avoid introducing a dependency on the underlying transport layer.
///
/// # Arguments
///
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
/// * `protocol` - Which protocol to use when constructing the request url, e.g. `Some("http")`
/// * `connector_fn` - Function which returns an implementation of `hyper::client::Connect`
pub fn try_new_with_connector<C>(
handle: Handle,
base_path: &str,
protocol: Option<&'static str>,
connector_fn: Box<Fn(&Handle) -> C + Send + Sync>,
) -> Result<Client<hyper::client::FutureResponse>, ClientInitError>
where
C: hyper::client::Connect + hyper::client::Service,
{
let connector = connector_fn(&handle);
let client_service = Box::new(hyper::Client::configure().connector(connector).build(
&handle,
));
Ok(Client {
client_service: Arc::new(client_service),
base_path: into_base_path(base_path, protocol)?,
})
}
/// Constructor for creating a `Client` by passing in a pre-made `hyper` client.
///
/// One should avoid relying on this function if possible, since it adds a dependency on the underlying transport
/// implementation, which it would be better to abstract away. Therefore, using this function may lead to a loss of
/// code generality, which may make it harder to move the application to a serverless environment, for example.
///
/// The reason for this function's existence is to support legacy test code, which did mocking at the hyper layer.
/// This is not a recommended way to write new tests. If other reasons are found for using this function, they
/// should be mentioned here.
#[deprecated(note="Use try_new_with_client_service instead")]
pub fn try_new_with_hyper_client(
hyper_client: Arc<Box<hyper::client::Service<Request=hyper::Request<hyper::Body>, Response=hyper::Response, Error=hyper::Error, Future=hyper::client::FutureResponse>>>,
handle: Handle,
base_path: &str
) -> Result<Client<hyper::client::FutureResponse>, ClientInitError>
{
Ok(Client {
client_service: hyper_client,
base_path: into_base_path(base_path, None)?,
})
}
}
impl<F> Client<F> where
F: Future<Item=hyper::Response, Error=hyper::Error> + 'static
{
/// Constructor for creating a `Client` by passing in a pre-made `hyper` client Service.
///
/// This allows adding custom wrappers around the underlying transport, for example for logging.
pub fn try_new_with_client_service(client_service: Arc<Box<hyper::client::Service<Request=hyper::Request<hyper::Body>, Response=hyper::Response, Error=hyper::Error, Future=F>>>,
handle: Handle,
base_path: &str)
-> Result<Client<F>, ClientInitError>
{
Ok(Client {
client_service: client_service,
base_path: into_base_path(base_path, None)?,
})
}
}
impl<F, C> Api<C> for Client<F> where
F: Future<Item=hyper::Response, Error=hyper::Error> + 'static,
C: Has<XSpanIdString> {
fn multipart_request_post(&self, param_string_field: String, param_binary_field: swagger::ByteArray, param_optional_string_field: Option<String>, param_object_field: Option<models::MultipartRequestObjectField>, context: &C) -> Box<Future<Item=MultipartRequestPostResponse, Error=ApiError>> {
let mut uri = format!(
"{}/multipart_request",
self.base_path
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());
let query_string_str = query_string.finish();
if !query_string_str.is_empty() {
uri += "?";
uri += &query_string_str;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build URI: {}", err))))),
};
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let mut multipart = Multipart::new();
// For each parameter, encode as appropriate and add to the multipart body as a stream.
let string_field_str = match serde_json::to_string(&param_string_field) {
Ok(str) => str,
Err(e) => return Box::new(futures::done(Err(ApiError(format!("Unable to parse string_field to string: {}", e))))),
};
let string_field_vec = string_field_str.as_bytes().to_vec();
let string_field_mime = mime::Mime::from_str("application/json").expect("impossible to fail to parse");
let string_field_cursor = Cursor::new(string_field_vec);
multipart.add_stream("string_field", string_field_cursor, None as Option<&str>, Some(string_field_mime));
let optional_string_field_str = match serde_json::to_string(&param_optional_string_field) {
Ok(str) => str,
Err(e) => return Box::new(futures::done(Err(ApiError(format!("Unable to parse optional_string_field to string: {}", e))))),
};
let optional_string_field_vec = optional_string_field_str.as_bytes().to_vec();
let optional_string_field_mime = mime::Mime::from_str("application/json").expect("impossible to fail to parse");
let optional_string_field_cursor = Cursor::new(optional_string_field_vec);
multipart.add_stream("optional_string_field", optional_string_field_cursor, None as Option<&str>, Some(optional_string_field_mime));
let object_field_str = match serde_json::to_string(&param_object_field) {
Ok(str) => str,
Err(e) => return Box::new(futures::done(Err(ApiError(format!("Unable to parse object_field to string: {}", e))))),
};
let object_field_vec = object_field_str.as_bytes().to_vec();
let object_field_mime = mime::Mime::from_str("application/json").expect("impossible to fail to parse");
let object_field_cursor = Cursor::new(object_field_vec);
multipart.add_stream("object_field", object_field_cursor, None as Option<&str>, Some(object_field_mime));
let binary_field_vec = param_binary_field.to_vec();
let binary_field_mime = match mime::Mime::from_str("application/octet-stream") {
Ok(mime) => mime,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to get mime type: {:?}", err))))),
};
let binary_field_cursor = Cursor::new(binary_field_vec);
let filename = None as Option<&str> ;
multipart.add_stream("binary_field", binary_field_cursor, filename, Some(binary_field_mime));
let mut fields = match multipart.prepare() {
Ok(fields) => fields,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build request: {}", err))))),
};
let mut body_string = String::new();
fields.to_body().read_to_string(&mut body_string).unwrap();
let boundary = fields.boundary();
let multipart_header = match Mime::from_str(&format!("multipart/form-data;boundary={}", boundary)) {
Ok(multipart_header) => multipart_header,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build multipart header: {:?}", err))))),
};
request.set_body(body_string.into_bytes());
request.headers_mut().set(ContentType(multipart_header));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
match response.status().as_u16() {
201 => {
let body = response.body();
Box::new(
future::ok(
MultipartRequestPostResponse::OK
)
) as Box<Future<Item=_, Error=_>>
},
code => {
let headers = response.headers().clone();
Box::new(response.body()
.take(100)
.concat2()
.then(move |body|
future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
match body {
Ok(ref body) => match str::from_utf8(body) {
Ok(body) => Cow::from(body),
Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
},
Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
})))
)
) as Box<Future<Item=_, Error=_>>
}
}
}))
}
}
#[derive(Debug)]
pub enum ClientInitError {
InvalidScheme,
InvalidUri(hyper::error::UriError),
MissingHost,
SslError(openssl::error::ErrorStack)
}
impl From<hyper::error::UriError> for ClientInitError {
fn from(err: hyper::error::UriError) -> ClientInitError {
ClientInitError::InvalidUri(err)
}
}
impl From<openssl::error::ErrorStack> for ClientInitError {
fn from(err: openssl::error::ErrorStack) -> ClientInitError {
ClientInitError::SslError(err)
}
}
impl fmt::Display for ClientInitError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
(self as &fmt::Debug).fmt(f)
}
}
impl error::Error for ClientInitError {
fn description(&self) -> &str {
"Failed to produce a hyper client."
}
}

View File

@@ -0,0 +1,101 @@
#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)]
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate futures;
extern crate chrono;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate mime;
// Logically this should be in the client and server modules, but rust doesn't allow `macro_use` from a module.
#[cfg(any(feature = "client", feature = "server"))]
#[macro_use]
extern crate hyper;
extern crate swagger;
#[macro_use]
extern crate url;
use futures::Stream;
use std::io::Error;
#[allow(unused_imports)]
use std::collections::HashMap;
pub use futures::Future;
#[cfg(any(feature = "client", feature = "server"))]
mod mimetypes;
pub use swagger::{ApiError, ContextWrapper};
pub const BASE_PATH: &'static str = "";
pub const API_VERSION: &'static str = "1.0.7";
#[derive(Debug, PartialEq)]
pub enum MultipartRequestPostResponse {
/// OK
OK ,
}
/// API
pub trait Api<C> {
fn multipart_request_post(&self, string_field: String, binary_field: swagger::ByteArray, optional_string_field: Option<String>, object_field: Option<models::MultipartRequestObjectField>, context: &C) -> Box<Future<Item=MultipartRequestPostResponse, Error=ApiError>>;
}
/// API without a `Context`
pub trait ApiNoContext {
fn multipart_request_post(&self, string_field: String, binary_field: swagger::ByteArray, optional_string_field: Option<String>, object_field: Option<models::MultipartRequestObjectField>) -> Box<Future<Item=MultipartRequestPostResponse, Error=ApiError>>;
}
/// Trait to extend an API to make it easy to bind it to a context.
pub trait ContextWrapperExt<'a, C> where Self: Sized {
/// Binds this API to a context.
fn with_context(self: &'a Self, context: C) -> ContextWrapper<'a, Self, C>;
}
impl<'a, T: Api<C> + Sized, C> ContextWrapperExt<'a, C> for T {
fn with_context(self: &'a T, context: C) -> ContextWrapper<'a, T, C> {
ContextWrapper::<T, C>::new(self, context)
}
}
impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
fn multipart_request_post(&self, string_field: String, binary_field: swagger::ByteArray, optional_string_field: Option<String>, object_field: Option<models::MultipartRequestObjectField>) -> Box<Future<Item=MultipartRequestPostResponse, Error=ApiError>> {
self.api().multipart_request_post(string_field, binary_field, optional_string_field, object_field, &self.context())
}
}
#[cfg(feature = "client")]
pub mod client;
// Re-export Client as a top-level name
#[cfg(feature = "client")]
pub use self::client::Client;
#[cfg(feature = "server")]
pub mod server;
// Re-export router() as a top-level name
#[cfg(feature = "server")]
pub use self::server::Service;
pub mod models;

View File

@@ -0,0 +1,18 @@
/// mime types for requests and responses
pub mod responses {
use hyper::mime::*;
// The macro is called per-operation to beat the recursion limit
}
pub mod requests {
use hyper::mime::*;
lazy_static! {
/// Create Mime objects for the request content types for MultipartRequestPost
pub static ref MULTIPART_REQUEST_POST: Mime = "multipart/form-data".parse().unwrap();
}
}

View File

@@ -0,0 +1,63 @@
#![allow(unused_imports, unused_qualifications, unused_extern_crates)]
extern crate chrono;
extern crate uuid;
use serde::ser::Serializer;
use std::collections::HashMap;
use models;
use swagger;
use std::string::ParseError;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MultipartRequest {
#[serde(rename = "string_field")]
pub string_field: String,
#[serde(rename = "optional_string_field")]
#[serde(skip_serializing_if="Option::is_none")]
pub optional_string_field: Option<String>,
#[serde(rename = "object_field")]
#[serde(skip_serializing_if="Option::is_none")]
pub object_field: Option<models::MultipartRequestObjectField>,
#[serde(rename = "binary_field")]
pub binary_field: swagger::ByteArray,
}
impl MultipartRequest {
pub fn new(string_field: String, binary_field: swagger::ByteArray, ) -> MultipartRequest {
MultipartRequest {
string_field: string_field,
optional_string_field: None,
object_field: None,
binary_field: binary_field,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MultipartRequestObjectField {
#[serde(rename = "field_a")]
pub field_a: String,
#[serde(rename = "field_b")]
#[serde(skip_serializing_if="Option::is_none")]
pub field_b: Option<Vec<String>>,
}
impl MultipartRequestObjectField {
pub fn new(field_a: String, ) -> MultipartRequestObjectField {
MultipartRequestObjectField {
field_a: field_a,
field_b: None,
}
}
}

View File

@@ -0,0 +1,91 @@
use std::io;
use std::marker::PhantomData;
use std::default::Default;
use hyper;
use hyper::{Request, Response, Error, StatusCode};
use server::url::form_urlencoded;
use swagger::auth::{Authorization, AuthData, Scopes};
use swagger::{Has, Pop, Push, XSpanIdString};
use Api;
pub struct NewAddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
pub fn new(inner: T) -> NewAddContext<T, A> {
NewAddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::NewService for NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Instance = AddContext<T::Instance, A>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
self.inner.new_service().map(|s| AddContext::new(s))
}
}
/// Middleware to extract authentication data from request
pub struct AddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
pub fn new(inner: T) -> AddContext<T, A> {
AddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::Service for AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Future = T::Future;
fn call(&self, req: Self::Request) -> Self::Future {
let context = A::default().push(XSpanIdString::get_or_generate(&req));
let context = context.push(None::<AuthData>);
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}

View File

@@ -0,0 +1,277 @@
#![allow(unused_extern_crates)]
extern crate serde_ignored;
extern crate tokio_core;
extern crate native_tls;
extern crate hyper_tls;
extern crate openssl;
extern crate mime;
extern crate chrono;
extern crate percent_encoding;
extern crate url;
extern crate uuid;
extern crate multipart;
use std::sync::Arc;
use std::marker::PhantomData;
use futures::{Future, future, Stream, stream};
use hyper;
use hyper::{Request, Response, Error, StatusCode};
use hyper::header::{Headers, ContentType};
use self::url::form_urlencoded;
use mimetypes;
use self::multipart::server::Multipart;
use self::multipart::server::save::SaveResult;
use std::fs;
use serde_json;
#[allow(unused_imports)]
use std::collections::{HashMap, BTreeMap};
#[allow(unused_imports)]
use swagger;
use std::io;
#[allow(unused_imports)]
use std::collections::BTreeSet;
pub use swagger::auth::Authorization;
use swagger::{ApiError, XSpanId, XSpanIdString, Has, RequestParser};
use swagger::auth::Scopes;
use {Api,
MultipartRequestPostResponse
};
#[allow(unused_imports)]
use models;
pub mod context;
header! { (Warning, "Warning") => [String] }
mod paths {
extern crate regex;
lazy_static! {
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
r"^/multipart_request$"
]).unwrap();
}
pub static ID_MULTIPART_REQUEST: usize = 0;
}
pub struct NewService<T, C> {
api_impl: Arc<T>,
marker: PhantomData<C>,
}
impl<T, C> NewService<T, C>
where
T: Api<C> + Clone + 'static,
C: Has<XSpanIdString> + 'static
{
pub fn new<U: Into<Arc<T>>>(api_impl: U) -> NewService<T, C> {
NewService{api_impl: api_impl.into(), marker: PhantomData}
}
}
impl<T, C> hyper::server::NewService for NewService<T, C>
where
T: Api<C> + Clone + 'static,
C: Has<XSpanIdString> + 'static
{
type Request = (Request, C);
type Response = Response;
type Error = Error;
type Instance = Service<T, C>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
Ok(Service::new(self.api_impl.clone()))
}
}
pub struct Service<T, C> {
api_impl: Arc<T>,
marker: PhantomData<C>,
}
impl<T, C> Service<T, C>
where
T: Api<C> + Clone + 'static,
C: Has<XSpanIdString> + 'static {
pub fn new<U: Into<Arc<T>>>(api_impl: U) -> Service<T, C> {
Service{api_impl: api_impl.into(), marker: PhantomData}
}
}
impl<T, C> hyper::server::Service for Service<T, C>
where
T: Api<C> + Clone + 'static,
C: Has<XSpanIdString> + 'static
{
type Request = (Request, C);
type Response = Response;
type Error = Error;
type Future = Box<Future<Item=Response, Error=Error>>;
fn call(&self, (req, mut context): Self::Request) -> Self::Future {
let api_impl = self.api_impl.clone();
let (method, uri, _, headers, body) = req.deconstruct();
let path = paths::GLOBAL_REGEX_SET.matches(uri.path());
// This match statement is duplicated below in `parse_operation_id()`.
// Please update both places if changing how this code is autogenerated.
match &method {
// MultipartRequestPost - POST /multipart_request
&hyper::Method::Post if path.matched(paths::ID_MULTIPART_REQUEST) => {
let boundary = match multipart_boundary(&headers) {
Some(boundary) => boundary.to_string(),
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body("Couldn't find valid multipart body"))),
};
// Form Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
Box::new(body.concat2()
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
// Read Form Parameters from body
let mut entries = match Multipart::with_body(&body.to_vec()[..], boundary).save().temp() {
SaveResult::Full(entries) => {
entries
},
_ => {
return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Unable to process all message parts"))))
},
};
let file_string_field = entries.files.remove("string_field");
let param_string_field = match file_string_field {
Some(file) => {
let path = &file[0].path;
let string_field_str = fs::read_to_string(path).expect("Reading saved String should never fail");
let string_field_model: String = match serde_json::from_str(&string_field_str) {
Ok(model) => model,
Err(e) => {
return Box::new(future::ok(
Response::new()
.with_status(StatusCode::BadRequest)
.with_body(format!("string_field data does not match API definition: {}", e))))
}
};
string_field_model
}
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Missing required form parameter string_field")))),
};
let file_optional_string_field = entries.files.remove("optional_string_field");
let param_optional_string_field = match file_optional_string_field {
Some(file) => {
let path = &file[0].path;
let optional_string_field_str = fs::read_to_string(path).unwrap();
let optional_string_field_model: String = serde_json::from_str(&optional_string_field_str).expect("Impossible to fail to serialise");
Some(optional_string_field_model)
}
None => None,
};
let file_object_field = entries.files.remove("object_field");
let param_object_field = match file_object_field {
Some(file) => {
let path = &file[0].path;
let object_field_str = fs::read_to_string(path).unwrap();
let object_field_model: models::MultipartRequestObjectField = serde_json::from_str(&object_field_str).expect("Impossible to fail to serialise");
Some(object_field_model)
}
None => None,
};
let file_binary_field = entries.files.remove("binary_field");
let param_binary_field = match file_binary_field {
Some(file) => {
let path = &file[0].path;
let binary_field_str = fs::read_to_string(path).unwrap();
swagger::ByteArray(binary_field_str.as_bytes().to_vec())
}
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Missing required form parameter binary_field")))),
};
Box::new(api_impl.multipart_request_post(param_string_field, param_binary_field, param_optional_string_field, param_object_field, &context)
.then(move |result| {
let mut response = Response::new();
response.headers_mut().set(XSpanId((&context as &Has<XSpanIdString>).get().0.to_string()));
match result {
Ok(rsp) => match rsp {
MultipartRequestPostResponse::OK
=> {
response.set_status(StatusCode::try_from(201).unwrap());
},
},
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
response.set_status(StatusCode::InternalServerError);
response.set_body("An internal error occurred");
},
}
future::ok(response)
}
))
as Box<Future<Item=Response, Error=Error>>
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read multipart body")))),
}
})
)
},
_ => Box::new(future::ok(Response::new().with_status(StatusCode::NotFound))) as Box<Future<Item=Response, Error=Error>>,
}
}
}
impl<T, C> Clone for Service<T, C>
{
fn clone(&self) -> Self {
Service {
api_impl: self.api_impl.clone(),
marker: self.marker.clone(),
}
}
}
/// Utility function to get the multipart boundary marker (if any) from the Headers.
fn multipart_boundary<'a>(headers: &'a Headers) -> Option<&'a str> {
headers.get::<ContentType>().and_then(|content_type| {
let ContentType(ref mime) = *content_type;
if mime.type_() == hyper::mime::MULTIPART && mime.subtype() == hyper::mime::FORM_DATA {
mime.get_param(hyper::mime::BOUNDARY).map(|x| x.as_str())
} else {
None
}
})
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {
fn parse_operation_id(request: &Request) -> Result<&'static str, ()> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// MultipartRequestPost - POST /multipart_request
&hyper::Method::Post if path.matched(paths::ID_MULTIPART_REQUEST) => Ok("MultipartRequestPost"),
_ => Err(()),
}
}
}

View File

@@ -23,8 +23,8 @@ swagger = "2"
#
lazy_static = "0.2"
log = "0.3.0"
mime = "0.3.3"
multipart = {version = "0.13.3", optional = true}
mime = "0.2.6"
multipart = {version = "0.13.3"}
native-tls = {version = "0.1.4", optional = true}
openssl = {version = "0.9.14", optional = true}
percent-encoding = {version = "1.0.0", optional = true}

View File

@@ -56,6 +56,7 @@ To run a client, follow one of the following simple steps:
```
cargo run --example client RequiredOctetStreamPut
cargo run --example client UuidGet
cargo run --example client XmlExtraPost
cargo run --example client XmlOtherPost
cargo run --example client XmlOtherPut
@@ -115,6 +116,7 @@ All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
[****](docs/default_api.md#) | **PUT** /required_octet_stream |
[****](docs/default_api.md#) | **GET** /uuid |
[****](docs/default_api.md#) | **POST** /xml_extra |
[****](docs/default_api.md#) | **POST** /xml_other |
[****](docs/default_api.md#) | **PUT** /xml_other |

View File

@@ -65,6 +65,15 @@ paths:
description: OK
400:
description: Bad Request
/uuid:
get:
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/UuidObject'
description: Duplicate Response long text. One.
/required_octet_stream:
put:
requestBody:

View File

@@ -5,6 +5,7 @@ All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
****](default_api.md#) | **PUT** /required_octet_stream |
****](default_api.md#) | **GET** /uuid |
****](default_api.md#) | **POST** /xml_extra |
****](default_api.md#) | **POST** /xml_other |
****](default_api.md#) | **PUT** /xml_other |
@@ -37,6 +38,28 @@ 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)
# ****
> uuid::Uuid ()
### Required Parameters
This endpoint does not need any parameter.
### Return type
[**uuid::Uuid**](UUID.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json,
[[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)
# ****
> (optional)

View File

@@ -20,6 +20,7 @@ use tokio_core::reactor;
use openapi_v3::{ApiNoContext, ContextWrapperExt,
ApiError,
RequiredOctetStreamPutResponse,
UuidGetResponse,
XmlExtraPostResponse,
XmlOtherPostResponse,
XmlOtherPutResponse,
@@ -34,6 +35,7 @@ fn main() {
.help("Sets the operation to run")
.possible_values(&[
"RequiredOctetStreamPut",
"UuidGet",
"XmlExtraPost",
"XmlOtherPost",
"XmlOtherPut",
@@ -84,6 +86,11 @@ fn main() {
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("UuidGet") => {
let result = core.run(client.uuid_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("XmlExtraPost") => {
let result = core.run(client.xml_extra_post(None));
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());

View File

@@ -12,6 +12,7 @@ use swagger::{Has, XSpanIdString};
use openapi_v3::{Api, ApiError,
RequiredOctetStreamPutResponse,
UuidGetResponse,
XmlExtraPostResponse,
XmlOtherPostResponse,
XmlOtherPutResponse,
@@ -41,6 +42,13 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
}
fn uuid_get(&self, context: &C) -> Box<Future<Item=UuidGetResponse, Error=ApiError>> {
let context = context.clone();
println!("uuid_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn xml_extra_post(&self, duplicate_xml_object: Option<models::DuplicateXmlObject>, context: &C) -> Box<Future<Item=XmlExtraPostResponse, Error=ApiError>> {
let context = context.clone();
println!("xml_extra_post({:?}) - X-Span-ID: {:?}", duplicate_xml_object, context.get().0.clone());

View File

@@ -7,8 +7,6 @@ extern crate mime;
extern crate chrono;
extern crate url;
use hyper;
use hyper::header::{Headers, ContentType};
use hyper::Uri;
@@ -26,9 +24,7 @@ use std::sync::Arc;
use std::str;
use std::str::FromStr;
use std::string::ToString;
use mimetypes;
use serde_json;
use serde_xml_rs;
@@ -41,6 +37,7 @@ use swagger::{ApiError, XSpanId, XSpanIdString, Has, AuthData};
use {Api,
RequiredOctetStreamPutResponse,
UuidGetResponse,
XmlExtraPostResponse,
XmlOtherPostResponse,
XmlOtherPutResponse,
@@ -273,17 +270,13 @@ impl<F, C> Api<C> for Client<F> where
let mut request = hyper::Request::new(hyper::Method::Put, uri);
// Body parameter
let body = param_body.0;
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::REQUIRED_OCTET_STREAM_PUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -321,6 +314,80 @@ impl<F, C> Api<C> for Client<F> where
}
fn uuid_get(&self, context: &C) -> Box<Future<Item=UuidGetResponse, Error=ApiError>> {
let mut uri = format!(
"{}/uuid",
self.base_path
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());
let query_string_str = query_string.finish();
if !query_string_str.is_empty() {
uri += "?";
uri += &query_string_str;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build URI: {}", err))))),
};
let mut request = hyper::Request::new(hyper::Method::Get, uri);
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
match response.status().as_u16() {
200 => {
let body = response.body();
Box::new(
body
.concat2()
.map_err(|e| ApiError(format!("Failed to read response: {}", e)))
.and_then(|body|
str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
.and_then(|body|
serde_json::from_str::<uuid::Uuid>(body)
.map_err(|e| e.into())
)
)
.map(move |body| {
UuidGetResponse::DuplicateResponseLongText(body)
})
) as Box<Future<Item=_, Error=_>>
},
code => {
let headers = response.headers().clone();
Box::new(response.body()
.take(100)
.concat2()
.then(move |body|
future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
match body {
Ok(ref body) => match str::from_utf8(body) {
Ok(body) => Cow::from(body),
Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
},
Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
})))
)
) as Box<Future<Item=_, Error=_>>
}
}
}))
}
fn xml_extra_post(&self, param_duplicate_xml_object: Option<models::DuplicateXmlObject>, context: &C) -> Box<Future<Item=XmlExtraPostResponse, Error=ApiError>> {
let mut uri = format!(
"{}/xml_extra",
@@ -347,14 +414,13 @@ impl<F, C> Api<C> for Client<F> where
body.to_xml()
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::XML_EXTRA_POST.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -427,14 +493,13 @@ if let Some(body) = body {
body.to_xml()
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::XML_OTHER_POST.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -507,14 +572,13 @@ if let Some(body) = body {
body.to_xml()
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::XML_OTHER_PUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -587,14 +651,13 @@ if let Some(body) = body {
body.to_xml()
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::XML_POST.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -667,14 +730,13 @@ if let Some(body) = body {
body.to_xml()
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::XML_PUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {

View File

@@ -11,6 +11,7 @@ extern crate chrono;
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate mime;
// Logically this should be in the client and server modules, but rust doesn't allow `macro_use` from a module.
#[cfg(any(feature = "client", feature = "server"))]
@@ -45,6 +46,12 @@ pub enum RequiredOctetStreamPutResponse {
OK ,
}
#[derive(Debug, PartialEq)]
pub enum UuidGetResponse {
/// Duplicate Response long text. One.
DuplicateResponseLongText ( uuid::Uuid ) ,
}
#[derive(Debug, PartialEq)]
pub enum XmlExtraPostResponse {
/// OK
@@ -93,6 +100,9 @@ pub trait Api<C> {
fn required_octet_stream_put(&self, body: swagger::ByteArray, context: &C) -> Box<Future<Item=RequiredOctetStreamPutResponse, Error=ApiError>>;
fn uuid_get(&self, context: &C) -> Box<Future<Item=UuidGetResponse, Error=ApiError>>;
fn xml_extra_post(&self, duplicate_xml_object: Option<models::DuplicateXmlObject>, context: &C) -> Box<Future<Item=XmlExtraPostResponse, Error=ApiError>>;
@@ -116,6 +126,9 @@ pub trait ApiNoContext {
fn required_octet_stream_put(&self, body: swagger::ByteArray) -> Box<Future<Item=RequiredOctetStreamPutResponse, Error=ApiError>>;
fn uuid_get(&self) -> Box<Future<Item=UuidGetResponse, Error=ApiError>>;
fn xml_extra_post(&self, duplicate_xml_object: Option<models::DuplicateXmlObject>) -> Box<Future<Item=XmlExtraPostResponse, Error=ApiError>>;
@@ -152,6 +165,11 @@ impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
}
fn uuid_get(&self) -> Box<Future<Item=UuidGetResponse, Error=ApiError>> {
self.api().uuid_get(&self.context())
}
fn xml_extra_post(&self, duplicate_xml_object: Option<models::DuplicateXmlObject>) -> Box<Future<Item=XmlExtraPostResponse, Error=ApiError>> {
self.api().xml_extra_post(duplicate_xml_object, &self.context())
}

View File

@@ -5,32 +5,43 @@ pub mod responses {
// The macro is called per-operation to beat the recursion limit
lazy_static! {
/// Create Mime objects for the response content types for UuidGet
pub static ref UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT: Mime = "application/json".parse().unwrap();
}
}
pub mod requests {
use hyper::mime::*;
/// Create Mime objects for the request content types for RequiredOctetStreamPut
lazy_static! {
/// Create Mime objects for the request content types for RequiredOctetStreamPut
pub static ref REQUIRED_OCTET_STREAM_PUT: Mime = "application/octet-stream".parse().unwrap();
}
/// Create Mime objects for the request content types for XmlExtraPost
lazy_static! {
/// Create Mime objects for the request content types for XmlExtraPost
pub static ref XML_EXTRA_POST: Mime = "application/xml".parse().unwrap();
}
/// Create Mime objects for the request content types for XmlOtherPost
lazy_static! {
/// Create Mime objects for the request content types for XmlOtherPost
pub static ref XML_OTHER_POST: Mime = "application/xml".parse().unwrap();
}
/// Create Mime objects for the request content types for XmlOtherPut
lazy_static! {
/// Create Mime objects for the request content types for XmlOtherPut
pub static ref XML_OTHER_PUT: Mime = "application/xml".parse().unwrap();
}
/// Create Mime objects for the request content types for XmlPost
lazy_static! {
/// Create Mime objects for the request content types for XmlPost
pub static ref XML_POST: Mime = "application/xml".parse().unwrap();
}
/// Create Mime objects for the request content types for XmlPut
lazy_static! {
/// Create Mime objects for the request content types for XmlPut
pub static ref XML_PUT: Mime = "application/xml".parse().unwrap();
}

View File

@@ -5,11 +5,10 @@ extern crate native_tls;
extern crate hyper_tls;
extern crate openssl;
extern crate mime;
extern crate uuid;
extern crate chrono;
extern crate percent_encoding;
extern crate url;
extern crate uuid;
use std::sync::Arc;
use std::marker::PhantomData;
@@ -19,7 +18,6 @@ use hyper::{Request, Response, Error, StatusCode};
use hyper::header::{Headers, ContentType};
use self::url::form_urlencoded;
use mimetypes;
use serde_json;
use serde_xml_rs;
@@ -38,6 +36,7 @@ use swagger::auth::Scopes;
use {Api,
RequiredOctetStreamPutResponse,
UuidGetResponse,
XmlExtraPostResponse,
XmlOtherPostResponse,
XmlOtherPutResponse,
@@ -55,17 +54,19 @@ mod paths {
extern crate regex;
lazy_static! {
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(&[
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
r"^/required_octet_stream$",
r"^/uuid$",
r"^/xml$",
r"^/xml_extra$",
r"^/xml_other$"
]).unwrap();
}
pub static ID_REQUIRED_OCTET_STREAM: usize = 0;
pub static ID_XML: usize = 1;
pub static ID_XML_EXTRA: usize = 2;
pub static ID_XML_OTHER: usize = 3;
pub static ID_UUID: usize = 1;
pub static ID_XML: usize = 2;
pub static ID_XML_EXTRA: usize = 3;
pub static ID_XML_OTHER: usize = 4;
}
pub struct NewService<T, C> {
@@ -133,12 +134,6 @@ where
// RequiredOctetStreamPut - PUT /required_octet_stream
&hyper::Method::Put if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -147,9 +142,7 @@ where
match result {
Ok(body) => {
let param_body: Option<swagger::ByteArray> = if !body.is_empty() {
Some(swagger::ByteArray(body.to_vec()))
} else {
None
};
@@ -157,8 +150,6 @@ where
Some(param_body) => param_body,
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body("Missing required body parameter body"))),
};
Box::new(api_impl.required_octet_stream_put(param_body, &context)
.then(move |result| {
let mut response = Response::new();
@@ -185,25 +176,57 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter body: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// UuidGet - GET /uuid
&hyper::Method::Get if path.matched(paths::ID_UUID) => {
Box::new({
{{
Box::new(api_impl.uuid_get(&context)
.then(move |result| {
let mut response = Response::new();
response.headers_mut().set(XSpanId((&context as &Has<XSpanIdString>).get().0.to_string()));
match result {
Ok(rsp) => match rsp {
UuidGetResponse::DuplicateResponseLongText
(body)
=> {
response.set_status(StatusCode::try_from(200).unwrap());
response.headers_mut().set(ContentType(mimetypes::responses::UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT.clone()));
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
response.set_body(body);
},
},
Err(_) => {
// Application code returned an error. This should not happen, as the implementation should
// return a valid response.
response.set_status(StatusCode::InternalServerError);
response.set_body("An internal error occurred");
},
}
future::ok(response)
}
))
}}
}) as Box<Future<Item=Response, Error=Error>>
},
// XmlExtraPost - POST /xml_extra
&hyper::Method::Post if path.matched(paths::ID_XML_EXTRA) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -211,25 +234,19 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_duplicate_xml_object) => param_duplicate_xml_object,
Err(_) => None,
}
} else {
None
};
Box::new(api_impl.xml_extra_post(param_duplicate_xml_object, &context)
.then(move |result| {
let mut response = Response::new();
@@ -267,25 +284,15 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter DuplicateXmlObject: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// XmlOtherPost - POST /xml_other
&hyper::Method::Post if path.matched(paths::ID_XML_OTHER) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -293,25 +300,19 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_another_xml_object) => param_another_xml_object,
Err(_) => None,
}
} else {
None
};
Box::new(api_impl.xml_other_post(param_another_xml_object, &context)
.then(move |result| {
let mut response = Response::new();
@@ -349,25 +350,15 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter AnotherXmlObject: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// XmlOtherPut - PUT /xml_other
&hyper::Method::Put if path.matched(paths::ID_XML_OTHER) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -375,25 +366,19 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_string: Option<models::AnotherXmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_string) => param_string,
Err(_) => None,
}
} else {
None
};
Box::new(api_impl.xml_other_put(param_string, &context)
.then(move |result| {
let mut response = Response::new();
@@ -431,25 +416,15 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter string: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// XmlPost - POST /xml
&hyper::Method::Post if path.matched(paths::ID_XML) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -457,25 +432,19 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_string: Option<models::XmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_string) => param_string,
Err(_) => None,
}
} else {
None
};
Box::new(api_impl.xml_post(param_string, &context)
.then(move |result| {
let mut response = Response::new();
@@ -513,25 +482,15 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter string: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// XmlPut - PUT /xml
&hyper::Method::Put if path.matched(paths::ID_XML) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -539,25 +498,19 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_xml_object: Option<models::XmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_xml_object) => param_xml_object,
Err(_) => None,
}
} else {
None
};
Box::new(api_impl.xml_put(param_xml_object, &context)
.then(move |result| {
let mut response = Response::new();
@@ -595,17 +548,13 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter XmlObject: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
_ => Box::new(future::ok(Response::new().with_status(StatusCode::NotFound))) as Box<Future<Item=Response, Error=Error>>,
}
}
@@ -621,6 +570,7 @@ impl<T, C> Clone for Service<T, C>
}
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {
@@ -631,6 +581,9 @@ impl RequestParser for ApiRequestParser {
// RequiredOctetStreamPut - PUT /required_octet_stream
&hyper::Method::Put if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Ok("RequiredOctetStreamPut"),
// UuidGet - GET /uuid
&hyper::Method::Get if path.matched(paths::ID_UUID) => Ok("UuidGet"),
// XmlExtraPost - POST /xml_extra
&hyper::Method::Post if path.matched(paths::ID_XML_EXTRA) => Ok("XmlExtraPost"),

View File

@@ -0,0 +1,18 @@
[build]
rustflags = [
"-W", "missing_docs", # detects missing documentation for public members
"-W", "trivial_casts", # detects trivial casts which could be removed
"-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed
"-W", "unsafe_code", # usage of `unsafe` code
"-W", "unused_qualifications", # detects unnecessarily qualified names
"-W", "unused_extern_crates", # extern crates that are never used
"-W", "unused_import_braces", # unnecessary braces around an imported item
"-D", "warnings", # all warnings should be denied
]

View File

@@ -0,0 +1,2 @@
target
Cargo.lock

View File

@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@@ -0,0 +1 @@
5.0.0-SNAPSHOT

View File

@@ -0,0 +1,48 @@
[package]
name = "ops-v3"
version = "0.0.1"
authors = []
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"
license = "Unlicense"
[features]
default = ["client", "server"]
client = ["serde_json", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"]
server = ["serde_json", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"]
[dependencies]
# Required by example server.
#
chrono = { version = "0.4", features = ["serde"] }
futures = "0.1"
hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true}
swagger = "2"
# Not required by example server.
#
lazy_static = "0.2"
log = "0.3.0"
mime = "0.2.6"
multipart = {version = "0.13.3"}
native-tls = {version = "0.1.4", optional = true}
openssl = {version = "0.9.14", optional = true}
percent-encoding = {version = "1.0.0", optional = true}
regex = {version = "0.2", optional = true}
serde = "1.0"
serde_derive = "1.0"
serde_ignored = {version = "0.0.4", optional = true}
serde_json = {version = "1.0", optional = true}
serde_urlencoded = {version = "0.5.1", optional = true}
tokio-core = {version = "0.1.6", optional = true}
tokio-proto = {version = "0.1.1", optional = true}
tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]}
url = {version = "1.5", optional = true}
uuid = {version = "0.5", optional = true, features = ["serde", "v4"]}
# ToDo: this should be updated to point at the official crate once
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
[dev-dependencies]
clap = "2.25"
error-chain = "0.12"

View File

@@ -0,0 +1,198 @@
# Rust API for ops-v3
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
## Overview
This client/server was generated by the [openapi-generator]
(https://openapi-generator.tech) project.
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
-
To see how to make this your own, look here:
[README]((https://openapi-generator.tech))
- API version: 0.0.1
This autogenerated project defines an API crate `ops-v3` which contains:
* An `Api` trait defining the API in Rust.
* Data types representing the underlying data model.
* A `Client` type which implements `Api` and issues HTTP requests for each operation.
* A router which accepts HTTP requests and invokes the appropriate `Api` method for each operation.
It also contains an example server and client which make use of `ops-v3`:
* The example server starts up a web server using the `ops-v3` router,
and supplies a trivial implementation of `Api` which returns failure for every operation.
* The example client provides a CLI which lets you invoke any single operation on the
`ops-v3` client by passing appropriate arguments on the command line.
You can use the example server and client as a basis for your own code.
See below for [more detail on implementing a server](#writing-a-server).
## Examples
Run examples with:
```
cargo run --example <example-name>
```
To pass in arguments to the examples, put them after `--`, for example:
```
cargo run --example client -- --help
```
### Running the server
To run the server, follow these simple steps:
```
cargo run --example server
```
### Running a client
To run a client, follow one of the following simple steps:
```
cargo run --example client Op10Get
cargo run --example client Op11Get
cargo run --example client Op12Get
cargo run --example client Op13Get
cargo run --example client Op14Get
cargo run --example client Op15Get
cargo run --example client Op16Get
cargo run --example client Op17Get
cargo run --example client Op18Get
cargo run --example client Op19Get
cargo run --example client Op1Get
cargo run --example client Op20Get
cargo run --example client Op21Get
cargo run --example client Op22Get
cargo run --example client Op23Get
cargo run --example client Op24Get
cargo run --example client Op25Get
cargo run --example client Op26Get
cargo run --example client Op27Get
cargo run --example client Op28Get
cargo run --example client Op29Get
cargo run --example client Op2Get
cargo run --example client Op30Get
cargo run --example client Op31Get
cargo run --example client Op32Get
cargo run --example client Op33Get
cargo run --example client Op34Get
cargo run --example client Op35Get
cargo run --example client Op36Get
cargo run --example client Op37Get
cargo run --example client Op3Get
cargo run --example client Op4Get
cargo run --example client Op5Get
cargo run --example client Op6Get
cargo run --example client Op7Get
cargo run --example client Op8Get
cargo run --example client Op9Get
```
### HTTPS
The examples can be run in HTTPS mode by passing in the flag `--https`, for example:
```
cargo run --example server -- --https
```
This will use the keys/certificates from the examples directory. Note that the server chain is signed with
`CN=localhost`.
## Writing a server
The server example is designed to form the basis for implementing your own server. Simply follow these steps.
* Set up a new Rust project, e.g., with `cargo init --bin`.
* Insert `ops-v3` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "ops-v3" ]`.
* Add `ops-v3 = {version = "0.0.1", path = "ops-v3"}` under `[dependencies]` in the root `Cargo.toml`.
* Copy the `[dependencies]` and `[dev-dependencies]` from `ops-v3/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section.
* Copy all of the `[dev-dependencies]`, but only the `[dependencies]` that are required by the example server. These should be clearly indicated by comments.
* Remove `"optional = true"` from each of these lines if present.
Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time:
```
cp ops-v3/examples/server.rs src/main.rs
cp ops-v3/examples/server_lib/mod.rs src/lib.rs
cp ops-v3/examples/server_lib/server.rs src/server.rs
```
Now
* From `src/main.rs`, remove the `mod server_lib;` line, and uncomment and fill in the `extern crate` line with the name of this server crate.
* Move the block of imports "required by the service library" from `src/main.rs` to `src/lib.rs` and uncomment.
* Change the `let server = server::Server {};` line to `let server = SERVICE_NAME::server().unwrap();` where `SERVICE_NAME` is the name of the server crate.
* Run `cargo build` to check it builds.
* Run `cargo fmt` to reformat the code.
* Commit the result before making any further changes (lest format changes get confused with your own updates).
Now replace the implementations in `src/server.rs` with your own code as required.
## Updating your server to track API changes
Later, if the API changes, you can copy new sections from the autogenerated API stub into your implementation.
Alternatively, implement the now-missing methods based on the compiler's error messages.
## Documentation for API Endpoints
All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
[****](docs/default_api.md#) | **GET** /op10 |
[****](docs/default_api.md#) | **GET** /op11 |
[****](docs/default_api.md#) | **GET** /op12 |
[****](docs/default_api.md#) | **GET** /op13 |
[****](docs/default_api.md#) | **GET** /op14 |
[****](docs/default_api.md#) | **GET** /op15 |
[****](docs/default_api.md#) | **GET** /op16 |
[****](docs/default_api.md#) | **GET** /op17 |
[****](docs/default_api.md#) | **GET** /op18 |
[****](docs/default_api.md#) | **GET** /op19 |
[****](docs/default_api.md#) | **GET** /op1 |
[****](docs/default_api.md#) | **GET** /op20 |
[****](docs/default_api.md#) | **GET** /op21 |
[****](docs/default_api.md#) | **GET** /op22 |
[****](docs/default_api.md#) | **GET** /op23 |
[****](docs/default_api.md#) | **GET** /op24 |
[****](docs/default_api.md#) | **GET** /op25 |
[****](docs/default_api.md#) | **GET** /op26 |
[****](docs/default_api.md#) | **GET** /op27 |
[****](docs/default_api.md#) | **GET** /op28 |
[****](docs/default_api.md#) | **GET** /op29 |
[****](docs/default_api.md#) | **GET** /op2 |
[****](docs/default_api.md#) | **GET** /op30 |
[****](docs/default_api.md#) | **GET** /op31 |
[****](docs/default_api.md#) | **GET** /op32 |
[****](docs/default_api.md#) | **GET** /op33 |
[****](docs/default_api.md#) | **GET** /op34 |
[****](docs/default_api.md#) | **GET** /op35 |
[****](docs/default_api.md#) | **GET** /op36 |
[****](docs/default_api.md#) | **GET** /op37 |
[****](docs/default_api.md#) | **GET** /op3 |
[****](docs/default_api.md#) | **GET** /op4 |
[****](docs/default_api.md#) | **GET** /op5 |
[****](docs/default_api.md#) | **GET** /op6 |
[****](docs/default_api.md#) | **GET** /op7 |
[****](docs/default_api.md#) | **GET** /op8 |
[****](docs/default_api.md#) | **GET** /op9 |
## Documentation For Models
## Documentation For Authorization
Endpoints do not require authorization.
## Author

View File

@@ -0,0 +1,195 @@
openapi: 3.0.1
info:
title: Regression test for large number of operations
version: 0.0.1
servers:
- url: /
paths:
/op1:
get:
responses:
200:
description: OK
/op2:
get:
responses:
200:
description: OK
/op3:
get:
responses:
200:
description: OK
/op4:
get:
responses:
200:
description: OK
/op5:
get:
responses:
200:
description: OK
/op6:
get:
responses:
200:
description: OK
/op7:
get:
responses:
200:
description: OK
/op8:
get:
responses:
200:
description: OK
/op9:
get:
responses:
200:
description: OK
/op10:
get:
responses:
200:
description: OK
/op11:
get:
responses:
200:
description: OK
/op12:
get:
responses:
200:
description: OK
/op13:
get:
responses:
200:
description: OK
/op14:
get:
responses:
200:
description: OK
/op15:
get:
responses:
200:
description: OK
/op16:
get:
responses:
200:
description: OK
/op17:
get:
responses:
200:
description: OK
/op18:
get:
responses:
200:
description: OK
/op19:
get:
responses:
200:
description: OK
/op20:
get:
responses:
200:
description: OK
/op21:
get:
responses:
200:
description: OK
/op22:
get:
responses:
200:
description: OK
/op23:
get:
responses:
200:
description: OK
/op24:
get:
responses:
200:
description: OK
/op25:
get:
responses:
200:
description: OK
/op26:
get:
responses:
200:
description: OK
/op27:
get:
responses:
200:
description: OK
/op28:
get:
responses:
200:
description: OK
/op29:
get:
responses:
200:
description: OK
/op30:
get:
responses:
200:
description: OK
/op31:
get:
responses:
200:
description: OK
/op32:
get:
responses:
200:
description: OK
/op33:
get:
responses:
200:
description: OK
/op34:
get:
responses:
200:
description: OK
/op35:
get:
responses:
200:
description: OK
/op36:
get:
responses:
200:
description: OK
/op37:
get:
responses:
200:
description: OK
components:
schemas: {}

View File

@@ -0,0 +1,859 @@
# default_api
All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
****](default_api.md#) | **GET** /op10 |
****](default_api.md#) | **GET** /op11 |
****](default_api.md#) | **GET** /op12 |
****](default_api.md#) | **GET** /op13 |
****](default_api.md#) | **GET** /op14 |
****](default_api.md#) | **GET** /op15 |
****](default_api.md#) | **GET** /op16 |
****](default_api.md#) | **GET** /op17 |
****](default_api.md#) | **GET** /op18 |
****](default_api.md#) | **GET** /op19 |
****](default_api.md#) | **GET** /op1 |
****](default_api.md#) | **GET** /op20 |
****](default_api.md#) | **GET** /op21 |
****](default_api.md#) | **GET** /op22 |
****](default_api.md#) | **GET** /op23 |
****](default_api.md#) | **GET** /op24 |
****](default_api.md#) | **GET** /op25 |
****](default_api.md#) | **GET** /op26 |
****](default_api.md#) | **GET** /op27 |
****](default_api.md#) | **GET** /op28 |
****](default_api.md#) | **GET** /op29 |
****](default_api.md#) | **GET** /op2 |
****](default_api.md#) | **GET** /op30 |
****](default_api.md#) | **GET** /op31 |
****](default_api.md#) | **GET** /op32 |
****](default_api.md#) | **GET** /op33 |
****](default_api.md#) | **GET** /op34 |
****](default_api.md#) | **GET** /op35 |
****](default_api.md#) | **GET** /op36 |
****](default_api.md#) | **GET** /op37 |
****](default_api.md#) | **GET** /op3 |
****](default_api.md#) | **GET** /op4 |
****](default_api.md#) | **GET** /op5 |
****](default_api.md#) | **GET** /op6 |
****](default_api.md#) | **GET** /op7 |
****](default_api.md#) | **GET** /op8 |
****](default_api.md#) | **GET** /op9 |
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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)
# ****
> ()
### Required Parameters
This endpoint does not need any parameter.
### 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,17 @@
-----BEGIN CERTIFICATE-----
MIICtjCCAZ4CCQDpKecRERZ0xDANBgkqhkiG9w0BAQsFADAdMQswCQYDVQQGEwJV
UzEOMAwGA1UEAxMFTXkgQ0EwHhcNMTcwNTIzMTYwMDIzWhcNMTcwNjIyMTYwMDIz
WjAdMQswCQYDVQQGEwJVUzEOMAwGA1UEAxMFTXkgQ0EwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCt66py3x7sCSASRF2D05L5wkNDxAUjQKYx23W8Gbwv
GMGykk89BIdU5LX1JB1cKiUOkoIxfwAYuWc2V/wzTvVV7+11besnk3uX1c9KiqUF
LIX7kn/z5hzS4aelhKvH+MJlSZCSlp1ytpZbwo5GB5Pi2SGH56jDBiBoDRNBVdWL
z4wH7TdrQjqWwNxIZumD5OGMtcfJyuX08iPiEOaslOeoMqzObhvjc9aUgjVjhqyA
FkJGTXsi0oaD7oml+NE+mTNfEeZvEJQpLSjBY0OvQHzuHkyGBShBnfu/9x7/NRwd
WaqsLiF7/re9KDGYdJwP7Cu6uxYfKAyWarp6h2mG/GIdAgMBAAEwDQYJKoZIhvcN
AQELBQADggEBAGIl/VVIafeq/AJOQ9r7TzzB2ABJYr7NZa6bTu5O1jSp1Fonac15
SZ8gvRxODgH22ZYSqghPG4xzq4J3hkytlQqm57ZEt2I2M3OqIp17Ndcc1xDYzpLl
tA0FrVn6crQTM8vQkTDtGesaCWX+7Fir5dK7HnYWzfpSmsOpST07PfbNisEXKOxG
Dj4lBL1OnhTjsJeymVS1pFvkKkrcEJO+IxFiHL3CDsWjcXB0Z+E1zBtPoYyYsNsO
rBrjUxcZewF4xqWZhpW90Mt61fY2nRgU0uUwHcvDQUqvmzKcsqYa4mPKzfBI5mxo
01Ta96cDD6pS5Y1hOflZ0g84f2g/7xBLLDA=
-----END CERTIFICATE-----

View File

@@ -0,0 +1,334 @@
#![allow(missing_docs, unused_variables, trivial_casts)]
extern crate ops_v3;
#[allow(unused_extern_crates)]
extern crate futures;
#[allow(unused_extern_crates)]
#[macro_use]
extern crate swagger;
#[allow(unused_extern_crates)]
extern crate uuid;
extern crate clap;
extern crate tokio_core;
use swagger::{ContextBuilder, EmptyContext, XSpanIdString, Has, Push, AuthData};
#[allow(unused_imports)]
use futures::{Future, future, Stream, stream};
use tokio_core::reactor;
#[allow(unused_imports)]
use ops_v3::{ApiNoContext, ContextWrapperExt,
ApiError,
Op10GetResponse,
Op11GetResponse,
Op12GetResponse,
Op13GetResponse,
Op14GetResponse,
Op15GetResponse,
Op16GetResponse,
Op17GetResponse,
Op18GetResponse,
Op19GetResponse,
Op1GetResponse,
Op20GetResponse,
Op21GetResponse,
Op22GetResponse,
Op23GetResponse,
Op24GetResponse,
Op25GetResponse,
Op26GetResponse,
Op27GetResponse,
Op28GetResponse,
Op29GetResponse,
Op2GetResponse,
Op30GetResponse,
Op31GetResponse,
Op32GetResponse,
Op33GetResponse,
Op34GetResponse,
Op35GetResponse,
Op36GetResponse,
Op37GetResponse,
Op3GetResponse,
Op4GetResponse,
Op5GetResponse,
Op6GetResponse,
Op7GetResponse,
Op8GetResponse,
Op9GetResponse
};
use clap::{App, Arg};
fn main() {
let matches = App::new("client")
.arg(Arg::with_name("operation")
.help("Sets the operation to run")
.possible_values(&[
"Op10Get",
"Op11Get",
"Op12Get",
"Op13Get",
"Op14Get",
"Op15Get",
"Op16Get",
"Op17Get",
"Op18Get",
"Op19Get",
"Op1Get",
"Op20Get",
"Op21Get",
"Op22Get",
"Op23Get",
"Op24Get",
"Op25Get",
"Op26Get",
"Op27Get",
"Op28Get",
"Op29Get",
"Op2Get",
"Op30Get",
"Op31Get",
"Op32Get",
"Op33Get",
"Op34Get",
"Op35Get",
"Op36Get",
"Op37Get",
"Op3Get",
"Op4Get",
"Op5Get",
"Op6Get",
"Op7Get",
"Op8Get",
"Op9Get",
])
.required(true)
.index(1))
.arg(Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"))
.arg(Arg::with_name("host")
.long("host")
.takes_value(true)
.default_value("localhost")
.help("Hostname to contact"))
.arg(Arg::with_name("port")
.long("port")
.takes_value(true)
.default_value("80")
.help("Port to contact"))
.get_matches();
let mut core = reactor::Core::new().unwrap();
let is_https = matches.is_present("https");
let base_url = format!("{}://{}:{}",
if is_https { "https" } else { "http" },
matches.value_of("host").unwrap(),
matches.value_of("port").unwrap());
let client = if matches.is_present("https") {
// Using Simple HTTPS
ops_v3::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
.expect("Failed to create HTTPS client")
} else {
// Using HTTP
ops_v3::Client::try_new_http(core.handle(), &base_url)
.expect("Failed to create HTTP client")
};
let context: make_context_ty!(ContextBuilder, EmptyContext, Option<AuthData>, XSpanIdString) =
make_context!(ContextBuilder, EmptyContext, None as Option<AuthData>, XSpanIdString(self::uuid::Uuid::new_v4().to_string()));
let client = client.with_context(context);
match matches.value_of("operation") {
Some("Op10Get") => {
let result = core.run(client.op10_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op11Get") => {
let result = core.run(client.op11_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op12Get") => {
let result = core.run(client.op12_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op13Get") => {
let result = core.run(client.op13_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op14Get") => {
let result = core.run(client.op14_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op15Get") => {
let result = core.run(client.op15_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op16Get") => {
let result = core.run(client.op16_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op17Get") => {
let result = core.run(client.op17_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op18Get") => {
let result = core.run(client.op18_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op19Get") => {
let result = core.run(client.op19_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op1Get") => {
let result = core.run(client.op1_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op20Get") => {
let result = core.run(client.op20_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op21Get") => {
let result = core.run(client.op21_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op22Get") => {
let result = core.run(client.op22_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op23Get") => {
let result = core.run(client.op23_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op24Get") => {
let result = core.run(client.op24_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op25Get") => {
let result = core.run(client.op25_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op26Get") => {
let result = core.run(client.op26_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op27Get") => {
let result = core.run(client.op27_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op28Get") => {
let result = core.run(client.op28_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op29Get") => {
let result = core.run(client.op29_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op2Get") => {
let result = core.run(client.op2_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op30Get") => {
let result = core.run(client.op30_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op31Get") => {
let result = core.run(client.op31_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op32Get") => {
let result = core.run(client.op32_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op33Get") => {
let result = core.run(client.op33_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op34Get") => {
let result = core.run(client.op34_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op35Get") => {
let result = core.run(client.op35_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op36Get") => {
let result = core.run(client.op36_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op37Get") => {
let result = core.run(client.op37_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op3Get") => {
let result = core.run(client.op3_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op4Get") => {
let result = core.run(client.op4_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op5Get") => {
let result = core.run(client.op5_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op6Get") => {
let result = core.run(client.op6_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op7Get") => {
let result = core.run(client.op7_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op8Get") => {
let result = core.run(client.op8_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
Some("Op9Get") => {
let result = core.run(client.op9_get());
println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
},
_ => {
panic!("Invalid operation provided")
}
}
}

View File

@@ -0,0 +1,66 @@
Certificate:
Data:
Version: 1 (0x0)
Serial Number: 4096 (0x1000)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=US, CN=My CA
Validity
Not Before: May 23 16:00:23 2017 GMT
Not After : Apr 29 16:00:23 2117 GMT
Subject: CN=localhost, C=US
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:c9:d4:43:60:50:fc:d6:0f:38:4d:5d:5e:aa:7c:
c0:5e:a9:ec:d9:93:78:d3:93:72:28:41:f5:08:a5:
ea:ac:67:07:d7:1f:f7:7d:74:69:7e:46:89:20:4b:
7a:2d:9b:02:08:e7:6f:0f:1d:0c:0f:c7:60:69:19:
4b:df:7e:ca:75:94:0b:49:71:e3:6d:f2:e8:79:fd:
ed:0a:94:67:55:f3:ca:6b:61:ba:58:b7:2e:dd:7b:
ca:b9:02:9f:24:36:ac:26:8f:04:8f:81:c8:35:10:
f4:aa:33:b2:24:16:f8:f7:1e:ea:f7:16:fe:fa:34:
c3:dd:bb:2c:ba:7a:df:4d:e2:da:1e:e5:d2:28:44:
6e:c8:96:e0:fd:09:0c:14:0c:31:dc:e0:ca:c1:a7:
9b:bf:16:8c:f7:36:3f:1b:2e:dd:90:eb:45:78:51:
bf:59:22:1e:c6:8c:0a:69:88:e5:03:5e:73:b7:fc:
93:7f:1b:46:1b:97:68:c5:c0:8b:35:1f:bb:1e:67:
7f:55:b7:3b:55:3f:ea:f2:ca:db:cc:52:cd:16:89:
db:15:47:bd:f2:cd:6c:7a:d7:b4:1a:ac:c8:15:6c:
6a:fb:77:c4:e9:f2:30:e0:14:24:66:65:6f:2a:e5:
2d:cc:f6:81:ae:57:c8:d1:9b:38:90:dc:60:93:02:
5e:cb
Exponent: 65537 (0x10001)
Signature Algorithm: sha256WithRSAEncryption
1c:7c:39:e8:3d:49:b2:09:1e:68:5a:2f:74:18:f4:63:b5:8c:
f6:e6:a1:e3:4d:95:90:99:ef:32:5c:34:40:e8:55:13:0e:e0:
1c:be:cd:ab:3f:64:38:99:5e:2b:c1:81:53:a0:18:a8:f6:ee:
6a:33:73:6c:9a:73:9d:86:08:5d:c7:11:38:46:4c:cd:a0:47:
37:8f:fe:a6:50:a9:02:21:99:42:86:5e:47:fe:65:56:60:1d:
16:53:86:bd:e4:63:c5:69:cf:fa:30:51:ab:a1:c3:50:53:cc:
66:1c:4c:ff:3f:2a:39:4d:a2:8f:9d:d1:a7:8b:22:e4:78:69:
24:06:83:4d:cc:0a:c0:87:69:9b:bc:80:a9:d2:b7:a5:23:84:
7e:a2:32:26:7c:78:0e:bd:db:cd:3b:69:18:33:b8:44:ef:96:
b4:99:86:ee:06:bd:51:1c:c7:a1:a4:0c:c4:4c:51:a0:df:ac:
14:07:88:8e:d7:39:45:fe:52:e0:a3:4c:db:5d:7a:ab:4d:e4:
ca:06:e8:bd:74:6f:46:e7:93:4a:4f:1b:67:e7:a5:9f:ef:9c:
02:49:d1:f2:d5:e9:53:ee:09:21:ac:08:c8:15:f7:af:35:b9:
4f:11:0f:43:ae:46:8e:fd:5b:8d:a3:4e:a7:2c:b7:25:ed:e4:
e5:94:1d:e3
-----BEGIN CERTIFICATE-----
MIICtTCCAZ0CAhAAMA0GCSqGSIb3DQEBCwUAMB0xCzAJBgNVBAYTAlVTMQ4wDAYD
VQQDEwVNeSBDQTAgFw0xNzA1MjMxNjAwMjNaGA8yMTE3MDQyOTE2MDAyM1owITES
MBAGA1UEAxMJbG9jYWxob3N0MQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBAMnUQ2BQ/NYPOE1dXqp8wF6p7NmTeNOTcihB9Qil6qxn
B9cf9310aX5GiSBLei2bAgjnbw8dDA/HYGkZS99+ynWUC0lx423y6Hn97QqUZ1Xz
ymthuli3Lt17yrkCnyQ2rCaPBI+ByDUQ9KozsiQW+Pce6vcW/vo0w927LLp6303i
2h7l0ihEbsiW4P0JDBQMMdzgysGnm78WjPc2Pxsu3ZDrRXhRv1kiHsaMCmmI5QNe
c7f8k38bRhuXaMXAizUfux5nf1W3O1U/6vLK28xSzRaJ2xVHvfLNbHrXtBqsyBVs
avt3xOnyMOAUJGZlbyrlLcz2ga5XyNGbOJDcYJMCXssCAwEAATANBgkqhkiG9w0B
AQsFAAOCAQEAHHw56D1JsgkeaFovdBj0Y7WM9uah402VkJnvMlw0QOhVEw7gHL7N
qz9kOJleK8GBU6AYqPbuajNzbJpznYYIXccROEZMzaBHN4/+plCpAiGZQoZeR/5l
VmAdFlOGveRjxWnP+jBRq6HDUFPMZhxM/z8qOU2ij53Rp4si5HhpJAaDTcwKwIdp
m7yAqdK3pSOEfqIyJnx4Dr3bzTtpGDO4RO+WtJmG7ga9URzHoaQMxExRoN+sFAeI
jtc5Rf5S4KNM2116q03kygbovXRvRueTSk8bZ+eln++cAknR8tXpU+4JIawIyBX3
rzW5TxEPQ65Gjv1bjaNOpyy3Je3k5ZQd4w==
-----END CERTIFICATE-----

View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJ1ENgUPzWDzhN
XV6qfMBeqezZk3jTk3IoQfUIpeqsZwfXH/d9dGl+RokgS3otmwII528PHQwPx2Bp
GUvffsp1lAtJceNt8uh5/e0KlGdV88prYbpYty7de8q5Ap8kNqwmjwSPgcg1EPSq
M7IkFvj3Hur3Fv76NMPduyy6et9N4toe5dIoRG7IluD9CQwUDDHc4MrBp5u/Foz3
Nj8bLt2Q60V4Ub9ZIh7GjAppiOUDXnO3/JN/G0Ybl2jFwIs1H7seZ39VtztVP+ry
ytvMUs0WidsVR73yzWx617QarMgVbGr7d8Tp8jDgFCRmZW8q5S3M9oGuV8jRmziQ
3GCTAl7LAgMBAAECggEBAKEd1q9j14KWYc64s6KLthGbutyxsinMMbxbct11fdIk
6YhdF3fJ35ETg9IJDr6rWEN9ZRX+jStncNpVfFEs6ThVd3Eo/nI+EEGaaIkikR93
X2a7fEPn7/yVHu70XdBN6L1bPDvHUeiy4W2hmRrgT90OjGm1rNRWHOm7yugOwIZu
HclzbR9Ca7EInFnotUiDQm9sw9VKHbJHqWx6OORdZrxR2ytYs0Qkq0XpGMvti2HW
7WAmKTg5QM8myXW7+/4iqb/u68wVBR2BBalShKmIf7lim9O3W2a1RjDdsvm/wNe9
I+D+Iq825vpqkKXcrxYlpVg7hYiaQaW/MNsEb7lQRjECgYEA/RJYby0POW+/k0Jn
jO8UmJVEMiuGa8WIUu/JJWMOmzRCukjSRNQOkt7niQrZPJYE8W6clM6RJTolWf9L
IL6mIb+mRaoudUk8SHGDq7ho1iMg9GK8lhYxvKh1Q6uv8EyVSkgLknAEY0NANKC1
zNdU5Dhven9aRX2gq9vP4XwMz2MCgYEAzCogQ7IFk+gkp3k491dOZnrGRoRCfuzo
4CJtyKFgOSd7BjmpcKkj0IPfVBjw6GjMIxfQRMTQmxAjjWevH45vG8l0Iiwz/gSp
81b5nsDEX5uv2Olcmcz5zxRFy36jOZ9ihMWinxcIlT2oDbyCdbruDKZq9ieJ9S8g
4qGx0OkwE3kCgYEA7CmAiU89U9YqqttfEq/RQoqY91CSwmO10d+ej9seuEtOsdRf
FIfnibulycdr7hP5TOxyBpO1802NqayJiWcgVYIpQf2MGTtcnCYCP+95NcvWZvj1
EAJqK6nwtFO1fcOZ1ZXh5qfOEGujsPkAbsXLnKXlsiTCMvMHSxl3pu5Cbg0CgYBf
JjbZNctRrjv+7Qj2hPLd4dQsIxGWc7ToWENP4J2mpVa5hQAJqFovoHXhjKohtk2F
AWEn243Y5oGbMjo0e74edhmwn2cvuF64MM2vBem/ISCn98IXT6cQskMA3qkVfsl8
VVs/x41ReGWs2TD3y0GMFbb9t1mdMfSiincDhNnKCQKBgGfeT4jKyYeCoCw4OLI1
G75Gd0METt/IkppwODPpNwj3Rp9I5jctWZFA/3wCX/zk0HgBeou5AFNS4nQZ/X/L
L9axbSdR7UJTGkT1r4gu3rLkPV4Tk+8XM03/JT2cofMlzQBuhvl1Pn4SgKowz7hl
lS76ECw4Av3T0S34VW9Z5oye
-----END PRIVATE KEY-----

View File

@@ -0,0 +1,75 @@
//! Main binary entry point for ops_v3 implementation.
#![allow(missing_docs)]
// Imports required by this file.
// extern crate <name of this crate>;
extern crate ops_v3;
extern crate swagger;
extern crate hyper;
extern crate openssl;
extern crate native_tls;
extern crate tokio_proto;
extern crate tokio_tls;
extern crate clap;
// Imports required by server library.
// extern crate ops_v3;
// extern crate swagger;
extern crate futures;
extern crate chrono;
#[macro_use]
extern crate error_chain;
use openssl::x509::X509_FILETYPE_PEM;
use openssl::ssl::{SslAcceptorBuilder, SslMethod};
use openssl::error::ErrorStack;
use hyper::server::Http;
use tokio_proto::TcpServer;
use clap::{App, Arg};
use swagger::auth::AllowAllAuthenticator;
use swagger::EmptyContext;
mod server_lib;
// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
fn ssl() -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ssl = SslAcceptorBuilder::mozilla_intermediate_raw(SslMethod::tls())?;
// Server authentication
ssl.set_private_key_file("examples/server-key.pem", X509_FILETYPE_PEM)?;
ssl.set_certificate_chain_file("examples/server-chain.pem")?;
ssl.check_private_key()?;
Ok(ssl)
}
/// Create custom server, wire it to the autogenerated router,
/// and pass it to the web server.
fn main() {
let matches = App::new("server")
.arg(Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"))
.get_matches();
let service_fn =
ops_v3::server::context::NewAddContext::<_, EmptyContext>::new(
AllowAllAuthenticator::new(
server_lib::NewService::new(),
"cosmo"
)
);
let addr = "127.0.0.1:80".parse().expect("Failed to parse bind address");
if matches.is_present("https") {
let ssl = ssl().expect("Failed to load SSL keys");
let builder: native_tls::TlsAcceptorBuilder = native_tls::backend::openssl::TlsAcceptorBuilderExt::from_openssl(ssl);
let tls_acceptor = builder.build().expect("Failed to build TLS acceptor");
TcpServer::new(tokio_tls::proto::Server::new(Http::new(), tls_acceptor), addr).serve(service_fn);
} else {
// Using HTTP
TcpServer::new(Http::new(), addr).serve(service_fn);
}
}

View File

@@ -0,0 +1,37 @@
//! Main library entry point for ops_v3 implementation.
mod server;
mod errors {
error_chain!{}
}
pub use self::errors::*;
use std::io;
use std::clone::Clone;
use std::marker::PhantomData;
use hyper;
use ops_v3;
use swagger::{Has, XSpanIdString};
pub struct NewService<C>{
marker: PhantomData<C>
}
impl<C> NewService<C>{
pub fn new() -> Self {
NewService{marker:PhantomData}
}
}
impl<C> hyper::server::NewService for NewService<C> where C: Has<XSpanIdString> + Clone + 'static {
type Request = (hyper::Request, C);
type Response = hyper::Response;
type Error = hyper::Error;
type Instance = ops_v3::server::Service<server::Server<C>, C>;
/// Instantiate a new server.
fn new_service(&self) -> io::Result<Self::Instance> {
Ok(ops_v3::server::Service::new(server::Server::new()))
}
}

View File

@@ -0,0 +1,326 @@
//! Server implementation of ops_v3.
#![allow(unused_imports)]
use futures::{self, Future};
use chrono;
use std::collections::HashMap;
use std::marker::PhantomData;
use swagger;
use swagger::{Has, XSpanIdString};
use ops_v3::{Api, ApiError,
Op10GetResponse,
Op11GetResponse,
Op12GetResponse,
Op13GetResponse,
Op14GetResponse,
Op15GetResponse,
Op16GetResponse,
Op17GetResponse,
Op18GetResponse,
Op19GetResponse,
Op1GetResponse,
Op20GetResponse,
Op21GetResponse,
Op22GetResponse,
Op23GetResponse,
Op24GetResponse,
Op25GetResponse,
Op26GetResponse,
Op27GetResponse,
Op28GetResponse,
Op29GetResponse,
Op2GetResponse,
Op30GetResponse,
Op31GetResponse,
Op32GetResponse,
Op33GetResponse,
Op34GetResponse,
Op35GetResponse,
Op36GetResponse,
Op37GetResponse,
Op3GetResponse,
Op4GetResponse,
Op5GetResponse,
Op6GetResponse,
Op7GetResponse,
Op8GetResponse,
Op9GetResponse
};
use ops_v3::models;
#[derive(Copy, Clone)]
pub struct Server<C> {
marker: PhantomData<C>,
}
impl<C> Server<C> {
pub fn new() -> Self {
Server{marker: PhantomData}
}
}
impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
fn op10_get(&self, context: &C) -> Box<Future<Item=Op10GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op10_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op11_get(&self, context: &C) -> Box<Future<Item=Op11GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op11_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op12_get(&self, context: &C) -> Box<Future<Item=Op12GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op12_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op13_get(&self, context: &C) -> Box<Future<Item=Op13GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op13_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op14_get(&self, context: &C) -> Box<Future<Item=Op14GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op14_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op15_get(&self, context: &C) -> Box<Future<Item=Op15GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op15_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op16_get(&self, context: &C) -> Box<Future<Item=Op16GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op16_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op17_get(&self, context: &C) -> Box<Future<Item=Op17GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op17_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op18_get(&self, context: &C) -> Box<Future<Item=Op18GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op18_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op19_get(&self, context: &C) -> Box<Future<Item=Op19GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op19_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op1_get(&self, context: &C) -> Box<Future<Item=Op1GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op1_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op20_get(&self, context: &C) -> Box<Future<Item=Op20GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op20_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op21_get(&self, context: &C) -> Box<Future<Item=Op21GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op21_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op22_get(&self, context: &C) -> Box<Future<Item=Op22GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op22_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op23_get(&self, context: &C) -> Box<Future<Item=Op23GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op23_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op24_get(&self, context: &C) -> Box<Future<Item=Op24GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op24_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op25_get(&self, context: &C) -> Box<Future<Item=Op25GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op25_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op26_get(&self, context: &C) -> Box<Future<Item=Op26GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op26_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op27_get(&self, context: &C) -> Box<Future<Item=Op27GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op27_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op28_get(&self, context: &C) -> Box<Future<Item=Op28GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op28_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op29_get(&self, context: &C) -> Box<Future<Item=Op29GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op29_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op2_get(&self, context: &C) -> Box<Future<Item=Op2GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op2_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op30_get(&self, context: &C) -> Box<Future<Item=Op30GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op30_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op31_get(&self, context: &C) -> Box<Future<Item=Op31GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op31_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op32_get(&self, context: &C) -> Box<Future<Item=Op32GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op32_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op33_get(&self, context: &C) -> Box<Future<Item=Op33GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op33_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op34_get(&self, context: &C) -> Box<Future<Item=Op34GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op34_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op35_get(&self, context: &C) -> Box<Future<Item=Op35GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op35_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op36_get(&self, context: &C) -> Box<Future<Item=Op36GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op36_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op37_get(&self, context: &C) -> Box<Future<Item=Op37GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op37_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op3_get(&self, context: &C) -> Box<Future<Item=Op3GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op3_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op4_get(&self, context: &C) -> Box<Future<Item=Op4GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op4_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op5_get(&self, context: &C) -> Box<Future<Item=Op5GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op5_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op6_get(&self, context: &C) -> Box<Future<Item=Op6GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op6_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op7_get(&self, context: &C) -> Box<Future<Item=Op7GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op7_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op8_get(&self, context: &C) -> Box<Future<Item=Op8GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op8_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
fn op9_get(&self, context: &C) -> Box<Future<Item=Op9GetResponse, Error=ApiError>> {
let context = context.clone();
println!("op9_get() - X-Span-ID: {:?}", context.get().0.clone());
Box::new(futures::failed("Generic failure".into()))
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,713 @@
#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)]
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate futures;
extern crate chrono;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate mime;
// Logically this should be in the client and server modules, but rust doesn't allow `macro_use` from a module.
#[cfg(any(feature = "client", feature = "server"))]
#[macro_use]
extern crate hyper;
extern crate swagger;
#[macro_use]
extern crate url;
use futures::Stream;
use std::io::Error;
#[allow(unused_imports)]
use std::collections::HashMap;
pub use futures::Future;
#[cfg(any(feature = "client", feature = "server"))]
mod mimetypes;
pub use swagger::{ApiError, ContextWrapper};
pub const BASE_PATH: &'static str = "";
pub const API_VERSION: &'static str = "0.0.1";
#[derive(Debug, PartialEq)]
pub enum Op10GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op11GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op12GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op13GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op14GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op15GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op16GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op17GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op18GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op19GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op1GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op20GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op21GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op22GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op23GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op24GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op25GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op26GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op27GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op28GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op29GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op2GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op30GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op31GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op32GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op33GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op34GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op35GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op36GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op37GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op3GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op4GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op5GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op6GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op7GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op8GetResponse {
/// OK
OK ,
}
#[derive(Debug, PartialEq)]
pub enum Op9GetResponse {
/// OK
OK ,
}
/// API
pub trait Api<C> {
fn op10_get(&self, context: &C) -> Box<Future<Item=Op10GetResponse, Error=ApiError>>;
fn op11_get(&self, context: &C) -> Box<Future<Item=Op11GetResponse, Error=ApiError>>;
fn op12_get(&self, context: &C) -> Box<Future<Item=Op12GetResponse, Error=ApiError>>;
fn op13_get(&self, context: &C) -> Box<Future<Item=Op13GetResponse, Error=ApiError>>;
fn op14_get(&self, context: &C) -> Box<Future<Item=Op14GetResponse, Error=ApiError>>;
fn op15_get(&self, context: &C) -> Box<Future<Item=Op15GetResponse, Error=ApiError>>;
fn op16_get(&self, context: &C) -> Box<Future<Item=Op16GetResponse, Error=ApiError>>;
fn op17_get(&self, context: &C) -> Box<Future<Item=Op17GetResponse, Error=ApiError>>;
fn op18_get(&self, context: &C) -> Box<Future<Item=Op18GetResponse, Error=ApiError>>;
fn op19_get(&self, context: &C) -> Box<Future<Item=Op19GetResponse, Error=ApiError>>;
fn op1_get(&self, context: &C) -> Box<Future<Item=Op1GetResponse, Error=ApiError>>;
fn op20_get(&self, context: &C) -> Box<Future<Item=Op20GetResponse, Error=ApiError>>;
fn op21_get(&self, context: &C) -> Box<Future<Item=Op21GetResponse, Error=ApiError>>;
fn op22_get(&self, context: &C) -> Box<Future<Item=Op22GetResponse, Error=ApiError>>;
fn op23_get(&self, context: &C) -> Box<Future<Item=Op23GetResponse, Error=ApiError>>;
fn op24_get(&self, context: &C) -> Box<Future<Item=Op24GetResponse, Error=ApiError>>;
fn op25_get(&self, context: &C) -> Box<Future<Item=Op25GetResponse, Error=ApiError>>;
fn op26_get(&self, context: &C) -> Box<Future<Item=Op26GetResponse, Error=ApiError>>;
fn op27_get(&self, context: &C) -> Box<Future<Item=Op27GetResponse, Error=ApiError>>;
fn op28_get(&self, context: &C) -> Box<Future<Item=Op28GetResponse, Error=ApiError>>;
fn op29_get(&self, context: &C) -> Box<Future<Item=Op29GetResponse, Error=ApiError>>;
fn op2_get(&self, context: &C) -> Box<Future<Item=Op2GetResponse, Error=ApiError>>;
fn op30_get(&self, context: &C) -> Box<Future<Item=Op30GetResponse, Error=ApiError>>;
fn op31_get(&self, context: &C) -> Box<Future<Item=Op31GetResponse, Error=ApiError>>;
fn op32_get(&self, context: &C) -> Box<Future<Item=Op32GetResponse, Error=ApiError>>;
fn op33_get(&self, context: &C) -> Box<Future<Item=Op33GetResponse, Error=ApiError>>;
fn op34_get(&self, context: &C) -> Box<Future<Item=Op34GetResponse, Error=ApiError>>;
fn op35_get(&self, context: &C) -> Box<Future<Item=Op35GetResponse, Error=ApiError>>;
fn op36_get(&self, context: &C) -> Box<Future<Item=Op36GetResponse, Error=ApiError>>;
fn op37_get(&self, context: &C) -> Box<Future<Item=Op37GetResponse, Error=ApiError>>;
fn op3_get(&self, context: &C) -> Box<Future<Item=Op3GetResponse, Error=ApiError>>;
fn op4_get(&self, context: &C) -> Box<Future<Item=Op4GetResponse, Error=ApiError>>;
fn op5_get(&self, context: &C) -> Box<Future<Item=Op5GetResponse, Error=ApiError>>;
fn op6_get(&self, context: &C) -> Box<Future<Item=Op6GetResponse, Error=ApiError>>;
fn op7_get(&self, context: &C) -> Box<Future<Item=Op7GetResponse, Error=ApiError>>;
fn op8_get(&self, context: &C) -> Box<Future<Item=Op8GetResponse, Error=ApiError>>;
fn op9_get(&self, context: &C) -> Box<Future<Item=Op9GetResponse, Error=ApiError>>;
}
/// API without a `Context`
pub trait ApiNoContext {
fn op10_get(&self) -> Box<Future<Item=Op10GetResponse, Error=ApiError>>;
fn op11_get(&self) -> Box<Future<Item=Op11GetResponse, Error=ApiError>>;
fn op12_get(&self) -> Box<Future<Item=Op12GetResponse, Error=ApiError>>;
fn op13_get(&self) -> Box<Future<Item=Op13GetResponse, Error=ApiError>>;
fn op14_get(&self) -> Box<Future<Item=Op14GetResponse, Error=ApiError>>;
fn op15_get(&self) -> Box<Future<Item=Op15GetResponse, Error=ApiError>>;
fn op16_get(&self) -> Box<Future<Item=Op16GetResponse, Error=ApiError>>;
fn op17_get(&self) -> Box<Future<Item=Op17GetResponse, Error=ApiError>>;
fn op18_get(&self) -> Box<Future<Item=Op18GetResponse, Error=ApiError>>;
fn op19_get(&self) -> Box<Future<Item=Op19GetResponse, Error=ApiError>>;
fn op1_get(&self) -> Box<Future<Item=Op1GetResponse, Error=ApiError>>;
fn op20_get(&self) -> Box<Future<Item=Op20GetResponse, Error=ApiError>>;
fn op21_get(&self) -> Box<Future<Item=Op21GetResponse, Error=ApiError>>;
fn op22_get(&self) -> Box<Future<Item=Op22GetResponse, Error=ApiError>>;
fn op23_get(&self) -> Box<Future<Item=Op23GetResponse, Error=ApiError>>;
fn op24_get(&self) -> Box<Future<Item=Op24GetResponse, Error=ApiError>>;
fn op25_get(&self) -> Box<Future<Item=Op25GetResponse, Error=ApiError>>;
fn op26_get(&self) -> Box<Future<Item=Op26GetResponse, Error=ApiError>>;
fn op27_get(&self) -> Box<Future<Item=Op27GetResponse, Error=ApiError>>;
fn op28_get(&self) -> Box<Future<Item=Op28GetResponse, Error=ApiError>>;
fn op29_get(&self) -> Box<Future<Item=Op29GetResponse, Error=ApiError>>;
fn op2_get(&self) -> Box<Future<Item=Op2GetResponse, Error=ApiError>>;
fn op30_get(&self) -> Box<Future<Item=Op30GetResponse, Error=ApiError>>;
fn op31_get(&self) -> Box<Future<Item=Op31GetResponse, Error=ApiError>>;
fn op32_get(&self) -> Box<Future<Item=Op32GetResponse, Error=ApiError>>;
fn op33_get(&self) -> Box<Future<Item=Op33GetResponse, Error=ApiError>>;
fn op34_get(&self) -> Box<Future<Item=Op34GetResponse, Error=ApiError>>;
fn op35_get(&self) -> Box<Future<Item=Op35GetResponse, Error=ApiError>>;
fn op36_get(&self) -> Box<Future<Item=Op36GetResponse, Error=ApiError>>;
fn op37_get(&self) -> Box<Future<Item=Op37GetResponse, Error=ApiError>>;
fn op3_get(&self) -> Box<Future<Item=Op3GetResponse, Error=ApiError>>;
fn op4_get(&self) -> Box<Future<Item=Op4GetResponse, Error=ApiError>>;
fn op5_get(&self) -> Box<Future<Item=Op5GetResponse, Error=ApiError>>;
fn op6_get(&self) -> Box<Future<Item=Op6GetResponse, Error=ApiError>>;
fn op7_get(&self) -> Box<Future<Item=Op7GetResponse, Error=ApiError>>;
fn op8_get(&self) -> Box<Future<Item=Op8GetResponse, Error=ApiError>>;
fn op9_get(&self) -> Box<Future<Item=Op9GetResponse, Error=ApiError>>;
}
/// Trait to extend an API to make it easy to bind it to a context.
pub trait ContextWrapperExt<'a, C> where Self: Sized {
/// Binds this API to a context.
fn with_context(self: &'a Self, context: C) -> ContextWrapper<'a, Self, C>;
}
impl<'a, T: Api<C> + Sized, C> ContextWrapperExt<'a, C> for T {
fn with_context(self: &'a T, context: C) -> ContextWrapper<'a, T, C> {
ContextWrapper::<T, C>::new(self, context)
}
}
impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
fn op10_get(&self) -> Box<Future<Item=Op10GetResponse, Error=ApiError>> {
self.api().op10_get(&self.context())
}
fn op11_get(&self) -> Box<Future<Item=Op11GetResponse, Error=ApiError>> {
self.api().op11_get(&self.context())
}
fn op12_get(&self) -> Box<Future<Item=Op12GetResponse, Error=ApiError>> {
self.api().op12_get(&self.context())
}
fn op13_get(&self) -> Box<Future<Item=Op13GetResponse, Error=ApiError>> {
self.api().op13_get(&self.context())
}
fn op14_get(&self) -> Box<Future<Item=Op14GetResponse, Error=ApiError>> {
self.api().op14_get(&self.context())
}
fn op15_get(&self) -> Box<Future<Item=Op15GetResponse, Error=ApiError>> {
self.api().op15_get(&self.context())
}
fn op16_get(&self) -> Box<Future<Item=Op16GetResponse, Error=ApiError>> {
self.api().op16_get(&self.context())
}
fn op17_get(&self) -> Box<Future<Item=Op17GetResponse, Error=ApiError>> {
self.api().op17_get(&self.context())
}
fn op18_get(&self) -> Box<Future<Item=Op18GetResponse, Error=ApiError>> {
self.api().op18_get(&self.context())
}
fn op19_get(&self) -> Box<Future<Item=Op19GetResponse, Error=ApiError>> {
self.api().op19_get(&self.context())
}
fn op1_get(&self) -> Box<Future<Item=Op1GetResponse, Error=ApiError>> {
self.api().op1_get(&self.context())
}
fn op20_get(&self) -> Box<Future<Item=Op20GetResponse, Error=ApiError>> {
self.api().op20_get(&self.context())
}
fn op21_get(&self) -> Box<Future<Item=Op21GetResponse, Error=ApiError>> {
self.api().op21_get(&self.context())
}
fn op22_get(&self) -> Box<Future<Item=Op22GetResponse, Error=ApiError>> {
self.api().op22_get(&self.context())
}
fn op23_get(&self) -> Box<Future<Item=Op23GetResponse, Error=ApiError>> {
self.api().op23_get(&self.context())
}
fn op24_get(&self) -> Box<Future<Item=Op24GetResponse, Error=ApiError>> {
self.api().op24_get(&self.context())
}
fn op25_get(&self) -> Box<Future<Item=Op25GetResponse, Error=ApiError>> {
self.api().op25_get(&self.context())
}
fn op26_get(&self) -> Box<Future<Item=Op26GetResponse, Error=ApiError>> {
self.api().op26_get(&self.context())
}
fn op27_get(&self) -> Box<Future<Item=Op27GetResponse, Error=ApiError>> {
self.api().op27_get(&self.context())
}
fn op28_get(&self) -> Box<Future<Item=Op28GetResponse, Error=ApiError>> {
self.api().op28_get(&self.context())
}
fn op29_get(&self) -> Box<Future<Item=Op29GetResponse, Error=ApiError>> {
self.api().op29_get(&self.context())
}
fn op2_get(&self) -> Box<Future<Item=Op2GetResponse, Error=ApiError>> {
self.api().op2_get(&self.context())
}
fn op30_get(&self) -> Box<Future<Item=Op30GetResponse, Error=ApiError>> {
self.api().op30_get(&self.context())
}
fn op31_get(&self) -> Box<Future<Item=Op31GetResponse, Error=ApiError>> {
self.api().op31_get(&self.context())
}
fn op32_get(&self) -> Box<Future<Item=Op32GetResponse, Error=ApiError>> {
self.api().op32_get(&self.context())
}
fn op33_get(&self) -> Box<Future<Item=Op33GetResponse, Error=ApiError>> {
self.api().op33_get(&self.context())
}
fn op34_get(&self) -> Box<Future<Item=Op34GetResponse, Error=ApiError>> {
self.api().op34_get(&self.context())
}
fn op35_get(&self) -> Box<Future<Item=Op35GetResponse, Error=ApiError>> {
self.api().op35_get(&self.context())
}
fn op36_get(&self) -> Box<Future<Item=Op36GetResponse, Error=ApiError>> {
self.api().op36_get(&self.context())
}
fn op37_get(&self) -> Box<Future<Item=Op37GetResponse, Error=ApiError>> {
self.api().op37_get(&self.context())
}
fn op3_get(&self) -> Box<Future<Item=Op3GetResponse, Error=ApiError>> {
self.api().op3_get(&self.context())
}
fn op4_get(&self) -> Box<Future<Item=Op4GetResponse, Error=ApiError>> {
self.api().op4_get(&self.context())
}
fn op5_get(&self) -> Box<Future<Item=Op5GetResponse, Error=ApiError>> {
self.api().op5_get(&self.context())
}
fn op6_get(&self) -> Box<Future<Item=Op6GetResponse, Error=ApiError>> {
self.api().op6_get(&self.context())
}
fn op7_get(&self) -> Box<Future<Item=Op7GetResponse, Error=ApiError>> {
self.api().op7_get(&self.context())
}
fn op8_get(&self) -> Box<Future<Item=Op8GetResponse, Error=ApiError>> {
self.api().op8_get(&self.context())
}
fn op9_get(&self) -> Box<Future<Item=Op9GetResponse, Error=ApiError>> {
self.api().op9_get(&self.context())
}
}
#[cfg(feature = "client")]
pub mod client;
// Re-export Client as a top-level name
#[cfg(feature = "client")]
pub use self::client::Client;
#[cfg(feature = "server")]
pub mod server;
// Re-export router() as a top-level name
#[cfg(feature = "server")]
pub use self::server::Service;
pub mod models;

View File

@@ -0,0 +1,13 @@
/// mime types for requests and responses
pub mod responses {
use hyper::mime::*;
// The macro is called per-operation to beat the recursion limit
}
pub mod requests {
use hyper::mime::*;
}

View File

@@ -0,0 +1,12 @@
#![allow(unused_imports, unused_qualifications, unused_extern_crates)]
extern crate chrono;
extern crate uuid;
use serde::ser::Serializer;
use std::collections::HashMap;
use models;
use swagger;
use std::string::ParseError;

View File

@@ -0,0 +1,91 @@
use std::io;
use std::marker::PhantomData;
use std::default::Default;
use hyper;
use hyper::{Request, Response, Error, StatusCode};
use server::url::form_urlencoded;
use swagger::auth::{Authorization, AuthData, Scopes};
use swagger::{Has, Pop, Push, XSpanIdString};
use Api;
pub struct NewAddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
pub fn new(inner: T) -> NewAddContext<T, A> {
NewAddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::NewService for NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Instance = AddContext<T::Instance, A>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
self.inner.new_service().map(|s| AddContext::new(s))
}
}
/// Middleware to extract authentication data from request
pub struct AddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
pub fn new(inner: T) -> AddContext<T, A> {
AddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::Service for AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Future = T::Future;
fn call(&self, req: Self::Request) -> Self::Future {
let context = A::default().push(XSpanIdString::get_or_generate(&req));
let context = context.push(None::<AuthData>);
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -23,8 +23,8 @@ swagger = "2"
#
lazy_static = "0.2"
log = "0.3.0"
mime = "0.3.3"
multipart = {version = "0.13.3", optional = true}
mime = "0.2.6"
multipart = {version = "0.13.3"}
native-tls = {version = "0.1.4", optional = true}
openssl = {version = "0.9.14", optional = true}
percent-encoding = {version = "1.0.0", optional = true}

View File

@@ -7,7 +7,7 @@ extern crate mime;
extern crate chrono;
extern crate url;
extern crate serde_urlencoded;
extern crate multipart;
use hyper;
use hyper::header::{Headers, ContentType};
@@ -26,9 +26,10 @@ use std::sync::Arc;
use std::str;
use std::str::FromStr;
use std::string::ToString;
use hyper::mime::Mime;
use std::io::Cursor;
use client::multipart::client::lazy::Multipart;
use mimetypes;
use serde_json;
use serde_xml_rs;
@@ -299,17 +300,13 @@ impl<F, C> Api<C> for Client<F> where
let mut request = hyper::Request::new(hyper::Method::Patch, uri);
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::TEST_SPECIAL_TAGS.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -382,20 +379,18 @@ impl<F, C> Api<C> for Client<F> where
let mut request = hyper::Request::new(hyper::Method::Post, uri);
// Body parameter
let body = param_body.map(|ref body| {
serde_json::to_string(body).expect("impossible to fail to serialize")
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::FAKE_OUTER_BOOLEAN_SERIALIZE.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -472,14 +467,13 @@ if let Some(body) = body {
serde_json::to_string(body).expect("impossible to fail to serialize")
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::FAKE_OUTER_COMPOSITE_SERIALIZE.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -556,14 +550,13 @@ if let Some(body) = body {
serde_json::to_string(body).expect("impossible to fail to serialize")
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::FAKE_OUTER_NUMBER_SERIALIZE.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -640,14 +633,13 @@ if let Some(body) = body {
serde_json::to_string(body).expect("impossible to fail to serialize")
});
if let Some(body) = body {
request.set_body(body);
if let Some(body) = body {
request.set_body(body);
}
request.headers_mut().set(ContentType(mimetypes::requests::FAKE_OUTER_STRING_SERIALIZE.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -722,14 +714,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Put, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::TEST_BODY_WITH_QUERY_PARAMS.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -790,14 +779,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Patch, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::TEST_CLIENT_MODEL.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -890,6 +876,7 @@ if let Some(body) = body {
request.headers_mut().set(ContentType(mimetypes::requests::TEST_ENDPOINT_PARAMETERS.clone()));
request.set_body(body.into_bytes());
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
if let Some(auth_data) = (context as &Has<Option<AuthData>>).get().as_ref() {
if let AuthData::Basic(ref basic_header) = *auth_data {
@@ -898,7 +885,6 @@ if let Some(body) = body {
))
}
}
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -986,15 +972,13 @@ if let Some(body) = body {
request.headers_mut().set(ContentType(mimetypes::requests::TEST_ENUM_PARAMETERS.clone()));
request.set_body(body.into_bytes());
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
// Header parameters
header! { (RequestEnumHeaderStringArray, "enum_header_string_array") => (String)* }
param_enum_header_string_array.map(|header| request.headers_mut().set(RequestEnumHeaderStringArray(header.clone())));
header! { (RequestEnumHeaderString, "enum_header_string") => [String] }
param_enum_header_string.map(|header| request.headers_mut().set(RequestEnumHeaderString(header)));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1064,14 +1048,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let body = serde_json::to_string(&param_param).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::TEST_INLINE_ADDITIONAL_PROPERTIES.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1139,9 +1120,8 @@ if let Some(body) = body {
request.headers_mut().set(ContentType(mimetypes::requests::TEST_JSON_FORM_DATA.clone()));
request.set_body(body.into_bytes());
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1205,17 +1185,13 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Patch, uri);
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::TEST_CLASSNAME.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1288,17 +1264,13 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
// Body parameter
let body = param_body.to_xml();
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::ADD_PET.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1360,12 +1332,9 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
// Header parameters
header! { (RequestApiKey, "api_key") => [String] }
param_api_key.map(|header| request.headers_mut().set(RequestApiKey(header)));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1428,8 +1397,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1515,8 +1482,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1607,7 +1572,6 @@ if let Some(body) = body {
request.headers_mut().set(ApiKey(api_key.to_string()));
}
}
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1700,14 +1664,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Put, uri);
let body = param_body.to_xml();
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::UPDATE_PET.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1793,9 +1754,8 @@ if let Some(body) = body {
request.headers_mut().set(ContentType(mimetypes::requests::UPDATE_PET_WITH_FORM.clone()));
request.set_body(body.into_bytes());
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1855,17 +1815,57 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let params = &[
("additionalMetadata", param_additional_metadata),
("file", param_file.map(|param| format!("{:?}", param))),
];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
let mut multipart = Multipart::new();
// For each parameter, encode as appropriate and add to the multipart body as a stream.
let additional_metadata_str = match serde_json::to_string(&param_additional_metadata) {
Ok(str) => str,
Err(e) => return Box::new(futures::done(Err(ApiError(format!("Unable to parse additional_metadata to string: {}", e))))),
};
let additional_metadata_vec = additional_metadata_str.as_bytes().to_vec();
let additional_metadata_mime = mime::Mime::from_str("application/json").expect("impossible to fail to parse");
let additional_metadata_cursor = Cursor::new(additional_metadata_vec);
multipart.add_stream("additional_metadata", additional_metadata_cursor, None as Option<&str>, Some(additional_metadata_mime));
let file_str = match serde_json::to_string(&param_file) {
Ok(str) => str,
Err(e) => return Box::new(futures::done(Err(ApiError(format!("Unable to parse file to string: {}", e))))),
};
let file_vec = file_str.as_bytes().to_vec();
let file_mime = mime::Mime::from_str("application/json").expect("impossible to fail to parse");
let file_cursor = Cursor::new(file_vec);
multipart.add_stream("file", file_cursor, None as Option<&str>, Some(file_mime));
let mut fields = match multipart.prepare() {
Ok(fields) => fields,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build request: {}", err))))),
};
let mut body_string = String::new();
fields.to_body().read_to_string(&mut body_string).unwrap();
let boundary = fields.boundary();
let multipart_header = match Mime::from_str(&format!("multipart/form-data;boundary={}", boundary)) {
Ok(multipart_header) => multipart_header,
Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build multipart header: {:?}", err))))),
};
request.set_body(body_string.into_bytes());
request.headers_mut().set(ContentType(multipart_header));
request.headers_mut().set(ContentType(mimetypes::requests::UPLOAD_FILE.clone()));
request.set_body(body.into_bytes());
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -1940,8 +1940,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2018,7 +2016,6 @@ if let Some(body) = body {
request.headers_mut().set(ApiKey(api_key.to_string()));
}
}
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2093,8 +2090,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2187,14 +2182,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::PLACE_ORDER.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2277,17 +2269,13 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::CREATE_USER.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2348,14 +2336,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::CREATE_USERS_WITH_ARRAY_INPUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2416,14 +2401,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::CREATE_USERS_WITH_LIST_INPUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2485,8 +2467,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2557,8 +2537,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2654,8 +2632,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2750,8 +2726,6 @@ if let Some(body) = body {
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -2812,14 +2786,11 @@ if let Some(body) = body {
let mut request = hyper::Request::new(hyper::Method::Put, uri);
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::UPDATE_USER.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {

View File

@@ -11,6 +11,7 @@ extern crate chrono;
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate mime;
// Logically this should be in the client and server modules, but rust doesn't allow `macro_use` from a module.
#[cfg(any(feature = "client", feature = "server"))]

View File

@@ -4,68 +4,84 @@ pub mod responses {
use hyper::mime::*;
// The macro is called per-operation to beat the recursion limit
/// Create Mime objects for the response content types for TestSpecialTags
lazy_static! {
/// Create Mime objects for the response content types for TestSpecialTags
pub static ref TEST_SPECIAL_TAGS_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for FakeOuterBooleanSerialize
lazy_static! {
/// Create Mime objects for the response content types for FakeOuterBooleanSerialize
pub static ref FAKE_OUTER_BOOLEAN_SERIALIZE_OUTPUT_BOOLEAN: Mime = "*/*".parse().unwrap();
}
/// Create Mime objects for the response content types for FakeOuterCompositeSerialize
lazy_static! {
/// Create Mime objects for the response content types for FakeOuterCompositeSerialize
pub static ref FAKE_OUTER_COMPOSITE_SERIALIZE_OUTPUT_COMPOSITE: Mime = "*/*".parse().unwrap();
}
/// Create Mime objects for the response content types for FakeOuterNumberSerialize
lazy_static! {
/// Create Mime objects for the response content types for FakeOuterNumberSerialize
pub static ref FAKE_OUTER_NUMBER_SERIALIZE_OUTPUT_NUMBER: Mime = "*/*".parse().unwrap();
}
/// Create Mime objects for the response content types for FakeOuterStringSerialize
lazy_static! {
/// Create Mime objects for the response content types for FakeOuterStringSerialize
pub static ref FAKE_OUTER_STRING_SERIALIZE_OUTPUT_STRING: Mime = "*/*".parse().unwrap();
}
/// Create Mime objects for the response content types for TestClientModel
lazy_static! {
/// Create Mime objects for the response content types for TestClientModel
pub static ref TEST_CLIENT_MODEL_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for TestClassname
lazy_static! {
/// Create Mime objects for the response content types for TestClassname
pub static ref TEST_CLASSNAME_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for FindPetsByStatus
lazy_static! {
/// Create Mime objects for the response content types for FindPetsByStatus
pub static ref FIND_PETS_BY_STATUS_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for FindPetsByTags
lazy_static! {
/// Create Mime objects for the response content types for FindPetsByTags
pub static ref FIND_PETS_BY_TAGS_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for GetPetById
lazy_static! {
/// Create Mime objects for the response content types for GetPetById
pub static ref GET_PET_BY_ID_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for UploadFile
lazy_static! {
/// Create Mime objects for the response content types for UploadFile
pub static ref UPLOAD_FILE_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for GetInventory
lazy_static! {
/// Create Mime objects for the response content types for GetInventory
pub static ref GET_INVENTORY_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for GetOrderById
lazy_static! {
/// Create Mime objects for the response content types for GetOrderById
pub static ref GET_ORDER_BY_ID_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for PlaceOrder
lazy_static! {
/// Create Mime objects for the response content types for PlaceOrder
pub static ref PLACE_ORDER_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for GetUserByName
lazy_static! {
/// Create Mime objects for the response content types for GetUserByName
pub static ref GET_USER_BY_NAME_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for LoginUser
lazy_static! {
/// Create Mime objects for the response content types for LoginUser
pub static ref LOGIN_USER_SUCCESSFUL_OPERATION: Mime = "application/json".parse().unwrap();
}
@@ -73,88 +89,109 @@ pub mod responses {
pub mod requests {
use hyper::mime::*;
/// Create Mime objects for the request content types for TestSpecialTags
lazy_static! {
/// Create Mime objects for the request content types for TestSpecialTags
pub static ref TEST_SPECIAL_TAGS: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for FakeOuterBooleanSerialize
lazy_static! {
/// Create Mime objects for the request content types for FakeOuterBooleanSerialize
pub static ref FAKE_OUTER_BOOLEAN_SERIALIZE: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for FakeOuterCompositeSerialize
lazy_static! {
/// Create Mime objects for the request content types for FakeOuterCompositeSerialize
pub static ref FAKE_OUTER_COMPOSITE_SERIALIZE: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for FakeOuterNumberSerialize
lazy_static! {
/// Create Mime objects for the request content types for FakeOuterNumberSerialize
pub static ref FAKE_OUTER_NUMBER_SERIALIZE: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for FakeOuterStringSerialize
lazy_static! {
/// Create Mime objects for the request content types for FakeOuterStringSerialize
pub static ref FAKE_OUTER_STRING_SERIALIZE: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for TestBodyWithQueryParams
lazy_static! {
/// Create Mime objects for the request content types for TestBodyWithQueryParams
pub static ref TEST_BODY_WITH_QUERY_PARAMS: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for TestClientModel
lazy_static! {
/// Create Mime objects for the request content types for TestClientModel
pub static ref TEST_CLIENT_MODEL: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for TestEndpointParameters
lazy_static! {
/// Create Mime objects for the request content types for TestEndpointParameters
pub static ref TEST_ENDPOINT_PARAMETERS: Mime = "application/x-www-form-urlencoded".parse().unwrap();
}
/// Create Mime objects for the request content types for TestEnumParameters
lazy_static! {
/// Create Mime objects for the request content types for TestEnumParameters
pub static ref TEST_ENUM_PARAMETERS: Mime = "application/x-www-form-urlencoded".parse().unwrap();
}
/// Create Mime objects for the request content types for TestInlineAdditionalProperties
lazy_static! {
/// Create Mime objects for the request content types for TestInlineAdditionalProperties
pub static ref TEST_INLINE_ADDITIONAL_PROPERTIES: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for TestJsonFormData
lazy_static! {
/// Create Mime objects for the request content types for TestJsonFormData
pub static ref TEST_JSON_FORM_DATA: Mime = "application/x-www-form-urlencoded".parse().unwrap();
}
/// Create Mime objects for the request content types for TestClassname
lazy_static! {
/// Create Mime objects for the request content types for TestClassname
pub static ref TEST_CLASSNAME: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for AddPet
lazy_static! {
/// Create Mime objects for the request content types for AddPet
pub static ref ADD_PET: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for UpdatePet
lazy_static! {
/// Create Mime objects for the request content types for UpdatePet
pub static ref UPDATE_PET: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for UpdatePetWithForm
lazy_static! {
/// Create Mime objects for the request content types for UpdatePetWithForm
pub static ref UPDATE_PET_WITH_FORM: Mime = "application/x-www-form-urlencoded".parse().unwrap();
}
/// Create Mime objects for the request content types for UploadFile
lazy_static! {
/// Create Mime objects for the request content types for UploadFile
pub static ref UPLOAD_FILE: Mime = "multipart/form-data".parse().unwrap();
}
/// Create Mime objects for the request content types for PlaceOrder
lazy_static! {
/// Create Mime objects for the request content types for PlaceOrder
pub static ref PLACE_ORDER: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for CreateUser
lazy_static! {
/// Create Mime objects for the request content types for CreateUser
pub static ref CREATE_USER: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for CreateUsersWithArrayInput
lazy_static! {
/// Create Mime objects for the request content types for CreateUsersWithArrayInput
pub static ref CREATE_USERS_WITH_ARRAY_INPUT: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for CreateUsersWithListInput
lazy_static! {
/// Create Mime objects for the request content types for CreateUsersWithListInput
pub static ref CREATE_USERS_WITH_LIST_INPUT: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for UpdateUser
lazy_static! {
/// Create Mime objects for the request content types for UpdateUser
pub static ref UPDATE_USER: Mime = "application/json".parse().unwrap();
}

View File

@@ -23,8 +23,8 @@ swagger = "2"
#
lazy_static = "0.2"
log = "0.3.0"
mime = "0.3.3"
multipart = {version = "0.13.3", optional = true}
mime = "0.2.6"
multipart = {version = "0.13.3"}
native-tls = {version = "0.1.4", optional = true}
openssl = {version = "0.9.14", optional = true}
percent-encoding = {version = "1.0.0", optional = true}

View File

@@ -7,8 +7,6 @@ extern crate mime;
extern crate chrono;
extern crate url;
use hyper;
use hyper::header::{Headers, ContentType};
use hyper::Uri;
@@ -26,12 +24,9 @@ use std::sync::Arc;
use std::str;
use std::str::FromStr;
use std::string::ToString;
use mimetypes;
use serde_json;
#[allow(unused_imports)]
use std::collections::{HashMap, BTreeMap};
#[allow(unused_imports)]
@@ -274,8 +269,6 @@ impl<F, C> Api<C> for Client<F> where
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -336,14 +329,11 @@ impl<F, C> Api<C> for Client<F> where
let mut request = hyper::Request::new(hyper::Method::Put, uri);
let body = serde_json::to_string(&param_nested_response).expect("impossible to fail to serialize");
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::DUMMY_PUT.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -405,8 +395,6 @@ impl<F, C> Api<C> for Client<F> where
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -480,14 +468,11 @@ impl<F, C> Api<C> for Client<F> where
let mut request = hyper::Request::new(hyper::Method::Post, uri);
let body = param_body;
request.set_body(body);
request.headers_mut().set(ContentType(mimetypes::requests::HTML_POST.clone()));
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {
@@ -562,8 +547,6 @@ impl<F, C> Api<C> for Client<F> where
request.headers_mut().set(XSpanId((context as &Has<XSpanIdString>).get().0.clone()));
Box::new(self.client_service.call(request)
.map_err(|e| ApiError(format!("No response received: {}", e)))
.and_then(|mut response| {

View File

@@ -11,6 +11,7 @@ extern crate chrono;
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate mime;
// Logically this should be in the client and server modules, but rust doesn't allow `macro_use` from a module.
#[cfg(any(feature = "client", feature = "server"))]

View File

@@ -4,16 +4,19 @@ pub mod responses {
use hyper::mime::*;
// The macro is called per-operation to beat the recursion limit
/// Create Mime objects for the response content types for FileResponseGet
lazy_static! {
/// Create Mime objects for the response content types for FileResponseGet
pub static ref FILE_RESPONSE_GET_SUCCESS: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the response content types for HtmlPost
lazy_static! {
/// Create Mime objects for the response content types for HtmlPost
pub static ref HTML_POST_SUCCESS: Mime = "text/html".parse().unwrap();
}
/// Create Mime objects for the response content types for RawJsonGet
lazy_static! {
/// Create Mime objects for the response content types for RawJsonGet
pub static ref RAW_JSON_GET_SUCCESS: Mime = "*/*".parse().unwrap();
}
@@ -21,12 +24,14 @@ pub mod responses {
pub mod requests {
use hyper::mime::*;
/// Create Mime objects for the request content types for DummyPut
lazy_static! {
/// Create Mime objects for the request content types for DummyPut
pub static ref DUMMY_PUT: Mime = "application/json".parse().unwrap();
}
/// Create Mime objects for the request content types for HtmlPost
lazy_static! {
/// Create Mime objects for the request content types for HtmlPost
pub static ref HTML_POST: Mime = "text/html".parse().unwrap();
}

View File

@@ -5,11 +5,10 @@ extern crate native_tls;
extern crate hyper_tls;
extern crate openssl;
extern crate mime;
extern crate uuid;
extern crate chrono;
extern crate percent_encoding;
extern crate url;
extern crate uuid;
use std::sync::Arc;
use std::marker::PhantomData;
@@ -19,10 +18,8 @@ use hyper::{Request, Response, Error, StatusCode};
use hyper::header::{Headers, ContentType};
use self::url::form_urlencoded;
use mimetypes;
use serde_json;
#[allow(unused_imports)]
use std::collections::{HashMap, BTreeMap};
#[allow(unused_imports)]
@@ -54,7 +51,7 @@ mod paths {
extern crate regex;
lazy_static! {
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(&[
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
r"^/dummy$",
r"^/file_response$",
r"^/html$",
@@ -132,16 +129,8 @@ where
// DummyGet - GET /dummy
&hyper::Method::Get if path.matched(paths::ID_DUMMY) => {
Box::new({
{{
Box::new(api_impl.dummy_get(&context)
.then(move |result| {
let mut response = Response::new();
@@ -168,22 +157,12 @@ where
future::ok(response)
}
))
}}
}) as Box<Future<Item=Response, Error=Error>>
},
// DummyPut - PUT /dummy
&hyper::Method::Put if path.matched(paths::ID_DUMMY) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -191,12 +170,9 @@ where
.then(move |result| -> Box<Future<Item=Response, Error=Error>> {
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
let param_nested_response: Option<models::InlineObject> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
@@ -204,7 +180,6 @@ where
Ok(param_nested_response) => param_nested_response,
Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse body parameter nested_response - doesn't match schema: {}", e)))),
}
} else {
None
};
@@ -212,8 +187,6 @@ where
Some(param_nested_response) => param_nested_response,
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body("Missing required body parameter nested_response"))),
};
Box::new(api_impl.dummy_put(param_nested_response, &context)
.then(move |result| {
let mut response = Response::new();
@@ -244,29 +217,17 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter nested_response: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// FileResponseGet - GET /file_response
&hyper::Method::Get if path.matched(paths::ID_FILE_RESPONSE) => {
Box::new({
{{
Box::new(api_impl.file_response_get(&context)
.then(move |result| {
let mut response = Response::new();
@@ -301,22 +262,12 @@ where
future::ok(response)
}
))
}}
}) as Box<Future<Item=Response, Error=Error>>
},
// HtmlPost - POST /html
&hyper::Method::Post if path.matched(paths::ID_HTML) => {
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -325,9 +276,7 @@ where
match result {
Ok(body) => {
let param_body: Option<String> = if !body.is_empty() {
Some(String::from_utf8(body.to_vec()).unwrap())
} else {
None
};
@@ -335,8 +284,6 @@ where
Some(param_body) => param_body,
None => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body("Missing required body parameter body"))),
};
Box::new(api_impl.html_post(param_body, &context)
.then(move |result| {
let mut response = Response::new();
@@ -371,29 +318,17 @@ where
future::ok(response)
}
))
},
Err(e) => Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't read body parameter body: {}", e)))),
}
})
) as Box<Future<Item=Response, Error=Error>>
},
// RawJsonGet - GET /raw_json
&hyper::Method::Get if path.matched(paths::ID_RAW_JSON) => {
Box::new({
{{
Box::new(api_impl.raw_json_get(&context)
.then(move |result| {
let mut response = Response::new();
@@ -428,14 +363,10 @@ where
future::ok(response)
}
))
}}
}) as Box<Future<Item=Response, Error=Error>>
},
_ => Box::new(future::ok(Response::new().with_status(StatusCode::NotFound))) as Box<Future<Item=Response, Error=Error>>,
}
}
@@ -451,6 +382,7 @@ impl<T, C> Clone for Service<T, C>
}
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {