forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-response-body-instance.mustache
More file actions
48 lines (47 loc) · 2.78 KB
/
server-response-body-instance.mustache
File metadata and controls
48 lines (47 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{{#dataType}}
{{#vendorExtensions}}
{{^x-produces-multipart-related}}
response.headers_mut().insert(
CONTENT_TYPE,
HeaderValue::from_static("{{{x-mime-type}}}"));
{{/x-produces-multipart-related}}
{{#x-produces-xml}}
// XML Body
{{^x-has-namespace}}
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
{{/x-has-namespace}}
{{#x-has-namespace}}
// An empty string is used to indicate a global namespace in xmltree.
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}}
// JSON Body
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
{{/x-produces-json}}
{{#x-produces-bytes}}
// Binary Body
let body = String::from_utf8(body.0).expect("Error converting octet stream to string");
{{/x-produces-bytes}}
{{#x-produces-plain-text}}
// Plain text Body
{{/x-produces-plain-text}}
{{#x-produces-multipart-related}}
// multipart/related Body
{{#formParams}}
let param_{{{paramName}}} = body.{{{paramName}}};
{{/formParams}}
{{#formParams}}
{{>generate-multipart-related}}
let header = "multipart/related";
response.headers_mut().insert(CONTENT_TYPE,
HeaderValue::from_bytes(
&["multipart/related; boundary=".as_bytes(), &boundary].concat())
.expect("Unable to create Content-Type header for multipart/related"));
{{/formParams}}
{{/x-produces-multipart-related}}
{{/vendorExtensions}}
*response.body_mut() = body_from_string(body);
{{/dataType}}