Skip to content

Commit 091e1da

Browse files
committed
Fixup dependency on forked serde_xml
1 parent 815a732 commit 091e1da

80 files changed

Lines changed: 1916 additions & 63 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ validator = { version = "0.16", features = ["derive"] }
101101
{{#usesXml}}
102102
# TODO: this should be updated to point at the official crate once
103103
# 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"}
104+
#serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
105+
serde-xml-rs = "0.8"
105106
{{/usesXml}}
106107
{{#apiUsesMultipart}}
107108
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ validator = { version = "0.20", features = ["derive"] }
9696
{{#usesXml}}
9797
# TODO: this should be updated to point at the official crate once
9898
# 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"}
100-
{{/usesXml}}
99+
#serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
100+
serde-xml-rs = "0.8"{{/usesXml}}
101101
{{#apiUsesMultipartFormData}}
102102
multipart = { version = "0.18", default-features = false, optional = true }
103103
{{/apiUsesMultipartFormData}}

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/multipart-v3/examples/server/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
123123
info!("multipart_related_request_post({:?}, {:?}, {:?}) - X-Span-ID: {:?}", required_binary_field, object_field, optional_binary_field, context.get().0.clone());
124124
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
125125
}
126+
126127
async fn multipart_request_post(
127128
&self,
128129
string_field: String,
@@ -134,6 +135,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
134135
info!("multipart_request_post(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", string_field, binary_field, optional_string_field, object_field, context.get().0.clone());
135136
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
136137
}
138+
137139
async fn multiple_identical_mime_types_post(
138140
&self,
139141
binary1: Option<swagger::ByteArray>,
@@ -143,4 +145,5 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
143145
info!("multiple_identical_mime_types_post({:?}, {:?}) - X-Span-ID: {:?}", binary1, binary2, context.get().0.clone());
144146
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
145147
}
148+
146149
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ impl<S, C> Api<C> for Client<S, C> where
444444
});
445445
body_parts.push(part);
446446
}
447+
447448
if let Some(optional_binary_field) = param_optional_binary_field {
448449
let part = Node::Part(Part {
449450
headers: {
@@ -456,6 +457,7 @@ impl<S, C> Api<C> for Client<S, C> where
456457
});
457458
body_parts.push(part);
458459
}
460+
459461
{
460462
let part = Node::Part(Part {
461463
headers: {
@@ -477,6 +479,7 @@ impl<S, C> Api<C> for Client<S, C> where
477479
write_multipart(&mut body, &boundary, &body_parts)
478480
.expect("Failed to write multipart body");
479481

482+
480483
let header = "multipart/related";
481484
request.headers_mut().insert(CONTENT_TYPE,
482485
match HeaderValue::from_bytes(
@@ -488,6 +491,7 @@ impl<S, C> Api<C> for Client<S, C> where
488491

489492
// Add the message body to the request object.
490493
*request.body_mut() = Body::from(body);
494+
491495
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
492496
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
493497
Ok(h) => h,
@@ -520,6 +524,7 @@ impl<S, C> Api<C> for Client<S, C> where
520524
}
521525
}
522526
}
527+
523528
async fn multipart_request_post(
524529
&self,
525530
param_string_field: String,
@@ -638,6 +643,8 @@ impl<S, C> Api<C> for Client<S, C> where
638643
Ok(h) => h,
639644
Err(e) => return Err(ApiError(format!("Unable to create header: {multipart_header} - {e}")))
640645
});
646+
647+
641648
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
642649
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
643650
Ok(h) => h,
@@ -670,6 +677,7 @@ impl<S, C> Api<C> for Client<S, C> where
670677
}
671678
}
672679
}
680+
673681
async fn multiple_identical_mime_types_post(
674682
&self,
675683
param_binary1: Option<swagger::ByteArray>,
@@ -722,6 +730,7 @@ impl<S, C> Api<C> for Client<S, C> where
722730
});
723731
body_parts.push(part);
724732
}
733+
725734
if let Some(binary2) = param_binary2 {
726735
let part = Node::Part(Part {
727736
headers: {
@@ -743,6 +752,7 @@ impl<S, C> Api<C> for Client<S, C> where
743752
write_multipart(&mut body, &boundary, &body_parts)
744753
.expect("Failed to write multipart body");
745754

755+
746756
let header = "multipart/related";
747757
request.headers_mut().insert(CONTENT_TYPE,
748758
match HeaderValue::from_bytes(
@@ -754,6 +764,7 @@ impl<S, C> Api<C> for Client<S, C> where
754764

755765
// Add the message body to the request object.
756766
*request.body_mut() = Body::from(body);
767+
757768
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
758769
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
759770
Ok(h) => h,
@@ -786,4 +797,5 @@ impl<S, C> Api<C> for Client<S, C> where
786797
}
787798
}
788799
}
800+
789801
}

samples/server/petstore/rust-server-deprecated/output/multipart-v3/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ pub enum MultipartRelatedRequestPostResponse {
2525
/// OK
2626
OK
2727
}
28+
2829
#[derive(Debug, PartialEq, Serialize, Deserialize)]
2930
pub enum MultipartRequestPostResponse {
3031
/// OK
3132
OK
3233
}
34+
3335
#[derive(Debug, PartialEq, Serialize, Deserialize)]
3436
pub enum MultipleIdenticalMimeTypesPostResponse {
3537
/// OK
3638
OK
3739
}
40+
3841
/// API
3942
#[async_trait]
4043
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]

0 commit comments

Comments
 (0)