[Rust][Server] Upgrade to tokio v1 (#11873)

* [Rust][Server] Upgrade hyper from 0.13 to 0.14, swagger-rs from 5.0.2 to 6.1.0

* Also upgrade tokio from 0.2 to 1.14

* Re-add JavaClientCodegenTest.java

* Fix incorrect slashes due to wrong generation

* Spelling fix: failuare -> failure

* Upgrade more packages

* Commit generated code

* Fix typo

Co-authored-by: Foorack / Max Faxälv <max@foorack.com>
This commit is contained in:
Samodya Abey 2022-03-16 02:29:36 -05:00 committed by GitHub
parent 941d4845d7
commit 4e602b66b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 677 additions and 656 deletions

View File

@ -61,10 +61,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -72,7 +72,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -96,7 +96,7 @@ uuid = {version = "0.8", features = ["serde", "v4"]}
{{/apiUsesUuid}}
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
{{#apiUsesMultipartRelated}}
mime_multipart = {version = "0.5", optional = true}
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
@ -124,12 +124,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -47,7 +47,7 @@ use crate::{{{operationId}}}Response;
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
{{#apiInfo}}
@ -58,7 +58,7 @@ impl<T> RequestParser<T> for ApiRequestParser {
{{#urls}}
{{#requests}}
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
&hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Ok("{{{operationId}}}"),
&hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"),
{{/requests}}
{{/urls}}
{{/callbacks}}
@ -66,7 +66,7 @@ impl<T> RequestParser<T> for ApiRequestParser {
{{/operations}}
{{/apis}}
{{/apiInfo}}
_ => Err(()),
_ => None,
}
}
}

View File

@ -418,7 +418,7 @@
let body = response.into_body();
{{#dataType}}
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
{{#vendorExtensions}}
{{#x-produces-bytes}}
@ -434,7 +434,9 @@
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
{{/x-produces-xml}}
{{#x-produces-json}}
let body = serde_json::from_str::<{{{dataType}}}>(body)?;
let body = serde_json::from_str::<{{{dataType}}}>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
{{/x-produces-json}}
{{#x-produces-plain-text}}
let body = body.to_string();
@ -477,7 +479,7 @@
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use {{{externCrateName}}}::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {

View File

@ -15,5 +15,5 @@
{
let context = context.clone();
info!("{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}({{#allParams}}{{#vendorExtensions}}{{{x-format-string}}}{{/vendorExtensions}}{{^-last}}, {{/-last}}{{/allParams}}) - X-Span-ID: {:?}"{{#allParams}}, {{{paramName}}}{{/allParams}}, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}

View File

@ -100,7 +100,7 @@ impl<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConne
}
#[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))]
type HttpConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector>;

View File

@ -26,7 +26,7 @@ pub mod callbacks;
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
{{#apiInfo}}
@ -34,12 +34,12 @@ impl<T> RequestParser<T> for ApiRequestParser {
{{#operations}}
{{#operation}}
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
&hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Ok("{{{operationId}}}"),
&hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"),
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
_ => Err(()),
_ => None,
}
}
}

View File

@ -209,7 +209,7 @@
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
{{#vendorExtensions}}
@ -279,7 +279,7 @@
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
use std::io::Read;
@ -368,7 +368,7 @@
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
let mut unused_elements: Vec<String> = vec![];

View File

@ -24,10 +24,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -35,7 +35,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -47,7 +47,7 @@ mime_0_2 = { package = "mime", version = "0.2.6", optional = true }
multipart = { version = "0.16", default-features = false, optional = true }
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
mime_multipart = {version = "0.5", optional = true}
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
serde_ignored = {version = "0.1.1", optional = true}
@ -70,12 +70,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use multipart_v3::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -116,7 +113,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("multipart_related_request_post({:?}, {:?}, {:?}) - X-Span-ID: {:?}", required_binary_field, object_field, optional_binary_field, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn multipart_request_post(
@ -129,7 +126,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("multipart_request_post(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", string_field, binary_field, optional_string_field, object_field, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn multiple_identical_mime_types_post(
@ -140,7 +137,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("multiple_identical_mime_types_post({:?}, {:?}) - X-Span-ID: {:?}", binary1, binary2, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -514,7 +514,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -667,7 +667,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -794,7 +794,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -155,7 +155,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
let mut unused_elements: Vec<String> = vec![];
@ -297,7 +297,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
use std::io::Read;
@ -446,7 +446,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
let mut unused_elements: Vec<String> = vec![];
@ -563,16 +563,16 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// MultipartRelatedRequestPost - POST /multipart_related_request
&hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => Ok("MultipartRelatedRequestPost"),
&hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => Some("MultipartRelatedRequestPost"),
// MultipartRequestPost - POST /multipart_request
&hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => Ok("MultipartRequestPost"),
&hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => Some("MultipartRequestPost"),
// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types
&hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => Ok("MultipleIdenticalMimeTypesPost"),
_ => Err(()),
&hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => Some("MultipleIdenticalMimeTypesPost"),
_ => None,
}
}
}

View File

@ -18,10 +18,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -29,7 +29,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -39,7 +39,7 @@ serde_json = "1.0"
# Crates included if required by the API definition
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -60,12 +60,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use no_example_v3::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -112,7 +109,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op_get({:?}) - X-Span-ID: {:?}", inline_object, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -445,7 +445,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -144,7 +144,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -223,12 +223,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// OpGet - GET /op
&hyper::Method::GET if path.matched(paths::ID_OP) => Ok("OpGet"),
_ => Err(()),
&hyper::Method::GET if path.matched(paths::ID_OP) => Some("OpGet"),
_ => None,
}
}
}

View File

@ -20,10 +20,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -31,7 +31,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -45,7 +45,7 @@ serde-xml-rs = {git = "git://github.com/Metaswitch/serde-xml-rs.git" , branch =
uuid = {version = "0.8", features = ["serde", "v4"]}
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -66,12 +66,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use openapi_v3::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -111,7 +108,7 @@ impl<C> CallbackApi<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("callback_callback_with_header_post({:?}) - X-Span-ID: {:?}", information, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn callback_callback_post(
@ -121,7 +118,7 @@ impl<C> CallbackApi<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("callback_callback_post() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use openapi_v3::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -137,7 +134,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("any_of_get({:?}) - X-Span-ID: {:?}", any_of, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn callback_with_header_post(
@ -147,7 +144,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("callback_with_header_post(\"{}\") - X-Span-ID: {:?}", url, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn complex_query_param_get(
@ -157,7 +154,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("complex_query_param_get({:?}) - X-Span-ID: {:?}", list_of_strings, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn enum_in_path_path_param_get(
@ -167,7 +164,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("enum_in_path_path_param_get({:?}) - X-Span-ID: {:?}", path_param, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn json_complex_query_param_get(
@ -177,7 +174,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("json_complex_query_param_get({:?}) - X-Span-ID: {:?}", list_of_strings, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn mandatory_request_header_get(
@ -187,7 +184,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("mandatory_request_header_get(\"{}\") - X-Span-ID: {:?}", x_header, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn merge_patch_json_get(
@ -196,7 +193,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("merge_patch_json_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Get some stuff.
@ -206,7 +203,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("multiget_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn multiple_auth_scheme_get(
@ -215,7 +212,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("multiple_auth_scheme_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn one_of_get(
@ -224,7 +221,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("one_of_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn override_server_get(
@ -233,7 +230,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("override_server_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Get some stuff with parameters.
@ -246,7 +243,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("paramget_get({:?}, {:?}, {:?}) - X-Span-ID: {:?}", uuid, some_object, some_list, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn readonly_auth_scheme_get(
@ -255,7 +252,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("readonly_auth_scheme_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn register_callback_post(
@ -265,7 +262,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("register_callback_post(\"{}\") - X-Span-ID: {:?}", url, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn required_octet_stream_put(
@ -275,7 +272,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("required_octet_stream_put({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn responses_with_headers_get(
@ -284,7 +281,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("responses_with_headers_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn rfc7807_get(
@ -293,7 +290,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("rfc7807_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn untyped_property_get(
@ -303,7 +300,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("untyped_property_get({:?}) - X-Span-ID: {:?}", object_untyped_props, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn uuid_get(
@ -312,7 +309,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("uuid_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn xml_extra_post(
@ -322,7 +319,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("xml_extra_post({:?}) - X-Span-ID: {:?}", duplicate_xml_object, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn xml_other_post(
@ -332,7 +329,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("xml_other_post({:?}) - X-Span-ID: {:?}", another_xml_object, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn xml_other_put(
@ -342,7 +339,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("xml_other_put({:?}) - X-Span-ID: {:?}", another_xml_array, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Post an array
@ -353,7 +350,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("xml_post({:?}) - X-Span-ID: {:?}", xml_array, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn xml_put(
@ -363,7 +360,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("xml_put({:?}) - X-Span-ID: {:?}", xml_object, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn create_repo(
@ -373,7 +370,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("create_repo({:?}) - X-Span-ID: {:?}", object_param, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn get_repo_info(
@ -383,7 +380,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_repo_info(\"{}\") - X-Span-ID: {:?}", repo_id, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -266,14 +266,14 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// CallbackCallbackWithHeaderPost - POST /{$request.query.url}/callback-with-header
&hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => Ok("CallbackCallbackWithHeaderPost"),
&hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => Some("CallbackCallbackWithHeaderPost"),
// CallbackCallbackPost - POST /{$request.query.url}/callback
&hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => Ok("CallbackCallbackPost"),
_ => Err(()),
&hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => Some("CallbackCallbackPost"),
_ => None,
}
}
}

View File

@ -458,11 +458,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnyOfObject>(body)?;
let body = serde_json::from_str::<models::AnyOfObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(AnyOfGetResponse::Success
(body)
)
@ -470,11 +472,13 @@ impl<S, C> Api<C> for Client<S, C> where
201 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Model12345AnyOfObject>(body)?;
let body = serde_json::from_str::<models::Model12345AnyOfObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(AnyOfGetResponse::AlternateSuccess
(body)
)
@ -482,11 +486,13 @@ impl<S, C> Api<C> for Client<S, C> where
202 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<swagger::AnyOf2<models::StringObject,models::UuidObject>>(body)?;
let body = serde_json::from_str::<swagger::AnyOf2<models::StringObject,models::UuidObject>>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(AnyOfGetResponse::AnyOfSuccess
(body)
)
@ -495,7 +501,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -567,7 +573,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -641,7 +647,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -712,7 +718,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -789,7 +795,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -870,7 +876,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -932,11 +938,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(MergePatchJsonGetResponse::Merge
(body)
)
@ -945,7 +953,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1007,11 +1015,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(MultigetGetResponse::JSONRsp
(body)
)
@ -1019,7 +1029,7 @@ impl<S, C> Api<C> for Client<S, C> where
201 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -1034,7 +1044,7 @@ impl<S, C> Api<C> for Client<S, C> where
202 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = swagger::ByteArray(body.to_vec());
Ok(MultigetGetResponse::OctetRsp
@ -1044,7 +1054,7 @@ impl<S, C> Api<C> for Client<S, C> where
203 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -1056,11 +1066,13 @@ impl<S, C> Api<C> for Client<S, C> where
204 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText
(body)
)
@ -1068,11 +1080,13 @@ impl<S, C> Api<C> for Client<S, C> where
205 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText_2
(body)
)
@ -1080,11 +1094,13 @@ impl<S, C> Api<C> for Client<S, C> where
206 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText_3
(body)
)
@ -1093,7 +1109,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1179,7 +1195,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1241,11 +1257,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<swagger::OneOf2<i32,Vec<String>>>(body)?;
let body = serde_json::from_str::<swagger::OneOf2<i32,Vec<String>>>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(OneOfGetResponse::Success
(body)
)
@ -1254,7 +1272,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1323,7 +1341,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1400,11 +1418,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body)?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(ParamgetGetResponse::JSONRsp
(body)
)
@ -1413,7 +1433,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1499,7 +1519,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1571,7 +1591,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1649,7 +1669,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1756,11 +1776,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body)?;
let body = serde_json::from_str::<String>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(ResponsesWithHeadersGetResponse::Success
{
body: body,
@ -1814,7 +1836,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1876,11 +1898,13 @@ impl<S, C> Api<C> for Client<S, C> where
204 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(Rfc7807GetResponse::OK
(body)
)
@ -1888,11 +1912,13 @@ impl<S, C> Api<C> for Client<S, C> where
404 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(Rfc7807GetResponse::NotFound
(body)
)
@ -1900,7 +1926,7 @@ impl<S, C> Api<C> for Client<S, C> where
406 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -1916,7 +1942,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1998,7 +2024,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2060,11 +2086,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<uuid::Uuid>(body)?;
let body = serde_json::from_str::<uuid::Uuid>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(UuidGetResponse::DuplicateResponseLongText
(body)
)
@ -2073,7 +2101,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2161,7 +2189,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2236,7 +2264,7 @@ impl<S, C> Api<C> for Client<S, C> where
201 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2258,7 +2286,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2346,7 +2374,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2434,7 +2462,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2524,7 +2552,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2603,7 +2631,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2667,11 +2695,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body)?;
let body = serde_json::from_str::<String>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(GetRepoInfoResponse::OK
(body)
)
@ -2680,7 +2710,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -123,7 +123,7 @@ impl<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConne
}
#[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))]
type HttpConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector>;
@ -300,7 +300,7 @@ impl<S, C> CallbackApi<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -370,7 +370,7 @@ impl<S, C> CallbackApi<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -1021,7 +1021,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let param_body: Option<swagger::ByteArray> = if !body.is_empty() {
@ -1261,7 +1261,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1360,7 +1360,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1427,7 +1427,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1505,7 +1505,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1572,7 +1572,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1639,7 +1639,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1706,7 +1706,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1868,62 +1868,62 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// AnyOfGet - GET /any-of
&hyper::Method::GET if path.matched(paths::ID_ANY_OF) => Ok("AnyOfGet"),
&hyper::Method::GET if path.matched(paths::ID_ANY_OF) => Some("AnyOfGet"),
// CallbackWithHeaderPost - POST /callback-with-header
&hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Ok("CallbackWithHeaderPost"),
&hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Some("CallbackWithHeaderPost"),
// ComplexQueryParamGet - GET /complex-query-param
&hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => Ok("ComplexQueryParamGet"),
&hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => Some("ComplexQueryParamGet"),
// EnumInPathPathParamGet - GET /enum_in_path/{path_param}
&hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => Ok("EnumInPathPathParamGet"),
&hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => Some("EnumInPathPathParamGet"),
// JsonComplexQueryParamGet - GET /json-complex-query-param
&hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => Ok("JsonComplexQueryParamGet"),
&hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => Some("JsonComplexQueryParamGet"),
// MandatoryRequestHeaderGet - GET /mandatory-request-header
&hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => Ok("MandatoryRequestHeaderGet"),
&hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => Some("MandatoryRequestHeaderGet"),
// MergePatchJsonGet - GET /merge-patch-json
&hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => Ok("MergePatchJsonGet"),
&hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => Some("MergePatchJsonGet"),
// MultigetGet - GET /multiget
&hyper::Method::GET if path.matched(paths::ID_MULTIGET) => Ok("MultigetGet"),
&hyper::Method::GET if path.matched(paths::ID_MULTIGET) => Some("MultigetGet"),
// MultipleAuthSchemeGet - GET /multiple_auth_scheme
&hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => Ok("MultipleAuthSchemeGet"),
&hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => Some("MultipleAuthSchemeGet"),
// OneOfGet - GET /one-of
&hyper::Method::GET if path.matched(paths::ID_ONE_OF) => Ok("OneOfGet"),
&hyper::Method::GET if path.matched(paths::ID_ONE_OF) => Some("OneOfGet"),
// OverrideServerGet - GET /override-server
&hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => Ok("OverrideServerGet"),
&hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => Some("OverrideServerGet"),
// ParamgetGet - GET /paramget
&hyper::Method::GET if path.matched(paths::ID_PARAMGET) => Ok("ParamgetGet"),
&hyper::Method::GET if path.matched(paths::ID_PARAMGET) => Some("ParamgetGet"),
// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme
&hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Ok("ReadonlyAuthSchemeGet"),
&hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Some("ReadonlyAuthSchemeGet"),
// RegisterCallbackPost - POST /register-callback
&hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Ok("RegisterCallbackPost"),
&hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Some("RegisterCallbackPost"),
// RequiredOctetStreamPut - PUT /required_octet_stream
&hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Ok("RequiredOctetStreamPut"),
&hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Some("RequiredOctetStreamPut"),
// ResponsesWithHeadersGet - GET /responses_with_headers
&hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => Ok("ResponsesWithHeadersGet"),
&hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => Some("ResponsesWithHeadersGet"),
// Rfc7807Get - GET /rfc7807
&hyper::Method::GET if path.matched(paths::ID_RFC7807) => Ok("Rfc7807Get"),
&hyper::Method::GET if path.matched(paths::ID_RFC7807) => Some("Rfc7807Get"),
// UntypedPropertyGet - GET /untyped_property
&hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => Ok("UntypedPropertyGet"),
&hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => Some("UntypedPropertyGet"),
// UuidGet - GET /uuid
&hyper::Method::GET if path.matched(paths::ID_UUID) => Ok("UuidGet"),
&hyper::Method::GET if path.matched(paths::ID_UUID) => Some("UuidGet"),
// XmlExtraPost - POST /xml_extra
&hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => Ok("XmlExtraPost"),
&hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => Some("XmlExtraPost"),
// XmlOtherPost - POST /xml_other
&hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => Ok("XmlOtherPost"),
&hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPost"),
// XmlOtherPut - PUT /xml_other
&hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => Ok("XmlOtherPut"),
&hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPut"),
// XmlPost - POST /xml
&hyper::Method::POST if path.matched(paths::ID_XML) => Ok("XmlPost"),
&hyper::Method::POST if path.matched(paths::ID_XML) => Some("XmlPost"),
// XmlPut - PUT /xml
&hyper::Method::PUT if path.matched(paths::ID_XML) => Ok("XmlPut"),
&hyper::Method::PUT if path.matched(paths::ID_XML) => Some("XmlPut"),
// CreateRepo - POST /repos
&hyper::Method::POST if path.matched(paths::ID_REPOS) => Ok("CreateRepo"),
&hyper::Method::POST if path.matched(paths::ID_REPOS) => Some("CreateRepo"),
// GetRepoInfo - GET /repos/{repoId}
&hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => Ok("GetRepoInfo"),
_ => Err(()),
&hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => Some("GetRepoInfo"),
_ => None,
}
}
}

View File

@ -18,10 +18,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -29,7 +29,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -39,7 +39,7 @@ serde_json = "1.0"
# Crates included if required by the API definition
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -60,12 +60,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use ops_v3::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -147,7 +144,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op10_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op11_get(
@ -156,7 +153,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op11_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op12_get(
@ -165,7 +162,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op12_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op13_get(
@ -174,7 +171,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op13_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op14_get(
@ -183,7 +180,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op14_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op15_get(
@ -192,7 +189,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op15_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op16_get(
@ -201,7 +198,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op16_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op17_get(
@ -210,7 +207,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op17_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op18_get(
@ -219,7 +216,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op18_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op19_get(
@ -228,7 +225,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op19_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op1_get(
@ -237,7 +234,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op1_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op20_get(
@ -246,7 +243,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op20_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op21_get(
@ -255,7 +252,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op21_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op22_get(
@ -264,7 +261,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op22_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op23_get(
@ -273,7 +270,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op23_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op24_get(
@ -282,7 +279,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op24_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op25_get(
@ -291,7 +288,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op25_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op26_get(
@ -300,7 +297,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op26_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op27_get(
@ -309,7 +306,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op27_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op28_get(
@ -318,7 +315,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op28_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op29_get(
@ -327,7 +324,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op29_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op2_get(
@ -336,7 +333,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op2_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op30_get(
@ -345,7 +342,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op30_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op31_get(
@ -354,7 +351,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op31_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op32_get(
@ -363,7 +360,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op32_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op33_get(
@ -372,7 +369,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op33_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op34_get(
@ -381,7 +378,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op34_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op35_get(
@ -390,7 +387,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op35_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op36_get(
@ -399,7 +396,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op36_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op37_get(
@ -408,7 +405,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op37_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op3_get(
@ -417,7 +414,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op3_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op4_get(
@ -426,7 +423,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op4_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op5_get(
@ -435,7 +432,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op5_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op6_get(
@ -444,7 +441,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op6_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op7_get(
@ -453,7 +450,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op7_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op8_get(
@ -462,7 +459,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op8_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn op9_get(
@ -471,7 +468,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("op9_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -469,7 +469,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -538,7 +538,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -607,7 +607,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -676,7 +676,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -745,7 +745,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -814,7 +814,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -883,7 +883,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -952,7 +952,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1021,7 +1021,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1090,7 +1090,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1159,7 +1159,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1228,7 +1228,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1297,7 +1297,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1366,7 +1366,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1435,7 +1435,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1504,7 +1504,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1573,7 +1573,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1642,7 +1642,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1711,7 +1711,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1780,7 +1780,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1849,7 +1849,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1918,7 +1918,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1987,7 +1987,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2056,7 +2056,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2125,7 +2125,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2194,7 +2194,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2263,7 +2263,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2332,7 +2332,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2401,7 +2401,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2470,7 +2470,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2539,7 +2539,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2608,7 +2608,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2677,7 +2677,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2746,7 +2746,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2815,7 +2815,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2884,7 +2884,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2953,7 +2953,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -1367,84 +1367,84 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// Op10Get - GET /op10
&hyper::Method::GET if path.matched(paths::ID_OP10) => Ok("Op10Get"),
&hyper::Method::GET if path.matched(paths::ID_OP10) => Some("Op10Get"),
// Op11Get - GET /op11
&hyper::Method::GET if path.matched(paths::ID_OP11) => Ok("Op11Get"),
&hyper::Method::GET if path.matched(paths::ID_OP11) => Some("Op11Get"),
// Op12Get - GET /op12
&hyper::Method::GET if path.matched(paths::ID_OP12) => Ok("Op12Get"),
&hyper::Method::GET if path.matched(paths::ID_OP12) => Some("Op12Get"),
// Op13Get - GET /op13
&hyper::Method::GET if path.matched(paths::ID_OP13) => Ok("Op13Get"),
&hyper::Method::GET if path.matched(paths::ID_OP13) => Some("Op13Get"),
// Op14Get - GET /op14
&hyper::Method::GET if path.matched(paths::ID_OP14) => Ok("Op14Get"),
&hyper::Method::GET if path.matched(paths::ID_OP14) => Some("Op14Get"),
// Op15Get - GET /op15
&hyper::Method::GET if path.matched(paths::ID_OP15) => Ok("Op15Get"),
&hyper::Method::GET if path.matched(paths::ID_OP15) => Some("Op15Get"),
// Op16Get - GET /op16
&hyper::Method::GET if path.matched(paths::ID_OP16) => Ok("Op16Get"),
&hyper::Method::GET if path.matched(paths::ID_OP16) => Some("Op16Get"),
// Op17Get - GET /op17
&hyper::Method::GET if path.matched(paths::ID_OP17) => Ok("Op17Get"),
&hyper::Method::GET if path.matched(paths::ID_OP17) => Some("Op17Get"),
// Op18Get - GET /op18
&hyper::Method::GET if path.matched(paths::ID_OP18) => Ok("Op18Get"),
&hyper::Method::GET if path.matched(paths::ID_OP18) => Some("Op18Get"),
// Op19Get - GET /op19
&hyper::Method::GET if path.matched(paths::ID_OP19) => Ok("Op19Get"),
&hyper::Method::GET if path.matched(paths::ID_OP19) => Some("Op19Get"),
// Op1Get - GET /op1
&hyper::Method::GET if path.matched(paths::ID_OP1) => Ok("Op1Get"),
&hyper::Method::GET if path.matched(paths::ID_OP1) => Some("Op1Get"),
// Op20Get - GET /op20
&hyper::Method::GET if path.matched(paths::ID_OP20) => Ok("Op20Get"),
&hyper::Method::GET if path.matched(paths::ID_OP20) => Some("Op20Get"),
// Op21Get - GET /op21
&hyper::Method::GET if path.matched(paths::ID_OP21) => Ok("Op21Get"),
&hyper::Method::GET if path.matched(paths::ID_OP21) => Some("Op21Get"),
// Op22Get - GET /op22
&hyper::Method::GET if path.matched(paths::ID_OP22) => Ok("Op22Get"),
&hyper::Method::GET if path.matched(paths::ID_OP22) => Some("Op22Get"),
// Op23Get - GET /op23
&hyper::Method::GET if path.matched(paths::ID_OP23) => Ok("Op23Get"),
&hyper::Method::GET if path.matched(paths::ID_OP23) => Some("Op23Get"),
// Op24Get - GET /op24
&hyper::Method::GET if path.matched(paths::ID_OP24) => Ok("Op24Get"),
&hyper::Method::GET if path.matched(paths::ID_OP24) => Some("Op24Get"),
// Op25Get - GET /op25
&hyper::Method::GET if path.matched(paths::ID_OP25) => Ok("Op25Get"),
&hyper::Method::GET if path.matched(paths::ID_OP25) => Some("Op25Get"),
// Op26Get - GET /op26
&hyper::Method::GET if path.matched(paths::ID_OP26) => Ok("Op26Get"),
&hyper::Method::GET if path.matched(paths::ID_OP26) => Some("Op26Get"),
// Op27Get - GET /op27
&hyper::Method::GET if path.matched(paths::ID_OP27) => Ok("Op27Get"),
&hyper::Method::GET if path.matched(paths::ID_OP27) => Some("Op27Get"),
// Op28Get - GET /op28
&hyper::Method::GET if path.matched(paths::ID_OP28) => Ok("Op28Get"),
&hyper::Method::GET if path.matched(paths::ID_OP28) => Some("Op28Get"),
// Op29Get - GET /op29
&hyper::Method::GET if path.matched(paths::ID_OP29) => Ok("Op29Get"),
&hyper::Method::GET if path.matched(paths::ID_OP29) => Some("Op29Get"),
// Op2Get - GET /op2
&hyper::Method::GET if path.matched(paths::ID_OP2) => Ok("Op2Get"),
&hyper::Method::GET if path.matched(paths::ID_OP2) => Some("Op2Get"),
// Op30Get - GET /op30
&hyper::Method::GET if path.matched(paths::ID_OP30) => Ok("Op30Get"),
&hyper::Method::GET if path.matched(paths::ID_OP30) => Some("Op30Get"),
// Op31Get - GET /op31
&hyper::Method::GET if path.matched(paths::ID_OP31) => Ok("Op31Get"),
&hyper::Method::GET if path.matched(paths::ID_OP31) => Some("Op31Get"),
// Op32Get - GET /op32
&hyper::Method::GET if path.matched(paths::ID_OP32) => Ok("Op32Get"),
&hyper::Method::GET if path.matched(paths::ID_OP32) => Some("Op32Get"),
// Op33Get - GET /op33
&hyper::Method::GET if path.matched(paths::ID_OP33) => Ok("Op33Get"),
&hyper::Method::GET if path.matched(paths::ID_OP33) => Some("Op33Get"),
// Op34Get - GET /op34
&hyper::Method::GET if path.matched(paths::ID_OP34) => Ok("Op34Get"),
&hyper::Method::GET if path.matched(paths::ID_OP34) => Some("Op34Get"),
// Op35Get - GET /op35
&hyper::Method::GET if path.matched(paths::ID_OP35) => Ok("Op35Get"),
&hyper::Method::GET if path.matched(paths::ID_OP35) => Some("Op35Get"),
// Op36Get - GET /op36
&hyper::Method::GET if path.matched(paths::ID_OP36) => Ok("Op36Get"),
&hyper::Method::GET if path.matched(paths::ID_OP36) => Some("Op36Get"),
// Op37Get - GET /op37
&hyper::Method::GET if path.matched(paths::ID_OP37) => Ok("Op37Get"),
&hyper::Method::GET if path.matched(paths::ID_OP37) => Some("Op37Get"),
// Op3Get - GET /op3
&hyper::Method::GET if path.matched(paths::ID_OP3) => Ok("Op3Get"),
&hyper::Method::GET if path.matched(paths::ID_OP3) => Some("Op3Get"),
// Op4Get - GET /op4
&hyper::Method::GET if path.matched(paths::ID_OP4) => Ok("Op4Get"),
&hyper::Method::GET if path.matched(paths::ID_OP4) => Some("Op4Get"),
// Op5Get - GET /op5
&hyper::Method::GET if path.matched(paths::ID_OP5) => Ok("Op5Get"),
&hyper::Method::GET if path.matched(paths::ID_OP5) => Some("Op5Get"),
// Op6Get - GET /op6
&hyper::Method::GET if path.matched(paths::ID_OP6) => Ok("Op6Get"),
&hyper::Method::GET if path.matched(paths::ID_OP6) => Some("Op6Get"),
// Op7Get - GET /op7
&hyper::Method::GET if path.matched(paths::ID_OP7) => Ok("Op7Get"),
&hyper::Method::GET if path.matched(paths::ID_OP7) => Some("Op7Get"),
// Op8Get - GET /op8
&hyper::Method::GET if path.matched(paths::ID_OP8) => Ok("Op8Get"),
&hyper::Method::GET if path.matched(paths::ID_OP8) => Some("Op8Get"),
// Op9Get - GET /op9
&hyper::Method::GET if path.matched(paths::ID_OP9) => Ok("Op9Get"),
_ => Err(()),
&hyper::Method::GET if path.matched(paths::ID_OP9) => Some("Op9Get"),
_ => None,
}
}
}

View File

@ -24,10 +24,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -35,7 +35,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -51,7 +51,7 @@ multipart = { version = "0.16", default-features = false, optional = true }
uuid = {version = "0.8", features = ["serde", "v4"]}
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -73,12 +73,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use petstore_with_fake_endpoints_models_for_testing::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -147,7 +144,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_special_tags({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn call123example(
@ -156,7 +153,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("call123example() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn fake_outer_boolean_serialize(
@ -166,7 +163,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("fake_outer_boolean_serialize({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn fake_outer_composite_serialize(
@ -176,7 +173,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("fake_outer_composite_serialize({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn fake_outer_number_serialize(
@ -186,7 +183,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("fake_outer_number_serialize({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn fake_outer_string_serialize(
@ -196,7 +193,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("fake_outer_string_serialize({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn fake_response_with_numerical_description(
@ -205,7 +202,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("fake_response_with_numerical_description() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn hyphen_param(
@ -215,7 +212,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("hyphen_param(\"{}\") - X-Span-ID: {:?}", hyphen_param, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn test_body_with_query_params(
@ -226,7 +223,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_body_with_query_params(\"{}\", {:?}) - X-Span-ID: {:?}", query, body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// To test \"client\" model
@ -237,7 +234,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_client_model({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@ -261,7 +258,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_endpoint_parameters({}, {}, \"{}\", {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, date, date_time, password, callback, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// To test enum parameters
@ -278,7 +275,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_enum_parameters({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double, enum_form_string, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// test inline additionalProperties
@ -289,7 +286,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_inline_additional_properties({:?}) - X-Span-ID: {:?}", param, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// test json serialization of form data
@ -301,7 +298,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_json_form_data(\"{}\", \"{}\") - X-Span-ID: {:?}", param, param2, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// To test class name in snake case
@ -312,7 +309,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("test_classname({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Add a new pet to the store
@ -323,7 +320,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("add_pet({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Deletes a pet
@ -335,7 +332,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("delete_pet({}, {:?}) - X-Span-ID: {:?}", pet_id, api_key, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Finds Pets by status
@ -346,7 +343,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("find_pets_by_status({:?}) - X-Span-ID: {:?}", status, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Finds Pets by tags
@ -357,7 +354,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("find_pets_by_tags({:?}) - X-Span-ID: {:?}", tags, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Find pet by ID
@ -368,7 +365,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_pet_by_id({}) - X-Span-ID: {:?}", pet_id, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Update an existing pet
@ -379,7 +376,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("update_pet({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Updates a pet in the store with form data
@ -392,7 +389,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("update_pet_with_form({}, {:?}, {:?}) - X-Span-ID: {:?}", pet_id, name, status, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// uploads an image
@ -405,7 +402,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("upload_file({}, {:?}, {:?}) - X-Span-ID: {:?}", pet_id, additional_metadata, file, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Delete purchase order by ID
@ -416,7 +413,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("delete_order(\"{}\") - X-Span-ID: {:?}", order_id, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Returns pet inventories by status
@ -426,7 +423,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_inventory() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Find purchase order by ID
@ -437,7 +434,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_order_by_id({}) - X-Span-ID: {:?}", order_id, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Place an order for a pet
@ -448,7 +445,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("place_order({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Create user
@ -459,7 +456,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("create_user({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Creates list of users with given input array
@ -470,7 +467,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("create_users_with_array_input({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Creates list of users with given input array
@ -481,7 +478,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("create_users_with_list_input({:?}) - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Delete user
@ -492,7 +489,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("delete_user(\"{}\") - X-Span-ID: {:?}", username, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Get user by user name
@ -503,7 +500,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_user_by_name(\"{}\") - X-Span-ID: {:?}", username, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Logs user into the system
@ -515,7 +512,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("login_user(\"{}\", \"{}\") - X-Span-ID: {:?}", username, password, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Logs out current logged in user session
@ -525,7 +522,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("logout_user() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Updated user
@ -537,7 +534,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("update_user(\"{}\", {:?}) - X-Span-ID: {:?}", username, body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -475,11 +475,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body)?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(TestSpecialTagsResponse::SuccessfulOperation
(body)
)
@ -488,7 +490,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -557,7 +559,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -632,11 +634,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<bool>(body)?;
let body = serde_json::from_str::<bool>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(FakeOuterBooleanSerializeResponse::OutputBoolean
(body)
)
@ -645,7 +649,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -720,11 +724,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::OuterComposite>(body)?;
let body = serde_json::from_str::<models::OuterComposite>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(FakeOuterCompositeSerializeResponse::OutputComposite
(body)
)
@ -733,7 +739,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -808,11 +814,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<f64>(body)?;
let body = serde_json::from_str::<f64>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(FakeOuterNumberSerializeResponse::OutputNumber
(body)
)
@ -821,7 +829,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -896,11 +904,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body)?;
let body = serde_json::from_str::<String>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(FakeOuterStringSerializeResponse::OutputString
(body)
)
@ -909,7 +919,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -978,7 +988,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1049,7 +1059,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1130,7 +1140,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1201,11 +1211,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body)?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(TestClientModelResponse::SuccessfulOperation
(body)
)
@ -1214,7 +1226,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1344,7 +1356,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1484,7 +1496,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1562,7 +1574,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1645,7 +1657,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1731,11 +1743,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body)?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(TestClassnameResponse::SuccessfulOperation
(body)
)
@ -1744,7 +1758,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1840,7 +1854,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1945,7 +1959,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2027,7 +2041,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2049,7 +2063,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2131,7 +2145,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2153,7 +2167,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2224,7 +2238,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2252,7 +2266,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2359,7 +2373,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2461,7 +2475,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2599,11 +2613,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ApiResponse>(body)?;
let body = serde_json::from_str::<models::ApiResponse>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(UploadFileResponse::SuccessfulOperation
(body)
)
@ -2612,7 +2628,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2689,7 +2705,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2758,11 +2774,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<std::collections::HashMap<String, i32>>(body)?;
let body = serde_json::from_str::<std::collections::HashMap<String, i32>>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(GetInventoryResponse::SuccessfulOperation
(body)
)
@ -2771,7 +2789,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2835,7 +2853,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2863,7 +2881,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -2936,7 +2954,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -2958,7 +2976,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3037,7 +3055,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3115,7 +3133,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3193,7 +3211,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3270,7 +3288,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3334,7 +3352,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -3362,7 +3380,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3460,7 +3478,7 @@ impl<S, C> Api<C> for Client<S, C> where
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -3486,7 +3504,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3555,7 +3573,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -3643,7 +3661,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -257,7 +257,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -366,7 +366,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -436,7 +436,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -506,7 +506,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -576,7 +576,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -755,7 +755,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -829,7 +829,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1125,7 +1125,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1243,7 +1243,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1353,7 +1353,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -1792,7 +1792,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -2023,7 +2023,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw();
let result = body.into_raw();
match result.await {
Ok(body) => {
use std::io::Read;
@ -2307,7 +2307,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -2391,7 +2391,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -2464,7 +2464,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -2537,7 +2537,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -2916,7 +2916,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -3026,80 +3026,80 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// TestSpecialTags - PATCH /another-fake/dummy
&hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => Ok("TestSpecialTags"),
&hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => Some("TestSpecialTags"),
// Call123example - GET /fake/operation-with-numeric-id
&hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => Ok("Call123example"),
&hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => Some("Call123example"),
// FakeOuterBooleanSerialize - POST /fake/outer/boolean
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => Ok("FakeOuterBooleanSerialize"),
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => Some("FakeOuterBooleanSerialize"),
// FakeOuterCompositeSerialize - POST /fake/outer/composite
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => Ok("FakeOuterCompositeSerialize"),
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => Some("FakeOuterCompositeSerialize"),
// FakeOuterNumberSerialize - POST /fake/outer/number
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => Ok("FakeOuterNumberSerialize"),
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => Some("FakeOuterNumberSerialize"),
// FakeOuterStringSerialize - POST /fake/outer/string
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => Ok("FakeOuterStringSerialize"),
&hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => Some("FakeOuterStringSerialize"),
// FakeResponseWithNumericalDescription - GET /fake/response-with-numerical-description
&hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => Ok("FakeResponseWithNumericalDescription"),
&hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => Some("FakeResponseWithNumericalDescription"),
// HyphenParam - GET /fake/hyphenParam/{hyphen-param}
&hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => Ok("HyphenParam"),
&hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => Some("HyphenParam"),
// TestBodyWithQueryParams - PUT /fake/body-with-query-params
&hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Ok("TestBodyWithQueryParams"),
&hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Some("TestBodyWithQueryParams"),
// TestClientModel - PATCH /fake
&hyper::Method::PATCH if path.matched(paths::ID_FAKE) => Ok("TestClientModel"),
&hyper::Method::PATCH if path.matched(paths::ID_FAKE) => Some("TestClientModel"),
// TestEndpointParameters - POST /fake
&hyper::Method::POST if path.matched(paths::ID_FAKE) => Ok("TestEndpointParameters"),
&hyper::Method::POST if path.matched(paths::ID_FAKE) => Some("TestEndpointParameters"),
// TestEnumParameters - GET /fake
&hyper::Method::GET if path.matched(paths::ID_FAKE) => Ok("TestEnumParameters"),
&hyper::Method::GET if path.matched(paths::ID_FAKE) => Some("TestEnumParameters"),
// TestInlineAdditionalProperties - POST /fake/inline-additionalProperties
&hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => Ok("TestInlineAdditionalProperties"),
&hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => Some("TestInlineAdditionalProperties"),
// TestJsonFormData - GET /fake/jsonFormData
&hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => Ok("TestJsonFormData"),
&hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => Some("TestJsonFormData"),
// TestClassname - PATCH /fake_classname_test
&hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => Ok("TestClassname"),
&hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => Some("TestClassname"),
// AddPet - POST /pet
&hyper::Method::POST if path.matched(paths::ID_PET) => Ok("AddPet"),
&hyper::Method::POST if path.matched(paths::ID_PET) => Some("AddPet"),
// DeletePet - DELETE /pet/{petId}
&hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => Ok("DeletePet"),
&hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => Some("DeletePet"),
// FindPetsByStatus - GET /pet/findByStatus
&hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => Ok("FindPetsByStatus"),
&hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => Some("FindPetsByStatus"),
// FindPetsByTags - GET /pet/findByTags
&hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => Ok("FindPetsByTags"),
&hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => Some("FindPetsByTags"),
// GetPetById - GET /pet/{petId}
&hyper::Method::GET if path.matched(paths::ID_PET_PETID) => Ok("GetPetById"),
&hyper::Method::GET if path.matched(paths::ID_PET_PETID) => Some("GetPetById"),
// UpdatePet - PUT /pet
&hyper::Method::PUT if path.matched(paths::ID_PET) => Ok("UpdatePet"),
&hyper::Method::PUT if path.matched(paths::ID_PET) => Some("UpdatePet"),
// UpdatePetWithForm - POST /pet/{petId}
&hyper::Method::POST if path.matched(paths::ID_PET_PETID) => Ok("UpdatePetWithForm"),
&hyper::Method::POST if path.matched(paths::ID_PET_PETID) => Some("UpdatePetWithForm"),
// UploadFile - POST /pet/{petId}/uploadImage
&hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => Ok("UploadFile"),
&hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => Some("UploadFile"),
// DeleteOrder - DELETE /store/order/{order_id}
&hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Ok("DeleteOrder"),
&hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("DeleteOrder"),
// GetInventory - GET /store/inventory
&hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => Ok("GetInventory"),
&hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => Some("GetInventory"),
// GetOrderById - GET /store/order/{order_id}
&hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Ok("GetOrderById"),
&hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("GetOrderById"),
// PlaceOrder - POST /store/order
&hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => Ok("PlaceOrder"),
&hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => Some("PlaceOrder"),
// CreateUser - POST /user
&hyper::Method::POST if path.matched(paths::ID_USER) => Ok("CreateUser"),
&hyper::Method::POST if path.matched(paths::ID_USER) => Some("CreateUser"),
// CreateUsersWithArrayInput - POST /user/createWithArray
&hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => Ok("CreateUsersWithArrayInput"),
&hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => Some("CreateUsersWithArrayInput"),
// CreateUsersWithListInput - POST /user/createWithList
&hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => Ok("CreateUsersWithListInput"),
&hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => Some("CreateUsersWithListInput"),
// DeleteUser - DELETE /user/{username}
&hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => Ok("DeleteUser"),
&hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => Some("DeleteUser"),
// GetUserByName - GET /user/{username}
&hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => Ok("GetUserByName"),
&hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => Some("GetUserByName"),
// LoginUser - GET /user/login
&hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => Ok("LoginUser"),
&hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => Some("LoginUser"),
// LogoutUser - GET /user/logout
&hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => Ok("LogoutUser"),
&hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => Some("LogoutUser"),
// UpdateUser - PUT /user/{username}
&hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => Ok("UpdateUser"),
_ => Err(()),
&hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => Some("UpdateUser"),
_ => None,
}
}
}

View File

@ -18,10 +18,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -29,7 +29,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -39,7 +39,7 @@ serde_json = "1.0"
# Crates included if required by the API definition
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -60,12 +60,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use ping_bearer_auth::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -111,7 +108,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("ping_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -450,7 +450,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -189,12 +189,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// PingGet - GET /ping
&hyper::Method::GET if path.matched(paths::ID_PING) => Ok("PingGet"),
_ => Err(()),
&hyper::Method::GET if path.matched(paths::ID_PING) => Some("PingGet"),
_ => None,
}
}
}

View File

@ -18,10 +18,10 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }
hyper-tls = { version = "0.5", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
[dependencies]
@ -29,7 +29,7 @@ openssl = {version = "0.10", optional = true }
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
mime = "0.3"
@ -39,7 +39,7 @@ serde_json = "1.0"
# Crates included if required by the API definition
# Common between server and client features
hyper = {version = "0.13", optional = true}
hyper = {version = "0.14", features = ["full"], optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
@ -60,12 +60,11 @@ frunk-enum-core = { version = "0.2.0", optional = true }
[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
tokio = { version = "1.14", features = ["full"] }
native-tls = "0.2"
tokio-tls = "0.3"
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
tokio-openssl = "0.6"
openssl = "0.10"
[[example]]

View File

@ -7,8 +7,6 @@ use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hyper::server::conn::Http;
use hyper::service::Service;
use log::info;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::SslAcceptorBuilder;
use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -20,7 +18,7 @@ use swagger::EmptyContext;
use tokio::net::TcpListener;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use rust_server_test::models;
@ -54,26 +52,25 @@ pub async fn create(addr: &str, https: bool) {
ssl.set_certificate_chain_file("examples/server-chain.pem").expect("Failed to set certificate chain");
ssl.check_private_key().expect("Failed to check private key");
let tls_acceptor = Arc::new(ssl.build());
let mut tcp_listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = tcp_listener.incoming();
let tls_acceptor = ssl.build();
let tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
loop {
if let Ok((tcp, _)) = tcp_listener.accept().await {
let ssl = Ssl::new(tls_acceptor.context()).unwrap();
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
tokio::spawn(async move {
let tls = tokio_openssl::accept(&*tls_acceptor, tcp).await.map_err(|_| ())?;
let tls = tokio_openssl::SslStream::new(ssl, tcp).map_err(|_| ())?;
let service = service.await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
Http::new()
.serve_connection(tls, service)
.await
.map_err(|_| ())
});
}
incoming = rest;
}
}
} else {
@ -119,7 +116,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("all_of_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// A dummy endpoint to make the spec valid.
@ -129,7 +126,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("dummy_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn dummy_put(
@ -139,7 +136,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("dummy_put({:?}) - X-Span-ID: {:?}", nested_response, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Get a file
@ -149,7 +146,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("file_response_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn get_structured_yaml(
@ -158,7 +155,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("get_structured_yaml() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Test HTML handling
@ -169,7 +166,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("html_post(\"{}\") - X-Span-ID: {:?}", body, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
async fn post_yaml(
@ -179,7 +176,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("post_yaml(\"{}\") - X-Span-ID: {:?}", value, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Get an arbitrary JSON blob.
@ -189,7 +186,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("raw_json_get() - X-Span-ID: {:?}", context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
/// Send an arbitrary JSON blob
@ -200,7 +197,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
let context = context.clone();
info!("solo_object_post({:?}) - X-Span-ID: {:?}", value, context.get().0.clone());
Err("Generic failure".into())
Err(ApiError("Generic failure".into()))
}
}

View File

@ -434,11 +434,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AllOfObject>(body)?;
let body = serde_json::from_str::<models::AllOfObject>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(AllOfGetResponse::OK
(body)
)
@ -447,7 +449,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -516,7 +518,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -594,7 +596,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -656,11 +658,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<swagger::ByteArray>(body)?;
let body = serde_json::from_str::<swagger::ByteArray>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(FileResponseGetResponse::Success
(body)
)
@ -669,7 +673,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -731,7 +735,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -744,7 +748,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -815,7 +819,7 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
@ -828,7 +832,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -906,7 +910,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -968,11 +972,13 @@ impl<S, C> Api<C> for Client<S, C> where
200 => {
let body = response.into_body();
let body = body
.to_raw()
.into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<serde_json::Value>(body)?;
let body = serde_json::from_str::<serde_json::Value>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
Ok(RawJsonGetResponse::Success
(body)
)
@ -981,7 +987,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,
@ -1061,7 +1067,7 @@ impl<S, C> Api<C> for Client<S, C> where
let headers = response.headers().clone();
let body = response.into_body()
.take(100)
.to_raw().await;
.into_raw().await;
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
code,
headers,

View File

@ -231,7 +231,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -376,7 +376,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let param_body: Option<String> = if !body.is_empty() {
@ -444,7 +444,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let param_value: Option<String> = if !body.is_empty() {
@ -541,7 +541,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// 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.
let result = body.to_raw().await;
let result = body.into_raw().await;
match result {
Ok(body) => {
let mut unused_elements = Vec::new();
@ -627,28 +627,28 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
fn parse_operation_id(request: &Request<T>) -> Result<&'static str, ()> {
fn parse_operation_id(request: &Request<T>) -> Option<&'static str> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// AllOfGet - GET /allOf
&hyper::Method::GET if path.matched(paths::ID_ALLOF) => Ok("AllOfGet"),
&hyper::Method::GET if path.matched(paths::ID_ALLOF) => Some("AllOfGet"),
// DummyGet - GET /dummy
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => Ok("DummyGet"),
&hyper::Method::GET if path.matched(paths::ID_DUMMY) => Some("DummyGet"),
// DummyPut - PUT /dummy
&hyper::Method::PUT if path.matched(paths::ID_DUMMY) => Ok("DummyPut"),
&hyper::Method::PUT if path.matched(paths::ID_DUMMY) => Some("DummyPut"),
// FileResponseGet - GET /file_response
&hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => Ok("FileResponseGet"),
&hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => Some("FileResponseGet"),
// GetStructuredYaml - GET /get-structured-yaml
&hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => Ok("GetStructuredYaml"),
&hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => Some("GetStructuredYaml"),
// HtmlPost - POST /html
&hyper::Method::POST if path.matched(paths::ID_HTML) => Ok("HtmlPost"),
&hyper::Method::POST if path.matched(paths::ID_HTML) => Some("HtmlPost"),
// PostYaml - POST /post-yaml
&hyper::Method::POST if path.matched(paths::ID_POST_YAML) => Ok("PostYaml"),
&hyper::Method::POST if path.matched(paths::ID_POST_YAML) => Some("PostYaml"),
// RawJsonGet - GET /raw_json
&hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => Ok("RawJsonGet"),
&hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => Some("RawJsonGet"),
// SoloObjectPost - POST /solo-object
&hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => Ok("SoloObjectPost"),
_ => Err(()),
&hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => Some("SoloObjectPost"),
_ => None,
}
}
}