diff --git a/docs/generators/rust-server.md b/docs/generators/rust-server.md index d24af6089b79..cadccd0fbccd 100644 --- a/docs/generators/rust-server.md +++ b/docs/generators/rust-server.md @@ -186,7 +186,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Name | Supported | Defined By | | ---- | --------- | ---------- | |Simple|✓|OAS2,OAS3 -|Composite|✗|OAS2,OAS3 +|Composite|✓|OAS2,OAS3 |Polymorphism|✗|OAS2,OAS3 |Union|✗|OAS3 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 40ab769081de..95aaf46b6fa8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -378,38 +378,34 @@ private void flattenComposedChildren(OpenAPI openAPI, String key, List c ListIterator listIterator = children.listIterator(); while (listIterator.hasNext()) { Schema component = listIterator.next(); - if (component instanceof ObjectSchema || // for inline schema with type:object - (component != null && component.getProperties() != null && - !component.getProperties().isEmpty())) { // for inline schema without type:object - Schema op = component; - if (op.get$ref() == null && op.getProperties() != null && op.getProperties().size() > 0) { - // If a `title` attribute is defined in the inline schema, codegen uses it to name the - // inline schema. Otherwise, we'll use the default naming such as InlineObject1, etc. - // We know that this is not the best way to name the model. - // - // Such naming strategy may result in issues. If the value of the 'title' attribute - // happens to match a schema defined elsewhere in the specification, 'innerModelName' - // will be the same as that other schema. - // - // To have complete control of the model naming, one can define the model separately - // instead of inline. - String innerModelName = resolveModelName(op.getTitle(), key); - Schema innerModel = modelFromProperty(openAPI, op, innerModelName); - String existing = matchGenerated(innerModel); - if (existing == null) { - openAPI.getComponents().addSchemas(innerModelName, innerModel); - addGenerated(innerModelName, innerModel); - Schema schema = new Schema().$ref(innerModelName); - schema.setRequired(op.getRequired()); - listIterator.set(schema); - } else { - Schema schema = new Schema().$ref(existing); - schema.setRequired(op.getRequired()); - listIterator.set(schema); - } + if ((component != null) && + (component.get$ref() == null) && + ((component.getProperties() != null && !component.getProperties().isEmpty()) || + (component.getEnum() != null && !component.getEnum().isEmpty()))) { + // If a `title` attribute is defined in the inline schema, codegen uses it to name the + // inline schema. Otherwise, we'll use the default naming such as InlineObject1, etc. + // We know that this is not the best way to name the model. + // + // Such naming strategy may result in issues. If the value of the 'title' attribute + // happens to match a schema defined elsewhere in the specification, 'innerModelName' + // will be the same as that other schema. + // + // To have complete control of the model naming, one can define the model separately + // instead of inline. + String innerModelName = resolveModelName(component.getTitle(), key); + Schema innerModel = modelFromProperty(openAPI, component, innerModelName); + String existing = matchGenerated(innerModel); + if (existing == null) { + openAPI.getComponents().addSchemas(innerModelName, innerModel); + addGenerated(innerModelName, innerModel); + Schema schema = new Schema().$ref(innerModelName); + schema.setRequired(component.getRequired()); + listIterator.set(schema); + } else { + Schema schema = new Schema().$ref(existing); + schema.setRequired(component.getRequired()); + listIterator.set(schema); } - } else { - // likely a reference to schema (not inline schema) } } } @@ -540,7 +536,7 @@ private void addGenerated(String name, Schema model) { */ private String sanitizeName(final String name) { return name - .replaceAll("^[0-9]", "_") // e.g. 12object => _2object + .replaceAll("^[0-9]", "_$0") // e.g. 12object => _12object .replaceAll("[^A-Za-z0-9]", "_"); // e.g. io.schema.User name => io_schema_User_name } @@ -671,6 +667,8 @@ private Schema modelFromProperty(OpenAPI openAPI, Schema object, String path) { model.setXml(xml); model.setRequired(object.getRequired()); model.setNullable(object.getNullable()); + model.setEnum(object.getEnum()); + model.setType(object.getType()); model.setDiscriminator(object.getDiscriminator()); model.setWriteOnly(object.getWriteOnly()); model.setUniqueItems(object.getUniqueItems()); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index 81b33ca2e946..2080fca66a72 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ComposedSchema; import io.swagger.v3.oas.models.media.FileSchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.XML; @@ -96,14 +97,11 @@ public RustServerCodegen() { SecurityFeature.OAuth2_Implicit )) .excludeGlobalFeatures( - GlobalFeature.XMLStructureDefinitions, GlobalFeature.LinkObjects, GlobalFeature.ParameterStyling ) .excludeSchemaSupportFeatures( - SchemaSupportFeature.Polymorphism, - SchemaSupportFeature.Union, - SchemaSupportFeature.Composite + SchemaSupportFeature.Polymorphism ) .excludeParameterFeatures( ParameterFeature.Cookie @@ -400,7 +398,7 @@ public String toModelName(String name) { } // model name starts with number - else if (name.matches("^\\d.*")) { + else if (camelizedName.matches("^\\d.*")) { // e.g. 200Response => Model200Response (after camelize) camelizedName = "Model" + camelizedName; LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelizedName); @@ -1191,8 +1189,11 @@ public String toInstantiationType(Schema p) { @Override public CodegenModel fromModel(String name, Schema model) { + LOGGER.trace("Creating model from schema: {}", model); + Map allDefinitions = ModelUtils.getSchemas(this.openAPI); CodegenModel mdl = super.fromModel(name, model); + mdl.vendorExtensions.put("x-upper-case-name", name.toUpperCase(Locale.ROOT)); if (!StringUtils.isEmpty(model.get$ref())) { Schema schema = allDefinitions.get(ModelUtils.getSimpleRef(model.get$ref())); @@ -1233,6 +1234,8 @@ public CodegenModel fromModel(String name, Schema model) { } else { mdl.arrayModelType = toModelName(mdl.arrayModelType); } + } else if ((mdl.anyOf.size() > 0) || (mdl.oneOf.size() > 0)) { + mdl.dataType = getSchemaType(model); } if (mdl.xmlNamespace != null) { @@ -1245,6 +1248,8 @@ public CodegenModel fromModel(String name, Schema model) { mdl.additionalPropertiesType = getTypeDeclaration(additionalProperties); } + LOGGER.trace("Created model: {}", mdl); + return mdl; } @@ -1403,6 +1408,28 @@ else if (ModelUtils.isBooleanSchema(p)) { return defaultValue; } + @Override + public String toOneOfName(List names, ComposedSchema composedSchema) { + List schemas = ModelUtils.getInterfaces(composedSchema); + + List types = new ArrayList<>(); + for (Schema s : schemas) { + types.add(getTypeDeclaration(s)); + } + return "swagger::OneOf" + types.size() + "<" + String.join(",", types) + ">"; + } + + @Override + public String toAnyOfName(List names, ComposedSchema composedSchema) { + List schemas = ModelUtils.getInterfaces(composedSchema); + + List types = new ArrayList<>(); + for (Schema s : schemas) { + types.add(getTypeDeclaration(s)); + } + return "swagger::AnyOf" + types.size() + "<" + String.join(",", types) + ">"; + } + @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); @@ -1529,6 +1556,8 @@ public Map postProcessModels(Map objs) { Map mo = (Map) _mo; CodegenModel cm = (CodegenModel) mo.get("model"); + LOGGER.trace("Post processing model: {}", cm); + if (cm.dataType != null && cm.dataType.equals("object")) { // Object isn't a sensible default. Instead, we set it to // 'null'. This ensures that we treat this model as a struct 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 6b4f9ffbb846..746e5dbd6cd5 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -4,10 +4,14 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; {{! Don't "use" structs here - they can conflict with the names of models, and mean that the code won't compile }} - -{{#models}}{{#model}} -{{#description}}/// {{{description}}} -{{/description}}{{#isEnum}}/// Enumeration of values. +{{#models}} +{{#model}} + +{{#description}} +/// {{{description}}} +{{/description}} +{{#isEnum}} +/// 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)] @@ -15,15 +19,23 @@ use crate::header; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]{{#xmlName}} #[serde(rename = "{{{xmlName}}}")]{{/xmlName}} -pub enum {{{classname}}} { {{#allowableValues}}{{#enumVars}} +pub enum {{{classname}}} { +{{#allowableValues}} + {{#enumVars}} #[serde(rename = {{{value}}})] - {{{name}}},{{/enumVars}}{{/allowableValues}} + {{{name}}}, + {{/enumVars}} +{{/allowableValues}} } impl std::fmt::Display for {{{classname}}} { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { {{#allowableValues}}{{#enumVars}} - {{{classname}}}::{{{name}}} => write!(f, "{}", {{{value}}}),{{/enumVars}}{{/allowableValues}} + match *self { +{{#allowableValues}} + {{#enumVars}} + {{{classname}}}::{{{name}}} => write!(f, "{}", {{{value}}}), + {{/enumVars}} +{{/allowableValues}} } } } @@ -62,8 +74,8 @@ impl std::convert::From<{{{dataType}}}> for {{{classname}}} { {{{classname}}}(x) } } - {{#vendorExtensions.x-is-string}} + impl std::string::ToString for {{{classname}}} { fn to_string(&self) -> String { self.0.to_string() @@ -121,45 +133,8 @@ impl ::std::str::FromStr for {{{classname}}} { {{/additionalPropertiesType}} {{/dataType}} {{^dataType}} -// Methods for converting between header::IntoHeaderValue<{{{classname}}}> and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue<{{{classname}}}>) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for {{classname}} - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue<{{{classname}}}> { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match <{{{classname}}} as std::str::FromStr>::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into {{classname}} - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - -{{#arrayModelType}}{{#vendorExtensions}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml +{{#arrayModelType}} +{{#vendorExtensions}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml #[allow(non_snake_case)] fn wrap_in_{{{x-item-xml-name}}}(item: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result where @@ -265,7 +240,9 @@ impl std::str::FromStr for {{{classname}}} { } } -{{/arrayModelType}}{{^arrayModelType}}{{! general struct}} +{{/arrayModelType}} +{{^arrayModelType}} +{{! general struct}} #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] {{#xmlName}} @@ -417,7 +394,7 @@ impl std::str::FromStr for {{{classname}}} { "{{{baseName}}}" => return std::result::Result::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| format!("{}", x))?), + "{{{baseName}}}" => intermediate_rep.{{{name}}}.push(<{{{dataType}}} as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), {{/isNullable}} {{/isContainer}} {{/isByteArray}} @@ -444,22 +421,60 @@ impl std::str::FromStr for {{{classname}}} { }) } } - {{/arrayModelType}} + +// Methods for converting between header::IntoHeaderValue<{{{classname}}}> and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue<{{{classname}}}>) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for {{classname}} - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue<{{{classname}}}> { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match <{{{classname}}} as std::str::FromStr>::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into {{classname}} - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + {{/dataType}} {{/isEnum}} - {{#usesXml}} {{#usesXmlNamespaces}} {{#xmlNamespace}} + impl {{{classname}}} { /// Associated constant for this model's XML namespace. #[allow(dead_code)] pub const NAMESPACE: &'static str = "{{{xmlNamespace}}}"; } - {{/xmlNamespace}} {{/usesXmlNamespaces}} + impl {{{classname}}} { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. @@ -478,4 +493,4 @@ impl {{{classname}}} { } {{/usesXml}} {{/model}} -{{/models}} \ No newline at end of file +{{/models}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/response.mustache b/modules/openapi-generator/src/main/resources/rust-server/response.mustache index 9269eea6386f..39ff27821652 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/response.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/response.mustache @@ -42,7 +42,7 @@ pub enum {{{operationId}}}Response { {{^required}} Option< {{/required}} - {{{datatype}}} + {{{dataType}}} {{^required}} > {{/required}} 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 f059f8dba910..0bcea44a508f 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 @@ -357,7 +357,6 @@ paths: responses: '200': description: Success - /repos/{repoId}: parameters: - in: path @@ -391,6 +390,51 @@ paths: responses: '200': description: Success + /one-of: + get: + responses: + '200': + description: Success + content: + application/json: + schema: + oneOf: + - type: integer + - type: array + items: + type: string + /any-of: + get: + parameters: + - name: any-of + in: query + description: list of any of objects + schema: + type: array + items: + $ref: '#/components/schemas/AnyOfObject' + minItems: 1 + responses: + '200': + description: Success + content: + application/json: + schema: + $ref: "#/components/schemas/AnyOfObject" + '201': + description: AlternateSuccess + content: + application/json: + schema: + $ref: "#/components/schemas/12345AnyOfObject" + '202': + description: AnyOfSuccess + content: + application/json: + schema: + anyOf: + - $ref: "#/components/schemas/StringObject" + - $ref: "#/components/schemas/UuidObject" /json-complex-query-param: get: parameters: @@ -418,6 +462,34 @@ components: test.read: Allowed to read state. test.write: Allowed to change state. schemas: + AnyOfProperty: + description: Test containing an anyOf object + properties: + requiredAnyOf: + $ref: '#/components/schemas/AnyOfObject' + optionalAnyOf: + $ref: '#/components/schemas/12345AnyOfObject' + required: + - requiredAnyOf + AnyOfObject: + description: Test a model containing an anyOf + anyOf: + - type: string + enum: + - FOO + - BAR + - type: string + description: Alternate option + 12345AnyOfObject: + description: Test a model containing an anyOf that starts with a number + anyOf: + - type: string + enum: + - FOO + - BAR + - "*" + - type: string + description: Alternate option EnumWithStarObject: description: Test a model containing a special character in the enum type: string diff --git a/samples/client/petstore/java/feign/feign10x/api/openapi.yaml b/samples/client/petstore/java/feign/feign10x/api/openapi.yaml index a49359fd348c..00cc0f2f4c26 100644 --- a/samples/client/petstore/java/feign/feign10x/api/openapi.yaml +++ b/samples/client/petstore/java/feign/feign10x/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/rust-server/output/multipart-v3/docs/MultipartRequest.md b/samples/server/petstore/rust-server/output/multipart-v3/docs/MultipartRequest.md deleted file mode 100644 index dc52f53832a0..000000000000 --- a/samples/server/petstore/rust-server/output/multipart-v3/docs/MultipartRequest.md +++ /dev/null @@ -1,13 +0,0 @@ -# MultipartRequest - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**string_field** | **String** | | -**optional_string_field** | **String** | | [optional] [default to None] -**object_field** | [***models::MultipartRequestObjectField**](multipart_request_object_field.md) | | [optional] [default to None] -**binary_field** | [***swagger::ByteArray**](ByteArray.md) | | - -[[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/multipart-v3/src/models.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs index b86806bfeebf..d201b0407f23 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 @@ -4,46 +4,6 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for InlineObject - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into InlineObject - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct InlineObject { @@ -128,36 +88,34 @@ impl std::str::FromStr for InlineObject { } } - - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MultipartRelatedRequest - value: {} is invalid {}", + format!("Invalid header value for InlineObject - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MultipartRelatedRequest - {}", + format!("Unable to convert header value '{}' into InlineObject - {}", value, err)) } }, @@ -242,7 +200,7 @@ impl std::str::FromStr for MultipartRelatedRequest { if let Some(key) = key_result { match key { - "object_field" => intermediate_rep.object_field.push(models::MultipartRequestObjectField::from_str(val).map_err(|x| format!("{}", x))?), + "object_field" => intermediate_rep.object_field.push(::from_str(val).map_err(|x| format!("{}", x))?), "optional_binary_field" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()), "required_binary_field" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MultipartRelatedRequest".to_string()) @@ -262,36 +220,34 @@ impl std::str::FromStr for MultipartRelatedRequest { } } - - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MultipartRequestObjectField - value: {} is invalid {}", + format!("Invalid header value for MultipartRelatedRequest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MultipartRequestObjectField - {}", + format!("Unable to convert header value '{}' into MultipartRelatedRequest - {}", value, err)) } }, @@ -372,7 +328,7 @@ impl std::str::FromStr for MultipartRequestObjectField { if let Some(key) = key_result { match key { - "field_a" => intermediate_rep.field_a.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "field_a" => intermediate_rep.field_a.push(::from_str(val).map_err(|x| format!("{}", x))?), "field_b" => return std::result::Result::Err("Parsing a container in this style is not supported in MultipartRequestObjectField".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MultipartRequestObjectField".to_string()) } @@ -390,4 +346,41 @@ impl std::str::FromStr for MultipartRequestObjectField { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for MultipartRequestObjectField - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into MultipartRequestObjectField - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs index 7caa4ed9c1e3..0175af64b567 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs @@ -4,46 +4,6 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for InlineObject - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into InlineObject - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct InlineObject { @@ -104,7 +64,7 @@ impl std::str::FromStr for InlineObject { if let Some(key) = key_result { match key { - "propery" => intermediate_rep.propery.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "propery" => intermediate_rep.propery.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing InlineObject".to_string()) } } @@ -120,4 +80,41 @@ impl std::str::FromStr for InlineObject { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for InlineObject - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into InlineObject - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} diff --git a/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES index 5f3122fbc3d0..d1eaac072b4a 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES @@ -7,11 +7,16 @@ docs/AdditionalPropertiesWithList.md docs/AnotherXmlArray.md docs/AnotherXmlInner.md docs/AnotherXmlObject.md +docs/AnyOfObject.md +docs/AnyOfObjectAnyOf.md +docs/AnyOfProperty.md docs/DuplicateXmlObject.md docs/EnumWithStarObject.md docs/Err.md docs/Error.md docs/InlineResponse201.md +docs/Model12345AnyOfObject.md +docs/Model12345AnyOfObjectAnyOf.md docs/MyId.md docs/MyIdList.md docs/NullableTest.md 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 b0fc2ee15f10..d0e29d93bf45 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/README.md @@ -61,6 +61,7 @@ cargo run --example server To run a client, follow one of the following simple steps: ``` +cargo run --example client AnyOfGet cargo run --example client CallbackWithHeaderPost cargo run --example client ComplexQueryParamGet cargo run --example client JsonComplexQueryParamGet @@ -68,6 +69,7 @@ cargo run --example client MandatoryRequestHeaderGet cargo run --example client MergePatchJsonGet cargo run --example client MultigetGet cargo run --example client MultipleAuthSchemeGet +cargo run --example client OneOfGet cargo run --example client OverrideServerGet cargo run --example client ParamgetGet cargo run --example client ReadonlyAuthSchemeGet @@ -117,6 +119,7 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- +[****](docs/default_api.md#) | **GET** /any-of | [****](docs/default_api.md#) | **POST** /callback-with-header | [****](docs/default_api.md#) | **GET** /complex-query-param | [****](docs/default_api.md#) | **GET** /enum_in_path/{path_param} | @@ -125,6 +128,7 @@ Method | HTTP request | Description [****](docs/default_api.md#) | **GET** /merge-patch-json | [****](docs/default_api.md#) | **GET** /multiget | Get some stuff. [****](docs/default_api.md#) | **GET** /multiple_auth_scheme | +[****](docs/default_api.md#) | **GET** /one-of | [****](docs/default_api.md#) | **GET** /override-server | [****](docs/default_api.md#) | **GET** /paramget | Get some stuff with parameters. [****](docs/default_api.md#) | **GET** /readonly_auth_scheme | @@ -149,11 +153,16 @@ Method | HTTP request | Description - [AnotherXmlArray](docs/AnotherXmlArray.md) - [AnotherXmlInner](docs/AnotherXmlInner.md) - [AnotherXmlObject](docs/AnotherXmlObject.md) + - [AnyOfObject](docs/AnyOfObject.md) + - [AnyOfObjectAnyOf](docs/AnyOfObjectAnyOf.md) + - [AnyOfProperty](docs/AnyOfProperty.md) - [DuplicateXmlObject](docs/DuplicateXmlObject.md) - [EnumWithStarObject](docs/EnumWithStarObject.md) - [Err](docs/Err.md) - [Error](docs/Error.md) - [InlineResponse201](docs/InlineResponse201.md) + - [Model12345AnyOfObject](docs/Model12345AnyOfObject.md) + - [Model12345AnyOfObjectAnyOf](docs/Model12345AnyOfObjectAnyOf.md) - [MyId](docs/MyId.md) - [MyIdList](docs/MyIdList.md) - [NullableTest](docs/NullableTest.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 984374b520a5..fab686f0ebf7 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 @@ -407,6 +407,54 @@ paths: description: Success tags: - Repo + /one-of: + get: + responses: + "200": + content: + application/json: + schema: + oneOf: + - type: integer + - items: + type: string + type: array + description: Success + /any-of: + get: + parameters: + - description: list of any of objects + explode: true + in: query + name: any-of + required: false + schema: + items: + $ref: '#/components/schemas/AnyOfObject' + minItems: 1 + type: array + style: form + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/AnyOfObject' + description: Success + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/12345AnyOfObject' + description: AlternateSuccess + "202": + content: + application/json: + schema: + anyOf: + - $ref: '#/components/schemas/StringObject' + - $ref: '#/components/schemas/UuidObject' + description: AnyOfSuccess /json-complex-query-param: get: parameters: @@ -426,6 +474,27 @@ paths: description: Success components: schemas: + AnyOfProperty: + description: Test containing an anyOf object + properties: + requiredAnyOf: + $ref: '#/components/schemas/AnyOfObject' + optionalAnyOf: + $ref: '#/components/schemas/12345AnyOfObject' + required: + - requiredAnyOf + AnyOfObject: + anyOf: + - $ref: '#/components/schemas/AnyOfObject_anyOf' + - description: Alternate option + type: string + description: Test a model containing an anyOf + "12345AnyOfObject": + anyOf: + - $ref: '#/components/schemas/_12345AnyOfObject_anyOf' + - description: Alternate option + type: string + description: Test a model containing an anyOf that starts with a number EnumWithStarObject: description: Test a model containing a special character in the enum enum: @@ -607,6 +676,17 @@ components: foo: type: string type: object + AnyOfObject_anyOf: + enum: + - FOO + - BAR + type: string + _12345AnyOfObject_anyOf: + enum: + - FOO + - BAR + - '*' + type: string securitySchemes: authScheme: flows: diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfObject.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfObject.md new file mode 100644 index 000000000000..36847cbf6949 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfObject.md @@ -0,0 +1,9 @@ +# AnyOfObject + +## 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/AnyOfObjectAnyOf.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfObjectAnyOf.md new file mode 100644 index 000000000000..079256f1726f --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfObjectAnyOf.md @@ -0,0 +1,9 @@ +# AnyOfObjectAnyOf + +## 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/AnyOfProperty.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfProperty.md new file mode 100644 index 000000000000..c4e69ef4caf6 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfProperty.md @@ -0,0 +1,11 @@ +# AnyOfProperty + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**required_any_of** | [***models::AnyOfObject**](AnyOfObject.md) | | +**optional_any_of** | [***models::Model12345AnyOfObject**](12345AnyOfObject.md) | | [optional] [default to None] + +[[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/Model12345AnyOfObject.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/Model12345AnyOfObject.md new file mode 100644 index 000000000000..8999550d65e6 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/Model12345AnyOfObject.md @@ -0,0 +1,9 @@ +# Model12345AnyOfObject + +## 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/Model12345AnyOfObjectAnyOf.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/Model12345AnyOfObjectAnyOf.md new file mode 100644 index 000000000000..096f40837fa6 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/Model12345AnyOfObjectAnyOf.md @@ -0,0 +1,9 @@ +# Model12345AnyOfObjectAnyOf + +## 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 42aa82f35d71..1358c8fb1b82 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 @@ -4,6 +4,7 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- +****](default_api.md#) | **GET** /any-of | ****](default_api.md#) | **POST** /callback-with-header | ****](default_api.md#) | **GET** /complex-query-param | ****](default_api.md#) | **GET** /enum_in_path/{path_param} | @@ -12,6 +13,7 @@ Method | HTTP request | Description ****](default_api.md#) | **GET** /merge-patch-json | ****](default_api.md#) | **GET** /multiget | Get some stuff. ****](default_api.md#) | **GET** /multiple_auth_scheme | +****](default_api.md#) | **GET** /one-of | ****](default_api.md#) | **GET** /override-server | ****](default_api.md#) | **GET** /paramget | Get some stuff with parameters. ****](default_api.md#) | **GET** /readonly_auth_scheme | @@ -28,6 +30,38 @@ Method | HTTP request | Description ****](default_api.md#) | **PUT** /xml | +# **** +> models::AnyOfObject (optional) + + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **optional** | **map[string]interface{}** | optional parameters | nil if no parameters + +### Optional Parameters +Optional parameters are passed through a map[string]interface{}. + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **any_of** | [**models::AnyOfObject**](models::AnyOfObject.md)| list of any of objects | + +### Return type + +[**models::AnyOfObject**](AnyOfObject.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[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) + # **** > (url) @@ -233,6 +267,28 @@ This endpoint does not need any parameter. [[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) +# **** +> swagger::OneOf2> () + + +### Required Parameters +This endpoint does not need any parameter. + +### Return type + +[**swagger::OneOf2>**](swagger::OneOf2>.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[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) + # **** > () 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 700e2ff22353..04b4e28dfde4 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 @@ -6,6 +6,7 @@ mod server; use futures::{future, Stream, stream}; #[allow(unused_imports)] use openapi_v3::{Api, ApiNoContext, Client, ContextWrapperExt, models, + AnyOfGetResponse, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, EnumInPathPathParamGetResponse, @@ -14,6 +15,7 @@ use openapi_v3::{Api, ApiNoContext, Client, ContextWrapperExt, models, MergePatchJsonGetResponse, MultigetGetResponse, MultipleAuthSchemeGetResponse, + OneOfGetResponse, OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, @@ -51,6 +53,7 @@ fn main() { .arg(Arg::with_name("operation") .help("Sets the operation to run") .possible_values(&[ + "AnyOfGet", "CallbackWithHeaderPost", "ComplexQueryParamGet", "JsonComplexQueryParamGet", @@ -58,6 +61,7 @@ fn main() { "MergePatchJsonGet", "MultigetGet", "MultipleAuthSchemeGet", + "OneOfGet", "OverrideServerGet", "ParamgetGet", "ReadonlyAuthSchemeGet", @@ -120,6 +124,12 @@ fn main() { rt.spawn(server::create("127.0.0.1:8081", false)); match matches.value_of("operation") { + Some("AnyOfGet") => { + let result = rt.block_on(client.any_of_get( + Some(&Vec::new()) + )); + info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); + }, Some("CallbackWithHeaderPost") => { let result = rt.block_on(client.callback_with_header_post( "url_example".to_string() @@ -167,6 +177,11 @@ fn main() { )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, + Some("OneOfGet") => { + let result = rt.block_on(client.one_of_get( + )); + info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); + }, Some("OverrideServerGet") => { let result = rt.block_on(client.override_server_get( )); 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 b5535b3ebd5f..a40212742c5c 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 @@ -96,6 +96,7 @@ impl Server { use openapi_v3::{ Api, + AnyOfGetResponse, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, EnumInPathPathParamGetResponse, @@ -104,6 +105,7 @@ use openapi_v3::{ MergePatchJsonGetResponse, MultigetGetResponse, MultipleAuthSchemeGetResponse, + OneOfGetResponse, OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, @@ -128,6 +130,16 @@ use swagger::ApiError; #[async_trait] impl Api for Server where C: Has + Send + Sync { + async fn any_of_get( + &self, + any_of: Option<&Vec>, + context: &C) -> Result + { + let context = context.clone(); + info!("any_of_get({:?}) - X-Span-ID: {:?}", any_of, context.get().0.clone()); + Err("Generic failuare".into()) + } + async fn callback_with_header_post( &self, url: String, @@ -206,6 +218,15 @@ impl Api for Server where C: Has + Send + Sync Err("Generic failuare".into()) } + async fn one_of_get( + &self, + context: &C) -> Result + { + let context = context.clone(); + info!("one_of_get() - X-Span-ID: {:?}", context.get().0.clone()); + Err("Generic failuare".into()) + } + async fn override_server_get( &self, context: &C) -> Result 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 3817bd07555b..396d05a98cb5 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 @@ -36,6 +36,7 @@ const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS const ID_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'|'); use crate::{Api, + AnyOfGetResponse, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, EnumInPathPathParamGetResponse, @@ -44,6 +45,7 @@ use crate::{Api, MergePatchJsonGetResponse, MultigetGetResponse, MultipleAuthSchemeGetResponse, + OneOfGetResponse, OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, @@ -405,6 +407,110 @@ impl Api for Client where } } + async fn any_of_get( + &self, + param_any_of: Option<&Vec>, + context: &C) -> Result + { + let mut client_service = self.client_service.clone(); + let mut uri = format!( + "{}/any-of", + self.base_path + ); + + // Query parameters + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_any_of) = param_any_of { + query_string.append_pair("any-of", + ¶m_any_of.iter().map(ToString::to_string).collect::>().join(",")); + } + query_string.finish() + }; + if !query_string.is_empty() { + uri += "?"; + uri += &query_string; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), + }; + + let mut request = match Request::builder() + .method("GET") + .uri(uri) + .body(Body::empty()) { + Ok(req) => req, + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) + }; + + let header = HeaderValue::from_str(Has::::get(context).0.clone().to_string().as_str()); + request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { + Ok(h) => h, + Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) + }); + + let mut response = client_service.call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))).await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(AnyOfGetResponse::Success + (body) + ) + } + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(AnyOfGetResponse::AlternateSuccess + (body) + ) + } + 202 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::>(body)?; + Ok(AnyOfGetResponse::AnyOfSuccess + (body) + ) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body() + .take(100) + .to_raw().await; + Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("", e), + }, + Err(e) => format!("", e), + } + ))) + } + } + } + async fn callback_with_header_post( &self, param_url: String, @@ -1089,6 +1195,81 @@ impl Api for Client where } } + async fn one_of_get( + &self, + context: &C) -> Result + { + let mut client_service = self.client_service.clone(); + let mut uri = format!( + "{}/one-of", + self.base_path + ); + + // Query parameters + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { + uri += "?"; + uri += &query_string; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), + }; + + let mut request = match Request::builder() + .method("GET") + .uri(uri) + .body(Body::empty()) { + Ok(req) => req, + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) + }; + + let header = HeaderValue::from_str(Has::::get(context).0.clone().to_string().as_str()); + request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { + Ok(h) => h, + Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) + }); + + let mut response = client_service.call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))).await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::>>(body)?; + Ok(OneOfGetResponse::Success + (body) + ) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body() + .take(100) + .to_raw().await; + Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("", e), + }, + Err(e) => format!("", e), + } + ))) + } + } + } + async fn override_server_get( &self, context: &C) -> Result 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 6a269c49f2a9..458aa65a99ac 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 @@ -11,6 +11,22 @@ type ServiceError = Box; pub const BASE_PATH: &'static str = ""; pub const API_VERSION: &'static str = "1.0.7"; +#[derive(Debug, PartialEq)] +#[must_use] +pub enum AnyOfGetResponse { + /// Success + Success + (models::AnyOfObject) + , + /// AlternateSuccess + AlternateSuccess + (models::Model12345AnyOfObject) + , + /// AnyOfSuccess + AnyOfSuccess + (swagger::AnyOf2) +} + #[derive(Debug, PartialEq)] pub enum CallbackWithHeaderPostResponse { /// OK @@ -86,6 +102,13 @@ pub enum MultipleAuthSchemeGetResponse { CheckThatLimitingToMultipleRequiredAuthSchemesWorks } +#[derive(Debug, PartialEq)] +pub enum OneOfGetResponse { + /// Success + Success + (swagger::OneOf2>) +} + #[derive(Debug, PartialEq)] pub enum OverrideServerGetResponse { /// Success. @@ -253,6 +276,11 @@ pub trait Api { Poll::Ready(Ok(())) } + async fn any_of_get( + &self, + any_of: Option<&Vec>, + context: &C) -> Result; + async fn callback_with_header_post( &self, url: String, @@ -291,6 +319,10 @@ pub trait Api { &self, context: &C) -> Result; + async fn one_of_get( + &self, + context: &C) -> Result; + async fn override_server_get( &self, context: &C) -> Result; @@ -380,6 +412,11 @@ pub trait ApiNoContext { fn context(&self) -> &C; + async fn any_of_get( + &self, + any_of: Option<&Vec>, + ) -> Result; + async fn callback_with_header_post( &self, url: String, @@ -418,6 +455,10 @@ pub trait ApiNoContext { &self, ) -> Result; + async fn one_of_get( + &self, + ) -> Result; + async fn override_server_get( &self, ) -> Result; @@ -522,6 +563,15 @@ impl + Send + Sync, C: Clone + Send + Sync> ApiNoContext for Contex ContextWrapper::context(self) } + async fn any_of_get( + &self, + any_of: Option<&Vec>, + ) -> Result + { + let context = self.context().clone(); + self.api().any_of_get(any_of, &context).await + } + async fn callback_with_header_post( &self, url: String, @@ -592,6 +642,14 @@ impl + Send + Sync, C: Clone + Send + Sync> ApiNoContext for Contex self.api().multiple_auth_scheme_get(&context).await } + async fn one_of_get( + &self, + ) -> Result + { + let context = self.context().clone(); + self.api().one_of_get(&context).await + } + async fn override_server_get( &self, ) -> Result 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 729d1279e63c..68647720d26d 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 @@ -4,7 +4,6 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AdditionalPropertiesWithList(std::collections::HashMap>); @@ -15,7 +14,6 @@ impl std::convert::From>> for Addi } } - impl std::convert::From for std::collections::HashMap> { fn from(x: AdditionalPropertiesWithList) -> Self { x.0 @@ -65,44 +63,6 @@ impl AdditionalPropertiesWithList { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnotherXmlArray - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnotherXmlArray - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - // Utility function for wrapping list elements when serializing xml #[allow(non_snake_case)] fn wrap_in_snake_another_xml_inner(item: &Vec, serializer: S) -> std::result::Result @@ -203,6 +163,45 @@ impl std::str::FromStr for AnotherXmlArray { } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for AnotherXmlArray - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into AnotherXmlArray - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + + impl AnotherXmlArray { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. @@ -266,6 +265,83 @@ impl AnotherXmlInner { } /// An XML object +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +#[serde(rename = "snake_another_xml_object")] +pub struct AnotherXmlObject { + #[serde(rename = "inner_string")] + #[serde(skip_serializing_if="Option::is_none")] + pub inner_string: Option, + +} + +impl AnotherXmlObject { + pub fn new() -> AnotherXmlObject { + AnotherXmlObject { + inner_string: None, + } + } +} + +/// Converts the AnotherXmlObject value to the Query Parameters representation (style=form, explode=false) +/// specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde serializer +impl std::string::ToString for AnotherXmlObject { + fn to_string(&self) -> String { + let mut params: Vec = vec![]; + + if let Some(ref inner_string) = self.inner_string { + params.push("inner_string".to_string()); + params.push(inner_string.to_string()); + } + + params.join(",").to_string() + } +} + +/// Converts Query Parameters representation (style=form, explode=false) to a AnotherXmlObject value +/// as specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde deserializer +impl std::str::FromStr for AnotherXmlObject { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + #[derive(Default)] + // An intermediate representation of the struct to use for parsing. + struct IntermediateRep { + pub inner_string: Vec, + } + + let mut intermediate_rep = IntermediateRep::default(); + + // Parse into intermediate representation + let mut string_iter = s.split(',').into_iter(); + let mut key_result = string_iter.next(); + + while key_result.is_some() { + let val = match string_iter.next() { + Some(x) => x, + None => return std::result::Result::Err("Missing value while parsing AnotherXmlObject".to_string()) + }; + + if let Some(key) = key_result { + match key { + "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + _ => return std::result::Result::Err("Unexpected key while parsing AnotherXmlObject".to_string()) + } + } + + // Get the next key + key_result = string_iter.next(); + } + + // Use the intermediate representation to return the struct + std::result::Result::Ok(AnotherXmlObject { + inner_string: intermediate_rep.inner_string.into_iter().next(), + }) + } +} + // Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] @@ -305,51 +381,57 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl AnotherXmlObject { + /// Associated constant for this model's XML namespace. + #[allow(dead_code)] + pub const NAMESPACE: &'static str = "http://foo.bar"; +} + +impl AnotherXmlObject { + /// 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 { + let mut namespaces = std::collections::BTreeMap::new(); + // An empty string is used to indicate a global namespace in xmltree. + namespaces.insert("".to_string(), Self::NAMESPACE.to_string()); + serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize") + } +} + +/// Test a model containing an anyOf #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] -#[serde(rename = "snake_another_xml_object")] -pub struct AnotherXmlObject { - #[serde(rename = "inner_string")] - #[serde(skip_serializing_if="Option::is_none")] - pub inner_string: Option, - +pub struct AnyOfObject { } -impl AnotherXmlObject { - pub fn new() -> AnotherXmlObject { - AnotherXmlObject { - inner_string: None, +impl AnyOfObject { + pub fn new() -> AnyOfObject { + AnyOfObject { } } } -/// Converts the AnotherXmlObject value to the Query Parameters representation (style=form, explode=false) +/// Converts the AnyOfObject value to the Query Parameters representation (style=form, explode=false) /// specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde serializer -impl std::string::ToString for AnotherXmlObject { +impl std::string::ToString for AnyOfObject { fn to_string(&self) -> String { let mut params: Vec = vec![]; - - if let Some(ref inner_string) = self.inner_string { - params.push("inner_string".to_string()); - params.push(inner_string.to_string()); - } - params.join(",").to_string() } } -/// Converts Query Parameters representation (style=form, explode=false) to a AnotherXmlObject value +/// Converts Query Parameters representation (style=form, explode=false) to a AnyOfObject value /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer -impl std::str::FromStr for AnotherXmlObject { +impl std::str::FromStr for AnyOfObject { type Err = String; fn from_str(s: &str) -> std::result::Result { #[derive(Default)] // An intermediate representation of the struct to use for parsing. struct IntermediateRep { - pub inner_string: Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -361,13 +443,12 @@ impl std::str::FromStr for AnotherXmlObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing AnotherXmlObject".to_string()) + None => return std::result::Result::Err("Missing value while parsing AnyOfObject".to_string()) }; if let Some(key) = key_result { match key { - "inner_string" => intermediate_rep.inner_string.push(String::from_str(val).map_err(|x| format!("{}", x))?), - _ => return std::result::Result::Err("Unexpected key while parsing AnotherXmlObject".to_string()) + _ => return std::result::Result::Err("Unexpected key while parsing AnyOfObject".to_string()) } } @@ -376,60 +457,213 @@ impl std::str::FromStr for AnotherXmlObject { } // Use the intermediate representation to return the struct - std::result::Result::Ok(AnotherXmlObject { - inner_string: intermediate_rep.inner_string.into_iter().next(), + std::result::Result::Ok(AnyOfObject { }) } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue -impl AnotherXmlObject { - /// Associated constant for this model's XML namespace. +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for AnyOfObject - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into AnyOfObject - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + + +impl AnyOfObject { + /// Helper function to allow us to convert this model to an XML string. + /// Will panic if serialisation fails. #[allow(dead_code)] - pub const NAMESPACE: &'static str = "http://foo.bar"; + pub(crate) fn to_xml(&self) -> String { + serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") + } } -impl AnotherXmlObject { +/// 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, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] +pub enum AnyOfObjectAnyOf { + #[serde(rename = "FOO")] + FOO, + #[serde(rename = "BAR")] + BAR, +} + +impl std::fmt::Display for AnyOfObjectAnyOf { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + AnyOfObjectAnyOf::FOO => write!(f, "{}", "FOO"), + AnyOfObjectAnyOf::BAR => write!(f, "{}", "BAR"), + } + } +} + +impl std::str::FromStr for AnyOfObjectAnyOf { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + match s { + "FOO" => std::result::Result::Ok(AnyOfObjectAnyOf::FOO), + "BAR" => std::result::Result::Ok(AnyOfObjectAnyOf::BAR), + _ => std::result::Result::Err(format!("Value not valid: {}", s)), + } + } +} + +impl AnyOfObjectAnyOf { /// 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 { - let mut namespaces = std::collections::BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), Self::NAMESPACE.to_string()); - serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize") + serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } -/// An XML object -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +/// Test containing an anyOf object +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct AnyOfProperty { + #[serde(rename = "requiredAnyOf")] + pub required_any_of: models::AnyOfObject, + + #[serde(rename = "optionalAnyOf")] + #[serde(skip_serializing_if="Option::is_none")] + pub optional_any_of: Option, + +} + +impl AnyOfProperty { + pub fn new(required_any_of: models::AnyOfObject, ) -> AnyOfProperty { + AnyOfProperty { + required_any_of: required_any_of, + optional_any_of: None, + } + } +} + +/// Converts the AnyOfProperty value to the Query Parameters representation (style=form, explode=false) +/// specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde serializer +impl std::string::ToString for AnyOfProperty { + fn to_string(&self) -> String { + let mut params: Vec = vec![]; + // Skipping requiredAnyOf in query parameter serialization + + // Skipping optionalAnyOf in query parameter serialization + + params.join(",").to_string() + } +} + +/// Converts Query Parameters representation (style=form, explode=false) to a AnyOfProperty value +/// as specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde deserializer +impl std::str::FromStr for AnyOfProperty { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + #[derive(Default)] + // An intermediate representation of the struct to use for parsing. + struct IntermediateRep { + pub required_any_of: Vec, + pub optional_any_of: Vec, + } + + let mut intermediate_rep = IntermediateRep::default(); + + // Parse into intermediate representation + let mut string_iter = s.split(',').into_iter(); + let mut key_result = string_iter.next(); + + while key_result.is_some() { + let val = match string_iter.next() { + Some(x) => x, + None => return std::result::Result::Err("Missing value while parsing AnyOfProperty".to_string()) + }; + + if let Some(key) = key_result { + match key { + "requiredAnyOf" => intermediate_rep.required_any_of.push(::from_str(val).map_err(|x| format!("{}", x))?), + "optionalAnyOf" => intermediate_rep.optional_any_of.push(::from_str(val).map_err(|x| format!("{}", x))?), + _ => return std::result::Result::Err("Unexpected key while parsing AnyOfProperty".to_string()) + } + } + + // Get the next key + key_result = string_iter.next(); + } + + // Use the intermediate representation to return the struct + std::result::Result::Ok(AnyOfProperty { + required_any_of: intermediate_rep.required_any_of.into_iter().next().ok_or("requiredAnyOf missing in AnyOfProperty".to_string())?, + optional_any_of: intermediate_rep.optional_any_of.into_iter().next(), + }) + } +} + +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for DuplicateXmlObject - value: {} is invalid {}", + format!("Invalid header value for AnyOfProperty - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into DuplicateXmlObject - {}", + format!("Unable to convert header value '{}' into AnyOfProperty - {}", value, err)) } }, @@ -441,6 +675,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl AnyOfProperty { + /// 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") + } +} + +/// An XML object #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "camelDuplicateXmlObject")] @@ -510,8 +754,8 @@ impl std::str::FromStr for DuplicateXmlObject { if let Some(key) = key_result { match 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))?), + "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + "inner_array" => intermediate_rep.inner_array.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing DuplicateXmlObject".to_string()) } } @@ -528,6 +772,44 @@ impl std::str::FromStr for DuplicateXmlObject { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for DuplicateXmlObject - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into DuplicateXmlObject - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl DuplicateXmlObject { /// Associated constant for this model's XML namespace. @@ -555,7 +837,7 @@ impl DuplicateXmlObject { #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] -pub enum EnumWithStarObject { +pub enum EnumWithStarObject { #[serde(rename = "FOO")] FOO, #[serde(rename = "BAR")] @@ -566,7 +848,7 @@ pub enum EnumWithStarObject { impl std::fmt::Display for EnumWithStarObject { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { + match *self { EnumWithStarObject::FOO => write!(f, "{}", "FOO"), EnumWithStarObject::BAR => write!(f, "{}", "BAR"), EnumWithStarObject::STAR => write!(f, "{}", "*"), @@ -700,6 +982,82 @@ impl Error { } } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct InlineResponse201 { + #[serde(rename = "foo")] + #[serde(skip_serializing_if="Option::is_none")] + pub foo: Option, + +} + +impl InlineResponse201 { + pub fn new() -> InlineResponse201 { + InlineResponse201 { + foo: None, + } + } +} + +/// Converts the InlineResponse201 value to the Query Parameters representation (style=form, explode=false) +/// specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde serializer +impl std::string::ToString for InlineResponse201 { + fn to_string(&self) -> String { + let mut params: Vec = vec![]; + + if let Some(ref foo) = self.foo { + params.push("foo".to_string()); + params.push(foo.to_string()); + } + + params.join(",").to_string() + } +} + +/// Converts Query Parameters representation (style=form, explode=false) to a InlineResponse201 value +/// as specified in https://swagger.io/docs/specification/serialization/ +/// Should be implemented in a serde deserializer +impl std::str::FromStr for InlineResponse201 { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + #[derive(Default)] + // An intermediate representation of the struct to use for parsing. + struct IntermediateRep { + pub foo: Vec, + } + + let mut intermediate_rep = IntermediateRep::default(); + + // Parse into intermediate representation + let mut string_iter = s.split(',').into_iter(); + let mut key_result = string_iter.next(); + + while key_result.is_some() { + let val = match string_iter.next() { + Some(x) => x, + None => return std::result::Result::Err("Missing value while parsing InlineResponse201".to_string()) + }; + + if let Some(key) = key_result { + match key { + "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| format!("{}", x))?), + _ => return std::result::Result::Err("Unexpected key while parsing InlineResponse201".to_string()) + } + } + + // Get the next key + key_result = string_iter.next(); + } + + // Use the intermediate representation to return the struct + std::result::Result::Ok(InlineResponse201 { + foo: intermediate_rep.foo.into_iter().next(), + }) + } +} + // Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] @@ -739,50 +1097,48 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl InlineResponse201 { + /// 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") + } +} + +/// Test a model containing an anyOf that starts with a number #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] -pub struct InlineResponse201 { - #[serde(rename = "foo")] - #[serde(skip_serializing_if="Option::is_none")] - pub foo: Option, - +pub struct Model12345AnyOfObject { } -impl InlineResponse201 { - pub fn new() -> InlineResponse201 { - InlineResponse201 { - foo: None, +impl Model12345AnyOfObject { + pub fn new() -> Model12345AnyOfObject { + Model12345AnyOfObject { } } } -/// Converts the InlineResponse201 value to the Query Parameters representation (style=form, explode=false) +/// Converts the Model12345AnyOfObject value to the Query Parameters representation (style=form, explode=false) /// specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde serializer -impl std::string::ToString for InlineResponse201 { +impl std::string::ToString for Model12345AnyOfObject { fn to_string(&self) -> String { let mut params: Vec = vec![]; - - if let Some(ref foo) = self.foo { - params.push("foo".to_string()); - params.push(foo.to_string()); - } - params.join(",").to_string() } } -/// Converts Query Parameters representation (style=form, explode=false) to a InlineResponse201 value +/// Converts Query Parameters representation (style=form, explode=false) to a Model12345AnyOfObject value /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer -impl std::str::FromStr for InlineResponse201 { +impl std::str::FromStr for Model12345AnyOfObject { type Err = String; fn from_str(s: &str) -> std::result::Result { #[derive(Default)] // An intermediate representation of the struct to use for parsing. struct IntermediateRep { - pub foo: Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -794,13 +1150,12 @@ impl std::str::FromStr for InlineResponse201 { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing InlineResponse201".to_string()) + None => return std::result::Result::Err("Missing value while parsing Model12345AnyOfObject".to_string()) }; if let Some(key) = key_result { match key { - "foo" => intermediate_rep.foo.push(String::from_str(val).map_err(|x| format!("{}", x))?), - _ => return std::result::Result::Err("Unexpected key while parsing InlineResponse201".to_string()) + _ => return std::result::Result::Err("Unexpected key while parsing Model12345AnyOfObject".to_string()) } } @@ -809,14 +1164,99 @@ impl std::str::FromStr for InlineResponse201 { } // Use the intermediate representation to return the struct - std::result::Result::Ok(InlineResponse201 { - foo: intermediate_rep.foo.into_iter().next(), + std::result::Result::Ok(Model12345AnyOfObject { }) } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue -impl InlineResponse201 { +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for Model12345AnyOfObject - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into Model12345AnyOfObject - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + + +impl Model12345AnyOfObject { + /// 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") + } +} + +/// 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, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] +pub enum Model12345AnyOfObjectAnyOf { + #[serde(rename = "FOO")] + FOO, + #[serde(rename = "BAR")] + BAR, + #[serde(rename = "*")] + STAR, +} + +impl std::fmt::Display for Model12345AnyOfObjectAnyOf { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + Model12345AnyOfObjectAnyOf::FOO => write!(f, "{}", "FOO"), + Model12345AnyOfObjectAnyOf::BAR => write!(f, "{}", "BAR"), + Model12345AnyOfObjectAnyOf::STAR => write!(f, "{}", "*"), + } + } +} + +impl std::str::FromStr for Model12345AnyOfObjectAnyOf { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + match s { + "FOO" => std::result::Result::Ok(Model12345AnyOfObjectAnyOf::FOO), + "BAR" => std::result::Result::Ok(Model12345AnyOfObjectAnyOf::BAR), + "*" => std::result::Result::Ok(Model12345AnyOfObjectAnyOf::STAR), + _ => std::result::Result::Err(format!("Value not valid: {}", s)), + } + } +} + +impl Model12345AnyOfObjectAnyOf { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] @@ -835,7 +1275,6 @@ impl std::convert::From for MyId { } } - impl std::convert::From for i32 { fn from(x: MyId) -> Self { x.0 @@ -865,44 +1304,6 @@ impl MyId { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MyIdList - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MyIdList - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MyIdList( @@ -993,43 +1394,34 @@ impl std::str::FromStr for MyIdList { } -impl MyIdList { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for NullableTest - value: {} is invalid {}", + format!("Invalid header value for MyIdList - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into NullableTest - {}", + format!("Unable to convert header value '{}' into MyIdList - {}", value, err)) } }, @@ -1041,6 +1433,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl MyIdList { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct NullableTest { @@ -1178,44 +1579,34 @@ impl std::str::FromStr for NullableTest { } } - -impl NullableTest { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectHeader - value: {} is invalid {}", + format!("Invalid header value for NullableTest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectHeader - {}", + format!("Unable to convert header value '{}' into NullableTest - {}", value, err)) } }, @@ -1227,6 +1618,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl NullableTest { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectHeader { @@ -1296,8 +1696,8 @@ impl std::str::FromStr for ObjectHeader { if let Some(key) = key_result { match 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))?), + "requiredObjectHeader" => intermediate_rep.required_object_header.push(::from_str(val).map_err(|x| format!("{}", x))?), + "optionalObjectHeader" => intermediate_rep.optional_object_header.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectHeader".to_string()) } } @@ -1314,44 +1714,34 @@ impl std::str::FromStr for ObjectHeader { } } - -impl ObjectHeader { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectParam - value: {} is invalid {}", + format!("Invalid header value for ObjectHeader - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectParam - {}", + format!("Unable to convert header value '{}' into ObjectHeader - {}", value, err)) } }, @@ -1363,6 +1753,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ObjectHeader { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectParam { @@ -1432,8 +1831,8 @@ impl std::str::FromStr for ObjectParam { if let Some(key) = key_result { match 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))?), + "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| format!("{}", x))?), + "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string()) } } @@ -1442,52 +1841,42 @@ impl std::str::FromStr for ObjectParam { key_result = string_iter.next(); } - // Use the intermediate representation to return the struct - std::result::Result::Ok(ObjectParam { - 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(), - }) - } -} - - -impl ObjectParam { - /// 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") + // Use the intermediate representation to return the struct + std::result::Result::Ok(ObjectParam { + 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(), + }) } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectUntypedProps - value: {} is invalid {}", + format!("Invalid header value for ObjectParam - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectUntypedProps - {}", + format!("Unable to convert header value '{}' into ObjectParam - {}", value, err)) } }, @@ -1499,6 +1888,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ObjectParam { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectUntypedProps { @@ -1577,10 +1975,10 @@ impl std::str::FromStr for ObjectUntypedProps { if let Some(key) = key_result { match key { - "required_untyped" => intermediate_rep.required_untyped.push(serde_json::Value::from_str(val).map_err(|x| format!("{}", x))?), + "required_untyped" => intermediate_rep.required_untyped.push(::from_str(val).map_err(|x| format!("{}", x))?), "required_untyped_nullable" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in ObjectUntypedProps".to_string()), - "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))?), + "not_required_untyped" => intermediate_rep.not_required_untyped.push(::from_str(val).map_err(|x| format!("{}", x))?), + "not_required_untyped_nullable" => intermediate_rep.not_required_untyped_nullable.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectUntypedProps".to_string()) } } @@ -1599,44 +1997,34 @@ impl std::str::FromStr for ObjectUntypedProps { } } - -impl ObjectUntypedProps { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectWithArrayOfObjects - value: {} is invalid {}", + format!("Invalid header value for ObjectUntypedProps - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectWithArrayOfObjects - {}", + format!("Unable to convert header value '{}' into ObjectUntypedProps - {}", value, err)) } }, @@ -1648,6 +2036,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ObjectUntypedProps { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectWithArrayOfObjects { @@ -1724,6 +2121,44 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for ObjectWithArrayOfObjects - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into ObjectWithArrayOfObjects - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl ObjectWithArrayOfObjects { /// Helper function to allow us to convert this model to an XML string. @@ -1796,7 +2231,6 @@ impl std::convert::From for OptionalObjectHeader { } } - impl std::convert::From for i32 { fn from(x: OptionalObjectHeader) -> Self { x.0 @@ -1836,7 +2270,6 @@ impl std::convert::From for RequiredObjectHeader { } } - impl std::convert::From for bool { fn from(x: RequiredObjectHeader) -> Self { x.0 @@ -1925,7 +2358,7 @@ impl Result { #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] -pub enum StringEnum { +pub enum StringEnum { #[serde(rename = "FOO")] FOO, #[serde(rename = "BAR")] @@ -1934,7 +2367,7 @@ pub enum StringEnum { impl std::fmt::Display for StringEnum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { + match *self { StringEnum::FOO => write!(f, "{}", "FOO"), StringEnum::BAR => write!(f, "{}", "BAR"), } @@ -2025,7 +2458,6 @@ impl std::convert::From for UuidObject { } } - impl std::convert::From for uuid::Uuid { fn from(x: UuidObject) -> Self { x.0 @@ -2055,44 +2487,6 @@ impl UuidObject { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for XmlArray - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into XmlArray - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - // Utility function for wrapping list elements when serializing xml #[allow(non_snake_case)] fn wrap_in_camelXmlInner(item: &Vec, serializer: S) -> std::result::Result @@ -2193,6 +2587,45 @@ impl std::str::FromStr for XmlArray { } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for XmlArray - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into XmlArray - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + + impl XmlArray { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. @@ -2256,45 +2689,6 @@ impl XmlInner { } /// An XML object -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for XmlObject - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into XmlObject - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "camelXmlObject")] @@ -2368,8 +2762,8 @@ impl std::str::FromStr for XmlObject { if let Some(key) = key_result { match 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))?), + "innerString" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + "other_inner_rename" => intermediate_rep.other_inner_rename.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing XmlObject".to_string()) } } @@ -2386,6 +2780,44 @@ impl std::str::FromStr for XmlObject { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for XmlObject - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into XmlObject - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl XmlObject { /// Associated constant for this model's XML namespace. 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 eb6ca9839322..ec6863b8bd3d 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 @@ -22,6 +22,7 @@ pub use crate::context; type ServiceFuture = BoxFuture<'static, Result, crate::ServiceError>>; use crate::{Api, + AnyOfGetResponse, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, EnumInPathPathParamGetResponse, @@ -30,6 +31,7 @@ use crate::{Api, MergePatchJsonGetResponse, MultigetGetResponse, MultipleAuthSchemeGetResponse, + OneOfGetResponse, OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, @@ -55,6 +57,7 @@ mod paths { lazy_static! { pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(vec![ + r"^/any-of$", r"^/callback-with-header$", r"^/complex-query-param$", r"^/enum_in_path/(?P[^/?#]*)$", @@ -63,6 +66,7 @@ mod paths { r"^/merge-patch-json$", r"^/multiget$", r"^/multiple_auth_scheme$", + r"^/one-of$", r"^/override-server$", r"^/paramget$", r"^/readonly_auth_scheme$", @@ -80,38 +84,40 @@ mod paths { ]) .expect("Unable to create global regex set"); } - pub(crate) static ID_CALLBACK_WITH_HEADER: usize = 0; - pub(crate) static ID_COMPLEX_QUERY_PARAM: usize = 1; - pub(crate) static ID_ENUM_IN_PATH_PATH_PARAM: usize = 2; + pub(crate) static ID_ANY_OF: usize = 0; + pub(crate) static ID_CALLBACK_WITH_HEADER: usize = 1; + pub(crate) static ID_COMPLEX_QUERY_PARAM: usize = 2; + pub(crate) static ID_ENUM_IN_PATH_PATH_PARAM: usize = 3; 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(crate) static ID_JSON_COMPLEX_QUERY_PARAM: usize = 3; - pub(crate) static ID_MANDATORY_REQUEST_HEADER: usize = 4; - pub(crate) static ID_MERGE_PATCH_JSON: usize = 5; - pub(crate) static ID_MULTIGET: usize = 6; - pub(crate) static ID_MULTIPLE_AUTH_SCHEME: usize = 7; - pub(crate) static ID_OVERRIDE_SERVER: usize = 8; - pub(crate) static ID_PARAMGET: usize = 9; - pub(crate) static ID_READONLY_AUTH_SCHEME: usize = 10; - pub(crate) static ID_REGISTER_CALLBACK: usize = 11; - pub(crate) static ID_REPOS: usize = 12; - pub(crate) static ID_REPOS_REPOID: usize = 13; + pub(crate) static ID_JSON_COMPLEX_QUERY_PARAM: usize = 4; + pub(crate) static ID_MANDATORY_REQUEST_HEADER: usize = 5; + pub(crate) static ID_MERGE_PATCH_JSON: usize = 6; + pub(crate) static ID_MULTIGET: usize = 7; + pub(crate) static ID_MULTIPLE_AUTH_SCHEME: usize = 8; + pub(crate) static ID_ONE_OF: usize = 9; + pub(crate) static ID_OVERRIDE_SERVER: usize = 10; + pub(crate) static ID_PARAMGET: usize = 11; + pub(crate) static ID_READONLY_AUTH_SCHEME: usize = 12; + pub(crate) static ID_REGISTER_CALLBACK: usize = 13; + pub(crate) static ID_REPOS: usize = 14; + pub(crate) static ID_REPOS_REPOID: usize = 15; lazy_static! { pub static ref REGEX_REPOS_REPOID: regex::Regex = regex::Regex::new(r"^/repos/(?P[^/?#]*)$") .expect("Unable to create regex for REPOS_REPOID"); } - pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 14; - pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 15; - pub(crate) static ID_RFC7807: usize = 16; - pub(crate) static ID_UNTYPED_PROPERTY: usize = 17; - pub(crate) static ID_UUID: usize = 18; - pub(crate) static ID_XML: usize = 19; - pub(crate) static ID_XML_EXTRA: usize = 20; - pub(crate) static ID_XML_OTHER: usize = 21; + pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 16; + pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 17; + pub(crate) static ID_RFC7807: usize = 18; + pub(crate) static ID_UNTYPED_PROPERTY: usize = 19; + pub(crate) static ID_UUID: usize = 20; + pub(crate) static ID_XML: usize = 21; + pub(crate) static ID_XML_EXTRA: usize = 22; + pub(crate) static ID_XML_OTHER: usize = 23; } pub struct MakeService where @@ -216,6 +222,76 @@ impl hyper::service::Service<(Request, C)> for Service where match &method { + // AnyOfGet - GET /any-of + &hyper::Method::GET if path.matched(paths::ID_ANY_OF) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); + let param_any_of = query_params.iter().filter(|e| e.0 == "any-of").map(|e| e.1.to_owned()) + .filter_map(|param_any_of| param_any_of.parse().ok()) + .collect::>(); + let param_any_of = if !param_any_of.is_empty() { + Some(param_any_of) + } else { + None + }; + + let result = api_impl.any_of_get( + param_any_of.as_ref(), + &context + ).await; + 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 { + AnyOfGetResponse::Success + (body) + => { + *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for ANY_OF_GET_SUCCESS")); + let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + }, + AnyOfGetResponse::AlternateSuccess + (body) + => { + *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for ANY_OF_GET_ALTERNATE_SUCCESS")); + let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + }, + AnyOfGetResponse::AnyOfSuccess + (body) + => { + *response.status_mut() = StatusCode::from_u16(202).expect("Unable to turn 202 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for ANY_OF_GET_ANY_OF_SUCCESS")); + let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + }, + }, + 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"); + }, + } + + Ok(response) + }, + // CallbackWithHeaderPost - POST /callback-with-header &hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) @@ -667,6 +743,42 @@ impl hyper::service::Service<(Request, C)> for Service where Ok(response) }, + // OneOfGet - GET /one-of + &hyper::Method::GET if path.matched(paths::ID_ONE_OF) => { + let result = api_impl.one_of_get( + &context + ).await; + 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 { + OneOfGetResponse::Success + (body) + => { + *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json") + .expect("Unable to create Content-Type header for ONE_OF_GET_SUCCESS")); + let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + }, + }, + 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"); + }, + } + + Ok(response) + }, + // OverrideServerGet - GET /override-server &hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => { let result = api_impl.override_server_get( @@ -1722,6 +1834,7 @@ impl hyper::service::Service<(Request, C)> for Service where Ok(response) }, + _ if path.matched(paths::ID_ANY_OF) => method_not_allowed(), _ if path.matched(paths::ID_CALLBACK_WITH_HEADER) => method_not_allowed(), _ if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => method_not_allowed(), _ if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => method_not_allowed(), @@ -1730,6 +1843,7 @@ impl hyper::service::Service<(Request, C)> for Service where _ if path.matched(paths::ID_MERGE_PATCH_JSON) => method_not_allowed(), _ if path.matched(paths::ID_MULTIGET) => method_not_allowed(), _ if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => method_not_allowed(), + _ if path.matched(paths::ID_ONE_OF) => method_not_allowed(), _ if path.matched(paths::ID_OVERRIDE_SERVER) => method_not_allowed(), _ if path.matched(paths::ID_PARAMGET) => method_not_allowed(), _ if path.matched(paths::ID_READONLY_AUTH_SCHEME) => method_not_allowed(), @@ -1757,6 +1871,8 @@ impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Result<&'static str, ()> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); match request.method() { + // AnyOfGet - GET /any-of + &hyper::Method::GET if path.matched(paths::ID_ANY_OF) => Ok("AnyOfGet"), // CallbackWithHeaderPost - POST /callback-with-header &hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Ok("CallbackWithHeaderPost"), // ComplexQueryParamGet - GET /complex-query-param @@ -1773,6 +1889,8 @@ impl RequestParser for ApiRequestParser { &hyper::Method::GET if path.matched(paths::ID_MULTIGET) => Ok("MultigetGet"), // MultipleAuthSchemeGet - GET /multiple_auth_scheme &hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => Ok("MultipleAuthSchemeGet"), + // OneOfGet - GET /one-of + &hyper::Method::GET if path.matched(paths::ID_ONE_OF) => Ok("OneOfGet"), // OverrideServerGet - GET /override-server &hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => Ok("OverrideServerGet"), // ParamgetGet - GET /paramget diff --git a/samples/server/petstore/rust-server/output/ops-v3/src/models.rs b/samples/server/petstore/rust-server/output/ops-v3/src/models.rs index aaf4182a33e3..cf82e33947d3 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/src/models.rs @@ -3,4 +3,3 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - 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 12dd045e2160..1c4d90d71d82 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 @@ -4,46 +4,6 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AdditionalPropertiesClass - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AdditionalPropertiesClass - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AdditionalPropertiesClass { @@ -127,44 +87,34 @@ impl std::str::FromStr for AdditionalPropertiesClass { } } - -impl AdditionalPropertiesClass { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Animal - value: {} is invalid {}", + format!("Invalid header value for AdditionalPropertiesClass - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Animal - {}", + format!("Unable to convert header value '{}' into AdditionalPropertiesClass - {}", value, err)) } }, @@ -176,6 +126,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl AdditionalPropertiesClass { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Animal { @@ -245,8 +204,8 @@ impl std::str::FromStr for Animal { if let Some(key) = key_result { match 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))?), + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Animal".to_string()) } } @@ -263,44 +222,34 @@ impl std::str::FromStr for Animal { } } - -impl Animal { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnimalFarm - value: {} is invalid {}", + format!("Invalid header value for Animal - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnimalFarm - {}", + format!("Unable to convert header value '{}' into Animal - {}", value, err)) } }, @@ -311,6 +260,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } } + +impl Animal { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnimalFarm( @@ -401,43 +360,34 @@ impl std::str::FromStr for AnimalFarm { } -impl AnimalFarm { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ApiResponse - value: {} is invalid {}", + format!("Invalid header value for AnimalFarm - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ApiResponse - {}", + format!("Unable to convert header value '{}' into AnimalFarm - {}", value, err)) } }, @@ -449,6 +399,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl AnimalFarm { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ApiResponse { @@ -533,9 +492,9 @@ impl std::str::FromStr for ApiResponse { if let Some(key) = key_result { match 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))?), + "code" => intermediate_rep.code.push(::from_str(val).map_err(|x| format!("{}", x))?), + "type" => intermediate_rep.type_.push(::from_str(val).map_err(|x| format!("{}", x))?), + "message" => intermediate_rep.message.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ApiResponse".to_string()) } } @@ -553,44 +512,34 @@ impl std::str::FromStr for ApiResponse { } } - -impl ApiResponse { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayOfArrayOfNumberOnly - value: {} is invalid {}", + format!("Invalid header value for ApiResponse - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayOfArrayOfNumberOnly - {}", + format!("Unable to convert header value '{}' into ApiResponse - {}", value, err)) } }, @@ -602,6 +551,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ApiResponse { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayOfArrayOfNumberOnly { @@ -674,44 +632,34 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { } } - -impl ArrayOfArrayOfNumberOnly { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayOfNumberOnly - value: {} is invalid {}", + format!("Invalid header value for ArrayOfArrayOfNumberOnly - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayOfNumberOnly - {}", + format!("Unable to convert header value '{}' into ArrayOfArrayOfNumberOnly - {}", value, err)) } }, @@ -723,6 +671,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ArrayOfArrayOfNumberOnly { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayOfNumberOnly { @@ -799,44 +756,34 @@ impl std::str::FromStr for ArrayOfNumberOnly { } } - -impl ArrayOfNumberOnly { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayTest - value: {} is invalid {}", + format!("Invalid header value for ArrayOfNumberOnly - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayTest - {}", + format!("Unable to convert header value '{}' into ArrayOfNumberOnly - {}", value, err)) } }, @@ -848,6 +795,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ArrayOfNumberOnly { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayTest { @@ -959,44 +915,34 @@ impl std::str::FromStr for ArrayTest { } } - -impl ArrayTest { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Capitalization - value: {} is invalid {}", + format!("Invalid header value for ArrayTest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Capitalization - {}", + format!("Unable to convert header value '{}' into ArrayTest - {}", value, err)) } }, @@ -1008,6 +954,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ArrayTest { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Capitalization { @@ -1129,12 +1084,12 @@ impl std::str::FromStr for Capitalization { if let Some(key) = key_result { match 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))?), + "smallCamel" => intermediate_rep.small_camel.push(::from_str(val).map_err(|x| format!("{}", x))?), + "CapitalCamel" => intermediate_rep.capital_camel.push(::from_str(val).map_err(|x| format!("{}", x))?), + "small_Snake" => intermediate_rep.small_snake.push(::from_str(val).map_err(|x| format!("{}", x))?), + "Capital_Snake" => intermediate_rep.capital_snake.push(::from_str(val).map_err(|x| format!("{}", x))?), + "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(::from_str(val).map_err(|x| format!("{}", x))?), + "ATT_NAME" => intermediate_rep.att_name.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Capitalization".to_string()) } } @@ -1155,44 +1110,34 @@ impl std::str::FromStr for Capitalization { } } - -impl Capitalization { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Cat - value: {} is invalid {}", + format!("Invalid header value for Capitalization - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Cat - {}", + format!("Unable to convert header value '{}' into Capitalization - {}", value, err)) } }, @@ -1204,6 +1149,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Capitalization { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Cat { @@ -1285,9 +1239,9 @@ impl std::str::FromStr for Cat { if let Some(key) = key_result { match 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))?), + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), + "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Cat".to_string()) } } @@ -1305,44 +1259,34 @@ impl std::str::FromStr for Cat { } } - -impl Cat { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for CatAllOf - value: {} is invalid {}", + format!("Invalid header value for Cat - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into CatAllOf - {}", + format!("Unable to convert header value '{}' into Cat - {}", value, err)) } }, @@ -1354,6 +1298,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Cat { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct CatAllOf { @@ -1414,7 +1367,7 @@ impl std::str::FromStr for CatAllOf { if let Some(key) = key_result { match key { - "declawed" => intermediate_rep.declawed.push(bool::from_str(val).map_err(|x| format!("{}", x))?), + "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing CatAllOf".to_string()) } } @@ -1430,44 +1383,34 @@ impl std::str::FromStr for CatAllOf { } } - -impl CatAllOf { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Category - value: {} is invalid {}", + format!("Invalid header value for CatAllOf - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Category - {}", + format!("Unable to convert header value '{}' into CatAllOf - {}", value, err)) } }, @@ -1479,6 +1422,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl CatAllOf { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Category")] @@ -1552,8 +1504,8 @@ impl std::str::FromStr for Category { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Category".to_string()) } } @@ -1570,45 +1522,34 @@ impl std::str::FromStr for Category { } } - -impl Category { - /// 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") - } -} - -/// Model for testing model with \"_class\" property -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ClassModel - value: {} is invalid {}", + format!("Invalid header value for Category - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ClassModel - {}", + format!("Unable to convert header value '{}' into Category - {}", value, err)) } }, @@ -1620,6 +1561,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Category { + /// 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") + } +} + +/// Model for testing model with \"_class\" property #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ClassModel { @@ -1680,7 +1631,7 @@ impl std::str::FromStr for ClassModel { if let Some(key) = key_result { match key { - "_class" => intermediate_rep._class.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "_class" => intermediate_rep._class.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ClassModel".to_string()) } } @@ -1696,44 +1647,34 @@ impl std::str::FromStr for ClassModel { } } - -impl ClassModel { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Client - value: {} is invalid {}", + format!("Invalid header value for ClassModel - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Client - {}", + format!("Unable to convert header value '{}' into ClassModel - {}", value, err)) } }, @@ -1745,6 +1686,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ClassModel { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Client { @@ -1805,7 +1755,7 @@ impl std::str::FromStr for Client { if let Some(key) = key_result { match key { - "client" => intermediate_rep.client.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "client" => intermediate_rep.client.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Client".to_string()) } } @@ -1821,44 +1771,34 @@ impl std::str::FromStr for Client { } } - -impl Client { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Dog - value: {} is invalid {}", + format!("Invalid header value for Client - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Dog - {}", + format!("Unable to convert header value '{}' into Client - {}", value, err)) } }, @@ -1870,6 +1810,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Client { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Dog { @@ -1951,9 +1900,9 @@ impl std::str::FromStr for Dog { if let Some(key) = key_result { match 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))?), + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), + "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Dog".to_string()) } } @@ -1971,44 +1920,34 @@ impl std::str::FromStr for Dog { } } - -impl Dog { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for DogAllOf - value: {} is invalid {}", + format!("Invalid header value for Dog - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into DogAllOf - {}", + format!("Unable to convert header value '{}' into Dog - {}", value, err)) } }, @@ -2020,6 +1959,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Dog { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct DogAllOf { @@ -2080,7 +2028,7 @@ impl std::str::FromStr for DogAllOf { if let Some(key) = key_result { match key { - "breed" => intermediate_rep.breed.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing DogAllOf".to_string()) } } @@ -2096,44 +2044,34 @@ impl std::str::FromStr for DogAllOf { } } - -impl DogAllOf { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for EnumArrays - value: {} is invalid {}", + format!("Invalid header value for DogAllOf - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into EnumArrays - {}", + format!("Unable to convert header value '{}' into DogAllOf - {}", value, err)) } }, @@ -2145,6 +2083,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl DogAllOf { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct EnumArrays { @@ -2228,7 +2175,7 @@ impl std::str::FromStr for EnumArrays { if let Some(key) = key_result { match key { - "just_symbol" => intermediate_rep.just_symbol.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "just_symbol" => intermediate_rep.just_symbol.push(::from_str(val).map_err(|x| format!("{}", x))?), "array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), "array_array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing EnumArrays".to_string()) @@ -2248,6 +2195,44 @@ impl std::str::FromStr for EnumArrays { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for EnumArrays - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into EnumArrays - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl EnumArrays { /// Helper function to allow us to convert this model to an XML string. @@ -2265,7 +2250,7 @@ impl EnumArrays { #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] -pub enum EnumClass { +pub enum EnumClass { #[serde(rename = "_abc")] _ABC, #[serde(rename = "-efg")] @@ -2276,7 +2261,7 @@ pub enum EnumClass { impl std::fmt::Display for EnumClass { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { + match *self { EnumClass::_ABC => write!(f, "{}", "_abc"), EnumClass::_EFG => write!(f, "{}", "-efg"), EnumClass::_XYZ_ => write!(f, "{}", "(xyz)"), @@ -2306,45 +2291,6 @@ impl EnumClass { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for EnumTest - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into EnumTest - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct EnumTest { @@ -2450,11 +2396,11 @@ impl std::str::FromStr for EnumTest { if let Some(key) = key_result { match 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))?), + "enum_string" => intermediate_rep.enum_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + "enum_string_required" => intermediate_rep.enum_string_required.push(::from_str(val).map_err(|x| format!("{}", x))?), + "enum_integer" => intermediate_rep.enum_integer.push(::from_str(val).map_err(|x| format!("{}", x))?), + "enum_number" => intermediate_rep.enum_number.push(::from_str(val).map_err(|x| format!("{}", x))?), + "outerEnum" => intermediate_rep.outer_enum.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing EnumTest".to_string()) } } @@ -2474,44 +2420,34 @@ impl std::str::FromStr for EnumTest { } } - -impl EnumTest { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for FormatTest - value: {} is invalid {}", + format!("Invalid header value for EnumTest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into FormatTest - {}", + format!("Unable to convert header value '{}' into EnumTest - {}", value, err)) } }, @@ -2523,6 +2459,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl EnumTest { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct FormatTest { @@ -2701,19 +2646,19 @@ impl std::str::FromStr for FormatTest { if let Some(key) = key_result { match 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))?), + "integer" => intermediate_rep.integer.push(::from_str(val).map_err(|x| format!("{}", x))?), + "int32" => intermediate_rep.int32.push(::from_str(val).map_err(|x| format!("{}", x))?), + "int64" => intermediate_rep.int64.push(::from_str(val).map_err(|x| format!("{}", x))?), + "number" => intermediate_rep.number.push(::from_str(val).map_err(|x| format!("{}", x))?), + "float" => intermediate_rep.float.push(::from_str(val).map_err(|x| format!("{}", x))?), + "double" => intermediate_rep.double.push(::from_str(val).map_err(|x| format!("{}", x))?), + "string" => intermediate_rep.string.push(::from_str(val).map_err(|x| format!("{}", x))?), "byte" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), "binary" => return std::result::Result::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))?), + "date" => intermediate_rep.date.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), + "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), + "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| format!("{}", x))?), + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing FormatTest".to_string()) } } @@ -2741,44 +2686,34 @@ impl std::str::FromStr for FormatTest { } } - -impl FormatTest { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for HasOnlyReadOnly - value: {} is invalid {}", + format!("Invalid header value for FormatTest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into HasOnlyReadOnly - {}", + format!("Unable to convert header value '{}' into FormatTest - {}", value, err)) } }, @@ -2790,6 +2725,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl FormatTest { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct HasOnlyReadOnly { @@ -2862,8 +2806,8 @@ impl std::str::FromStr for HasOnlyReadOnly { if let Some(key) = key_result { match 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))?), + "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| format!("{}", x))?), + "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing HasOnlyReadOnly".to_string()) } } @@ -2880,44 +2824,34 @@ impl std::str::FromStr for HasOnlyReadOnly { } } - -impl HasOnlyReadOnly { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for List - value: {} is invalid {}", + format!("Invalid header value for HasOnlyReadOnly - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into List - {}", + format!("Unable to convert header value '{}' into HasOnlyReadOnly - {}", value, err)) } }, @@ -2929,6 +2863,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl HasOnlyReadOnly { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct List { @@ -2989,7 +2932,7 @@ impl std::str::FromStr for List { if let Some(key) = key_result { match key { - "123-list" => intermediate_rep.param_123_list.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "123-list" => intermediate_rep.param_123_list.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing List".to_string()) } } @@ -3005,44 +2948,34 @@ impl std::str::FromStr for List { } } - -impl List { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MapTest - value: {} is invalid {}", + format!("Invalid header value for List - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MapTest - {}", + format!("Unable to convert header value '{}' into List - {}", value, err)) } }, @@ -3054,6 +2987,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl List { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MapTest { @@ -3150,44 +3092,34 @@ impl std::str::FromStr for MapTest { } } - -impl MapTest { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MixedPropertiesAndAdditionalPropertiesClass - value: {} is invalid {}", + format!("Invalid header value for MapTest - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MixedPropertiesAndAdditionalPropertiesClass - {}", + format!("Unable to convert header value '{}' into MapTest - {}", value, err)) } }, @@ -3199,6 +3131,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl MapTest { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MixedPropertiesAndAdditionalPropertiesClass { @@ -3272,8 +3213,8 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { if let Some(key) = key_result { match 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))?), + "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| format!("{}", x))?), + "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), "map" => return std::result::Result::Err("Parsing a container in this style is not supported in MixedPropertiesAndAdditionalPropertiesClass".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MixedPropertiesAndAdditionalPropertiesClass".to_string()) } @@ -3292,45 +3233,34 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { } } - -impl MixedPropertiesAndAdditionalPropertiesClass { - /// 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") - } -} - -/// Model for testing model name starting with number -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Model200Response - value: {} is invalid {}", + format!("Invalid header value for MixedPropertiesAndAdditionalPropertiesClass - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Model200Response - {}", + format!("Unable to convert header value '{}' into MixedPropertiesAndAdditionalPropertiesClass - {}", value, err)) } }, @@ -3342,6 +3272,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl MixedPropertiesAndAdditionalPropertiesClass { + /// 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") + } +} + +/// Model for testing model name starting with number #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Name")] @@ -3415,8 +3355,8 @@ impl std::str::FromStr for Model200Response { if let Some(key) = key_result { match 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))?), + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "class" => intermediate_rep.class.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Model200Response".to_string()) } } @@ -3433,45 +3373,34 @@ impl std::str::FromStr for Model200Response { } } - -impl Model200Response { - /// 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") - } -} - -/// Model for testing reserved words -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ModelReturn - value: {} is invalid {}", + format!("Invalid header value for Model200Response - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ModelReturn - {}", + format!("Unable to convert header value '{}' into Model200Response - {}", value, err)) } }, @@ -3483,6 +3412,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Model200Response { + /// 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") + } +} + +/// Model for testing reserved words #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Return")] @@ -3544,7 +3483,7 @@ impl std::str::FromStr for ModelReturn { if let Some(key) = key_result { match key { - "return" => intermediate_rep.return_.push(i32::from_str(val).map_err(|x| format!("{}", x))?), + "return" => intermediate_rep.return_.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ModelReturn".to_string()) } } @@ -3560,45 +3499,34 @@ impl std::str::FromStr for ModelReturn { } } - -impl ModelReturn { - /// 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") - } -} - -/// Model for testing model name same as property name -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Name - value: {} is invalid {}", + format!("Invalid header value for ModelReturn - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Name - {}", + format!("Unable to convert header value '{}' into ModelReturn - {}", value, err)) } }, @@ -3610,6 +3538,16 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ModelReturn { + /// 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") + } +} + +/// Model for testing model name same as property name #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Name")] @@ -3704,10 +3642,10 @@ impl std::str::FromStr for Name { if let Some(key) = key_result { match 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))?), + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "snake_case" => intermediate_rep.snake_case.push(::from_str(val).map_err(|x| format!("{}", x))?), + "property" => intermediate_rep.property.push(::from_str(val).map_err(|x| format!("{}", x))?), + "123Number" => intermediate_rep.param_123_number.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Name".to_string()) } } @@ -3726,44 +3664,34 @@ impl std::str::FromStr for Name { } } - -impl Name { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for NumberOnly - value: {} is invalid {}", + format!("Invalid header value for Name - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into NumberOnly - {}", + format!("Unable to convert header value '{}' into Name - {}", value, err)) } }, @@ -3775,6 +3703,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Name { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct NumberOnly { @@ -3835,7 +3772,7 @@ impl std::str::FromStr for NumberOnly { if let Some(key) = key_result { match key { - "JustNumber" => intermediate_rep.just_number.push(f64::from_str(val).map_err(|x| format!("{}", x))?), + "JustNumber" => intermediate_rep.just_number.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing NumberOnly".to_string()) } } @@ -3851,44 +3788,34 @@ impl std::str::FromStr for NumberOnly { } } - -impl NumberOnly { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectContainingObjectWithOnlyAdditionalProperties - value: {} is invalid {}", + format!("Invalid header value for NumberOnly - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectContainingObjectWithOnlyAdditionalProperties - {}", + format!("Unable to convert header value '{}' into NumberOnly - {}", value, err)) } }, @@ -3900,6 +3827,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl NumberOnly { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectContainingObjectWithOnlyAdditionalProperties { @@ -3956,7 +3892,7 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { if let Some(key) = key_result { match key { - "inner" => intermediate_rep.inner.push(models::ObjectWithOnlyAdditionalProperties::from_str(val).map_err(|x| format!("{}", x))?), + "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectContainingObjectWithOnlyAdditionalProperties".to_string()) } } @@ -3972,6 +3908,44 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for ObjectContainingObjectWithOnlyAdditionalProperties - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into ObjectContainingObjectWithOnlyAdditionalProperties - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl ObjectContainingObjectWithOnlyAdditionalProperties { /// Helper function to allow us to convert this model to an XML string. @@ -3992,7 +3966,6 @@ impl std::convert::From> for ObjectWit } } - impl std::convert::From for std::collections::HashMap { fn from(x: ObjectWithOnlyAdditionalProperties) -> Self { x.0 @@ -4042,45 +4015,6 @@ impl ObjectWithOnlyAdditionalProperties { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Order - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Order - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Order")] @@ -4200,12 +4134,12 @@ impl std::str::FromStr for Order { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "petId" => intermediate_rep.pet_id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "quantity" => intermediate_rep.quantity.push(::from_str(val).map_err(|x| format!("{}", x))?), + "shipDate" => intermediate_rep.ship_date.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), + "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| format!("{}", x))?), + "complete" => intermediate_rep.complete.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Order".to_string()) } } @@ -4226,6 +4160,44 @@ impl std::str::FromStr for Order { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for Order - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into Order - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl Order { /// Helper function to allow us to convert this model to an XML string. @@ -4246,7 +4218,6 @@ impl std::convert::From for OuterBoolean { } } - impl std::convert::From for bool { fn from(x: OuterBoolean) -> Self { x.0 @@ -4266,55 +4237,16 @@ impl std::ops::DerefMut for OuterBoolean { } } - -impl OuterBoolean { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for OuterComposite - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into OuterComposite - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } + +impl OuterBoolean { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OuterComposite { @@ -4399,9 +4331,9 @@ impl std::str::FromStr for OuterComposite { if let Some(key) = key_result { match 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))?), + "my_number" => intermediate_rep.my_number.push(::from_str(val).map_err(|x| format!("{}", x))?), + "my_string" => intermediate_rep.my_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + "my_boolean" => intermediate_rep.my_boolean.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing OuterComposite".to_string()) } } @@ -4419,6 +4351,44 @@ impl std::str::FromStr for OuterComposite { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for OuterComposite - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into OuterComposite - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl OuterComposite { /// Helper function to allow us to convert this model to an XML string. @@ -4436,7 +4406,7 @@ impl OuterComposite { #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] -pub enum OuterEnum { +pub enum OuterEnum { #[serde(rename = "placed")] PLACED, #[serde(rename = "approved")] @@ -4447,7 +4417,7 @@ pub enum OuterEnum { impl std::fmt::Display for OuterEnum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { + match *self { OuterEnum::PLACED => write!(f, "{}", "placed"), OuterEnum::APPROVED => write!(f, "{}", "approved"), OuterEnum::DELIVERED => write!(f, "{}", "delivered"), @@ -4487,7 +4457,6 @@ impl std::convert::From for OuterNumber { } } - impl std::convert::From for f64 { fn from(x: OuterNumber) -> Self { x.0 @@ -4569,45 +4538,6 @@ impl OuterString { } } -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Pet - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Pet - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Pet")] @@ -4717,12 +4647,12 @@ impl std::str::FromStr for Pet { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "category" => intermediate_rep.category.push(::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), "photoUrls" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), "tags" => return std::result::Result::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))?), + "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Pet".to_string()) } } @@ -4743,44 +4673,34 @@ impl std::str::FromStr for Pet { } } - -impl Pet { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ReadOnlyFirst - value: {} is invalid {}", + format!("Invalid header value for Pet - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ReadOnlyFirst - {}", + format!("Unable to convert header value '{}' into Pet - {}", value, err)) } }, @@ -4792,6 +4712,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Pet { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ReadOnlyFirst { @@ -4864,8 +4793,8 @@ impl std::str::FromStr for ReadOnlyFirst { if let Some(key) = key_result { match 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))?), + "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| format!("{}", x))?), + "baz" => intermediate_rep.baz.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ReadOnlyFirst".to_string()) } } @@ -4882,44 +4811,34 @@ impl std::str::FromStr for ReadOnlyFirst { } } - -impl ReadOnlyFirst { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for SpecialModelName - value: {} is invalid {}", + format!("Invalid header value for ReadOnlyFirst - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into SpecialModelName - {}", + format!("Unable to convert header value '{}' into ReadOnlyFirst - {}", value, err)) } }, @@ -4931,6 +4850,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl ReadOnlyFirst { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "$special[model.name]")] @@ -4992,7 +4920,7 @@ impl std::str::FromStr for SpecialModelName { if let Some(key) = key_result { match key { - "$special[property.name]" => intermediate_rep.special_property_name.push(i64::from_str(val).map_err(|x| format!("{}", x))?), + "$special[property.name]" => intermediate_rep.special_property_name.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing SpecialModelName".to_string()) } } @@ -5008,44 +4936,34 @@ impl std::str::FromStr for SpecialModelName { } } - -impl SpecialModelName { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Tag - value: {} is invalid {}", + format!("Invalid header value for SpecialModelName - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Tag - {}", + format!("Unable to convert header value '{}' into SpecialModelName - {}", value, err)) } }, @@ -5057,6 +4975,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl SpecialModelName { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "Tag")] @@ -5130,8 +5057,8 @@ impl std::str::FromStr for Tag { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing Tag".to_string()) } } @@ -5148,44 +5075,34 @@ impl std::str::FromStr for Tag { } } - -impl Tag { - /// 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") - } -} - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for User - value: {} is invalid {}", + format!("Invalid header value for Tag - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into User - {}", + format!("Unable to convert header value '{}' into Tag - {}", value, err)) } }, @@ -5197,6 +5114,15 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +impl Tag { + /// 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, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] #[serde(rename = "User")] @@ -5343,14 +5269,14 @@ impl std::str::FromStr for User { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "username" => intermediate_rep.username.push(::from_str(val).map_err(|x| format!("{}", x))?), + "firstName" => intermediate_rep.first_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "lastName" => intermediate_rep.last_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + "email" => intermediate_rep.email.push(::from_str(val).map_err(|x| format!("{}", x))?), + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), + "phone" => intermediate_rep.phone.push(::from_str(val).map_err(|x| format!("{}", x))?), + "userStatus" => intermediate_rep.user_status.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing User".to_string()) } } @@ -5373,6 +5299,44 @@ impl std::str::FromStr for User { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for User - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into User - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} + impl User { /// Helper function to allow us to convert this model to an XML 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 b8085bcd85a0..5bb9c13acba1 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 @@ -4,46 +4,6 @@ use crate::models; #[cfg(any(feature = "client", feature = "server"))] use crate::header; - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ANullableContainer - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ANullableContainer - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ANullableContainer { @@ -133,6 +93,43 @@ impl std::str::FromStr for ANullableContainer { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for ANullableContainer - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into ANullableContainer - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +} /// An additionalPropertiesObject @@ -146,7 +143,6 @@ impl std::convert::From> for Additiona } } - impl std::convert::From for std::collections::HashMap { fn from(x: AdditionalPropertiesObject) -> Self { x.0 @@ -187,46 +183,6 @@ impl ::std::str::FromStr for AdditionalPropertiesObject { } } - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { - type Error = String; - - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { - let hdr_value = hdr_value.to_string(); - match hyper::header::HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AllOfObject - value: {} is invalid {}", - hdr_value, e)) - } - } -} - -#[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { - type Error = String; - - fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { - match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AllOfObject - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) - } - } -} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AllOfObject { @@ -299,8 +255,8 @@ impl std::str::FromStr for AllOfObject { if let Some(key) = key_result { match 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))?), + "sampleProperty" => intermediate_rep.sample_property.push(::from_str(val).map_err(|x| format!("{}", x))?), + "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing AllOfObject".to_string()) } } @@ -317,36 +273,34 @@ impl std::str::FromStr for AllOfObject { } } - - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for BaseAllOf - value: {} is invalid {}", + format!("Invalid header value for AllOfObject - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into BaseAllOf - {}", + format!("Unable to convert header value '{}' into AllOfObject - {}", value, err)) } }, @@ -418,7 +372,7 @@ impl std::str::FromStr for BaseAllOf { if let Some(key) = key_result { match key { - "sampleBasePropery" => intermediate_rep.sample_base_propery.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing BaseAllOf".to_string()) } } @@ -434,37 +388,34 @@ impl std::str::FromStr for BaseAllOf { } } - - -/// structured response -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for GetYamlResponse - value: {} is invalid {}", + format!("Invalid header value for BaseAllOf - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into GetYamlResponse - {}", + format!("Unable to convert header value '{}' into BaseAllOf - {}", value, err)) } }, @@ -476,6 +427,7 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +/// structured response #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct GetYamlResponse { @@ -537,7 +489,7 @@ impl std::str::FromStr for GetYamlResponse { if let Some(key) = key_result { match key { - "value" => intermediate_rep.value.push(String::from_str(val).map_err(|x| format!("{}", x))?), + "value" => intermediate_rep.value.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing GetYamlResponse".to_string()) } } @@ -553,36 +505,34 @@ impl std::str::FromStr for GetYamlResponse { } } - - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for InlineObject - value: {} is invalid {}", + format!("Invalid header value for GetYamlResponse - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into InlineObject - {}", + format!("Unable to convert header value '{}' into GetYamlResponse - {}", value, err)) } }, @@ -663,8 +613,8 @@ impl std::str::FromStr for InlineObject { if let Some(key) = key_result { match 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))?), + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing InlineObject".to_string()) } } @@ -681,37 +631,34 @@ impl std::str::FromStr for InlineObject { } } - - -/// An object of objects -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectOfObjects - value: {} is invalid {}", + format!("Invalid header value for InlineObject - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectOfObjects - {}", + format!("Unable to convert header value '{}' into InlineObject - {}", value, err)) } }, @@ -723,6 +670,7 @@ impl std::convert::TryFrom for header::IntoHeaderVal } +/// An object of objects #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectOfObjects { @@ -779,7 +727,7 @@ impl std::str::FromStr for ObjectOfObjects { if let Some(key) = key_result { match key { - "inner" => intermediate_rep.inner.push(models::ObjectOfObjectsInner::from_str(val).map_err(|x| format!("{}", x))?), + "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjects".to_string()) } } @@ -795,36 +743,34 @@ impl std::str::FromStr for ObjectOfObjects { } } - - -// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom> for hyper::header::HeaderValue { +impl std::convert::TryFrom> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectOfObjectsInner - value: {} is invalid {}", + format!("Invalid header value for ObjectOfObjects - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom for header::IntoHeaderValue { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match ::from_str(value) { + match ::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectOfObjectsInner - {}", + format!("Unable to convert header value '{}' into ObjectOfObjects - {}", value, err)) } }, @@ -905,8 +851,8 @@ impl std::str::FromStr for ObjectOfObjectsInner { if let Some(key) = key_result { match 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))?), + "required_thing" => intermediate_rep.required_thing.push(::from_str(val).map_err(|x| format!("{}", x))?), + "optional_thing" => intermediate_rep.optional_thing.push(::from_str(val).map_err(|x| format!("{}", x))?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjectsInner".to_string()) } } @@ -923,4 +869,41 @@ impl std::str::FromStr for ObjectOfObjectsInner { } } +// Methods for converting between header::IntoHeaderValue and hyper::header::HeaderValue + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom> for hyper::header::HeaderValue { + type Error = String; + + fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + let hdr_value = hdr_value.to_string(); + match hyper::header::HeaderValue::from_str(&hdr_value) { + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err( + format!("Invalid header value for ObjectOfObjectsInner - value: {} is invalid {}", + hdr_value, e)) + } + } +} + +#[cfg(any(feature = "client", feature = "server"))] +impl std::convert::TryFrom for header::IntoHeaderValue { + type Error = String; + + fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result { + match hdr_value.to_str() { + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), + std::result::Result::Err(err) => std::result::Result::Err( + format!("Unable to convert header value '{}' into ObjectOfObjectsInner - {}", + value, err)) + } + }, + std::result::Result::Err(e) => std::result::Result::Err( + format!("Unable to convert header: {:?} to string: {}", + hdr_value, e)) + } + } +}