forked from loafle/openapi-generator-original
[Rust Server] Make parse error Display-able (#5490)
* [Rust Server] Make parse error displayable Change error type to be displayable to prevent compile errors * [Rust Server] Add test for enum in path * Update samples
This commit is contained in:
parent
e4be8a107f
commit
16646b39c1
@ -45,11 +45,16 @@ impl ::std::fmt::Display for {{{classname}}} {
|
||||
}
|
||||
|
||||
impl ::std::str::FromStr for {{{classname}}} {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
{{#allowableValues}}{{#enumVars}} {{{value}}} => Ok({{{classname}}}::{{{name}}}),
|
||||
{{/enumVars}}{{/allowableValues}} _ => Err(()),
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{value}}} => Ok({{{classname}}}::{{{name}}}),
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
_ => Err(format!("Value not valid: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,11 +122,10 @@ impl ::std::string::ToString for {{{classname}}} {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for {{{classname}}} {
|
||||
type Err = ();
|
||||
type Err = &'static str;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Parsing additionalProperties in this style is not supported yet
|
||||
Err(())
|
||||
Err("Parsing additionalProperties for {{{classname}}} is not supported")
|
||||
}
|
||||
}
|
||||
{{/additionalPropertiesType}}
|
||||
@ -338,7 +342,7 @@ impl ::std::string::ToString for {{{classname}}} {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for {{{classname}}} {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -358,35 +362,35 @@ impl ::std::str::FromStr for {{{classname}}} {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing {{{classname}}}".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
{{#vars}}
|
||||
{{#isBinary}}
|
||||
"{{{baseName}}}" => return Err(()), // Parsing binary data in this style is not supported yet
|
||||
"{{{baseName}}}" => return Err("Parsing binary data in this style is not supported in {{{classname}}}".to_string()),
|
||||
{{/isBinary}}
|
||||
{{^isBinary}}
|
||||
{{#isByteArray}}
|
||||
"{{{baseName}}}" => return Err(()), // Parsing binary data in this style is not supported yet
|
||||
"{{{baseName}}}" => return Err("Parsing binary data in this style is not supported in {{{classname}}}".to_string()),
|
||||
{{/isByteArray}}
|
||||
{{^isByteArray}}
|
||||
{{#isContainer}}
|
||||
"{{{baseName}}}" => return Err(()), // Parsing a container in this style is not supported yet
|
||||
"{{{baseName}}}" => return Err("Parsing a container in this style is not supported in {{{classname}}}".to_string()),
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#isNullable}}
|
||||
"{{{baseName}}}" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"{{{baseName}}}" => return Err("Parsing a nullable type in this style is not supported in {{{classname}}}".to_string()),
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
"{{{baseName}}}" => intermediate_rep.{{{name}}}.push({{{dataType}}}::from_str(val).map_err(|x| ())?),
|
||||
"{{{baseName}}}" => intermediate_rep.{{{name}}}.push({{{dataType}}}::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
{{/isNullable}}
|
||||
{{/isContainer}}
|
||||
{{/isByteArray}}
|
||||
{{/isBinary}}
|
||||
{{/vars}}
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
_ => return Err("Unexpected key while parsing {{{classname}}}".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,10 +402,10 @@ impl ::std::str::FromStr for {{{classname}}} {
|
||||
Ok({{{classname}}} {
|
||||
{{#vars}}
|
||||
{{#isNullable}}
|
||||
{{{name}}}: Err(())?,
|
||||
{{{name}}}: Err("Nullable types not supported in {{{classname}}}".to_string())?,
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
{{{name}}}: intermediate_rep.{{{name}}}.into_iter().next(){{#required}}.ok_or(())?{{/required}},
|
||||
{{{name}}}: intermediate_rep.{{{name}}}.into_iter().next(){{#required}}.ok_or("{{{baseName}}} missing in {{{classname}}}".to_string())?{{/required}},
|
||||
{{/isNullable}}
|
||||
{{/vars}}
|
||||
})
|
||||
|
@ -319,6 +319,17 @@ paths:
|
||||
application/merge-patch+json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/anotherXmlObject"
|
||||
/enum_in_path/{path_param}:
|
||||
get:
|
||||
parameters:
|
||||
- name: path_param
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/StringEnum'
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
@ -474,3 +485,8 @@ components:
|
||||
items:
|
||||
type: string
|
||||
nullable: true
|
||||
StringEnum:
|
||||
type: string
|
||||
enum:
|
||||
- FOO
|
||||
- BAR
|
||||
|
@ -74,7 +74,7 @@ impl ::std::string::ToString for MultipartRelatedRequest {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for MultipartRelatedRequest {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -94,15 +94,15 @@ impl ::std::str::FromStr for MultipartRelatedRequest {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing MultipartRelatedRequest".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"object_field" => intermediate_rep.object_field.push(models::MultipartRequestObjectField::from_str(val).map_err(|x| ())?),
|
||||
"optional_binary_field" => return Err(()), // Parsing binary data in this style is not supported yet
|
||||
"required_binary_field" => return Err(()), // Parsing binary data in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"object_field" => intermediate_rep.object_field.push(models::MultipartRequestObjectField::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"optional_binary_field" => return Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()),
|
||||
"required_binary_field" => return Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()),
|
||||
_ => return Err("Unexpected key while parsing MultipartRelatedRequest".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ impl ::std::str::FromStr for MultipartRelatedRequest {
|
||||
Ok(MultipartRelatedRequest {
|
||||
object_field: intermediate_rep.object_field.into_iter().next(),
|
||||
optional_binary_field: intermediate_rep.optional_binary_field.into_iter().next(),
|
||||
required_binary_field: intermediate_rep.required_binary_field.into_iter().next().ok_or(())?,
|
||||
required_binary_field: intermediate_rep.required_binary_field.into_iter().next().ok_or("required_binary_field missing in MultipartRelatedRequest".to_string())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ impl ::std::string::ToString for MultipartRequest {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for MultipartRequest {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -216,16 +216,16 @@ impl ::std::str::FromStr for MultipartRequest {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing MultipartRequest".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"string_field" => intermediate_rep.string_field.push(String::from_str(val).map_err(|x| ())?),
|
||||
"optional_string_field" => intermediate_rep.optional_string_field.push(String::from_str(val).map_err(|x| ())?),
|
||||
"object_field" => intermediate_rep.object_field.push(models::MultipartRequestObjectField::from_str(val).map_err(|x| ())?),
|
||||
"binary_field" => return Err(()), // Parsing binary data in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"string_field" => intermediate_rep.string_field.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"optional_string_field" => intermediate_rep.optional_string_field.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"object_field" => intermediate_rep.object_field.push(models::MultipartRequestObjectField::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"binary_field" => return Err("Parsing binary data in this style is not supported in MultipartRequest".to_string()),
|
||||
_ => return Err("Unexpected key while parsing MultipartRequest".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,10 +235,10 @@ impl ::std::str::FromStr for MultipartRequest {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(MultipartRequest {
|
||||
string_field: intermediate_rep.string_field.into_iter().next().ok_or(())?,
|
||||
string_field: intermediate_rep.string_field.into_iter().next().ok_or("string_field missing in MultipartRequest".to_string())?,
|
||||
optional_string_field: intermediate_rep.optional_string_field.into_iter().next(),
|
||||
object_field: intermediate_rep.object_field.into_iter().next(),
|
||||
binary_field: intermediate_rep.binary_field.into_iter().next().ok_or(())?,
|
||||
binary_field: intermediate_rep.binary_field.into_iter().next().ok_or("binary_field missing in MultipartRequest".to_string())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -305,7 +305,7 @@ impl ::std::string::ToString for MultipartRequestObjectField {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for MultipartRequestObjectField {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -324,14 +324,14 @@ impl ::std::str::FromStr for MultipartRequestObjectField {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing MultipartRequestObjectField".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"field_a" => intermediate_rep.field_a.push(String::from_str(val).map_err(|x| ())?),
|
||||
"field_b" => return Err(()), // Parsing a container in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"field_a" => intermediate_rep.field_a.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"field_b" => return Err("Parsing a container in this style is not supported in MultipartRequestObjectField".to_string()),
|
||||
_ => return Err("Unexpected key while parsing MultipartRequestObjectField".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +341,7 @@ impl ::std::str::FromStr for MultipartRequestObjectField {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(MultipartRequestObjectField {
|
||||
field_a: intermediate_rep.field_a.into_iter().next().ok_or(())?,
|
||||
field_a: intermediate_rep.field_a.into_iter().next().ok_or("field_a missing in MultipartRequestObjectField".to_string())?,
|
||||
field_b: intermediate_rep.field_b.into_iter().next(),
|
||||
})
|
||||
}
|
||||
|
@ -113,6 +113,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** /enum_in_path/{path_param} |
|
||||
[****](docs/default_api.md#) | **GET** /mandatory-request-header |
|
||||
[****](docs/default_api.md#) | **GET** /merge-patch-json |
|
||||
[****](docs/default_api.md#) | **GET** /multiget | Get some stuff.
|
||||
@ -149,6 +150,7 @@ Method | HTTP request | Description
|
||||
- [ObjectWithArrayOfObjects](docs/ObjectWithArrayOfObjects.md)
|
||||
- [OptionalObjectHeader](docs/OptionalObjectHeader.md)
|
||||
- [RequiredObjectHeader](docs/RequiredObjectHeader.md)
|
||||
- [StringEnum](docs/StringEnum.md)
|
||||
- [StringObject](docs/StringObject.md)
|
||||
- [UuidObject](docs/UuidObject.md)
|
||||
- [XmlArray](docs/XmlArray.md)
|
||||
|
@ -325,6 +325,19 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/anotherXmlObject'
|
||||
description: merge-patch+json-encoded response
|
||||
/enum_in_path/{path_param}:
|
||||
get:
|
||||
parameters:
|
||||
- explode: false
|
||||
in: path
|
||||
name: path_param
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/StringEnum'
|
||||
style: simple
|
||||
responses:
|
||||
"200":
|
||||
description: Success
|
||||
components:
|
||||
schemas:
|
||||
EnumWithStarObject:
|
||||
@ -480,6 +493,11 @@ components:
|
||||
required:
|
||||
- nullable
|
||||
type: object
|
||||
StringEnum:
|
||||
enum:
|
||||
- FOO
|
||||
- BAR
|
||||
type: string
|
||||
inline_response_201:
|
||||
properties:
|
||||
foo:
|
||||
|
@ -0,0 +1,9 @@
|
||||
# StringEnum
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -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** /enum_in_path/{path_param} |
|
||||
****](default_api.md#) | **GET** /mandatory-request-header |
|
||||
****](default_api.md#) | **GET** /merge-patch-json |
|
||||
****](default_api.md#) | **GET** /multiget | Get some stuff.
|
||||
@ -49,6 +50,31 @@ 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)
|
||||
|
||||
# ****
|
||||
> (path_param)
|
||||
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**path_param** | [****](.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)
|
||||
|
||||
# ****
|
||||
> (x_header)
|
||||
|
||||
|
@ -25,6 +25,7 @@ use futures::{Future, future, Stream, stream};
|
||||
use openapi_v3::{Api, ApiNoContext, Client, ContextWrapperExt,
|
||||
ApiError,
|
||||
CallbackWithHeaderPostResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
MultigetGetResponse,
|
||||
@ -125,6 +126,14 @@ fn main() {
|
||||
));
|
||||
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(
|
||||
???
|
||||
));
|
||||
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has<XSpanIdString>).get().clone());
|
||||
},
|
||||
*/
|
||||
Some("MandatoryRequestHeaderGet") => {
|
||||
let result = rt.block_on(client.mandatory_request_header_get(
|
||||
"x_header_example".to_string()
|
||||
|
@ -88,6 +88,7 @@ use openapi_v3::{
|
||||
Api,
|
||||
ApiError,
|
||||
CallbackWithHeaderPostResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
MultigetGetResponse,
|
||||
@ -119,6 +120,16 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
|
||||
Box::new(future::err("Generic failure".into()))
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
context: &C) -> Box<Future<Item=EnumInPathPathParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
let context = context.clone();
|
||||
info!("enum_in_path_path_param_get({:?}) - X-Span-ID: {:?}", path_param, context.get().0.clone());
|
||||
Box::new(future::err("Generic failure".into()))
|
||||
}
|
||||
|
||||
fn mandatory_request_header_get(
|
||||
&self,
|
||||
x_header: String,
|
||||
|
@ -40,6 +40,7 @@ define_encode_set! {
|
||||
|
||||
use {Api,
|
||||
CallbackWithHeaderPostResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
MultigetGetResponse,
|
||||
@ -329,6 +330,79 @@ impl<C, F> Api<C> for Client<F> where
|
||||
}))
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
param_path_param: models::StringEnum,
|
||||
context: &C) -> Box<dyn Future<Item=EnumInPathPathParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
let mut uri = format!(
|
||||
"{}/enum_in_path/{path_param}",
|
||||
self.base_path
|
||||
,path_param=utf8_percent_encode(¶m_path_param.to_string(), ID_ENCODE_SET)
|
||||
);
|
||||
|
||||
// Query parameters
|
||||
let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
|
||||
let query_string_str = query_string.finish();
|
||||
if !query_string_str.is_empty() {
|
||||
uri += "?";
|
||||
uri += &query_string_str;
|
||||
}
|
||||
|
||||
let uri = match Uri::from_str(&uri) {
|
||||
Ok(uri) => uri,
|
||||
Err(err) => return Box::new(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(
|
||||
EnumInPathPathParamGetResponse::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 mandatory_request_header_get(
|
||||
&self,
|
||||
param_x_header: String,
|
||||
|
@ -79,6 +79,12 @@ pub enum CallbackWithHeaderPostResponse {
|
||||
OK
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum EnumInPathPathParamGetResponse {
|
||||
/// Success
|
||||
Success
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum MandatoryRequestHeaderGetResponse {
|
||||
/// Success
|
||||
@ -252,6 +258,11 @@ pub trait Api<C> {
|
||||
url: String,
|
||||
context: &C) -> Box<dyn Future<Item=CallbackWithHeaderPostResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
context: &C) -> Box<dyn Future<Item=EnumInPathPathParamGetResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn mandatory_request_header_get(
|
||||
&self,
|
||||
x_header: String,
|
||||
@ -344,6 +355,11 @@ pub trait ApiNoContext {
|
||||
url: String,
|
||||
) -> Box<dyn Future<Item=CallbackWithHeaderPostResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
) -> Box<dyn Future<Item=EnumInPathPathParamGetResponse, Error=ApiError> + Send>;
|
||||
|
||||
fn mandatory_request_header_get(
|
||||
&self,
|
||||
x_header: String,
|
||||
@ -450,6 +466,14 @@ impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
|
||||
self.api().callback_with_header_post(url, &self.context())
|
||||
}
|
||||
|
||||
fn enum_in_path_path_param_get(
|
||||
&self,
|
||||
path_param: models::StringEnum,
|
||||
) -> Box<dyn Future<Item=EnumInPathPathParamGetResponse, Error=ApiError> + Send>
|
||||
{
|
||||
self.api().enum_in_path_path_param_get(path_param, &self.context())
|
||||
}
|
||||
|
||||
fn mandatory_request_header_get(
|
||||
&self,
|
||||
x_header: String,
|
||||
|
@ -4,6 +4,7 @@ pub mod responses {
|
||||
|
||||
|
||||
|
||||
|
||||
/// Create &str objects for the response content types for MergePatchJsonGet
|
||||
pub static MERGE_PATCH_JSON_GET_MERGE: &str = "application/merge-patch+json";
|
||||
|
||||
@ -62,6 +63,7 @@ pub mod requests {
|
||||
|
||||
|
||||
|
||||
|
||||
/// Create &str objects for the request content types for RequiredOctetStreamPut
|
||||
pub static REQUIRED_OCTET_STREAM_PUT: &str = "application/octet-stream";
|
||||
|
||||
|
@ -234,7 +234,7 @@ impl ::std::string::ToString for AnotherXmlObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for AnotherXmlObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -252,13 +252,13 @@ impl ::std::str::FromStr for AnotherXmlObject {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing AnotherXmlObject".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"inner_string" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"inner_string" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing AnotherXmlObject".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ impl ::std::string::ToString for DuplicateXmlObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for DuplicateXmlObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -372,14 +372,14 @@ impl ::std::str::FromStr for DuplicateXmlObject {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing DuplicateXmlObject".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"inner_string" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| ())?),
|
||||
"inner_array" => intermediate_rep.inner_array.push(models::XmlArray::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"inner_string" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"inner_array" => intermediate_rep.inner_array.push(models::XmlArray::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing DuplicateXmlObject".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ impl ::std::str::FromStr for DuplicateXmlObject {
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(DuplicateXmlObject {
|
||||
inner_string: intermediate_rep.inner_string.into_iter().next(),
|
||||
inner_array: intermediate_rep.inner_array.into_iter().next().ok_or(())?,
|
||||
inner_array: intermediate_rep.inner_array.into_iter().next().ok_or("inner_array missing in DuplicateXmlObject".to_string())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -442,13 +442,14 @@ impl ::std::fmt::Display for EnumWithStarObject {
|
||||
}
|
||||
|
||||
impl ::std::str::FromStr for EnumWithStarObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"FOO" => Ok(EnumWithStarObject::FOO),
|
||||
"BAR" => Ok(EnumWithStarObject::BAR),
|
||||
"*" => Ok(EnumWithStarObject::STAR),
|
||||
_ => Err(()),
|
||||
_ => Err(format!("Value not valid: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -514,7 +515,7 @@ impl ::std::string::ToString for InlineResponse201 {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for InlineResponse201 {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -532,13 +533,13 @@ impl ::std::str::FromStr for InlineResponse201 {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing InlineResponse201".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"foo" => intermediate_rep.foo.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"foo" => intermediate_rep.foo.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing InlineResponse201".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -815,7 +816,7 @@ impl ::std::string::ToString for NullableTest {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for NullableTest {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -837,17 +838,17 @@ impl ::std::str::FromStr for NullableTest {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing NullableTest".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"nullable" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"nullableWithNullDefault" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"nullableWithPresentDefault" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"nullableWithNoDefault" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"nullableArray" => return Err(()), // Parsing a container in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"nullable" => return Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
|
||||
"nullableWithNullDefault" => return Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
|
||||
"nullableWithPresentDefault" => return Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
|
||||
"nullableWithNoDefault" => return Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
|
||||
"nullableArray" => return Err("Parsing a container in this style is not supported in NullableTest".to_string()),
|
||||
_ => return Err("Unexpected key while parsing NullableTest".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -857,11 +858,11 @@ impl ::std::str::FromStr for NullableTest {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(NullableTest {
|
||||
nullable: Err(())?,
|
||||
nullable_with_null_default: Err(())?,
|
||||
nullable_with_present_default: Err(())?,
|
||||
nullable_with_no_default: Err(())?,
|
||||
nullable_array: Err(())?,
|
||||
nullable: Err("Nullable types not supported in NullableTest".to_string())?,
|
||||
nullable_with_null_default: Err("Nullable types not supported in NullableTest".to_string())?,
|
||||
nullable_with_present_default: Err("Nullable types not supported in NullableTest".to_string())?,
|
||||
nullable_with_no_default: Err("Nullable types not supported in NullableTest".to_string())?,
|
||||
nullable_array: Err("Nullable types not supported in NullableTest".to_string())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -936,7 +937,7 @@ impl ::std::string::ToString for ObjectHeader {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectHeader {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -955,14 +956,14 @@ impl ::std::str::FromStr for ObjectHeader {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectHeader".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"requiredObjectHeader" => intermediate_rep.required_object_header.push(bool::from_str(val).map_err(|x| ())?),
|
||||
"optionalObjectHeader" => intermediate_rep.optional_object_header.push(isize::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"requiredObjectHeader" => intermediate_rep.required_object_header.push(bool::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"optionalObjectHeader" => intermediate_rep.optional_object_header.push(isize::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing ObjectHeader".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -972,7 +973,7 @@ impl ::std::str::FromStr for ObjectHeader {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(ObjectHeader {
|
||||
required_object_header: intermediate_rep.required_object_header.into_iter().next().ok_or(())?,
|
||||
required_object_header: intermediate_rep.required_object_header.into_iter().next().ok_or("requiredObjectHeader missing in ObjectHeader".to_string())?,
|
||||
optional_object_header: intermediate_rep.optional_object_header.into_iter().next(),
|
||||
})
|
||||
}
|
||||
@ -1048,7 +1049,7 @@ impl ::std::string::ToString for ObjectParam {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectParam {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -1067,14 +1068,14 @@ impl ::std::str::FromStr for ObjectParam {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectParam".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"requiredParam" => intermediate_rep.required_param.push(bool::from_str(val).map_err(|x| ())?),
|
||||
"optionalParam" => intermediate_rep.optional_param.push(isize::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"requiredParam" => intermediate_rep.required_param.push(bool::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"optionalParam" => intermediate_rep.optional_param.push(isize::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing ObjectParam".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1084,7 +1085,7 @@ impl ::std::str::FromStr for ObjectParam {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(ObjectParam {
|
||||
required_param: intermediate_rep.required_param.into_iter().next().ok_or(())?,
|
||||
required_param: intermediate_rep.required_param.into_iter().next().ok_or("requiredParam missing in ObjectParam".to_string())?,
|
||||
optional_param: intermediate_rep.optional_param.into_iter().next(),
|
||||
})
|
||||
}
|
||||
@ -1167,7 +1168,7 @@ impl ::std::string::ToString for ObjectUntypedProps {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectUntypedProps {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -1188,16 +1189,16 @@ impl ::std::str::FromStr for ObjectUntypedProps {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectUntypedProps".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"required_untyped" => intermediate_rep.required_untyped.push(serde_json::Value::from_str(val).map_err(|x| ())?),
|
||||
"required_untyped_nullable" => intermediate_rep.required_untyped_nullable.push(serde_json::Value::from_str(val).map_err(|x| ())?),
|
||||
"not_required_untyped" => intermediate_rep.not_required_untyped.push(serde_json::Value::from_str(val).map_err(|x| ())?),
|
||||
"not_required_untyped_nullable" => intermediate_rep.not_required_untyped_nullable.push(serde_json::Value::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"required_untyped" => intermediate_rep.required_untyped.push(serde_json::Value::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"required_untyped_nullable" => intermediate_rep.required_untyped_nullable.push(serde_json::Value::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"not_required_untyped" => intermediate_rep.not_required_untyped.push(serde_json::Value::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"not_required_untyped_nullable" => intermediate_rep.not_required_untyped_nullable.push(serde_json::Value::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing ObjectUntypedProps".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1207,8 +1208,8 @@ impl ::std::str::FromStr for ObjectUntypedProps {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(ObjectUntypedProps {
|
||||
required_untyped: intermediate_rep.required_untyped.into_iter().next().ok_or(())?,
|
||||
required_untyped_nullable: intermediate_rep.required_untyped_nullable.into_iter().next().ok_or(())?,
|
||||
required_untyped: intermediate_rep.required_untyped.into_iter().next().ok_or("required_untyped missing in ObjectUntypedProps".to_string())?,
|
||||
required_untyped_nullable: intermediate_rep.required_untyped_nullable.into_iter().next().ok_or("required_untyped_nullable missing in ObjectUntypedProps".to_string())?,
|
||||
not_required_untyped: intermediate_rep.not_required_untyped.into_iter().next(),
|
||||
not_required_untyped_nullable: intermediate_rep.not_required_untyped_nullable.into_iter().next(),
|
||||
})
|
||||
@ -1277,7 +1278,7 @@ impl ::std::string::ToString for ObjectWithArrayOfObjects {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectWithArrayOfObjects {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -1295,13 +1296,13 @@ impl ::std::str::FromStr for ObjectWithArrayOfObjects {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectWithArrayOfObjects".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"objectArray" => return Err(()), // Parsing a container in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"objectArray" => return Err("Parsing a container in this style is not supported in ObjectWithArrayOfObjects".to_string()),
|
||||
_ => return Err("Unexpected key while parsing ObjectWithArrayOfObjects".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1406,6 +1407,50 @@ impl RequiredObjectHeader {
|
||||
}
|
||||
}
|
||||
|
||||
/// Enumeration of values.
|
||||
/// Since this enum's variants do not hold data, we can easily define them them as `#[repr(C)]`
|
||||
/// which helps with FFI.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(LabelledGenericEnum))]
|
||||
pub enum StringEnum {
|
||||
#[serde(rename = "FOO")]
|
||||
FOO,
|
||||
#[serde(rename = "BAR")]
|
||||
BAR,
|
||||
}
|
||||
|
||||
impl ::std::fmt::Display for StringEnum {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
match *self {
|
||||
StringEnum::FOO => write!(f, "{}", "FOO"),
|
||||
StringEnum::BAR => write!(f, "{}", "BAR"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::str::FromStr for StringEnum {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"FOO" => Ok(StringEnum::FOO),
|
||||
"BAR" => Ok(StringEnum::BAR),
|
||||
_ => Err(format!("Value not valid: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StringEnum {
|
||||
/// Helper function to allow us to convert this model to an XML string.
|
||||
/// Will panic if serialisation fails.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn to_xml(&self) -> String {
|
||||
serde_xml_rs::to_string(&self).expect("impossible to fail to serialize")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||
pub struct StringObject(String);
|
||||
@ -1725,7 +1770,7 @@ impl ::std::string::ToString for XmlObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for XmlObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -1744,14 +1789,14 @@ impl ::std::str::FromStr for XmlObject {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing XmlObject".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"innerString" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| ())?),
|
||||
"other_inner_rename" => intermediate_rep.other_inner_rename.push(isize::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"innerString" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"other_inner_rename" => intermediate_rep.other_inner_rename.push(isize::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing XmlObject".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ pub use crate::context;
|
||||
|
||||
use {Api,
|
||||
CallbackWithHeaderPostResponse,
|
||||
EnumInPathPathParamGetResponse,
|
||||
MandatoryRequestHeaderGetResponse,
|
||||
MergePatchJsonGetResponse,
|
||||
MultigetGetResponse,
|
||||
@ -53,6 +54,7 @@ mod paths {
|
||||
lazy_static! {
|
||||
pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![
|
||||
r"^/callback-with-header$",
|
||||
r"^/enum_in_path/(?P<path_param>[^/?#]*)$",
|
||||
r"^/mandatory-request-header$",
|
||||
r"^/merge-patch-json$",
|
||||
r"^/multiget$",
|
||||
@ -72,21 +74,27 @@ mod paths {
|
||||
.expect("Unable to create global regex set");
|
||||
}
|
||||
pub static ID_CALLBACK_WITH_HEADER: usize = 0;
|
||||
pub static ID_MANDATORY_REQUEST_HEADER: usize = 1;
|
||||
pub static ID_MERGE_PATCH_JSON: usize = 2;
|
||||
pub static ID_MULTIGET: usize = 3;
|
||||
pub static ID_MULTIPLE_AUTH_SCHEME: usize = 4;
|
||||
pub static ID_PARAMGET: usize = 5;
|
||||
pub static ID_READONLY_AUTH_SCHEME: usize = 6;
|
||||
pub static ID_REGISTER_CALLBACK: usize = 7;
|
||||
pub static ID_REQUIRED_OCTET_STREAM: usize = 8;
|
||||
pub static ID_RESPONSES_WITH_HEADERS: usize = 9;
|
||||
pub static ID_RFC7807: usize = 10;
|
||||
pub static ID_UNTYPED_PROPERTY: usize = 11;
|
||||
pub static ID_UUID: usize = 12;
|
||||
pub static ID_XML: usize = 13;
|
||||
pub static ID_XML_EXTRA: usize = 14;
|
||||
pub static ID_XML_OTHER: usize = 15;
|
||||
pub static ID_ENUM_IN_PATH_PATH_PARAM: usize = 1;
|
||||
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_PARAMGET: usize = 6;
|
||||
pub static ID_READONLY_AUTH_SCHEME: usize = 7;
|
||||
pub static ID_REGISTER_CALLBACK: usize = 8;
|
||||
pub static ID_REQUIRED_OCTET_STREAM: usize = 9;
|
||||
pub static ID_RESPONSES_WITH_HEADERS: usize = 10;
|
||||
pub static ID_RFC7807: usize = 11;
|
||||
pub static ID_UNTYPED_PROPERTY: usize = 12;
|
||||
pub static ID_UUID: usize = 13;
|
||||
pub static ID_XML: usize = 14;
|
||||
pub static ID_XML_EXTRA: usize = 15;
|
||||
pub static ID_XML_OTHER: usize = 16;
|
||||
}
|
||||
|
||||
pub struct MakeService<T, RC> {
|
||||
@ -218,6 +226,66 @@ where
|
||||
}) 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
|
||||
let path: &str = &uri.path().to_string();
|
||||
let path_params =
|
||||
paths::REGEX_ENUM_IN_PATH_PATH_PARAM
|
||||
.captures(&path)
|
||||
.unwrap_or_else(||
|
||||
panic!("Path {} matched RE ENUM_IN_PATH_PATH_PARAM in set but failed match against \"{}\"", path, paths::REGEX_ENUM_IN_PATH_PATH_PARAM.as_str())
|
||||
);
|
||||
|
||||
let param_path_param = match percent_encoding::percent_decode(path_params["path_param"].as_bytes()).decode_utf8() {
|
||||
Ok(param_path_param) => match param_path_param.parse::<models::StringEnum>() {
|
||||
Ok(param_path_param) => param_path_param,
|
||||
Err(e) => return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't parse path parameter path_param: {}", e)))
|
||||
.expect("Unable to create Bad Request response for invalid path parameter"))),
|
||||
},
|
||||
Err(_) => return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["path_param"])))
|
||||
.expect("Unable to create Bad Request response for invalid percent decode")))
|
||||
};
|
||||
|
||||
Box::new({
|
||||
{{
|
||||
Box::new(
|
||||
api_impl.enum_in_path_path_param_get(
|
||||
param_path_param,
|
||||
&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 {
|
||||
EnumInPathPathParamGetResponse::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
|
||||
},
|
||||
|
||||
// MandatoryRequestHeaderGet - GET /mandatory-request-header
|
||||
&hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => {
|
||||
// Header parameters
|
||||
@ -1363,6 +1431,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"),
|
||||
// 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
|
||||
&hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => Ok("MandatoryRequestHeaderGet"),
|
||||
// MergePatchJsonGet - GET /merge-patch-json
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -73,7 +73,7 @@ impl ::std::string::ToString for ANullableContainer {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ANullableContainer {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -92,14 +92,14 @@ impl ::std::str::FromStr for ANullableContainer {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ANullableContainer".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"NullableThing" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
"RequiredNullableThing" => return Err(()), // Parsing a nullable type in this style is not supported yet
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"NullableThing" => return Err("Parsing a nullable type in this style is not supported in ANullableContainer".to_string()),
|
||||
"RequiredNullableThing" => return Err("Parsing a nullable type in this style is not supported in ANullableContainer".to_string()),
|
||||
_ => return Err("Unexpected key while parsing ANullableContainer".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,8 +109,8 @@ impl ::std::str::FromStr for ANullableContainer {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(ANullableContainer {
|
||||
nullable_thing: Err(())?,
|
||||
required_nullable_thing: Err(())?,
|
||||
nullable_thing: Err("Nullable types not supported in ANullableContainer".to_string())?,
|
||||
required_nullable_thing: Err("Nullable types not supported in ANullableContainer".to_string())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -162,11 +162,10 @@ impl ::std::string::ToString for AdditionalPropertiesObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for AdditionalPropertiesObject {
|
||||
type Err = ();
|
||||
type Err = &'static str;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Parsing additionalProperties in this style is not supported yet
|
||||
Err(())
|
||||
Err("Parsing additionalProperties for AdditionalPropertiesObject is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +233,7 @@ impl ::std::string::ToString for AllOfObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for AllOfObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -253,14 +252,14 @@ impl ::std::str::FromStr for AllOfObject {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing AllOfObject".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"sampleProperty" => intermediate_rep.sample_property.push(String::from_str(val).map_err(|x| ())?),
|
||||
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"sampleProperty" => intermediate_rep.sample_property.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing AllOfObject".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +329,7 @@ impl ::std::string::ToString for BaseAllOf {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for BaseAllOf {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -348,13 +347,13 @@ impl ::std::str::FromStr for BaseAllOf {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing BaseAllOf".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing BaseAllOf".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +424,7 @@ impl ::std::string::ToString for GetYamlResponse {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for GetYamlResponse {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -443,13 +442,13 @@ impl ::std::str::FromStr for GetYamlResponse {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing GetYamlResponse".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"value" => intermediate_rep.value.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"value" => intermediate_rep.value.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing GetYamlResponse".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -526,7 +525,7 @@ impl ::std::string::ToString for InlineObject {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for InlineObject {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -545,14 +544,14 @@ impl ::std::str::FromStr for InlineObject {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing InlineObject".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"id" => intermediate_rep.id.push(String::from_str(val).map_err(|x| ())?),
|
||||
"password" => intermediate_rep.password.push(String::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"id" => intermediate_rep.id.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"password" => intermediate_rep.password.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing InlineObject".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,7 +561,7 @@ impl ::std::str::FromStr for InlineObject {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(InlineObject {
|
||||
id: intermediate_rep.id.into_iter().next().ok_or(())?,
|
||||
id: intermediate_rep.id.into_iter().next().ok_or("id missing in InlineObject".to_string())?,
|
||||
password: intermediate_rep.password.into_iter().next(),
|
||||
})
|
||||
}
|
||||
@ -619,7 +618,7 @@ impl ::std::string::ToString for ObjectOfObjects {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectOfObjects {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -637,13 +636,13 @@ impl ::std::str::FromStr for ObjectOfObjects {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectOfObjects".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"inner" => intermediate_rep.inner.push(models::ObjectOfObjectsInner::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"inner" => intermediate_rep.inner.push(models::ObjectOfObjectsInner::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing ObjectOfObjects".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -720,7 +719,7 @@ impl ::std::string::ToString for ObjectOfObjectsInner {
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl ::std::str::FromStr for ObjectOfObjectsInner {
|
||||
type Err = ();
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[derive(Default)]
|
||||
@ -739,14 +738,14 @@ impl ::std::str::FromStr for ObjectOfObjectsInner {
|
||||
while key_result.is_some() {
|
||||
let val = match string_iter.next() {
|
||||
Some(x) => x,
|
||||
None => return Err(())
|
||||
None => return Err("Missing value while parsing ObjectOfObjectsInner".to_string())
|
||||
};
|
||||
|
||||
if let Some(key) = key_result {
|
||||
match key {
|
||||
"required_thing" => intermediate_rep.required_thing.push(String::from_str(val).map_err(|x| ())?),
|
||||
"optional_thing" => intermediate_rep.optional_thing.push(isize::from_str(val).map_err(|x| ())?),
|
||||
_ => return Err(()) // Parse error - unexpected key
|
||||
"required_thing" => intermediate_rep.required_thing.push(String::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
"optional_thing" => intermediate_rep.optional_thing.push(isize::from_str(val).map_err(|x| format!("{}", x))?),
|
||||
_ => return Err("Unexpected key while parsing ObjectOfObjectsInner".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -756,7 +755,7 @@ impl ::std::str::FromStr for ObjectOfObjectsInner {
|
||||
|
||||
// Use the intermediate representation to return the struct
|
||||
Ok(ObjectOfObjectsInner {
|
||||
required_thing: intermediate_rep.required_thing.into_iter().next().ok_or(())?,
|
||||
required_thing: intermediate_rep.required_thing.into_iter().next().ok_or("required_thing missing in ObjectOfObjectsInner".to_string())?,
|
||||
optional_thing: intermediate_rep.optional_thing.into_iter().next(),
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user