forked from loafle/openapi-generator-original
[rust-server] asynchronous support via hyper v0.11 (#7896)
* End use of deprecated openssl method * Enhance rust-server to use hyper 0.11 to support handling operations asynchronously The changes are complete and working (at least for microservices tested within Metaswitch). This isn't completely compatible with the (previous/current) synchronous swagger-codegen. Specifically, * `Client` is no longer `Send + Sync` * Api implementations used by Server are no longer expected to be `Send + Sync` (which is good, because it's quite hard if `Client` isn't) * the code to create `Client`s and `Server`s, and hook them into `hyper` or `tokio` is different. Importantly, though, the business logic itself should be unchanged. * Re-adds the `basePath` element to all server endpoints. This mean clients and servers can talk to each other again. * Fix multipart formdata codegen * Fix up handling of multipart messages * Fix server -> client multipart message response * Correct handling of optional file types * Add authorization header to requests with basic auth * Add client support for `application/x-www-form-urlencoded` * Import uuid library if headers use UUID type * Add BASE_PATH to the server module. * Wrap client connector * Support both query and body parameters on the same operation
This commit is contained in:
committed by
William Cheng
parent
c8650d0e34
commit
6c7813e79c
@@ -8,13 +8,16 @@ extern crate swagger;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate uuid;
|
||||
extern crate clap;
|
||||
extern crate tokio_core;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use futures::{Future, future, Stream, stream};
|
||||
use tokio_core::reactor;
|
||||
#[allow(unused_imports)]
|
||||
use petstore_api::{ApiNoContext, ContextWrapperExt,
|
||||
ApiError,
|
||||
TestSpecialTagsResponse,
|
||||
TestBodyWithQueryParamsResponse,
|
||||
FakeOuterBooleanSerializeResponse,
|
||||
FakeOuterCompositeSerializeResponse,
|
||||
FakeOuterNumberSerializeResponse,
|
||||
@@ -93,18 +96,19 @@ fn main() {
|
||||
.help("Port to contact"))
|
||||
.get_matches();
|
||||
|
||||
let mut core = reactor::Core::new().unwrap();
|
||||
let is_https = matches.is_present("https");
|
||||
let base_url = format!("{}://{}:{}",
|
||||
if is_https { "https" } else { "http" },
|
||||
matches.value_of("host").unwrap(),
|
||||
matches.value_of("port").unwrap());
|
||||
let client = if is_https {
|
||||
let client = if matches.is_present("https") {
|
||||
// Using Simple HTTPS
|
||||
petstore_api::Client::try_new_https(&base_url, "examples/ca.pem")
|
||||
petstore_api::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
|
||||
.expect("Failed to create HTTPS client")
|
||||
} else {
|
||||
// Using HTTP
|
||||
petstore_api::Client::try_new_http(&base_url)
|
||||
petstore_api::Client::try_new_http(core.handle(), &base_url)
|
||||
.expect("Failed to create HTTP client")
|
||||
};
|
||||
|
||||
@@ -115,165 +119,171 @@ fn main() {
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("TestSpecialTags") => {
|
||||
// let result = client.test_special_tags(???).wait();
|
||||
// let result = core.run(client.test_special_tags(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("TestBodyWithQueryParams") => {
|
||||
// let result = core.run(client.test_body_with_query_params(???, "query_example".to_string()));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("FakeOuterBooleanSerialize") => {
|
||||
let result = client.fake_outer_boolean_serialize(None).wait();
|
||||
let result = core.run(client.fake_outer_boolean_serialize(None));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("FakeOuterCompositeSerialize") => {
|
||||
let result = client.fake_outer_composite_serialize(None).wait();
|
||||
let result = core.run(client.fake_outer_composite_serialize(None));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("FakeOuterNumberSerialize") => {
|
||||
let result = client.fake_outer_number_serialize(None).wait();
|
||||
let result = core.run(client.fake_outer_number_serialize(None));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("FakeOuterStringSerialize") => {
|
||||
let result = client.fake_outer_string_serialize(None).wait();
|
||||
let result = core.run(client.fake_outer_string_serialize(None));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("TestClientModel") => {
|
||||
// let result = client.test_client_model(???).wait();
|
||||
// let result = core.run(client.test_client_model(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("TestEndpointParameters") => {
|
||||
let result = client.test_endpoint_parameters(8.14, 1.2, "pattern_without_delimiter_example".to_string(), swagger::ByteArray(Vec::from("B")), Some(56), Some(56), Some(789), Some(3.4), Some("string_example".to_string()), Some(swagger::ByteArray(Vec::from("B"))), None, None, Some("password_example".to_string()), Some("callback_example".to_string())).wait();
|
||||
let result = core.run(client.test_endpoint_parameters(8.14, 1.2, "pattern_without_delimiter_example".to_string(), swagger::ByteArray(Vec::from("B")), Some(56), Some(56), Some(789), Some(3.4), Some("string_example".to_string()), Some(swagger::ByteArray(Vec::from("B"))), None, None, Some("password_example".to_string()), Some("callback_example".to_string())));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("TestEnumParameters") => {
|
||||
let result = client.test_enum_parameters(Some(&Vec::new()), Some("enum_form_string_example".to_string()), Some(&Vec::new()), Some("enum_header_string_example".to_string()), Some(&Vec::new()), Some("enum_query_string_example".to_string()), Some(56), Some(1.2)).wait();
|
||||
let result = core.run(client.test_enum_parameters(Some(&Vec::new()), Some("enum_form_string_example".to_string()), Some(&Vec::new()), Some("enum_header_string_example".to_string()), Some(&Vec::new()), Some("enum_query_string_example".to_string()), Some(56), Some(1.2)));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("TestInlineAdditionalProperties") => {
|
||||
// let result = client.test_inline_additional_properties(???).wait();
|
||||
// let result = core.run(client.test_inline_additional_properties(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("TestJsonFormData") => {
|
||||
let result = client.test_json_form_data("param_example".to_string(), "param2_example".to_string()).wait();
|
||||
let result = core.run(client.test_json_form_data("param_example".to_string(), "param2_example".to_string()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("TestClassname") => {
|
||||
// let result = client.test_classname(???).wait();
|
||||
// let result = core.run(client.test_classname(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("AddPet") => {
|
||||
// let result = client.add_pet(???).wait();
|
||||
// let result = core.run(client.add_pet(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("DeletePet") => {
|
||||
let result = client.delete_pet(789, Some("api_key_example".to_string())).wait();
|
||||
let result = core.run(client.delete_pet(789, Some("api_key_example".to_string())));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("FindPetsByStatus") => {
|
||||
let result = client.find_pets_by_status(&Vec::new()).wait();
|
||||
let result = core.run(client.find_pets_by_status(&Vec::new()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("FindPetsByTags") => {
|
||||
let result = client.find_pets_by_tags(&Vec::new()).wait();
|
||||
let result = core.run(client.find_pets_by_tags(&Vec::new()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("GetPetById") => {
|
||||
let result = client.get_pet_by_id(789).wait();
|
||||
let result = core.run(client.get_pet_by_id(789));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("UpdatePet") => {
|
||||
// let result = client.update_pet(???).wait();
|
||||
// let result = core.run(client.update_pet(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("UpdatePetWithForm") => {
|
||||
let result = client.update_pet_with_form(789, Some("name_example".to_string()), Some("status_example".to_string())).wait();
|
||||
let result = core.run(client.update_pet_with_form(789, Some("name_example".to_string()), Some("status_example".to_string())));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("UploadFile") => {
|
||||
let result = client.upload_file(789, Some("additional_metadata_example".to_string()), Box::new(future::ok(Some(Box::new(stream::once(Ok(b"hello".to_vec()))) as Box<Stream<Item=_, Error=_> + Send>))) as Box<Future<Item=_, Error=_> + Send>).wait();
|
||||
let result = core.run(client.upload_file(789, Some("additional_metadata_example".to_string()), Box::new(future::ok(Some(Box::new(stream::once(Ok(b"hello".to_vec()))) as Box<Stream<Item=_, Error=_> + Send>))) as Box<Future<Item=_, Error=_> + Send>));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("DeleteOrder") => {
|
||||
let result = client.delete_order("order_id_example".to_string()).wait();
|
||||
let result = core.run(client.delete_order("order_id_example".to_string()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("GetInventory") => {
|
||||
let result = client.get_inventory().wait();
|
||||
let result = core.run(client.get_inventory());
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("GetOrderById") => {
|
||||
let result = client.get_order_by_id(789).wait();
|
||||
let result = core.run(client.get_order_by_id(789));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("PlaceOrder") => {
|
||||
// let result = client.place_order(???).wait();
|
||||
// let result = core.run(client.place_order(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("CreateUser") => {
|
||||
// let result = client.create_user(???).wait();
|
||||
// let result = core.run(client.create_user(???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
Some("CreateUsersWithArrayInput") => {
|
||||
let result = client.create_users_with_array_input(&Vec::new()).wait();
|
||||
let result = core.run(client.create_users_with_array_input(&Vec::new()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("CreateUsersWithListInput") => {
|
||||
let result = client.create_users_with_list_input(&Vec::new()).wait();
|
||||
let result = core.run(client.create_users_with_list_input(&Vec::new()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("DeleteUser") => {
|
||||
let result = client.delete_user("username_example".to_string()).wait();
|
||||
let result = core.run(client.delete_user("username_example".to_string()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("GetUserByName") => {
|
||||
let result = client.get_user_by_name("username_example".to_string()).wait();
|
||||
let result = core.run(client.get_user_by_name("username_example".to_string()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("LoginUser") => {
|
||||
let result = client.login_user("username_example".to_string(), "password_example".to_string()).wait();
|
||||
let result = core.run(client.login_user("username_example".to_string(), "password_example".to_string()));
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
Some("LogoutUser") => {
|
||||
let result = client.logout_user().wait();
|
||||
let result = core.run(client.logout_user());
|
||||
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
},
|
||||
|
||||
// Disabled because there's no example.
|
||||
// Some("UpdateUser") => {
|
||||
// let result = client.update_user("username_example".to_string(), ???).wait();
|
||||
// let result = core.run(client.update_user("username_example".to_string(), ???));
|
||||
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
|
||||
// },
|
||||
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
// extern crate <name of this crate>;
|
||||
extern crate petstore_api;
|
||||
extern crate swagger;
|
||||
extern crate iron;
|
||||
extern crate hyper_openssl;
|
||||
extern crate hyper;
|
||||
extern crate openssl;
|
||||
extern crate native_tls;
|
||||
extern crate tokio_proto;
|
||||
extern crate tokio_tls;
|
||||
extern crate clap;
|
||||
|
||||
// Imports required by server library.
|
||||
@@ -18,18 +21,19 @@ extern crate chrono;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
use hyper_openssl::OpensslServer;
|
||||
use hyper_openssl::openssl::x509::X509_FILETYPE_PEM;
|
||||
use hyper_openssl::openssl::ssl::{SslAcceptorBuilder, SslMethod};
|
||||
use hyper_openssl::openssl::error::ErrorStack;
|
||||
|
||||
use openssl::x509::X509_FILETYPE_PEM;
|
||||
use openssl::ssl::{SslAcceptorBuilder, SslMethod};
|
||||
use openssl::error::ErrorStack;
|
||||
use hyper::server::Http;
|
||||
use tokio_proto::TcpServer;
|
||||
use clap::{App, Arg};
|
||||
use iron::{Iron, Chain};
|
||||
use swagger::auth::AllowAllMiddleware;
|
||||
use swagger::auth::AllowAllAuthenticator;
|
||||
|
||||
mod server_lib;
|
||||
|
||||
/// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
|
||||
fn ssl() -> Result<OpensslServer, ErrorStack> {
|
||||
// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
|
||||
fn ssl() -> Result<SslAcceptorBuilder, ErrorStack> {
|
||||
let mut ssl = SslAcceptorBuilder::mozilla_intermediate_raw(SslMethod::tls())?;
|
||||
|
||||
// Server authentication
|
||||
@@ -37,7 +41,7 @@ fn ssl() -> Result<OpensslServer, ErrorStack> {
|
||||
ssl.set_certificate_chain_file("examples/server-chain.pem")?;
|
||||
ssl.check_private_key()?;
|
||||
|
||||
Ok(OpensslServer::from(ssl.build()))
|
||||
Ok(ssl)
|
||||
}
|
||||
|
||||
/// Create custom server, wire it to the autogenerated router,
|
||||
@@ -49,20 +53,22 @@ fn main() {
|
||||
.help("Whether to use HTTPS or not"))
|
||||
.get_matches();
|
||||
|
||||
let server = server_lib::server().unwrap();
|
||||
let router = petstore_api::router(server);
|
||||
|
||||
let mut chain = Chain::new(router);
|
||||
chain.link_before(petstore_api::server::ExtractAuthData);
|
||||
// add authentication middlewares into the chain here
|
||||
// for the purpose of this example, pretend we have authenticated a user
|
||||
chain.link_before(AllowAllMiddleware::new("cosmo"));
|
||||
let service_fn =
|
||||
petstore_api::server::auth::NewService::new(
|
||||
AllowAllAuthenticator::new(
|
||||
server_lib::NewService,
|
||||
"cosmo"
|
||||
)
|
||||
);
|
||||
|
||||
let addr = "127.0.0.1:80".parse().expect("Failed to parse bind address");
|
||||
if matches.is_present("https") {
|
||||
// Using Simple HTTPS
|
||||
Iron::new(chain).https("localhost:80", ssl().expect("Failed to load SSL keys")).expect("Failed to start HTTPS server");
|
||||
let ssl = ssl().expect("Failed to load SSL keys");
|
||||
let builder: native_tls::TlsAcceptorBuilder = native_tls::backend::openssl::TlsAcceptorBuilderExt::from_openssl(ssl);
|
||||
let tls_acceptor = builder.build().expect("Failed to build TLS acceptor");
|
||||
TcpServer::new(tokio_tls::proto::Server::new(Http::new(), tls_acceptor), addr).serve(service_fn);
|
||||
} else {
|
||||
// Using HTTP
|
||||
Iron::new(chain).http("localhost:80").expect("Failed to start HTTP server");
|
||||
TcpServer::new(Http::new(), addr).serve(service_fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,20 @@ mod errors {
|
||||
}
|
||||
|
||||
pub use self::errors::*;
|
||||
use std::io;
|
||||
use hyper;
|
||||
use petstore_api;
|
||||
|
||||
/// Instantiate a new server.
|
||||
pub fn server() -> Result<server::Server> {
|
||||
Ok(server::Server {})
|
||||
pub struct NewService;
|
||||
|
||||
impl hyper::server::NewService for NewService {
|
||||
type Request = (hyper::Request, petstore_api::Context);
|
||||
type Response = hyper::Response;
|
||||
type Error = hyper::Error;
|
||||
type Instance = petstore_api::server::Service<server::Server>;
|
||||
|
||||
/// Instantiate a new server.
|
||||
fn new_service(&self) -> io::Result<Self::Instance> {
|
||||
Ok(petstore_api::server::Service::new(server::Server))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ use chrono;
|
||||
use futures::Stream;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Error;
|
||||
|
||||
use swagger;
|
||||
|
||||
use petstore_api::{Api, ApiError, Context,
|
||||
TestSpecialTagsResponse,
|
||||
TestBodyWithQueryParamsResponse,
|
||||
FakeOuterBooleanSerializeResponse,
|
||||
FakeOuterCompositeSerializeResponse,
|
||||
FakeOuterNumberSerializeResponse,
|
||||
@@ -50,133 +52,140 @@ pub struct Server;
|
||||
impl Api for Server {
|
||||
|
||||
/// To test special tags
|
||||
fn test_special_tags(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestSpecialTagsResponse, Error=ApiError> + Send> {
|
||||
fn test_special_tags(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestSpecialTagsResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_special_tags({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
|
||||
fn fake_outer_boolean_serialize(&self, body: Option<models::OuterBoolean>, context: &Context) -> Box<Future<Item=FakeOuterBooleanSerializeResponse, Error=ApiError> + Send> {
|
||||
fn test_body_with_query_params(&self, body: models::User, query: String, context: &Context) -> Box<Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_body_with_query_params({:?}, \"{}\") - X-Span-ID: {:?}", body, query, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
|
||||
fn fake_outer_boolean_serialize(&self, body: Option<models::OuterBoolean>, context: &Context) -> Box<Future<Item=FakeOuterBooleanSerializeResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("fake_outer_boolean_serialize({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
|
||||
fn fake_outer_composite_serialize(&self, body: Option<models::OuterComposite>, context: &Context) -> Box<Future<Item=FakeOuterCompositeSerializeResponse, Error=ApiError> + Send> {
|
||||
fn fake_outer_composite_serialize(&self, body: Option<models::OuterComposite>, context: &Context) -> Box<Future<Item=FakeOuterCompositeSerializeResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("fake_outer_composite_serialize({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
|
||||
fn fake_outer_number_serialize(&self, body: Option<models::OuterNumber>, context: &Context) -> Box<Future<Item=FakeOuterNumberSerializeResponse, Error=ApiError> + Send> {
|
||||
fn fake_outer_number_serialize(&self, body: Option<models::OuterNumber>, context: &Context) -> Box<Future<Item=FakeOuterNumberSerializeResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("fake_outer_number_serialize({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
|
||||
fn fake_outer_string_serialize(&self, body: Option<models::OuterString>, context: &Context) -> Box<Future<Item=FakeOuterStringSerializeResponse, Error=ApiError> + Send> {
|
||||
fn fake_outer_string_serialize(&self, body: Option<models::OuterString>, context: &Context) -> Box<Future<Item=FakeOuterStringSerializeResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("fake_outer_string_serialize({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// To test \"client\" model
|
||||
fn test_client_model(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestClientModelResponse, Error=ApiError> + Send> {
|
||||
fn test_client_model(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestClientModelResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_client_model({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
fn test_endpoint_parameters(&self, number: f64, double: f64, pattern_without_delimiter: String, byte: swagger::ByteArray, integer: Option<i32>, int32: Option<i32>, int64: Option<i64>, float: Option<f32>, string: Option<String>, binary: Option<swagger::ByteArray>, date: Option<chrono::DateTime<chrono::Utc>>, date_time: Option<chrono::DateTime<chrono::Utc>>, password: Option<String>, callback: Option<String>, context: &Context) -> Box<Future<Item=TestEndpointParametersResponse, Error=ApiError> + Send> {
|
||||
fn test_endpoint_parameters(&self, number: f64, double: f64, pattern_without_delimiter: String, byte: swagger::ByteArray, integer: Option<i32>, int32: Option<i32>, int64: Option<i64>, float: Option<f32>, string: Option<String>, binary: Option<swagger::ByteArray>, date: Option<chrono::DateTime<chrono::Utc>>, date_time: Option<chrono::DateTime<chrono::Utc>>, password: Option<String>, callback: Option<String>, context: &Context) -> Box<Future<Item=TestEndpointParametersResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_endpoint_parameters({}, {}, \"{}\", {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, date, date_time, password, callback, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// To test enum parameters
|
||||
fn test_enum_parameters(&self, enum_form_string_array: Option<&Vec<String>>, enum_form_string: Option<String>, enum_header_string_array: Option<&Vec<String>>, enum_header_string: Option<String>, enum_query_string_array: Option<&Vec<String>>, enum_query_string: Option<String>, enum_query_integer: Option<i32>, enum_query_double: Option<f64>, context: &Context) -> Box<Future<Item=TestEnumParametersResponse, Error=ApiError> + Send> {
|
||||
fn test_enum_parameters(&self, enum_form_string_array: Option<&Vec<String>>, enum_form_string: Option<String>, enum_header_string_array: Option<&Vec<String>>, enum_header_string: Option<String>, enum_query_string_array: Option<&Vec<String>>, enum_query_string: Option<String>, enum_query_integer: Option<i32>, enum_query_double: Option<f64>, context: &Context) -> Box<Future<Item=TestEnumParametersResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_enum_parameters({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", enum_form_string_array, enum_form_string, enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// test inline additionalProperties
|
||||
fn test_inline_additional_properties(&self, param: object, context: &Context) -> Box<Future<Item=TestInlineAdditionalPropertiesResponse, Error=ApiError> + Send> {
|
||||
fn test_inline_additional_properties(&self, param: object, context: &Context) -> Box<Future<Item=TestInlineAdditionalPropertiesResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_inline_additional_properties({:?}) - X-Span-ID: {:?}", param, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// test json serialization of form data
|
||||
fn test_json_form_data(&self, param: String, param2: String, context: &Context) -> Box<Future<Item=TestJsonFormDataResponse, Error=ApiError> + Send> {
|
||||
fn test_json_form_data(&self, param: String, param2: String, context: &Context) -> Box<Future<Item=TestJsonFormDataResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_json_form_data(\"{}\", \"{}\") - X-Span-ID: {:?}", param, param2, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// To test class name in snake case
|
||||
fn test_classname(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestClassnameResponse, Error=ApiError> + Send> {
|
||||
fn test_classname(&self, body: models::Client, context: &Context) -> Box<Future<Item=TestClassnameResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("test_classname({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Add a new pet to the store
|
||||
fn add_pet(&self, body: models::Pet, context: &Context) -> Box<Future<Item=AddPetResponse, Error=ApiError> + Send> {
|
||||
fn add_pet(&self, body: models::Pet, context: &Context) -> Box<Future<Item=AddPetResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("add_pet({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Deletes a pet
|
||||
fn delete_pet(&self, pet_id: i64, api_key: Option<String>, context: &Context) -> Box<Future<Item=DeletePetResponse, Error=ApiError> + Send> {
|
||||
fn delete_pet(&self, pet_id: i64, api_key: Option<String>, context: &Context) -> Box<Future<Item=DeletePetResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("delete_pet({}, {:?}) - X-Span-ID: {:?}", pet_id, api_key, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Finds Pets by status
|
||||
fn find_pets_by_status(&self, status: &Vec<String>, context: &Context) -> Box<Future<Item=FindPetsByStatusResponse, Error=ApiError> + Send> {
|
||||
fn find_pets_by_status(&self, status: &Vec<String>, context: &Context) -> Box<Future<Item=FindPetsByStatusResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("find_pets_by_status({:?}) - X-Span-ID: {:?}", status, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Finds Pets by tags
|
||||
fn find_pets_by_tags(&self, tags: &Vec<String>, context: &Context) -> Box<Future<Item=FindPetsByTagsResponse, Error=ApiError> + Send> {
|
||||
fn find_pets_by_tags(&self, tags: &Vec<String>, context: &Context) -> Box<Future<Item=FindPetsByTagsResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("find_pets_by_tags({:?}) - X-Span-ID: {:?}", tags, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Find pet by ID
|
||||
fn get_pet_by_id(&self, pet_id: i64, context: &Context) -> Box<Future<Item=GetPetByIdResponse, Error=ApiError> + Send> {
|
||||
fn get_pet_by_id(&self, pet_id: i64, context: &Context) -> Box<Future<Item=GetPetByIdResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("get_pet_by_id({}) - X-Span-ID: {:?}", pet_id, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Update an existing pet
|
||||
fn update_pet(&self, body: models::Pet, context: &Context) -> Box<Future<Item=UpdatePetResponse, Error=ApiError> + Send> {
|
||||
fn update_pet(&self, body: models::Pet, context: &Context) -> Box<Future<Item=UpdatePetResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("update_pet({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Updates a pet in the store with form data
|
||||
fn update_pet_with_form(&self, pet_id: i64, name: Option<String>, status: Option<String>, context: &Context) -> Box<Future<Item=UpdatePetWithFormResponse, Error=ApiError> + Send> {
|
||||
fn update_pet_with_form(&self, pet_id: i64, name: Option<String>, status: Option<String>, context: &Context) -> Box<Future<Item=UpdatePetWithFormResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("update_pet_with_form({}, {:?}, {:?}) - X-Span-ID: {:?}", pet_id, name, status, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// uploads an image
|
||||
fn upload_file(&self, pet_id: i64, additional_metadata: Option<String>, file: Box<Future<Item=Option<Box<Stream<Item=Vec<u8>, Error=Error> + Send>>, Error=Error> + Send>, context: &Context) -> Box<Future<Item=UploadFileResponse, Error=ApiError> + Send> {
|
||||
fn upload_file(&self, pet_id: i64, additional_metadata: Option<String>, file: Box<Future<Item=Option<Box<Stream<Item=Vec<u8>, Error=Error> + Send>>, Error=Error> + Send>, context: &Context) -> Box<Future<Item=UploadFileResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("upload_file({}, {:?}, ) - X-Span-ID: {:?}", pet_id, additional_metadata, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
let _ = file; //Suppresses unused param warning
|
||||
@@ -184,84 +193,84 @@ impl Api for Server {
|
||||
}
|
||||
|
||||
/// Delete purchase order by ID
|
||||
fn delete_order(&self, order_id: String, context: &Context) -> Box<Future<Item=DeleteOrderResponse, Error=ApiError> + Send> {
|
||||
fn delete_order(&self, order_id: String, context: &Context) -> Box<Future<Item=DeleteOrderResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("delete_order(\"{}\") - X-Span-ID: {:?}", order_id, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Returns pet inventories by status
|
||||
fn get_inventory(&self, context: &Context) -> Box<Future<Item=GetInventoryResponse, Error=ApiError> + Send> {
|
||||
fn get_inventory(&self, context: &Context) -> Box<Future<Item=GetInventoryResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("get_inventory() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Find purchase order by ID
|
||||
fn get_order_by_id(&self, order_id: i64, context: &Context) -> Box<Future<Item=GetOrderByIdResponse, Error=ApiError> + Send> {
|
||||
fn get_order_by_id(&self, order_id: i64, context: &Context) -> Box<Future<Item=GetOrderByIdResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("get_order_by_id({}) - X-Span-ID: {:?}", order_id, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Place an order for a pet
|
||||
fn place_order(&self, body: models::Order, context: &Context) -> Box<Future<Item=PlaceOrderResponse, Error=ApiError> + Send> {
|
||||
fn place_order(&self, body: models::Order, context: &Context) -> Box<Future<Item=PlaceOrderResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("place_order({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Create user
|
||||
fn create_user(&self, body: models::User, context: &Context) -> Box<Future<Item=CreateUserResponse, Error=ApiError> + Send> {
|
||||
fn create_user(&self, body: models::User, context: &Context) -> Box<Future<Item=CreateUserResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("create_user({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Creates list of users with given input array
|
||||
fn create_users_with_array_input(&self, body: &Vec<models::User>, context: &Context) -> Box<Future<Item=CreateUsersWithArrayInputResponse, Error=ApiError> + Send> {
|
||||
fn create_users_with_array_input(&self, body: &Vec<models::User>, context: &Context) -> Box<Future<Item=CreateUsersWithArrayInputResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("create_users_with_array_input({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Creates list of users with given input array
|
||||
fn create_users_with_list_input(&self, body: &Vec<models::User>, context: &Context) -> Box<Future<Item=CreateUsersWithListInputResponse, Error=ApiError> + Send> {
|
||||
fn create_users_with_list_input(&self, body: &Vec<models::User>, context: &Context) -> Box<Future<Item=CreateUsersWithListInputResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("create_users_with_list_input({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Delete user
|
||||
fn delete_user(&self, username: String, context: &Context) -> Box<Future<Item=DeleteUserResponse, Error=ApiError> + Send> {
|
||||
fn delete_user(&self, username: String, context: &Context) -> Box<Future<Item=DeleteUserResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("delete_user(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Get user by user name
|
||||
fn get_user_by_name(&self, username: String, context: &Context) -> Box<Future<Item=GetUserByNameResponse, Error=ApiError> + Send> {
|
||||
fn get_user_by_name(&self, username: String, context: &Context) -> Box<Future<Item=GetUserByNameResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("get_user_by_name(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Logs user into the system
|
||||
fn login_user(&self, username: String, password: String, context: &Context) -> Box<Future<Item=LoginUserResponse, Error=ApiError> + Send> {
|
||||
fn login_user(&self, username: String, password: String, context: &Context) -> Box<Future<Item=LoginUserResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("login_user(\"{}\", \"{}\") - X-Span-ID: {:?}", username, password, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Logs out current logged in user session
|
||||
fn logout_user(&self, context: &Context) -> Box<Future<Item=LogoutUserResponse, Error=ApiError> + Send> {
|
||||
fn logout_user(&self, context: &Context) -> Box<Future<Item=LogoutUserResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("logout_user() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
}
|
||||
|
||||
/// Updated user
|
||||
fn update_user(&self, username: String, body: models::User, context: &Context) -> Box<Future<Item=UpdateUserResponse, Error=ApiError> + Send> {
|
||||
fn update_user(&self, username: String, body: models::User, context: &Context) -> Box<Future<Item=UpdateUserResponse, Error=ApiError>> {
|
||||
let context = context.clone();
|
||||
println!("update_user(\"{}\", {:?}) - X-Span-ID: {:?}", username, body, context.x_span_id.unwrap_or(String::from("<none>")).clone());
|
||||
Box::new(futures::failed("Generic failure".into()))
|
||||
|
||||
Reference in New Issue
Block a user