diff --git a/modules/openapi-generator/src/main/resources/rust-server/models.mustache b/modules/openapi-generator/src/main/resources/rust-server/models.mustache index 5ae3ea34c04..5b3668a04b1 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -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 { 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 { - // 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 { #[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}} }) diff --git a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml index d7c72b8a8e2..83f979a2d16 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml @@ -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 diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs index 10350fbc947..b003cefb9a7 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs @@ -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 { #[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 { #[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 { #[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(), }) } diff --git a/samples/server/petstore/rust-server/output/openapi-v3/README.md b/samples/server/petstore/rust-server/output/openapi-v3/README.md index 521daab8edf..d2a7a17bde3 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/README.md @@ -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) diff --git a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml index 42a7d0490bd..1f8c4b7fd30 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml @@ -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: diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/StringEnum.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/StringEnum.md new file mode 100644 index 00000000000..b0009f7e826 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/StringEnum.md @@ -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) + + diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md index c2314051514..97803dd5c60 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.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) diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs index e9bf7602944..d443f693844 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs @@ -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).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).get().clone()); + }, + */ Some("MandatoryRequestHeaderGet") => { let result = rt.block_on(client.mandatory_request_header_get( "x_header_example".to_string() diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs index abd531c7e48..c87bc45e4ad 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs @@ -88,6 +88,7 @@ use openapi_v3::{ Api, ApiError, CallbackWithHeaderPostResponse, + EnumInPathPathParamGetResponse, MandatoryRequestHeaderGetResponse, MergePatchJsonGetResponse, MultigetGetResponse, @@ -119,6 +120,16 @@ impl Api for Server where C: Has{ Box::new(future::err("Generic failure".into())) } + fn enum_in_path_path_param_get( + &self, + path_param: models::StringEnum, + context: &C) -> Box + 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, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs index 15e87298a46..1a173b5bd81 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs @@ -40,6 +40,7 @@ define_encode_set! { use {Api, CallbackWithHeaderPostResponse, + EnumInPathPathParamGetResponse, MandatoryRequestHeaderGetResponse, MergePatchJsonGetResponse, MultigetGetResponse, @@ -329,6 +330,79 @@ impl Api for Client where })) } + fn enum_in_path_path_param_get( + &self, + param_path_param: models::StringEnum, + context: &C) -> Box + 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).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 + 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!("", e)), + }, + Err(e) => Cow::from(format!("", e)), + }))) + ) + ) as Box + Send> + } + } + })) + } + fn mandatory_request_header_get( &self, param_x_header: String, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs index 4a9dbec1054..93e339fed8b 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs @@ -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 { url: String, context: &C) -> Box + Send>; + fn enum_in_path_path_param_get( + &self, + path_param: models::StringEnum, + context: &C) -> Box + Send>; + fn mandatory_request_header_get( &self, x_header: String, @@ -344,6 +355,11 @@ pub trait ApiNoContext { url: String, ) -> Box + Send>; + fn enum_in_path_path_param_get( + &self, + path_param: models::StringEnum, + ) -> Box + Send>; + fn mandatory_request_header_get( &self, x_header: String, @@ -450,6 +466,14 @@ impl<'a, T: Api, 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 + Send> + { + self.api().enum_in_path_path_param_get(path_param, &self.context()) + } + fn mandatory_request_header_get( &self, x_header: String, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/mimetypes.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/mimetypes.rs index 8234adc0b19..082339031e8 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/mimetypes.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/mimetypes.rs @@ -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"; diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs index cdf8ef22ebd..e4fd70660a7 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs @@ -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 { #[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 { #[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 { 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 { #[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 { #[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 { #[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 { #[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 { #[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 { #[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 { + 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 { #[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()) } } diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs index 264da06ab72..6b8dd8cf72a 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs @@ -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[^/?#]*)$", 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[^/?#]*)$") + .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 { @@ -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::() { + 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).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 RequestParser 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 diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index 176af25d287..923f7fc4682 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -69,7 +69,7 @@ impl ::std::string::ToString for AdditionalPropertiesClass { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for AdditionalPropertiesClass { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -88,14 +88,14 @@ impl ::std::str::FromStr for AdditionalPropertiesClass { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing AdditionalPropertiesClass".to_string()) }; if let Some(key) = key_result { match key { - "map_property" => return Err(()), // Parsing a container in this style is not supported yet - "map_of_map_property" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "map_property" => return Err("Parsing a container in this style is not supported in AdditionalPropertiesClass".to_string()), + "map_of_map_property" => return Err("Parsing a container in this style is not supported in AdditionalPropertiesClass".to_string()), + _ => return Err("Unexpected key while parsing AdditionalPropertiesClass".to_string()) } } @@ -181,7 +181,7 @@ impl ::std::string::ToString for Animal { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Animal { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -200,14 +200,14 @@ impl ::std::str::FromStr for Animal { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Animal".to_string()) }; if let Some(key) = key_result { match key { - "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| ())?), - "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Animal".to_string()) } } @@ -217,7 +217,7 @@ impl ::std::str::FromStr for Animal { // Use the intermediate representation to return the struct Ok(Animal { - class_name: intermediate_rep.class_name.into_iter().next().ok_or(())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Animal".to_string())?, color: intermediate_rep.color.into_iter().next(), }) } @@ -418,7 +418,7 @@ impl ::std::string::ToString for ApiResponse { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ApiResponse { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -438,15 +438,15 @@ impl ::std::str::FromStr for ApiResponse { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ApiResponse".to_string()) }; if let Some(key) = key_result { match key { - "code" => intermediate_rep.code.push(i32::from_str(val).map_err(|x| ())?), - "type" => intermediate_rep.type_.push(String::from_str(val).map_err(|x| ())?), - "message" => intermediate_rep.message.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "code" => intermediate_rep.code.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "type" => intermediate_rep.type_.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "message" => intermediate_rep.message.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing ApiResponse".to_string()) } } @@ -521,7 +521,7 @@ impl ::std::string::ToString for ArrayOfArrayOfNumberOnly { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ArrayOfArrayOfNumberOnly { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -539,13 +539,13 @@ impl ::std::str::FromStr for ArrayOfArrayOfNumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ArrayOfArrayOfNumberOnly".to_string()) }; if let Some(key) = key_result { match key { - "ArrayArrayNumber" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "ArrayArrayNumber" => return Err("Parsing a container in this style is not supported in ArrayOfArrayOfNumberOnly".to_string()), + _ => return Err("Unexpected key while parsing ArrayOfArrayOfNumberOnly".to_string()) } } @@ -622,7 +622,7 @@ impl ::std::string::ToString for ArrayOfNumberOnly { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ArrayOfNumberOnly { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -640,13 +640,13 @@ impl ::std::str::FromStr for ArrayOfNumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ArrayOfNumberOnly".to_string()) }; if let Some(key) = key_result { match key { - "ArrayNumber" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "ArrayNumber" => return Err("Parsing a container in this style is not supported in ArrayOfNumberOnly".to_string()), + _ => return Err("Unexpected key while parsing ArrayOfNumberOnly".to_string()) } } @@ -749,7 +749,7 @@ impl ::std::string::ToString for ArrayTest { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ArrayTest { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -770,16 +770,16 @@ impl ::std::str::FromStr for ArrayTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ArrayTest".to_string()) }; if let Some(key) = key_result { match key { - "array_of_string" => return Err(()), // Parsing a container in this style is not supported yet - "array_array_of_integer" => return Err(()), // Parsing a container in this style is not supported yet - "array_array_of_model" => return Err(()), // Parsing a container in this style is not supported yet - "array_of_enum" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "array_of_string" => return Err("Parsing a container in this style is not supported in ArrayTest".to_string()), + "array_array_of_integer" => return Err("Parsing a container in this style is not supported in ArrayTest".to_string()), + "array_array_of_model" => return Err("Parsing a container in this style is not supported in ArrayTest".to_string()), + "array_of_enum" => return Err("Parsing a container in this style is not supported in ArrayTest".to_string()), + _ => return Err("Unexpected key while parsing ArrayTest".to_string()) } } @@ -915,7 +915,7 @@ impl ::std::string::ToString for Capitalization { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Capitalization { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -938,18 +938,18 @@ impl ::std::str::FromStr for Capitalization { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Capitalization".to_string()) }; if let Some(key) = key_result { match key { - "smallCamel" => intermediate_rep.small_camel.push(String::from_str(val).map_err(|x| ())?), - "CapitalCamel" => intermediate_rep.capital_camel.push(String::from_str(val).map_err(|x| ())?), - "small_Snake" => intermediate_rep.small_snake.push(String::from_str(val).map_err(|x| ())?), - "Capital_Snake" => intermediate_rep.capital_snake.push(String::from_str(val).map_err(|x| ())?), - "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(String::from_str(val).map_err(|x| ())?), - "ATT_NAME" => intermediate_rep.att_name.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "smallCamel" => intermediate_rep.small_camel.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "CapitalCamel" => intermediate_rep.capital_camel.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "small_Snake" => intermediate_rep.small_snake.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "Capital_Snake" => intermediate_rep.capital_snake.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "ATT_NAME" => intermediate_rep.att_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Capitalization".to_string()) } } @@ -1050,7 +1050,7 @@ impl ::std::string::ToString for Cat { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Cat { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1070,15 +1070,15 @@ impl ::std::str::FromStr for Cat { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Cat".to_string()) }; if let Some(key) = key_result { match key { - "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| ())?), - "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| ())?), - "declawed" => intermediate_rep.declawed.push(bool::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "declawed" => intermediate_rep.declawed.push(bool::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Cat".to_string()) } } @@ -1088,7 +1088,7 @@ impl ::std::str::FromStr for Cat { // Use the intermediate representation to return the struct Ok(Cat { - class_name: intermediate_rep.class_name.into_iter().next().ok_or(())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Cat".to_string())?, color: intermediate_rep.color.into_iter().next(), declawed: intermediate_rep.declawed.into_iter().next(), }) @@ -1157,7 +1157,7 @@ impl ::std::string::ToString for CatAllOf { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for CatAllOf { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1175,13 +1175,13 @@ impl ::std::str::FromStr for CatAllOf { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing CatAllOf".to_string()) }; if let Some(key) = key_result { match key { - "declawed" => intermediate_rep.declawed.push(bool::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "declawed" => intermediate_rep.declawed.push(bool::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing CatAllOf".to_string()) } } @@ -1270,7 +1270,7 @@ impl ::std::string::ToString for Category { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Category { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1289,14 +1289,14 @@ impl ::std::str::FromStr for Category { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Category".to_string()) }; if let Some(key) = key_result { match key { - "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| ())?), - "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Category".to_string()) } } @@ -1375,7 +1375,7 @@ impl ::std::string::ToString for ClassModel { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ClassModel { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1393,13 +1393,13 @@ impl ::std::str::FromStr for ClassModel { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ClassModel".to_string()) }; if let Some(key) = key_result { match key { - "_class" => intermediate_rep._class.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "_class" => intermediate_rep._class.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing ClassModel".to_string()) } } @@ -1476,7 +1476,7 @@ impl ::std::string::ToString for Client { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Client { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1494,13 +1494,13 @@ impl ::std::str::FromStr for Client { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Client".to_string()) }; if let Some(key) = key_result { match key { - "client" => intermediate_rep.client.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "client" => intermediate_rep.client.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Client".to_string()) } } @@ -1596,7 +1596,7 @@ impl ::std::string::ToString for Dog { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Dog { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1616,15 +1616,15 @@ impl ::std::str::FromStr for Dog { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Dog".to_string()) }; if let Some(key) = key_result { match key { - "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| ())?), - "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| ())?), - "breed" => intermediate_rep.breed.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "className" => intermediate_rep.class_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "breed" => intermediate_rep.breed.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Dog".to_string()) } } @@ -1634,7 +1634,7 @@ impl ::std::str::FromStr for Dog { // Use the intermediate representation to return the struct Ok(Dog { - class_name: intermediate_rep.class_name.into_iter().next().ok_or(())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Dog".to_string())?, color: intermediate_rep.color.into_iter().next(), breed: intermediate_rep.breed.into_iter().next(), }) @@ -1703,7 +1703,7 @@ impl ::std::string::ToString for DogAllOf { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for DogAllOf { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1721,13 +1721,13 @@ impl ::std::str::FromStr for DogAllOf { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing DogAllOf".to_string()) }; if let Some(key) = key_result { match key { - "breed" => intermediate_rep.breed.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "breed" => intermediate_rep.breed.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing DogAllOf".to_string()) } } @@ -1825,7 +1825,7 @@ impl ::std::string::ToString for EnumArrays { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for EnumArrays { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -1845,15 +1845,15 @@ impl ::std::str::FromStr for EnumArrays { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing EnumArrays".to_string()) }; if let Some(key) = key_result { match key { - "just_symbol" => intermediate_rep.just_symbol.push(String::from_str(val).map_err(|x| ())?), - "array_enum" => return Err(()), // Parsing a container in this style is not supported yet - "array_array_enum" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "just_symbol" => intermediate_rep.just_symbol.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "array_enum" => return Err("Parsing a container in this style is not supported in EnumArrays".to_string()), + "array_array_enum" => return Err("Parsing a container in this style is not supported in EnumArrays".to_string()), + _ => return Err("Unexpected key while parsing EnumArrays".to_string()) } } @@ -1907,13 +1907,14 @@ impl ::std::fmt::Display for EnumClass { } impl ::std::str::FromStr for EnumClass { - type Err = (); + type Err = String; + fn from_str(s: &str) -> Result { match s { "_abc" => Ok(EnumClass::_ABC), "-efg" => Ok(EnumClass::_EFG), "(xyz)" => Ok(EnumClass::_XYZ_), - _ => Err(()), + _ => Err(format!("Value not valid: {}", s)), } } } @@ -2020,7 +2021,7 @@ impl ::std::string::ToString for EnumTest { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for EnumTest { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2042,17 +2043,17 @@ impl ::std::str::FromStr for EnumTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing EnumTest".to_string()) }; if let Some(key) = key_result { match key { - "enum_string" => intermediate_rep.enum_string.push(String::from_str(val).map_err(|x| ())?), - "enum_string_required" => intermediate_rep.enum_string_required.push(String::from_str(val).map_err(|x| ())?), - "enum_integer" => intermediate_rep.enum_integer.push(i32::from_str(val).map_err(|x| ())?), - "enum_number" => intermediate_rep.enum_number.push(f64::from_str(val).map_err(|x| ())?), - "outerEnum" => intermediate_rep.outer_enum.push(models::OuterEnum::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "enum_string" => intermediate_rep.enum_string.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "enum_string_required" => intermediate_rep.enum_string_required.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "enum_integer" => intermediate_rep.enum_integer.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "enum_number" => intermediate_rep.enum_number.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + "outerEnum" => intermediate_rep.outer_enum.push(models::OuterEnum::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing EnumTest".to_string()) } } @@ -2063,7 +2064,7 @@ impl ::std::str::FromStr for EnumTest { // Use the intermediate representation to return the struct Ok(EnumTest { enum_string: intermediate_rep.enum_string.into_iter().next(), - enum_string_required: intermediate_rep.enum_string_required.into_iter().next().ok_or(())?, + enum_string_required: intermediate_rep.enum_string_required.into_iter().next().ok_or("enum_string_required missing in EnumTest".to_string())?, enum_integer: intermediate_rep.enum_integer.into_iter().next(), enum_number: intermediate_rep.enum_number.into_iter().next(), outer_enum: intermediate_rep.outer_enum.into_iter().next(), @@ -2239,7 +2240,7 @@ impl ::std::string::ToString for FormatTest { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for FormatTest { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2269,25 +2270,25 @@ impl ::std::str::FromStr for FormatTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing FormatTest".to_string()) }; if let Some(key) = key_result { match key { - "integer" => intermediate_rep.integer.push(u8::from_str(val).map_err(|x| ())?), - "int32" => intermediate_rep.int32.push(u32::from_str(val).map_err(|x| ())?), - "int64" => intermediate_rep.int64.push(i64::from_str(val).map_err(|x| ())?), - "number" => intermediate_rep.number.push(f64::from_str(val).map_err(|x| ())?), - "float" => intermediate_rep.float.push(f32::from_str(val).map_err(|x| ())?), - "double" => intermediate_rep.double.push(f64::from_str(val).map_err(|x| ())?), - "string" => intermediate_rep.string.push(String::from_str(val).map_err(|x| ())?), - "byte" => return Err(()), // Parsing binary data in this style is not supported yet - "binary" => return Err(()), // Parsing binary data in this style is not supported yet - "date" => intermediate_rep.date.push(chrono::DateTime::::from_str(val).map_err(|x| ())?), - "dateTime" => intermediate_rep.date_time.push(chrono::DateTime::::from_str(val).map_err(|x| ())?), - "uuid" => intermediate_rep.uuid.push(uuid::Uuid::from_str(val).map_err(|x| ())?), - "password" => intermediate_rep.password.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "integer" => intermediate_rep.integer.push(u8::from_str(val).map_err(|x| format!("{}", x))?), + "int32" => intermediate_rep.int32.push(u32::from_str(val).map_err(|x| format!("{}", x))?), + "int64" => intermediate_rep.int64.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "number" => intermediate_rep.number.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + "float" => intermediate_rep.float.push(f32::from_str(val).map_err(|x| format!("{}", x))?), + "double" => intermediate_rep.double.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + "string" => intermediate_rep.string.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "byte" => return Err("Parsing binary data in this style is not supported in FormatTest".to_string()), + "binary" => return Err("Parsing binary data in this style is not supported in FormatTest".to_string()), + "date" => intermediate_rep.date.push(chrono::DateTime::::from_str(val).map_err(|x| format!("{}", x))?), + "dateTime" => intermediate_rep.date_time.push(chrono::DateTime::::from_str(val).map_err(|x| format!("{}", x))?), + "uuid" => intermediate_rep.uuid.push(uuid::Uuid::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 FormatTest".to_string()) } } @@ -2300,16 +2301,16 @@ impl ::std::str::FromStr for FormatTest { integer: intermediate_rep.integer.into_iter().next(), int32: intermediate_rep.int32.into_iter().next(), int64: intermediate_rep.int64.into_iter().next(), - number: intermediate_rep.number.into_iter().next().ok_or(())?, + number: intermediate_rep.number.into_iter().next().ok_or("number missing in FormatTest".to_string())?, float: intermediate_rep.float.into_iter().next(), double: intermediate_rep.double.into_iter().next(), string: intermediate_rep.string.into_iter().next(), - byte: intermediate_rep.byte.into_iter().next().ok_or(())?, + byte: intermediate_rep.byte.into_iter().next().ok_or("byte missing in FormatTest".to_string())?, binary: intermediate_rep.binary.into_iter().next(), - date: intermediate_rep.date.into_iter().next().ok_or(())?, + date: intermediate_rep.date.into_iter().next().ok_or("date missing in FormatTest".to_string())?, date_time: intermediate_rep.date_time.into_iter().next(), uuid: intermediate_rep.uuid.into_iter().next(), - password: intermediate_rep.password.into_iter().next().ok_or(())?, + password: intermediate_rep.password.into_iter().next().ok_or("password missing in FormatTest".to_string())?, }) } } @@ -2387,7 +2388,7 @@ impl ::std::string::ToString for HasOnlyReadOnly { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for HasOnlyReadOnly { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2406,14 +2407,14 @@ impl ::std::str::FromStr for HasOnlyReadOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing HasOnlyReadOnly".to_string()) }; if let Some(key) = key_result { match key { - "bar" => intermediate_rep.bar.push(String::from_str(val).map_err(|x| ())?), - "foo" => intermediate_rep.foo.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "bar" => intermediate_rep.bar.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "foo" => intermediate_rep.foo.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing HasOnlyReadOnly".to_string()) } } @@ -2491,7 +2492,7 @@ impl ::std::string::ToString for List { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for List { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2509,13 +2510,13 @@ impl ::std::str::FromStr for List { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing List".to_string()) }; if let Some(key) = key_result { match key { - "123-list" => intermediate_rep.param_123_list.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "123-list" => intermediate_rep.param_123_list.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing List".to_string()) } } @@ -2606,7 +2607,7 @@ impl ::std::string::ToString for MapTest { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for MapTest { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2626,15 +2627,15 @@ impl ::std::str::FromStr for MapTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing MapTest".to_string()) }; if let Some(key) = key_result { match key { - "map_map_of_string" => return Err(()), // Parsing a container in this style is not supported yet - "map_map_of_enum" => return Err(()), // Parsing a container in this style is not supported yet - "map_of_enum_string" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "map_map_of_string" => return Err("Parsing a container in this style is not supported in MapTest".to_string()), + "map_map_of_enum" => return Err("Parsing a container in this style is not supported in MapTest".to_string()), + "map_of_enum_string" => return Err("Parsing a container in this style is not supported in MapTest".to_string()), + _ => return Err("Unexpected key while parsing MapTest".to_string()) } } @@ -2724,7 +2725,7 @@ impl ::std::string::ToString for MixedPropertiesAndAdditionalPropertiesClass { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2744,15 +2745,15 @@ impl ::std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing MixedPropertiesAndAdditionalPropertiesClass".to_string()) }; if let Some(key) = key_result { match key { - "uuid" => intermediate_rep.uuid.push(uuid::Uuid::from_str(val).map_err(|x| ())?), - "dateTime" => intermediate_rep.date_time.push(chrono::DateTime::::from_str(val).map_err(|x| ())?), - "map" => return Err(()), // Parsing a container in this style is not supported yet - _ => return Err(()) // Parse error - unexpected key + "uuid" => intermediate_rep.uuid.push(uuid::Uuid::from_str(val).map_err(|x| format!("{}", x))?), + "dateTime" => intermediate_rep.date_time.push(chrono::DateTime::::from_str(val).map_err(|x| format!("{}", x))?), + "map" => return Err("Parsing a container in this style is not supported in MixedPropertiesAndAdditionalPropertiesClass".to_string()), + _ => return Err("Unexpected key while parsing MixedPropertiesAndAdditionalPropertiesClass".to_string()) } } @@ -2844,7 +2845,7 @@ impl ::std::string::ToString for Model200Response { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Model200Response { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2863,14 +2864,14 @@ impl ::std::str::FromStr for Model200Response { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Model200Response".to_string()) }; if let Some(key) = key_result { match key { - "name" => intermediate_rep.name.push(i32::from_str(val).map_err(|x| ())?), - "class" => intermediate_rep.class.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "name" => intermediate_rep.name.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "class" => intermediate_rep.class.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Model200Response".to_string()) } } @@ -2950,7 +2951,7 @@ impl ::std::string::ToString for ModelReturn { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ModelReturn { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -2968,13 +2969,13 @@ impl ::std::str::FromStr for ModelReturn { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ModelReturn".to_string()) }; if let Some(key) = key_result { match key { - "return" => intermediate_rep.return_.push(i32::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "return" => intermediate_rep.return_.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing ModelReturn".to_string()) } } @@ -3083,7 +3084,7 @@ impl ::std::string::ToString for Name { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Name { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3104,16 +3105,16 @@ impl ::std::str::FromStr for Name { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Name".to_string()) }; if let Some(key) = key_result { match key { - "name" => intermediate_rep.name.push(i32::from_str(val).map_err(|x| ())?), - "snake_case" => intermediate_rep.snake_case.push(i32::from_str(val).map_err(|x| ())?), - "property" => intermediate_rep.property.push(String::from_str(val).map_err(|x| ())?), - "123Number" => intermediate_rep.param_123_number.push(isize::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "name" => intermediate_rep.name.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "snake_case" => intermediate_rep.snake_case.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "property" => intermediate_rep.property.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "123Number" => intermediate_rep.param_123_number.push(isize::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Name".to_string()) } } @@ -3123,7 +3124,7 @@ impl ::std::str::FromStr for Name { // Use the intermediate representation to return the struct Ok(Name { - name: intermediate_rep.name.into_iter().next().ok_or(())?, + name: intermediate_rep.name.into_iter().next().ok_or("name missing in Name".to_string())?, snake_case: intermediate_rep.snake_case.into_iter().next(), property: intermediate_rep.property.into_iter().next(), param_123_number: intermediate_rep.param_123_number.into_iter().next(), @@ -3193,7 +3194,7 @@ impl ::std::string::ToString for NumberOnly { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for NumberOnly { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3211,13 +3212,13 @@ impl ::std::str::FromStr for NumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing NumberOnly".to_string()) }; if let Some(key) = key_result { match key { - "JustNumber" => intermediate_rep.just_number.push(f64::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "JustNumber" => intermediate_rep.just_number.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing NumberOnly".to_string()) } } @@ -3290,7 +3291,7 @@ impl ::std::string::ToString for ObjectContainingObjectWithOnlyAdditionalPropert /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3308,13 +3309,13 @@ impl ::std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ObjectContainingObjectWithOnlyAdditionalProperties".to_string()) }; if let Some(key) = key_result { match key { - "inner" => intermediate_rep.inner.push(models::ObjectWithOnlyAdditionalProperties::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "inner" => intermediate_rep.inner.push(models::ObjectWithOnlyAdditionalProperties::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing ObjectContainingObjectWithOnlyAdditionalProperties".to_string()) } } @@ -3383,11 +3384,10 @@ impl ::std::string::ToString for ObjectWithOnlyAdditionalProperties { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ObjectWithOnlyAdditionalProperties { - type Err = (); + type Err = &'static str; fn from_str(s: &str) -> Result { - // Parsing additionalProperties in this style is not supported yet - Err(()) + Err("Parsing additionalProperties for ObjectWithOnlyAdditionalProperties is not supported") } } @@ -3506,7 +3506,7 @@ impl ::std::string::ToString for Order { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Order { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3529,18 +3529,18 @@ impl ::std::str::FromStr for Order { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Order".to_string()) }; if let Some(key) = key_result { match key { - "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| ())?), - "petId" => intermediate_rep.pet_id.push(i64::from_str(val).map_err(|x| ())?), - "quantity" => intermediate_rep.quantity.push(i32::from_str(val).map_err(|x| ())?), - "shipDate" => intermediate_rep.ship_date.push(chrono::DateTime::::from_str(val).map_err(|x| ())?), - "status" => intermediate_rep.status.push(String::from_str(val).map_err(|x| ())?), - "complete" => intermediate_rep.complete.push(bool::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "petId" => intermediate_rep.pet_id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "quantity" => intermediate_rep.quantity.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "shipDate" => intermediate_rep.ship_date.push(chrono::DateTime::::from_str(val).map_err(|x| format!("{}", x))?), + "status" => intermediate_rep.status.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "complete" => intermediate_rep.complete.push(bool::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Order".to_string()) } } @@ -3684,7 +3684,7 @@ impl ::std::string::ToString for OuterComposite { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for OuterComposite { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3704,15 +3704,15 @@ impl ::std::str::FromStr for OuterComposite { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing OuterComposite".to_string()) }; if let Some(key) = key_result { match key { - "my_number" => intermediate_rep.my_number.push(f64::from_str(val).map_err(|x| ())?), - "my_string" => intermediate_rep.my_string.push(String::from_str(val).map_err(|x| ())?), - "my_boolean" => intermediate_rep.my_boolean.push(bool::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "my_number" => intermediate_rep.my_number.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + "my_string" => intermediate_rep.my_string.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "my_boolean" => intermediate_rep.my_boolean.push(bool::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing OuterComposite".to_string()) } } @@ -3766,13 +3766,14 @@ impl ::std::fmt::Display for OuterEnum { } impl ::std::str::FromStr for OuterEnum { - type Err = (); + type Err = String; + fn from_str(s: &str) -> Result { match s { "placed" => Ok(OuterEnum::PLACED), "approved" => Ok(OuterEnum::APPROVED), "delivered" => Ok(OuterEnum::DELIVERED), - _ => Err(()), + _ => Err(format!("Value not valid: {}", s)), } } } @@ -3968,7 +3969,7 @@ impl ::std::string::ToString for Pet { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Pet { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -3991,18 +3992,18 @@ impl ::std::str::FromStr for Pet { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Pet".to_string()) }; if let Some(key) = key_result { match key { - "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| ())?), - "category" => intermediate_rep.category.push(models::Category::from_str(val).map_err(|x| ())?), - "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| ())?), - "photoUrls" => return Err(()), // Parsing a container in this style is not supported yet - "tags" => return Err(()), // Parsing a container in this style is not supported yet - "status" => intermediate_rep.status.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "category" => intermediate_rep.category.push(models::Category::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "photoUrls" => return Err("Parsing a container in this style is not supported in Pet".to_string()), + "tags" => return Err("Parsing a container in this style is not supported in Pet".to_string()), + "status" => intermediate_rep.status.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Pet".to_string()) } } @@ -4014,8 +4015,8 @@ impl ::std::str::FromStr for Pet { Ok(Pet { id: intermediate_rep.id.into_iter().next(), category: intermediate_rep.category.into_iter().next(), - name: intermediate_rep.name.into_iter().next().ok_or(())?, - photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or(())?, + name: intermediate_rep.name.into_iter().next().ok_or("name missing in Pet".to_string())?, + photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or("photoUrls missing in Pet".to_string())?, tags: intermediate_rep.tags.into_iter().next(), status: intermediate_rep.status.into_iter().next(), }) @@ -4095,7 +4096,7 @@ impl ::std::string::ToString for ReadOnlyFirst { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for ReadOnlyFirst { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -4114,14 +4115,14 @@ impl ::std::str::FromStr for ReadOnlyFirst { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing ReadOnlyFirst".to_string()) }; if let Some(key) = key_result { match key { - "bar" => intermediate_rep.bar.push(String::from_str(val).map_err(|x| ())?), - "baz" => intermediate_rep.baz.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "bar" => intermediate_rep.bar.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "baz" => intermediate_rep.baz.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing ReadOnlyFirst".to_string()) } } @@ -4200,7 +4201,7 @@ impl ::std::string::ToString for SpecialModelName { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for SpecialModelName { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -4218,13 +4219,13 @@ impl ::std::str::FromStr for SpecialModelName { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing SpecialModelName".to_string()) }; if let Some(key) = key_result { match key { - "$special[property.name]" => intermediate_rep.special_property_name.push(i64::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "$special[property.name]" => intermediate_rep.special_property_name.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing SpecialModelName".to_string()) } } @@ -4313,7 +4314,7 @@ impl ::std::string::ToString for Tag { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for Tag { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -4332,14 +4333,14 @@ impl ::std::str::FromStr for Tag { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing Tag".to_string()) }; if let Some(key) = key_result { match key { - "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| ())?), - "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing Tag".to_string()) } } @@ -4496,7 +4497,7 @@ impl ::std::string::ToString for User { /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer impl ::std::str::FromStr for User { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { #[derive(Default)] @@ -4521,20 +4522,20 @@ impl ::std::str::FromStr for User { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return Err(()) + None => return Err("Missing value while parsing User".to_string()) }; if let Some(key) = key_result { match key { - "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| ())?), - "username" => intermediate_rep.username.push(String::from_str(val).map_err(|x| ())?), - "firstName" => intermediate_rep.first_name.push(String::from_str(val).map_err(|x| ())?), - "lastName" => intermediate_rep.last_name.push(String::from_str(val).map_err(|x| ())?), - "email" => intermediate_rep.email.push(String::from_str(val).map_err(|x| ())?), - "password" => intermediate_rep.password.push(String::from_str(val).map_err(|x| ())?), - "phone" => intermediate_rep.phone.push(String::from_str(val).map_err(|x| ())?), - "userStatus" => intermediate_rep.user_status.push(i32::from_str(val).map_err(|x| ())?), - _ => return Err(()) // Parse error - unexpected key + "id" => intermediate_rep.id.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "username" => intermediate_rep.username.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "firstName" => intermediate_rep.first_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "lastName" => intermediate_rep.last_name.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "email" => intermediate_rep.email.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "password" => intermediate_rep.password.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "phone" => intermediate_rep.phone.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "userStatus" => intermediate_rep.user_status.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + _ => return Err("Unexpected key while parsing User".to_string()) } } diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs index ab8b5d92c3f..58f1387e08a 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs @@ -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 { #[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 { - // 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 { #[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 { #[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 { #[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 { #[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 { #[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 { #[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(), }) }