forked from loafle/openapi-generator-original
[Rust Server] Support complex query parameters (#5831)
* [Rust Server] Support complex query parameters * [Rust Server] Remove unused extern crate * [Rust Server] tokio should be a dev-dependency * [Rust Server] Add test for complex query params * Update samples Co-authored-by: Matt Williams
This commit is contained in:
committed by
GitHub
parent
cdb500c156
commit
95105cef2e
@@ -87,7 +87,6 @@ mime_multipart = {version = "0.5", optional = true}
|
||||
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
|
||||
{{/apiUsesMultipartRelated}}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -111,6 +110,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
{{^apiUsesUuid}}
|
||||
uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
{{/apiUsesUuid}}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
{{^required}}
|
||||
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
|
||||
{{/required}}
|
||||
query_string.append_pair("{{{baseName}}}", ¶m_{{{paramName}}}{{#isListContainer}}.join(","){{/isListContainer}}{{^isListContainer}}.to_string(){{/isListContainer}});
|
||||
query_string.append_pair("{{{baseName}}}", ¶m_{{{paramName}}}{{#isListContainer}}.iter().map(ToString::to_string).collect::<Vec<String>>().join(","){{/isListContainer}}{{^isListContainer}}.to_string(){{/isListContainer}});
|
||||
{{^required}}
|
||||
}
|
||||
{{/required}}
|
||||
|
||||
@@ -67,8 +67,6 @@ extern crate mime_multipart;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
{{#apiUsesUuid}}extern crate uuid;{{/apiUsesUuid}}
|
||||
|
||||
@@ -64,6 +64,12 @@ impl std::convert::From<{{{dataType}}}> for {{{classname}}} {
|
||||
}
|
||||
|
||||
{{#vendorExtensions.isString}}
|
||||
impl std::string::ToString for {{{classname}}} {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for {{{classname}}} {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
{{/-first}}
|
||||
let param_{{{paramName}}} = query_params.iter().filter(|e| e.0 == "{{{baseName}}}").map(|e| e.1.to_owned())
|
||||
{{#isListContainer}}
|
||||
.filter_map(|param_{{{paramName}}}| param_{{{paramName}}}.parse::<{{{baseType}}}>().ok())
|
||||
.filter_map(|param_{{{paramName}}}| param_{{{paramName}}}.parse().ok())
|
||||
.collect::<Vec<_>>();
|
||||
{{^required}}
|
||||
let param_{{{paramName}}} = if !param_{{{paramName}}}.is_empty() {
|
||||
|
||||
@@ -337,6 +337,27 @@ paths:
|
||||
responses:
|
||||
"204":
|
||||
description: Success.
|
||||
/merge-patch-json:
|
||||
get:
|
||||
responses:
|
||||
200:
|
||||
description: merge-patch+json-encoded response
|
||||
content:
|
||||
application/merge-patch+json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/anotherXmlObject"
|
||||
/complex-query-param:
|
||||
get:
|
||||
parameters:
|
||||
- name: list-of-strings
|
||||
in: query
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/StringObject'
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
|
||||
@@ -49,7 +49,6 @@ hyper = {version = "0.12", 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.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -70,6 +69,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
|
||||
@@ -46,8 +46,6 @@ extern crate mime_multipart;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ serde_json = "1.0"
|
||||
# Common between server and client features
|
||||
hyper = {version = "0.12", optional = true}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -60,6 +59,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
|
||||
@@ -39,8 +39,6 @@ extern crate hyper_openssl;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
# Common between server and client features
|
||||
hyper = {version = "0.12", optional = true}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -66,6 +65,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
tokio-openssl = "0.3"
|
||||
|
||||
@@ -62,6 +62,7 @@ To run a client, follow one of the following simple steps:
|
||||
|
||||
```
|
||||
cargo run --example client CallbackWithHeaderPost
|
||||
cargo run --example client ComplexQueryParamGet
|
||||
cargo run --example client MandatoryRequestHeaderGet
|
||||
cargo run --example client MergePatchJsonGet
|
||||
cargo run --example client MultigetGet
|
||||
@@ -114,6 +115,7 @@ All URIs are relative to *http://localhost*
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[****](docs/default_api.md#) | **POST** /callback-with-header |
|
||||
[****](docs/default_api.md#) | **GET** /complex-query-param |
|
||||
[****](docs/default_api.md#) | **GET** /enum_in_path/{path_param} |
|
||||
[****](docs/default_api.md#) | **GET** /mandatory-request-header |
|
||||
[****](docs/default_api.md#) | **GET** /merge-patch-json |
|
||||
|
||||
@@ -345,6 +345,21 @@ paths:
|
||||
description: Success.
|
||||
servers:
|
||||
- url: /override
|
||||
/complex-query-param:
|
||||
get:
|
||||
parameters:
|
||||
- explode: true
|
||||
in: query
|
||||
name: list-of-strings
|
||||
required: false
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/StringObject'
|
||||
type: array
|
||||
style: form
|
||||
responses:
|
||||
"200":
|
||||
description: Success
|
||||
components:
|
||||
schemas:
|
||||
EnumWithStarObject:
|
||||
|
||||
@@ -5,6 +5,7 @@ All URIs are relative to *http://localhost*
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
****](default_api.md#) | **POST** /callback-with-header |
|
||||
****](default_api.md#) | **GET** /complex-query-param |
|
||||
****](default_api.md#) | **GET** /enum_in_path/{path_param} |
|
||||
****](default_api.md#) | **GET** /mandatory-request-header |
|
||||
****](default_api.md#) | **GET** /merge-patch-json |
|
||||
@@ -51,6 +52,38 @@ No authorization required
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# ****
|
||||
> (optional)
|
||||
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
|
||||
|
||||
### Optional Parameters
|
||||
Optional parameters are passed through a map[string]interface{}.
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**list_of_strings** | [**String**](String.md)| |
|
||||
|
||||
### Return type
|
||||
|
||||
(empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: Not defined
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# ****
|
||||
> (path_param)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use futures::{Future, future, Stream, stream};
|
||||
use openapi_v3::{Api, ApiNoContext, Client, ContextWrapperExt,
|
||||
ApiError,
|
||||
CallbackWithHeaderPostResponse,
|
||||
ComplexQueryParamGetResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
@@ -66,6 +67,7 @@ fn main() {
|
||||
.help("Sets the operation to run")
|
||||
.possible_values(&[
|
||||
"CallbackWithHeaderPost",
|
||||
"ComplexQueryParamGet",
|
||||
"MandatoryRequestHeaderGet",
|
||||
"MergePatchJsonGet",
|
||||
"MultigetGet",
|
||||
@@ -136,6 +138,12 @@ fn main() {
|
||||
));
|
||||
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
|
||||
},
|
||||
Some("ComplexQueryParamGet") => {
|
||||
let result = rt.block_on(client.complex_query_param_get(
|
||||
Some(&Vec::new())
|
||||
));
|
||||
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
|
||||
},
|
||||
/* Disabled because there's no example.
|
||||
Some("EnumInPathPathParamGet") => {
|
||||
let result = rt.block_on(client.enum_in_path_path_param_get(
|
||||
|
||||
@@ -106,6 +106,7 @@ use openapi_v3::{
|
||||
Api,
|
||||
ApiError,
|
||||
CallbackWithHeaderPostResponse,
|
||||
ComplexQueryParamGetResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
@@ -139,6 +140,16 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
|
||||
Box::new(future::err("Generic failure".into()))
|
||||
}
|
||||
|
||||
fn complex_query_param_get(
|
||||
&self,
|
||||
list_of_strings: Option<&Vec<models::StringObject>>,
|
||||
context: &C) -> Box<Future<Item=ComplexQueryParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
let context = context.clone();
|
||||
info!("complex_query_param_get({:?}) - X-Span-ID: {:?}", list_of_strings, context.get().0.clone());
|
||||
Box::new(future::err("Generic failure".into()))
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
|
||||
@@ -36,6 +36,7 @@ define_encode_set! {
|
||||
|
||||
use {Api,
|
||||
CallbackWithHeaderPostResponse,
|
||||
ComplexQueryParamGetResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
@@ -346,6 +347,81 @@ impl<C, F> Api<C> for Client<F> where
|
||||
}))
|
||||
}
|
||||
|
||||
fn complex_query_param_get(
|
||||
&self,
|
||||
param_list_of_strings: Option<&Vec<models::StringObject>>,
|
||||
context: &C) -> Box<dyn Future<Item=ComplexQueryParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
let mut uri = format!(
|
||||
"{}/complex-query-param",
|
||||
self.base_path
|
||||
);
|
||||
|
||||
// Query parameters
|
||||
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||
if let Some(param_list_of_strings) = param_list_of_strings {
|
||||
query_string.append_pair("list-of-strings", ¶m_list_of_strings.iter().map(ToString::to_string).collect::<Vec<String>>().join(","));
|
||||
}
|
||||
let query_string_str = query_string.finish();
|
||||
if !query_string_str.is_empty() {
|
||||
uri += "?";
|
||||
uri += &query_string_str;
|
||||
}
|
||||
|
||||
let uri = match Uri::from_str(&uri) {
|
||||
Ok(uri) => uri,
|
||||
Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
|
||||
};
|
||||
|
||||
let mut request = match hyper::Request::builder()
|
||||
.method("GET")
|
||||
.uri(uri)
|
||||
.body(Body::empty()) {
|
||||
Ok(req) => req,
|
||||
Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
|
||||
};
|
||||
|
||||
let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
|
||||
});
|
||||
|
||||
Box::new(self.client_service.request(request)
|
||||
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||
.and_then(|mut response| {
|
||||
match response.status().as_u16() {
|
||||
200 => {
|
||||
let body = response.into_body();
|
||||
Box::new(
|
||||
future::ok(
|
||||
ComplexQueryParamGetResponse::Success
|
||||
)
|
||||
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||
},
|
||||
code => {
|
||||
let headers = response.headers().clone();
|
||||
Box::new(response.into_body()
|
||||
.take(100)
|
||||
.concat2()
|
||||
.then(move |body|
|
||||
future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
|
||||
code,
|
||||
headers,
|
||||
match body {
|
||||
Ok(ref body) => match str::from_utf8(body) {
|
||||
Ok(body) => Cow::from(body),
|
||||
Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
|
||||
},
|
||||
Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
|
||||
})))
|
||||
)
|
||||
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
param_path_param: models::StringEnum,
|
||||
|
||||
@@ -39,8 +39,6 @@ extern crate hyper_openssl;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate uuid;
|
||||
@@ -68,6 +66,12 @@ pub enum CallbackWithHeaderPostResponse {
|
||||
OK
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ComplexQueryParamGetResponse {
|
||||
/// Success
|
||||
Success
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum EnumInPathPathParamGetResponse {
|
||||
/// Success
|
||||
@@ -261,6 +265,11 @@ pub trait Api<C> {
|
||||
url: String,
|
||||
context: &C) -> Box<dyn Future<Item=CallbackWithHeaderPostResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn complex_query_param_get(
|
||||
&self,
|
||||
list_of_strings: Option<&Vec<models::StringObject>>,
|
||||
context: &C) -> Box<dyn Future<Item=ComplexQueryParamGetResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
@@ -362,6 +371,11 @@ pub trait ApiNoContext {
|
||||
url: String,
|
||||
) -> Box<dyn Future<Item=CallbackWithHeaderPostResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn complex_query_param_get(
|
||||
&self,
|
||||
list_of_strings: Option<&Vec<models::StringObject>>,
|
||||
) -> Box<dyn Future<Item=ComplexQueryParamGetResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
@@ -477,6 +491,14 @@ impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
|
||||
self.api().callback_with_header_post(url, &self.context())
|
||||
}
|
||||
|
||||
fn complex_query_param_get(
|
||||
&self,
|
||||
list_of_strings: Option<&Vec<models::StringObject>>,
|
||||
) -> Box<dyn Future<Item=ComplexQueryParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
self.api().complex_query_param_get(list_of_strings, &self.context())
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
|
||||
@@ -138,6 +138,12 @@ impl std::convert::From<String> for AnotherXmlInner {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for AnotherXmlInner {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for AnotherXmlInner {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -471,6 +477,12 @@ impl std::convert::From<String> for Err {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for Err {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Err {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -517,6 +529,12 @@ impl std::convert::From<String> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for Error {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Error {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -1441,6 +1459,12 @@ impl std::convert::From<String> for Ok {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for Ok {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Ok {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -1567,6 +1591,12 @@ impl std::convert::From<String> for Result {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for Result {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Result {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -1657,6 +1687,12 @@ impl std::convert::From<String> for StringObject {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for StringObject {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for StringObject {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
@@ -1867,6 +1903,12 @@ impl std::convert::From<String> for XmlInner {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for XmlInner {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for XmlInner {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
|
||||
@@ -23,6 +23,7 @@ pub use crate::context;
|
||||
|
||||
use {Api,
|
||||
CallbackWithHeaderPostResponse,
|
||||
ComplexQueryParamGetResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
@@ -52,6 +53,7 @@ mod paths {
|
||||
lazy_static! {
|
||||
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
|
||||
r"^/callback-with-header$",
|
||||
r"^/complex-query-param$",
|
||||
r"^/enum_in_path/(?P<path_param>[^/?#]*)$",
|
||||
r"^/mandatory-request-header$",
|
||||
r"^/merge-patch-json$",
|
||||
@@ -73,28 +75,29 @@ mod paths {
|
||||
.expect("Unable to create global regex set");
|
||||
}
|
||||
pub static ID_CALLBACK_WITH_HEADER: usize = 0;
|
||||
pub static ID_ENUM_IN_PATH_PATH_PARAM: usize = 1;
|
||||
pub static ID_COMPLEX_QUERY_PARAM: usize = 1;
|
||||
pub static ID_ENUM_IN_PATH_PATH_PARAM: usize = 2;
|
||||
lazy_static! {
|
||||
pub static ref REGEX_ENUM_IN_PATH_PATH_PARAM: regex::Regex =
|
||||
regex::Regex::new(r"^/enum_in_path/(?P<path_param>[^/?#]*)$")
|
||||
.expect("Unable to create regex for ENUM_IN_PATH_PATH_PARAM");
|
||||
}
|
||||
pub static ID_MANDATORY_REQUEST_HEADER: usize = 2;
|
||||
pub static ID_MERGE_PATCH_JSON: usize = 3;
|
||||
pub static ID_MULTIGET: usize = 4;
|
||||
pub static ID_MULTIPLE_AUTH_SCHEME: usize = 5;
|
||||
pub static ID_OVERRIDE_SERVER: usize = 6;
|
||||
pub static ID_PARAMGET: usize = 7;
|
||||
pub static ID_READONLY_AUTH_SCHEME: usize = 8;
|
||||
pub static ID_REGISTER_CALLBACK: usize = 9;
|
||||
pub static ID_REQUIRED_OCTET_STREAM: usize = 10;
|
||||
pub static ID_RESPONSES_WITH_HEADERS: usize = 11;
|
||||
pub static ID_RFC7807: usize = 12;
|
||||
pub static ID_UNTYPED_PROPERTY: usize = 13;
|
||||
pub static ID_UUID: usize = 14;
|
||||
pub static ID_XML: usize = 15;
|
||||
pub static ID_XML_EXTRA: usize = 16;
|
||||
pub static ID_XML_OTHER: usize = 17;
|
||||
pub static ID_MANDATORY_REQUEST_HEADER: usize = 3;
|
||||
pub static ID_MERGE_PATCH_JSON: usize = 4;
|
||||
pub static ID_MULTIGET: usize = 5;
|
||||
pub static ID_MULTIPLE_AUTH_SCHEME: usize = 6;
|
||||
pub static ID_OVERRIDE_SERVER: usize = 7;
|
||||
pub static ID_PARAMGET: usize = 8;
|
||||
pub static ID_READONLY_AUTH_SCHEME: usize = 9;
|
||||
pub static ID_REGISTER_CALLBACK: usize = 10;
|
||||
pub static ID_REQUIRED_OCTET_STREAM: usize = 11;
|
||||
pub static ID_RESPONSES_WITH_HEADERS: usize = 12;
|
||||
pub static ID_RFC7807: usize = 13;
|
||||
pub static ID_UNTYPED_PROPERTY: usize = 14;
|
||||
pub static ID_UUID: usize = 15;
|
||||
pub static ID_XML: usize = 16;
|
||||
pub static ID_XML_EXTRA: usize = 17;
|
||||
pub static ID_XML_OTHER: usize = 18;
|
||||
}
|
||||
|
||||
pub struct MakeService<T, RC> {
|
||||
@@ -236,6 +239,54 @@ where
|
||||
}) as Self::Future
|
||||
},
|
||||
|
||||
// ComplexQueryParamGet - GET /complex-query-param
|
||||
&hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => {
|
||||
// Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
|
||||
let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::<Vec<_>>();
|
||||
let param_list_of_strings = query_params.iter().filter(|e| e.0 == "list-of-strings").map(|e| e.1.to_owned())
|
||||
.filter_map(|param_list_of_strings| param_list_of_strings.parse().ok())
|
||||
.collect::<Vec<_>>();
|
||||
let param_list_of_strings = if !param_list_of_strings.is_empty() {
|
||||
Some(param_list_of_strings)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Box::new({
|
||||
{{
|
||||
Box::new(
|
||||
api_impl.complex_query_param_get(
|
||||
param_list_of_strings.as_ref(),
|
||||
&context
|
||||
).then(move |result| {
|
||||
let mut response = Response::new(Body::empty());
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("x-span-id"),
|
||||
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str())
|
||||
.expect("Unable to create X-Span-ID header value"));
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
ComplexQueryParamGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
// Application code returned an error. This should not happen, as the implementation should
|
||||
// return a valid response.
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
*response.body_mut() = Body::from("An internal error occurred");
|
||||
},
|
||||
}
|
||||
|
||||
future::ok(response)
|
||||
}
|
||||
))
|
||||
}}
|
||||
}) as Self::Future
|
||||
},
|
||||
|
||||
// EnumInPathPathParamGet - GET /enum_in_path/{path_param}
|
||||
&hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => {
|
||||
// Path parameters
|
||||
@@ -1451,6 +1502,7 @@ where
|
||||
},
|
||||
|
||||
_ if path.matched(paths::ID_CALLBACK_WITH_HEADER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => method_not_allowed(),
|
||||
_ if path.matched(paths::ID_MERGE_PATCH_JSON) => method_not_allowed(),
|
||||
@@ -1495,6 +1547,8 @@ impl<T> RequestParser<T> for ApiRequestParser {
|
||||
match request.method() {
|
||||
// CallbackWithHeaderPost - POST /callback-with-header
|
||||
&hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Ok("CallbackWithHeaderPost"),
|
||||
// ComplexQueryParamGet - GET /complex-query-param
|
||||
&hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => Ok("ComplexQueryParamGet"),
|
||||
// EnumInPathPathParamGet - GET /enum_in_path/{path_param}
|
||||
&hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => Ok("EnumInPathPathParamGet"),
|
||||
// MandatoryRequestHeaderGet - GET /mandatory-request-header
|
||||
|
||||
@@ -39,7 +39,6 @@ serde_json = "1.0"
|
||||
# Common between server and client features
|
||||
hyper = {version = "0.12", optional = true}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -60,6 +59,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
|
||||
@@ -39,8 +39,6 @@ extern crate hyper_openssl;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
# Common between server and client features
|
||||
hyper = {version = "0.12", optional = true}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -72,6 +71,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
tokio-openssl = "0.3"
|
||||
|
||||
@@ -1310,7 +1310,7 @@ impl<C, F> Api<C> for Client<F> where
|
||||
// Query parameters
|
||||
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||
if let Some(param_enum_query_string_array) = param_enum_query_string_array {
|
||||
query_string.append_pair("enum_query_string_array", ¶m_enum_query_string_array.join(","));
|
||||
query_string.append_pair("enum_query_string_array", ¶m_enum_query_string_array.iter().map(ToString::to_string).collect::<Vec<String>>().join(","));
|
||||
}
|
||||
if let Some(param_enum_query_string) = param_enum_query_string {
|
||||
query_string.append_pair("enum_query_string", ¶m_enum_query_string.to_string());
|
||||
@@ -1887,7 +1887,7 @@ impl<C, F> Api<C> for Client<F> where
|
||||
|
||||
// Query parameters
|
||||
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||
query_string.append_pair("status", ¶m_status.join(","));
|
||||
query_string.append_pair("status", ¶m_status.iter().map(ToString::to_string).collect::<Vec<String>>().join(","));
|
||||
let query_string_str = query_string.finish();
|
||||
if !query_string_str.is_empty() {
|
||||
uri += "?";
|
||||
@@ -1999,7 +1999,7 @@ impl<C, F> Api<C> for Client<F> where
|
||||
|
||||
// Query parameters
|
||||
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||
query_string.append_pair("tags", ¶m_tags.join(","));
|
||||
query_string.append_pair("tags", ¶m_tags.iter().map(ToString::to_string).collect::<Vec<String>>().join(","));
|
||||
let query_string_str = query_string.finish();
|
||||
if !query_string_str.is_empty() {
|
||||
uri += "?";
|
||||
|
||||
@@ -41,8 +41,6 @@ extern crate mime_0_2;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate uuid;
|
||||
|
||||
@@ -3887,6 +3887,12 @@ impl std::convert::From<String> for OuterString {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::string::ToString for OuterString {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for OuterString {
|
||||
type Err = std::string::ParseError;
|
||||
fn from_str(x: &str) -> std::result::Result<Self, Self::Err> {
|
||||
|
||||
@@ -1037,7 +1037,7 @@ where
|
||||
// Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
|
||||
let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::<Vec<_>>();
|
||||
let param_enum_query_string_array = query_params.iter().filter(|e| e.0 == "enum_query_string_array").map(|e| e.1.to_owned())
|
||||
.filter_map(|param_enum_query_string_array| param_enum_query_string_array.parse::<String>().ok())
|
||||
.filter_map(|param_enum_query_string_array| param_enum_query_string_array.parse().ok())
|
||||
.collect::<Vec<_>>();
|
||||
let param_enum_query_string_array = if !param_enum_query_string_array.is_empty() {
|
||||
Some(param_enum_query_string_array)
|
||||
@@ -1561,7 +1561,7 @@ where
|
||||
// Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
|
||||
let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::<Vec<_>>();
|
||||
let param_status = query_params.iter().filter(|e| e.0 == "status").map(|e| e.1.to_owned())
|
||||
.filter_map(|param_status| param_status.parse::<String>().ok())
|
||||
.filter_map(|param_status| param_status.parse().ok())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Box::new({
|
||||
@@ -1645,7 +1645,7 @@ where
|
||||
// Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
|
||||
let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::<Vec<_>>();
|
||||
let param_tags = query_params.iter().filter(|e| e.0 == "tags").map(|e| e.1.to_owned())
|
||||
.filter_map(|param_tags| param_tags.parse::<String>().ok())
|
||||
.filter_map(|param_tags| param_tags.parse().ok())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Box::new({
|
||||
|
||||
@@ -39,7 +39,6 @@ serde_json = "1.0"
|
||||
# Common between server and client features
|
||||
hyper = {version = "0.12", optional = true}
|
||||
serde_ignored = {version = "0.0.4", optional = true}
|
||||
tokio = {version = "0.1.17", optional = true}
|
||||
url = {version = "1.5", optional = true}
|
||||
|
||||
# Client-specific
|
||||
@@ -60,6 +59,7 @@ frunk-enum-core = { version = "0.2.0", optional = true }
|
||||
clap = "2.25"
|
||||
error-chain = "0.12"
|
||||
env_logger = "0.6"
|
||||
tokio = "0.1.17"
|
||||
uuid = {version = "0.7", features = ["serde", "v4"]}
|
||||
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
|
||||
|
||||
@@ -39,8 +39,6 @@ extern crate hyper_openssl;
|
||||
extern crate percent_encoding;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate serde_ignored;
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
extern crate tokio;
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user