Skip to content

Commit 97aa4a8

Browse files
authored
Fixup dependency on forked serde_xml (#21664)
1 parent 5ba0650 commit 97aa4a8

File tree

15 files changed

+97
-74
lines changed

15 files changed

+97
-74
lines changed

.github/workflows/samples-rust.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
working-directory: ${{ matrix.sample }}
5151
run: |
5252
set -e
53-
# Skip samples/client/petstore/rust/ as it's tests are failing.
53+
# Skip samples/client/petstore/rust/ as its tests are failing.
5454
if [[ "${{ matrix.sample }}" == "samples/client/petstore/rust/" ]]; then
5555
echo "Skipping tests for samples/client/petstore/rust/"
5656
exit 0

modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ validator = { version = "0.16", features = ["derive"] }
9999

100100
# Crates included if required by the API definition
101101
{{#usesXml}}
102-
# TODO: this should be updated to point at the official crate once
103-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
104-
serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
102+
serde-xml-rs = "0.8"
105103
{{/usesXml}}
106104
{{#apiUsesMultipart}}
107105
mime_0_2 = { package = "mime", version = "0.2.6", optional = true }

modules/openapi-generator/src/main/resources/rust-server-deprecated/models.mustache

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,19 @@ impl ::std::str::FromStr for {{{classname}}} {
159159
{{#arrayModelType}}
160160
{{#vendorExtensions}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml
161161
#[allow(non_snake_case)]
162-
fn wrap_in_{{{x-item-xml-name}}}<S>(item: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
162+
fn wrap_in_{{{x-item-xml-name}}}<S>(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
163163
where
164164
S: serde::ser::Serializer,
165165
{
166-
serde_xml_rs::wrap_primitives(item, serializer, "{{{x-item-xml-name}}}")
167-
}
166+
use serde::ser::SerializeMap;
168167
168+
let mut map = serializer.serialize_map(None)?;
169+
for ref item in items {
170+
map.serialize_key("{{{x-item-xml-name}}}")?;
171+
map.serialize_value(item)?;
172+
}
173+
map.end()
174+
}
169175
{{/x-item-xml-name}}
170176
{{/vendorExtensions}}
171177
{{! vec}}
@@ -633,10 +639,10 @@ impl {{{classname}}} {
633639
#[allow(dead_code)]
634640
pub(crate) fn as_xml(&self) -> String {
635641
{{#xmlNamespace}}
636-
let mut namespaces = std::collections::BTreeMap::new();
637642
// An empty string is used to indicate a global namespace in xmltree.
638-
namespaces.insert("".to_string(), Self::NAMESPACE.to_string());
639-
serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize")
643+
let config = serde_xml_rs::SerdeXml::new()
644+
.namespace("", Self::NAMESPACE);
645+
config.to_string(&self).expect("impossible to fail to serialize")
640646
{{/xmlNamespace}}
641647
{{^xmlNamespace}}
642648
serde_xml_rs::to_string(&self).expect("impossible to fail to serialize")

modules/openapi-generator/src/main/resources/rust-server-deprecated/server-response-body-instance.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
1313
{{/x-has-namespace}}
1414
{{#x-has-namespace}}
15-
let mut namespaces = std::collections::BTreeMap::new();
16-
1715
// An empty string is used to indicate a global namespace in xmltree.
18-
namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string());
19-
let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
16+
let config = serde_xml_rs::SerdeXml::new()
17+
.namespace("", {{{dataType}}}::NAMESPACE);
18+
let body = config.to_string(&body).expect("impossible to fail to serialize");
2019
{{/x-has-namespace}}
2120
{{/x-produces-xml}}
2221
{{#x-produces-json}}

modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ validator = { version = "0.20", features = ["derive"] }
9494

9595
# Crates included if required by the API definition
9696
{{#usesXml}}
97-
# TODO: this should be updated to point at the official crate once
98-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
99-
serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
97+
serde-xml-rs = "0.8"
10098
{{/usesXml}}
10199
{{#apiUsesMultipartFormData}}
102100
multipart = { version = "0.18", default-features = false, optional = true }

modules/openapi-generator/src/main/resources/rust-server/models.mustache

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,18 @@ impl ::std::str::FromStr for {{{classname}}} {
158158
{{#arrayModelType}}
159159
{{#vendorExtensions}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml
160160
#[allow(non_snake_case)]
161-
fn wrap_in_{{{x-item-xml-name}}}<S>(item: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
161+
fn wrap_in_{{{x-item-xml-name}}}<S>(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
162162
where
163163
S: serde::ser::Serializer,
164164
{
165-
serde_xml_rs::wrap_primitives(item, serializer, "{{{x-item-xml-name}}}")
165+
use serde::ser::SerializeMap;
166+
167+
let mut map = serializer.serialize_map(None)?;
168+
for ref item in items {
169+
map.serialize_key("{{{x-item-xml-name}}}")?;
170+
map.serialize_value(item)?;
171+
}
172+
map.end()
166173
}
167174
168175
{{/x-item-xml-name}}
@@ -632,10 +639,10 @@ impl {{{classname}}} {
632639
#[allow(dead_code)]
633640
pub(crate) fn as_xml(&self) -> String {
634641
{{#xmlNamespace}}
635-
let mut namespaces = std::collections::BTreeMap::new();
636642
// An empty string is used to indicate a global namespace in xmltree.
637-
namespaces.insert("".to_string(), Self::NAMESPACE.to_string());
638-
serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize")
643+
let config = serde_xml_rs::SerdeXml::new()
644+
.namespace("", Self::NAMESPACE);
645+
config.to_string(&self).expect("impossible to fail to serialize")
639646
{{/xmlNamespace}}
640647
{{^xmlNamespace}}
641648
serde_xml_rs::to_string(&self).expect("impossible to fail to serialize")

modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
1313
{{/x-has-namespace}}
1414
{{#x-has-namespace}}
15-
let mut namespaces = std::collections::BTreeMap::new();
16-
1715
// An empty string is used to indicate a global namespace in xmltree.
18-
namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string());
19-
let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
16+
let config = serde_xml_rs::SerdeXml::new()
17+
.namespace("", {{{dataType}}}::NAMESPACE);
18+
let body = config.to_string(&body).expect("impossible to fail to serialize");
2019
{{/x-has-namespace}}
2120
{{/x-produces-xml}}
2221
{{#x-produces-json}}

samples/server/petstore/rust-server-deprecated/output/openapi-v3/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ serde_json = "1.0"
4545
validator = { version = "0.16", features = ["derive"] }
4646

4747
# Crates included if required by the API definition
48-
# TODO: this should be updated to point at the official crate once
49-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
50-
serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
48+
serde-xml-rs = "0.8"
5149
uuid = {version = "1.3.1", features = ["serde", "v4"]}
5250

5351
# Common between server and client features

samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,19 @@ impl AdditionalPropertiesWithNullable {
464464

465465
// Utility function for wrapping list elements when serializing xml
466466
#[allow(non_snake_case)]
467-
fn wrap_in_snake_another_xml_inner<S>(item: &Vec<String>, serializer: S) -> std::result::Result<S::Ok, S::Error>
467+
fn wrap_in_snake_another_xml_inner<S>(items: &Vec<String>, serializer: S) -> std::result::Result<S::Ok, S::Error>
468468
where
469469
S: serde::ser::Serializer,
470470
{
471-
serde_xml_rs::wrap_primitives(item, serializer, "snake_another_xml_inner")
472-
}
471+
use serde::ser::SerializeMap;
473472

473+
let mut map = serializer.serialize_map(None)?;
474+
for ref item in items {
475+
map.serialize_key("snake_another_xml_inner")?;
476+
map.serialize_value(item)?;
477+
}
478+
map.end()
479+
}
474480
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
475481
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
476482
pub struct AnotherXmlArray(
@@ -953,10 +959,10 @@ impl AnotherXmlObject {
953959
/// Will panic if serialisation fails.
954960
#[allow(dead_code)]
955961
pub(crate) fn as_xml(&self) -> String {
956-
let mut namespaces = std::collections::BTreeMap::new();
957962
// An empty string is used to indicate a global namespace in xmltree.
958-
namespaces.insert("".to_string(), Self::NAMESPACE.to_string());
959-
serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize")
963+
let config = serde_xml_rs::SerdeXml::new()
964+
.namespace("", Self::NAMESPACE);
965+
config.to_string(&self).expect("impossible to fail to serialize")
960966
}
961967
}
962968

@@ -1854,10 +1860,10 @@ impl DuplicateXmlObject {
18541860
/// Will panic if serialisation fails.
18551861
#[allow(dead_code)]
18561862
pub(crate) fn as_xml(&self) -> String {
1857-
let mut namespaces = std::collections::BTreeMap::new();
18581863
// An empty string is used to indicate a global namespace in xmltree.
1859-
namespaces.insert("".to_string(), Self::NAMESPACE.to_string());
1860-
serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize")
1864+
let config = serde_xml_rs::SerdeXml::new()
1865+
.namespace("", Self::NAMESPACE);
1866+
config.to_string(&self).expect("impossible to fail to serialize")
18611867
}
18621868
}
18631869

@@ -5191,13 +5197,19 @@ impl UuidObject {
51915197

51925198
// Utility function for wrapping list elements when serializing xml
51935199
#[allow(non_snake_case)]
5194-
fn wrap_in_camelXmlInner<S>(item: &Vec<String>, serializer: S) -> std::result::Result<S::Ok, S::Error>
5200+
fn wrap_in_camelXmlInner<S>(items: &Vec<String>, serializer: S) -> std::result::Result<S::Ok, S::Error>
51955201
where
51965202
S: serde::ser::Serializer,
51975203
{
5198-
serde_xml_rs::wrap_primitives(item, serializer, "camelXmlInner")
5199-
}
5204+
use serde::ser::SerializeMap;
52005205

5206+
let mut map = serializer.serialize_map(None)?;
5207+
for ref item in items {
5208+
map.serialize_key("camelXmlInner")?;
5209+
map.serialize_value(item)?;
5210+
}
5211+
map.end()
5212+
}
52015213
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
52025214
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
52035215
pub struct XmlArray(
@@ -5695,9 +5707,9 @@ impl XmlObject {
56955707
/// Will panic if serialisation fails.
56965708
#[allow(dead_code)]
56975709
pub(crate) fn as_xml(&self) -> String {
5698-
let mut namespaces = std::collections::BTreeMap::new();
56995710
// An empty string is used to indicate a global namespace in xmltree.
5700-
namespaces.insert("".to_string(), Self::NAMESPACE.to_string());
5701-
serde_xml_rs::to_string_with_namespaces(&self, namespaces).expect("impossible to fail to serialize")
5711+
let config = serde_xml_rs::SerdeXml::new()
5712+
.namespace("", Self::NAMESPACE);
5713+
config.to_string(&self).expect("impossible to fail to serialize")
57025714
}
57035715
}

samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,11 +1652,10 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
16521652
HeaderValue::from_str("text/xml")
16531653
.expect("Unable to create Content-Type header for text/xml"));
16541654
// XML Body
1655-
let mut namespaces = std::collections::BTreeMap::new();
1656-
16571655
// An empty string is used to indicate a global namespace in xmltree.
1658-
namespaces.insert("".to_string(), models::AnotherXmlObject::NAMESPACE.to_string());
1659-
let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
1656+
let config = serde_xml_rs::SerdeXml::new()
1657+
.namespace("", models::AnotherXmlObject::NAMESPACE);
1658+
let body = config.to_string(&body).expect("impossible to fail to serialize");
16601659
*response.body_mut() = Body::from(body);
16611660
},
16621661
XmlOtherPostResponse::BadRequest

0 commit comments

Comments
 (0)