Skip to content

Commit

Permalink
merged PR OpenAPITools#9919 and updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoverson committed Aug 20, 2021
1 parent 07e81c7 commit 83a12d2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ 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]
# Common
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.2"
swagger = { version = "6.1", features = ["client", "tcp", "tls"] }
log = "0.4.0"
mime = "0.3"

Expand All @@ -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", optional = true}
{{#apiUsesMultipartRelated}}
mime_multipart = {version = "0.5", optional = true}
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
Expand All @@ -115,21 +115,22 @@ percent-encoding = {version = "2.1.0", optional = true}
regex = {version = "1.3", optional = true}

# Conversion
frunk = { version = "0.3.0", optional = true }
frunk_derives = { version = "0.3.0", optional = true }
frunk_core = { version = "0.3.0", optional = true }
frunk = { version = "0.4.0", optional = true }
frunk_derives = { version = "0.4.0", optional = true }
frunk_core = { version = "0.4.0", optional = true }
frunk-enum-derive = { version = "0.2.0", optional = true }
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"] }
env_logger = "0.9"
tokio = { version = "1.10.0", features = ["rt-multi-thread", "net", "macros"] }
tokio-stream = "0.1.7"
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.2"
openssl = "0.10"

[[example]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -434,7 +434,7 @@
.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!("Could not de serialize {{{dataType}}}: {}", e)))?;
{{/x-produces-json}}
{{#x-produces-plain-text}}
let body = body.to_string();
Expand Down Expand Up @@ -477,7 +477,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,41 @@

#![allow(unused_imports)]

use std::future::Future;
use std::marker::PhantomData;
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::{
Arc,
Mutex,
};
use std::task::{
Context,
Poll,
};

use async_trait::async_trait;
use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt};
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;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use swagger::{Has, XSpanIdString};
use openssl::ssl::Ssl;
use swagger::auth::MakeAllowAllAuthenticator;
use swagger::EmptyContext;
use swagger::{
EmptyContext,
Has,
XSpanIdString,
};
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::{SslAcceptorBuilder, SslAcceptor, SslFiletype, SslMethod};

use {{{externCrateName}}}::models;

Expand Down Expand Up @@ -55,25 +71,27 @@ pub async fn create(addr: &str, https: bool) {
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 tcp_listener = TcpListener::bind(&addr).await.unwrap();
while let (Some(tcp), rest) = incoming.into_future().await {
if let Ok(tcp) = tcp {
let addr = tcp.peer_addr().expect("Unable to get remote address");
let service = service.call(addr);
let tls_acceptor = Arc::clone(&tls_acceptor);
while let Ok((tcp, _)) = tcp_listener.accept().await {
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(|_| ())?;
tokio::spawn(async move {
let ssl = Ssl::new(tls_acceptor.context()).expect("Failed to create async Ssl instance");
let mut stream =
tokio_openssl::SslStream::new(ssl, tcp).expect("Failed to create async SslStream");
let service = service.await.map_err(|_| ())?;
Pin::new(&mut stream).accept().await.map_err(|_| ())?;
Http::new().serve_connection(tls, service).await.map_err(|_| ())
});
}
let service = service.await.map_err(|_| ())?;
incoming = rest;
Http::new()
.serve_connection(stream, service)
.await
.map_err(|_| ())
});
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{{/allParams}}
context: &C) -> Result<{{{operationId}}}Response, ApiError>
{
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 failuare".into())
Err(ApiError("Generic failure".into()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ 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}}
{{#apis}}
{{#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,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class Configuration {
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
}

get fetchApi(): FetchAPI {
get fetchApi(): FetchAPI | undefined{
return this.configuration.fetchApi;
}

Expand Down

0 comments on commit 83a12d2

Please sign in to comment.