diff --git a/.github/workflows/samples-rust.yaml b/.github/workflows/samples-rust.yaml index b46265ca16a6..5ad9823d5d5b 100644 --- a/.github/workflows/samples-rust.yaml +++ b/.github/workflows/samples-rust.yaml @@ -50,7 +50,7 @@ jobs: working-directory: ${{ matrix.sample }} run: | set -e - # Skip samples/client/petstore/rust/ as it's tests are failing. + # Skip samples/client/petstore/rust/ as its tests are failing. if [[ "${{ matrix.sample }}" == "samples/client/petstore/rust/" ]]; then echo "Skipping tests for samples/client/petstore/rust/" exit 0 diff --git a/modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache index cec9e012796a..da9c6a599b77 100644 --- a/modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache @@ -99,9 +99,7 @@ validator = { version = "0.16", features = ["derive"] } # Crates included if required by the API definition {{#usesXml}} -# TODO: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"} +serde-xml-rs = "0.8" {{/usesXml}} {{#apiUsesMultipart}} mime_0_2 = { package = "mime", version = "0.2.6", optional = true } diff --git a/modules/openapi-generator/src/main/resources/rust-server-deprecated/models.mustache b/modules/openapi-generator/src/main/resources/rust-server-deprecated/models.mustache index 4dfc68f61cb0..540c6d87e74d 100644 --- a/modules/openapi-generator/src/main/resources/rust-server-deprecated/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server-deprecated/models.mustache @@ -159,13 +159,19 @@ impl ::std::str::FromStr for {{{classname}}} { {{#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 +fn wrap_in_{{{x-item-xml-name}}}(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "{{{x-item-xml-name}}}") -} + use serde::ser::SerializeMap; + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("{{{x-item-xml-name}}}")?; + map.serialize_value(item)?; + } + map.end() +} {{/x-item-xml-name}} {{/vendorExtensions}} {{! vec}} @@ -633,10 +639,10 @@ impl {{{classname}}} { #[allow(dead_code)] pub(crate) fn as_xml(&self) -> String { {{#xmlNamespace}} - 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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") {{/xmlNamespace}} {{^xmlNamespace}} serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") diff --git a/modules/openapi-generator/src/main/resources/rust-server-deprecated/server-response-body-instance.mustache b/modules/openapi-generator/src/main/resources/rust-server-deprecated/server-response-body-instance.mustache index 9bb648c525f7..710e65b8b5bb 100644 --- a/modules/openapi-generator/src/main/resources/rust-server-deprecated/server-response-body-instance.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server-deprecated/server-response-body-instance.mustache @@ -12,11 +12,10 @@ let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{#x-has-namespace}} - let mut namespaces = std::collections::BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string()); - let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + let config = serde_xml_rs::SerdeXml::new() + .namespace("", {{{dataType}}}::NAMESPACE); + let body = config.to_string(&body).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{/x-produces-xml}} {{#x-produces-json}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache index 12fc2bebcb97..dab769c0ec70 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache @@ -94,9 +94,7 @@ validator = { version = "0.20", features = ["derive"] } # Crates included if required by the API definition {{#usesXml}} -# TODO: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"} +serde-xml-rs = "0.8" {{/usesXml}} {{#apiUsesMultipartFormData}} multipart = { version = "0.18", default-features = false, optional = true } 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 8f2339c2cb6f..b56876d6eb47 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -158,11 +158,18 @@ impl ::std::str::FromStr for {{{classname}}} { {{#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 +fn wrap_in_{{{x-item-xml-name}}}(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "{{{x-item-xml-name}}}") + use serde::ser::SerializeMap; + + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("{{{x-item-xml-name}}}")?; + map.serialize_value(item)?; + } + map.end() } {{/x-item-xml-name}} @@ -632,10 +639,10 @@ impl {{{classname}}} { #[allow(dead_code)] pub(crate) fn as_xml(&self) -> String { {{#xmlNamespace}} - 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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") {{/xmlNamespace}} {{^xmlNamespace}} serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache index b21e7a6db834..27e9f30b1234 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache @@ -12,11 +12,10 @@ let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{#x-has-namespace}} - let mut namespaces = std::collections::BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string()); - let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + let config = serde_xml_rs::SerdeXml::new() + .namespace("", {{{dataType}}}::NAMESPACE); + let body = config.to_string(&body).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{/x-produces-xml}} {{#x-produces-json}} diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/Cargo.toml b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/Cargo.toml index 4f8d249eb265..c4cec054c7c7 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/Cargo.toml +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/Cargo.toml @@ -45,9 +45,7 @@ serde_json = "1.0" validator = { version = "0.16", features = ["derive"] } # Crates included if required by the API definition -# TODO: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"} +serde-xml-rs = "0.8" uuid = {version = "1.3.1", features = ["serde", "v4"]} # Common between server and client features diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs index d93d890a243a..84f8141a3cbc 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs @@ -464,13 +464,19 @@ impl AdditionalPropertiesWithNullable { // 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 +fn wrap_in_snake_another_xml_inner(items: &Vec, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "snake_another_xml_inner") -} + use serde::ser::SerializeMap; + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("snake_another_xml_inner")?; + map.serialize_value(item)?; + } + map.end() +} #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnotherXmlArray( @@ -953,10 +959,10 @@ impl AnotherXmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } @@ -1854,10 +1860,10 @@ impl DuplicateXmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } @@ -5191,13 +5197,19 @@ impl UuidObject { // Utility function for wrapping list elements when serializing xml #[allow(non_snake_case)] -fn wrap_in_camelXmlInner(item: &Vec, serializer: S) -> std::result::Result +fn wrap_in_camelXmlInner(items: &Vec, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "camelXmlInner") -} + use serde::ser::SerializeMap; + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("camelXmlInner")?; + map.serialize_value(item)?; + } + map.end() +} #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct XmlArray( @@ -5695,9 +5707,9 @@ impl XmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs index b61d9c1c07de..db2d5290a1bc 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs @@ -1652,11 +1652,10 @@ impl hyper::service::Service<(Request, C)> for Service where HeaderValue::from_str("text/xml") .expect("Unable to create Content-Type header for text/xml")); // XML Body - let mut namespaces = std::collections::BTreeMap::new(); - // An empty string is used to indicate a global namespace in xmltree. - namespaces.insert("".to_string(), models::AnotherXmlObject::NAMESPACE.to_string()); - let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + let config = serde_xml_rs::SerdeXml::new() + .namespace("", models::AnotherXmlObject::NAMESPACE); + let body = config.to_string(&body).expect("impossible to fail to serialize"); *response.body_mut() = Body::from(body); }, XmlOtherPostResponse::BadRequest diff --git a/samples/server/petstore/rust-server-deprecated/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml b/samples/server/petstore/rust-server-deprecated/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml index 0c809c91fdd6..4adf1eb310d2 100644 --- a/samples/server/petstore/rust-server-deprecated/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml +++ b/samples/server/petstore/rust-server-deprecated/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml @@ -48,9 +48,7 @@ serde_json = "1.0" validator = { version = "0.16", features = ["derive"] } # Crates included if required by the API definition -# TODO: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"} +serde-xml-rs = "0.8" mime_0_2 = { package = "mime", version = "0.2.6", optional = true } multipart = { version = "0.16", default-features = false, optional = true } uuid = {version = "1.3.1", features = ["serde", "v4"]} diff --git a/samples/server/petstore/rust-server/output/openapi-v3/Cargo.toml b/samples/server/petstore/rust-server/output/openapi-v3/Cargo.toml index 931919cbd406..2fc526d80090 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/Cargo.toml +++ b/samples/server/petstore/rust-server/output/openapi-v3/Cargo.toml @@ -46,9 +46,7 @@ serde_json = "1.0" validator = { version = "0.20", features = ["derive"] } # Crates included if required by the API definition -# TODO: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"} +serde-xml-rs = "0.8" uuid = { version = "1.17.0", features = ["serde", "v4"]} # Common between server and client features 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 de464d40b9c6..c24dfb69f4c5 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 @@ -463,11 +463,18 @@ impl AdditionalPropertiesWithNullable { // 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 +fn wrap_in_snake_another_xml_inner(items: &Vec, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "snake_another_xml_inner") + use serde::ser::SerializeMap; + + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("snake_another_xml_inner")?; + map.serialize_value(item)?; + } + map.end() } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -952,10 +959,10 @@ impl AnotherXmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } @@ -1853,10 +1860,10 @@ impl DuplicateXmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } @@ -5190,11 +5197,18 @@ impl UuidObject { // Utility function for wrapping list elements when serializing xml #[allow(non_snake_case)] -fn wrap_in_camelXmlInner(item: &Vec, serializer: S) -> std::result::Result +fn wrap_in_camelXmlInner(items: &Vec, serializer: S) -> std::result::Result where S: serde::ser::Serializer, { - serde_xml_rs::wrap_primitives(item, serializer, "camelXmlInner") + use serde::ser::SerializeMap; + + let mut map = serializer.serialize_map(None)?; + for ref item in items { + map.serialize_key("camelXmlInner")?; + map.serialize_value(item)?; + } + map.end() } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -5694,9 +5708,9 @@ impl XmlObject { /// Will panic if serialisation fails. #[allow(dead_code)] pub(crate) fn as_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") + let config = serde_xml_rs::SerdeXml::new() + .namespace("", Self::NAMESPACE); + config.to_string(&self).expect("impossible to fail to serialize") } } 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 5fc291aad0ba..ac28b04a475a 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 @@ -1748,11 +1748,10 @@ impl hyper::service::Service<(Request, C)> for Service