[Rust Server] Refactor Mustache templates for request/response body handling (#19347)

* [Rust Server] Refactor Mustache templates for request/response body handling

* Update samples
This commit is contained in:
Richard Whitehouse 2024-08-14 08:25:08 +01:00 committed by GitHub
parent 8f7354a2a2
commit daf52229e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 1644 additions and 1143 deletions

View File

@ -821,12 +821,15 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
} else if (isMimetypePlain(mediaType)) { } else if (isMimetypePlain(mediaType)) {
consumesPlainText = true; consumesPlainText = true;
} else if (isMimetypeWwwFormUrlEncoded(mediaType)) { } else if (isMimetypeWwwFormUrlEncoded(mediaType)) {
op.vendorExtensions.put("x-consumes-form", true);
additionalProperties.put("usesUrlEncodedForm", true); additionalProperties.put("usesUrlEncodedForm", true);
} else if (isMimetypeMultipartFormData(mediaType)) { } else if (isMimetypeMultipartFormData(mediaType)) {
op.vendorExtensions.put("x-consumes-multipart", true); op.vendorExtensions.put("x-consumes-multipart", true);
op.vendorExtensions.put("x-consumes-multipart-form", true);
additionalProperties.put("apiUsesMultipartFormData", true); additionalProperties.put("apiUsesMultipartFormData", true);
additionalProperties.put("apiUsesMultipart", true); additionalProperties.put("apiUsesMultipart", true);
} else if (isMimetypeMultipartRelated(mediaType)) { } else if (isMimetypeMultipartRelated(mediaType)) {
op.vendorExtensions.put("x-consumes-multipart", true);
op.vendorExtensions.put("x-consumes-multipart-related", true); op.vendorExtensions.put("x-consumes-multipart-related", true);
additionalProperties.put("apiUsesMultipartRelated", true); additionalProperties.put("apiUsesMultipartRelated", true);
additionalProperties.put("apiUsesMultipart", true); additionalProperties.put("apiUsesMultipart", true);
@ -835,15 +838,23 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
} }
} }
if (op.bodyParams.size() > 0 || op.formParams.size() > 0){
op.vendorExtensions.put("x-has-request-body", true);
}
String underscoredOperationId = underscore(op.operationId).toUpperCase(Locale.ROOT); String underscoredOperationId = underscore(op.operationId).toUpperCase(Locale.ROOT);
if (op.bodyParam != null) { if (op.bodyParam != null) {
// Default to consuming json // Default to consuming json
op.bodyParam.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId); op.bodyParam.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId);
if (consumesXml) { if (consumesXml) {
op.vendorExtensions.put("x-consumes-basic", true);
op.bodyParam.vendorExtensions.put("x-consumes-xml", true); op.bodyParam.vendorExtensions.put("x-consumes-xml", true);
} else if (consumesPlainText) { } else if (consumesPlainText) {
op.vendorExtensions.put("x-consumes-basic", true);
op.bodyParam.vendorExtensions.put("x-consumes-plain-text", true); op.bodyParam.vendorExtensions.put("x-consumes-plain-text", true);
} else { } else {
op.vendorExtensions.put("x-consumes-basic", true);
op.bodyParam.vendorExtensions.put("x-consumes-json", true); op.bodyParam.vendorExtensions.put("x-consumes-json", true);
} }
} }
@ -855,10 +866,13 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
// Default to producing json if nothing else is specified // Default to producing json if nothing else is specified
if (consumesXml) { if (consumesXml) {
op.vendorExtensions.put("x-consumes-basic", true);
param.vendorExtensions.put("x-consumes-xml", true); param.vendorExtensions.put("x-consumes-xml", true);
} else if (consumesPlainText) { } else if (consumesPlainText) {
op.vendorExtensions.put("x-consumes-basic", true);
param.vendorExtensions.put("x-consumes-plain-text", true); param.vendorExtensions.put("x-consumes-plain-text", true);
} else { } else {
op.vendorExtensions.put("x-consumes-basic", true);
param.vendorExtensions.put("x-consumes-json", true); param.vendorExtensions.put("x-consumes-json", true);
} }
} }

View File

@ -85,217 +85,7 @@
Ok(req) => req, Ok(req) => req,
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
{{>client-request-body-instance}}
{{#vendorExtensions}}
{{#x-consumes-multipart}}
let (body_string, multipart_header) = {
let mut multipart = Multipart::new();
{{#vendorExtensions}}
{{#formParams}}
{{#-first}}
// For each parameter, encode as appropriate and add to the multipart body as a stream.
{{/-first}}
{{^isByteArray}}
{{#jsonSchema}}
let {{{paramName}}}_str = match serde_json::to_string(&param_{{{paramName}}}) {
Ok(str) => str,
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {}", e))),
};
let {{{paramName}}}_vec = {{{paramName}}}_str.as_bytes().to_vec();
let {{{paramName}}}_mime = mime_0_2::Mime::from_str("application/json").expect("impossible to fail to parse");
let {{{paramName}}}_cursor = Cursor::new({{{paramName}}}_vec);
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, None as Option<&str>, Some({{{paramName}}}_mime));
{{/jsonSchema}}
{{/isByteArray}}
{{#isByteArray}}
let {{{paramName}}}_vec = param_{{{paramName}}}.to_vec();
let {{{paramName}}}_mime = match mime_0_2::Mime::from_str("application/octet-stream") {
Ok(mime) => mime,
Err(err) => return Err(ApiError(format!("Unable to get mime type: {:?}", err))),
};
let {{{paramName}}}_cursor = Cursor::new({{{paramName}}}_vec);
let filename = None as Option<&str> ;
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, filename, Some({{{paramName}}}_mime));
{{/isByteArray}}
{{/formParams}}
{{/vendorExtensions}}
let mut fields = match multipart.prepare() {
Ok(fields) => fields,
Err(err) => return Err(ApiError(format!("Unable to build request: {}", err))),
};
let mut body_string = String::new();
match fields.read_to_string(&mut body_string) {
Ok(_) => (),
Err(err) => return Err(ApiError(format!("Unable to build body: {}", err))),
}
let boundary = fields.boundary();
let multipart_header = format!("multipart/form-data;boundary={}", boundary);
(body_string, multipart_header)
};
*request.body_mut() = Body::from(body_string);
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e)))
});
{{/x-consumes-multipart}}
{{^x-consumes-multipart}}
{{#vendorExtensions}}
{{^x-consumes-multipart-related}}
{{#formParams}}
{{#-first}}
let params = &[
{{/-first}}
("{{{baseName}}}", {{#vendorExtensions}}{{#required}}Some({{#isString}}param_{{{paramName}}}{{/isString}}{{^isString}}format!("{:?}", param_{{{paramName}}}){{/isString}}){{/required}}{{^required}}{{#isString}}param_{{{paramName}}}{{/isString}}{{^isString}}param_{{{paramName}}}.map(|param| format!("{:?}", param)){{/isString}}{{/required}}{{/vendorExtensions}}),
{{#-last}}
];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
*request.body_mut() = Body::from(body.into_bytes());
{{/-last}}
{{/formParams}}
{{/x-consumes-multipart-related}}
{{#x-consumes-multipart-related}}
{{#formParams}}
{{#-first}}
// Construct the Body for a multipart/related request. The mime 0.2.6 library
// does not parse quoted-string parameters correctly. The boundary doesn't
// need to be a quoted string if it does not contain a '/', hence ensure
// no such boundary is used.
let mut boundary = generate_boundary();
for b in boundary.iter_mut() {
if b == &(b'/') {
*b = b'=';
}
}
let mut body_parts = vec![];
{{/-first}}
{{#required}}
{
{{/required}}
{{^required}}
if let Some({{{paramName}}}) = param_{{{paramName}}} {
{{/required}}
let part = Node::Part(Part {
headers: {
let mut h = Headers::new();
h.set(ContentType("{{{contentType}}}".parse().unwrap()));
h.set_raw("Content-ID", vec![b"{{{baseName}}}".to_vec()]);
h
},
{{#isBinary}}
body: {{#required}}param_{{/required}}{{{paramName}}}.0,
{{/isBinary}}
{{^isBinary}}
body: serde_json::to_string(&{{{paramName}}})
.expect("Impossible to fail to serialize")
.into_bytes(),
{{/isBinary}}
});
body_parts.push(part);
}
{{#-last}}
// Write the body into a vec.
let mut body: Vec<u8> = vec![];
write_multipart(&mut body, &boundary, &body_parts)
.expect("Failed to write multipart body");
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
request.headers_mut().insert(CONTENT_TYPE,
match HeaderValue::from_bytes(
&[header.as_bytes(), "; boundary=".as_bytes(), &boundary, "; type=\"application/json\"".as_bytes()].concat()
) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
{{/-last}}
{{/formParams}}
{{/x-consumes-multipart-related}}
{{/vendorExtensions}}
{{#bodyParam}}
{{#-first}}
// Body parameter
{{/-first}}
{{#vendorExtensions}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
let body = param_{{{paramName}}}.0;
{{/isByteArray}}
{{^isByteArray}}
let body = param_{{{paramName}}};
{{/isByteArray}}
{{/x-consumes-plain-text}}
{{#required}}
{{#x-consumes-xml}}
let body = param_{{{paramName}}}.as_xml();
{{/x-consumes-xml}}
{{#x-consumes-json}}
let body = serde_json::to_string(&param_{{{paramName}}}).expect("impossible to fail to serialize");
{{/x-consumes-json}}
{{/required}}
{{^required}}
let body = param_{{{paramName}}}.map(|ref body| {
{{#x-consumes-xml}}
body.as_xml()
{{/x-consumes-xml}}
{{#x-consumes-json}}
serde_json::to_string(body).expect("impossible to fail to serialize")
{{/x-consumes-json}}
});
{{/required}}
{{/vendorExtensions}}
{{#-last}}
{{/-last}}
{{/bodyParam}}
{{#bodyParam}}
{{^required}}
if let Some(body) = body {
{{/required}}
*request.body_mut() = Body::from(body);
{{^required}}
}
{{/required}}
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
{{#-last}}
{{/-last}}
{{/bodyParam}}
{{/x-consumes-multipart}}
{{/vendorExtensions}}
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -421,29 +211,9 @@
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
{{#vendorExtensions}}
{{#x-produces-bytes}} {{>client-response-body-instance}}
let body = swagger::ByteArray(body.to_vec());
{{/x-produces-bytes}}
{{^x-produces-bytes}}
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
{{#x-produces-xml}}
// ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<{{{dataType}}}>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
{{/x-produces-xml}}
{{#x-produces-json}}
let body = serde_json::from_str::<{{{dataType}}}>(body).map_err(|e| {
ApiError(format!("Response body did not match the schema: {}", e))
})?;
{{/x-produces-json}}
{{#x-produces-plain-text}}
let body = body.to_string();
{{/x-produces-plain-text}}
{{/x-produces-bytes}}
{{/vendorExtensions}}
Ok({{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}} Ok({{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
{{^headers}} {{^headers}}
(body) (body)

View File

@ -0,0 +1,84 @@
{{#vendorExtensions}}
{{#x-consumes-multipart-form}}
// Consumes multipart/form body
{{>client-request-body-multipart-form}}
{{/x-consumes-multipart-form}}
{{#x-consumes-multipart-related}}
// Consumes multipart/related body
{{#formParams}}
{{>generate-multipart-related}}
{{/formParams}}
let header = "multipart/related";
request.headers_mut().insert(CONTENT_TYPE,
match HeaderValue::from_bytes(
&[header.as_bytes(), "; boundary=".as_bytes(), &boundary, "; type=\"application/json\"".as_bytes()].concat()
) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
{{/x-consumes-multipart-related}}
{{#x-consumes-form}}
// Consumes form body
{{#formParams}}
{{#-first}}
let params = &[
{{/-first}}
("{{{baseName}}}", {{#vendorExtensions}}{{#required}}Some({{#isString}}param_{{{paramName}}}{{/isString}}{{^isString}}format!("{:?}", param_{{{paramName}}}){{/isString}}){{/required}}{{^required}}{{#isString}}param_{{{paramName}}}{{/isString}}{{^isString}}param_{{{paramName}}}.map(|param| format!("{:?}", param)){{/isString}}{{/required}}{{/vendorExtensions}}),
{{#-last}}
];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body.into_bytes());
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
{{/-last}}
{{/formParams}}
{{/x-consumes-form}}
{{#x-consumes-basic}}
// Consumes basic body
{{#bodyParam}}
// Body parameter
{{^required}}
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
{{/required}}
{{#vendorExtensions}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
let body = param_{{{paramName}}}.0;
{{/isByteArray}}
{{^isByteArray}}
let body = param_{{{paramName}}};
{{/isByteArray}}
{{/x-consumes-plain-text}}
{{#x-consumes-xml}}
let body = param_{{{paramName}}}.as_xml();
{{/x-consumes-xml}}
{{#x-consumes-json}}
let body = serde_json::to_string(&param_{{{paramName}}}).expect("impossible to fail to serialize");
{{/x-consumes-json}}
{{/vendorExtensions}}
*request.body_mut() = Body::from(body);
{{^required}}
}
{{/required}}
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
});
{{/bodyParam}}
{{/x-consumes-basic}}
{{/vendorExtensions}}

View File

@ -0,0 +1,65 @@
let (body_string, multipart_header) = {
let mut multipart = Multipart::new();
{{#vendorExtensions}}
{{#formParams}}
{{#-first}}
// For each parameter, encode as appropriate and add to the multipart body as a stream.
{{/-first}}
{{^isByteArray}}
{{#jsonSchema}}
let {{{paramName}}}_str = match serde_json::to_string(&param_{{{paramName}}}) {
Ok(str) => str,
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {}", e))),
};
let {{{paramName}}}_vec = {{{paramName}}}_str.as_bytes().to_vec();
let {{{paramName}}}_mime = mime_0_2::Mime::from_str("application/json").expect("impossible to fail to parse");
let {{{paramName}}}_cursor = Cursor::new({{{paramName}}}_vec);
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, None as Option<&str>, Some({{{paramName}}}_mime));
{{/jsonSchema}}
{{/isByteArray}}
{{#isByteArray}}
let {{{paramName}}}_vec = param_{{{paramName}}}.to_vec();
let {{{paramName}}}_mime = match mime_0_2::Mime::from_str("application/octet-stream") {
Ok(mime) => mime,
Err(err) => return Err(ApiError(format!("Unable to get mime type: {:?}", err))),
};
let {{{paramName}}}_cursor = Cursor::new({{{paramName}}}_vec);
let filename = None as Option<&str> ;
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, filename, Some({{{paramName}}}_mime));
{{/isByteArray}}
{{/formParams}}
{{/vendorExtensions}}
let mut fields = match multipart.prepare() {
Ok(fields) => fields,
Err(err) => return Err(ApiError(format!("Unable to build request: {}", err))),
};
let mut body_string = String::new();
match fields.read_to_string(&mut body_string) {
Ok(_) => (),
Err(err) => return Err(ApiError(format!("Unable to build body: {}", err))),
}
let boundary = fields.boundary();
let multipart_header = format!("multipart/form-data;boundary={}", boundary);
(body_string, multipart_header)
};
*request.body_mut() = Body::from(body_string);
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) {
Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e)))
});

View File

@ -0,0 +1,22 @@
{{#vendorExtensions}}
{{#x-produces-bytes}}
let body = swagger::ByteArray(body.to_vec());
{{/x-produces-bytes}}
{{^x-produces-bytes}}
let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
{{#x-produces-xml}}
// ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<{{{dataType}}}>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
{{/x-produces-xml}}
{{#x-produces-json}}
let body = serde_json::from_str::<{{{dataType}}}>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
{{/x-produces-json}}
{{#x-produces-plain-text}}
let body = body.to_string();
{{/x-produces-plain-text}}
{{/x-produces-bytes}}
{{/vendorExtensions}}

View File

@ -0,0 +1,76 @@
// Create headers from top-level content type header.
let multipart_headers = match swagger::multipart::related::create_multipart_headers(header.headers.get(CONTENT_TYPE)) {
Ok(headers) => headers,
Err(e) => {
return Err(ApiError(e));
}
};
// &*body expresses the body as a byteslice, &mut provides a
// mutable reference to that byteslice.
let nodes = match read_multipart_body(&mut&*body, &multipart_headers, false) {
Ok(nodes) => nodes,
Err(e) => {
return Err(ApiError(format!("Could not read multipart body for {{operationId}}: {}", e)));
}
};
{{#formParams}}
let mut param_{{{paramName}}} = None;
{{/formParams}}
for node in nodes {
if let Node::Part(part) = node {
let content_type = part.content_type().map(|x| format!("{}",x));
match content_type.as_ref().map(|x| x.as_str()) {
{{#formParams}}
{{^isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
// Extract JSON part.
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
let json_data: {{{dataType}}} = match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in JSON part: {}", path);
}) {
Ok(json_data) => json_data,
Err(e) => return Err(ApiError(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
};
// Push JSON part to return object.
param_{{{paramName}}}.get_or_insert(json_data);
},
{{/isBinary}}
{{#isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
param_{{{paramName}}}.get_or_insert(swagger::ByteArray(part.body));
},
{{/isBinary}}
{{/formParams}}
Some(content_type) => {
warn!("Ignoring unexpected content type: {}", content_type);
},
None => {
warn!("Missing content type");
},
}
} else {
return Err(ApiError(format!("Unexpected part in multipart body for {{operationId}}: {:?}", node)));
}
}
{{#formParams}}
{{#-first}}
// Check that the required multipart chunks are present.
{{/-first}}
{{#required}}
let param_{{{paramName}}} = match param_{{{paramName}}} {
Some(x) => x,
None => return Err(ApiError("Missing required multipart/related parameter {{{paramName}}}"))
};
{{/required}}
{{/formParams}}
{{^vendorExtensions.x-consumes-basic}}
let body = {{{dataType}}} {
{{#formParams}}
{{{paramName}}}: param_{{{paramName}}},
{{/formParams}}
};
{{/vendorExtensions.x-consumes-basic}}

View File

@ -0,0 +1,45 @@
{{#-first}}
// Construct the Body for a multipart/related request. The mime 0.2.6 library
// does not parse quoted-string parameters correctly. The boundary doesn't
// need to be a quoted string if it does not contain a '/', hence ensure
// no such boundary is used.
let mut boundary = generate_boundary();
for b in boundary.iter_mut() {
if b == &(b'/') {
*b = b'=';
}
}
let mut body_parts = vec![];
{{/-first}}
{{#required}}
{
{{/required}}
{{^required}}
if let Some({{{paramName}}}) = param_{{{paramName}}} {
{{/required}}
let part = Node::Part(Part {
headers: {
let mut h = Headers::new();
h.set(ContentType("{{{contentType}}}".parse().unwrap()));
h.set_raw("Content-ID", vec![b"{{{baseName}}}".to_vec()]);
h
},
{{#isBinary}}
body: {{#required}}param_{{/required}}{{{paramName}}}.0,
{{/isBinary}}
{{^isBinary}}
body: serde_json::to_string(&{{{paramName}}})
.expect("Impossible to fail to serialize")
.into_bytes(),
{{/isBinary}}
});
body_parts.push(part);
}
{{#-last}}
// Write the body into a vec.
let mut body: Vec<u8> = vec![];
write_multipart(&mut body, &boundary, &body_parts)
.expect("Failed to write multipart body");
{{/-last}}

View File

@ -38,16 +38,6 @@
{{/hasAuthMethods}} {{/hasAuthMethods}}
{{#vendorExtensions}} {{#vendorExtensions}}
{{#x-consumes-multipart}}
let boundary = match swagger::multipart::form::boundary(&headers) {
Some(boundary) => boundary.to_string(),
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Couldn't find valid multipart body".to_string()))
.expect("Unable to create Bad Request response for incorrect boundary")),
};
{{/x-consumes-multipart}}
{{#x-has-path-params}} {{#x-has-path-params}}
// Path parameters // Path parameters
let path: &str = uri.path(); let path: &str = uri.path();
@ -202,278 +192,22 @@
{{/-last}} {{/-last}}
{{/queryParams}} {{/queryParams}}
{{#vendorExtensions}} {{#vendorExtensions.x-has-request-body}}
{{^x-consumes-multipart}} // Handle body parameters (note that non-required body parameters will ignore garbage
{{#bodyParams}}
{{#-first}}
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
{{#vendorExtensions}} {{^vendorExtensions.x-consumes-multipart-form}}
{{^x-consumes-plain-text}} {{^vendorExtensions.x-consumes-form}}
let mut unused_elements = Vec::new(); {{^bodyParam.vendorExtensions.x-consumes-plain-text}}
{{/x-consumes-plain-text}} let mut unused_elements : Vec<String> = vec![];
let param_{{{paramName}}}: Option<{{{dataType}}}> = if !body.is_empty() { {{/bodyParam.vendorExtensions.x-consumes-plain-text}}
{{#x-consumes-xml}} {{/vendorExtensions.x-consumes-form}}
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); {{/vendorExtensions.x-consumes-multipart-form}}
{{/x-consumes-xml}} {{>server-request-body-instance}}
{{#x-consumes-json}} {{/vendorExtensions.x-has-request-body}}
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
{{/x-consumes-json}}
{{^x-consumes-plain-text}}
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_{{{paramName}}}) => param_{{{paramName}}},
{{#required}}
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - doesn't match schema: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to schema")),
{{/required}}
{{^required}}
Err(_) => None,
{{/required}}
}
{{/x-consumes-plain-text}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
Some(swagger::ByteArray(body.to_vec()))
{{/isByteArray}}
{{#isString}}
match String::from_utf8(body.to_vec()) {
Ok(param_{{{paramName}}}) => Some(param_{{{paramName}}}),
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - not valid UTF-8: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to UTF-8")),
}
{{/isString}}
{{/x-consumes-plain-text}}
{{/vendorExtensions}}
} else {
None
};
{{#required}}
let param_{{{paramName}}} = match param_{{{paramName}}} {
Some(param_{{{paramName}}}) => param_{{{paramName}}},
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required body parameter {{{baseName}}}"))
.expect("Unable to create Bad Request response for missing body parameter {{{baseName}}}")),
};
{{/required}}
{{/-first}}
{{#-last}}
{{/-last}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{#x-consumes-multipart}}
{{^bodyParams}}
{{#vendorExtensions}}
// Form Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
let result = body.into_raw();
match result.await {
Ok(body) => {
use std::io::Read;
// Read Form Parameters from body
let mut entries = match Multipart::with_body(&body.to_vec()[..], boundary).save().temp() {
SaveResult::Full(entries) => {
entries
},
_ => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Unable to process all message parts".to_string()))
.expect("Unable to create Bad Request response due to failure to process all message"))
},
};
{{#formParams}}
let field_{{{paramName}}} = entries.fields.remove("{{{paramName}}}");
let param_{{{paramName}}} = match field_{{{paramName}}} {
Some(field) => {
let mut reader = field[0].data.readable().expect("Unable to read field for {{{paramName}}}");
{{^required}}
Some({
{{/required}}
{{#isByteArray}}
let mut data = vec![];
reader.read_to_end(&mut data).expect("Reading saved binary data should never fail");
swagger::ByteArray(data)
{{/isByteArray}}
{{^isByteArray}}
{{#jsonSchema}}
let mut data = String::new();
reader.read_to_string(&mut data).expect("Reading saved String should never fail");
let {{{paramName}}}_model: {{{dataType}}} = match serde_json::from_str(&data) {
Ok(model) => model,
Err(e) => {
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("{{{paramName}}} data does not match API definition : {}", e)))
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
}
};
{{{paramName}}}_model
{{/jsonSchema}}
{{/isByteArray}}
{{^required}}
})
{{/required}}
},
None => {
{{#required}}
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required form parameter {{{paramName}}}".to_string()))
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
{{/required}}
{{^required}}
None
{{/required}}
}
};
{{/formParams}}
{{/vendorExtensions}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{^x-consumes-multipart-related}}
{{^x-consumes-multipart}}
{{^bodyParams}}
{{#vendorExtensions}}
{{#formParams}}
{{#-first}}
// Form parameters
{{/-first}}
let param_{{{paramName}}} = {{^isContainer}}{{#vendorExtensions}}{{{x-example}}};{{/vendorExtensions}}{{/isContainer}}{{#isArray}}{{#required}}Vec::new();{{/required}}{{^required}}None;{{/required}}{{/isArray}}{{#isMap}}None;{{/isMap}}
{{#-last}}
{{/-last}}
{{/formParams}}
{{/vendorExtensions}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{/x-consumes-multipart-related}}
{{#x-consumes-multipart-related}}
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
let result = body.into_raw();
match result.await {
Ok(body) => {
let mut unused_elements: Vec<String> = vec![];
// Get multipart chunks.
// Extract the top-level content type header.
let content_type_mime = headers
.get(CONTENT_TYPE)
.ok_or_else(|| "Missing content-type header".to_string())
.and_then(|v| v.to_str().map_err(|e| format!("Couldn't read content-type header value for {{operationId}}: {}", e)))
.and_then(|v| v.parse::<Mime2>().map_err(|_e| "Couldn't parse content-type header value for {{operationId}}".to_string()));
// Insert top-level content type header into a Headers object.
let mut multi_part_headers = Headers::new();
match content_type_mime {
Ok(content_type_mime) => {
multi_part_headers.set(ContentType(content_type_mime));
},
Err(e) => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(e))
.expect("Unable to create Bad Request response due to unable to read content-type header for {{operationId}}"));
}
}
// &*body expresses the body as a byteslice, &mut provides a
// mutable reference to that byteslice.
let nodes = match read_multipart_body(&mut&*body, &multi_part_headers, false) {
Ok(nodes) => nodes,
Err(e) => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Could not read multipart body for {{operationId}}: {}", e)))
.expect("Unable to create Bad Request response due to unable to read multipart body for {{operationId}}"));
}
};
{{#formParams}}
let mut param_{{{paramName}}} = None;
{{/formParams}}
for node in nodes {
if let Node::Part(part) = node {
let content_type = part.content_type().map(|x| format!("{}",x));
match content_type.as_deref() {
{{#formParams}}
{{^isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
// Extract JSON part.
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in JSON part: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(json_data) => json_data,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{dataType}} due to schema"))
};
// Push JSON part to return object.
param_{{{paramName}}}.get_or_insert(json_data);
},
{{/isBinary}}
{{#isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
param_{{{paramName}}}.get_or_insert(swagger::ByteArray(part.body));
},
{{/isBinary}}
{{/formParams}}
Some(content_type) => {
warn!("Ignoring unexpected content type: {}", content_type);
unused_elements.push(content_type.to_string());
},
None => {
warn!("Missing content type");
},
}
} else {
unimplemented!("No support for handling unexpected parts");
// unused_elements.push();
}
}
{{#formParams}}
{{#-first}}
// Check that the required multipart chunks are present.
{{/-first}}
{{#required}}
let param_{{{paramName}}} = match param_required_binary_field {
Some(x) => x,
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required multipart/related parameter {{{paramName}}}".to_string()))
.expect("Unable to create Bad Request response for missing multipart/related parameter {{{paramName}}} due to schema"))
};
{{/required}}
{{#-last}}
{{/-last}}
{{/formParams}}
{{/x-consumes-multipart-related}}
{{/vendorExtensions}}
let result = api_impl.{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}( let result = api_impl.{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
{{#vendorExtensions}} {{#vendorExtensions}}
{{#x-callback-params}} {{#x-callback-params}}
@ -491,19 +225,20 @@
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str()) HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
.expect("Unable to create X-Span-ID header value")); .expect("Unable to create X-Span-ID header value"));
{{#bodyParams}} {{#vendorExtensions.x-has-request-body}}
{{#vendorExtensions}} {{^vendorExtensions.x-consumes-multipart-form}}
{{^x-consumes-plain-text}} {{^vendorExtensions.x-consumes-form}}
{{^bodyParam.vendorExtensions.x-consumes-plain-text}}
if !unused_elements.is_empty() { if !unused_elements.is_empty() {
response.headers_mut().insert( response.headers_mut().insert(
HeaderName::from_static("warning"), HeaderName::from_static("warning"),
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
{{/bodyParam.vendorExtensions.x-consumes-plain-text}}
{{/x-consumes-plain-text}} {{/vendorExtensions.x-consumes-form}}
{{/vendorExtensions}} {{/vendorExtensions.x-consumes-multipart-form}}
{{/bodyParams}} {{/vendorExtensions.x-has-request-body}}
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
{{#responses}} {{#responses}}
@ -535,7 +270,9 @@
{{/headers}} {{/headers}}
{{/dataType}} {{/dataType}}
=> { => {
*response.status_mut() = StatusCode::from_u16({{{code}}}).expect("Unable to turn {{{code}}} into a StatusCode");
{{#headers}} {{#headers}}
{{^required}} {{^required}}
if let Some({{{name}}}) = {{{name}}} { if let Some({{{name}}}) = {{{name}}} {
{{/required}} {{/required}}
@ -557,45 +294,7 @@
} }
{{/required}} {{/required}}
{{/headers}} {{/headers}}
*response.status_mut() = StatusCode::from_u16({{{code}}}).expect("Unable to turn {{{code}}} into a StatusCode"); {{>server-response-body-instance}}
{{#produces}}
{{#-first}}
{{#dataType}}
{{#vendorExtensions}}
response.headers_mut().insert(
CONTENT_TYPE,
HeaderValue::from_str("{{{x-mime-type}}}")
.expect("Unable to create Content-Type header for {{{x-uppercase-operation-id}}}_{{x-uppercase-response-id}}"));
{{/vendorExtensions}}
{{/dataType}}
{{/-first}}
{{/produces}}
{{#dataType}}
{{#vendorExtensions}}
{{#x-produces-xml}}
{{^x-has-namespace}}
let body_content = 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_content = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
{{/x-has-namespace}}
{{/x-produces-xml}}
{{#x-produces-json}}
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
{{/x-produces-json}}
{{#x-produces-bytes}}
let body_content = body.0;
{{/x-produces-bytes}}
{{#x-produces-plain-text}}
let body_content = body;
{{/x-produces-plain-text}}
{{/vendorExtensions}}
*response.body_mut() = Body::from(body_content);
{{/dataType}}
}, },
{{/responses}} {{/responses}}
}, },
@ -608,44 +307,12 @@
} }
Ok(response) Ok(response)
{{#vendorExtensions}} {{#vendorExtensions.x-has-request-body}}
{{^x-consumes-multipart}}
{{^bodyParams}}
{{#vendorExtensions}}
{{#x-consumes-multipart-related}}
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter {{{baseName}}}: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter {{{baseName}}}")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
{{/x-consumes-multipart-related}} {{/vendorExtensions.x-has-request-body}}
{{/vendorExtensions}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{/vendorExtensions}}
{{#bodyParams}}
{{#-first}}
},
Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter {{{baseName}}}: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter {{{baseName}}}")),
}
{{/-first}}
{{/bodyParams}}
{{#vendorExtensions}}
{{#x-consumes-multipart}}
{{^bodyParams}}
{{#vendorExtensions}}
},
Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Couldn't read multipart body".to_string()))
.expect("Unable to create Bad Request response due to unable read multipart body")),
}
{{/vendorExtensions}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{/vendorExtensions}}
}, },

View File

@ -0,0 +1,52 @@
{{#vendorExtensions}}
let param_{{{paramName}}}: Option<{{{dataType}}}> = if !body.is_empty() {
{{#x-consumes-xml}}
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
{{/x-consumes-xml}}
{{#x-consumes-json}}
let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
{{/x-consumes-json}}
{{^x-consumes-plain-text}}
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(param_{{{paramName}}}) => param_{{{paramName}}},
{{#required}}
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - doesn't match schema: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to schema")),
{{/required}}
{{^required}}
Err(_) => None,
{{/required}}
}
{{/x-consumes-plain-text}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
Some(swagger::ByteArray(body.to_vec()))
{{/isByteArray}}
{{#isString}}
match String::from_utf8(body.to_vec()) {
Ok(param_{{{paramName}}}) => Some(param_{{{paramName}}}),
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - not valid UTF-8: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to UTF-8")),
}
{{/isString}}
{{/x-consumes-plain-text}}
{{/vendorExtensions}}
} else {
None
};
{{#required}}
let param_{{{paramName}}} = match param_{{{paramName}}} {
Some(param_{{{paramName}}}) => param_{{{paramName}}},
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required body parameter {{{baseName}}}"))
.expect("Unable to create Bad Request response for missing body parameter {{{baseName}}}")),
};
{{/required}}

View File

@ -0,0 +1,24 @@
{{#vendorExtensions}}
{{#formParams}}
{{#-first}}
// Form parameters
{{/-first}}
let param_{{{paramName}}} =
{{^isContainer}}
{{#vendorExtensions}}
{{{x-example}}};
{{/vendorExtensions}}
{{/isContainer}}
{{#isArray}}
{{#required}}
Vec::new();
{{/required}}
{{^required}}
None;
{{/required}}
{{/isArray}}
{{#isMap}}
None;
{{/isMap}}
{{/formParams}}
{{/vendorExtensions}}

View File

@ -0,0 +1,20 @@
{{#vendorExtensions}}
{{#x-consumes-multipart}}
{{#x-consumes-multipart-related}}
{{>server-request-body-multipart-related}}
{{/x-consumes-multipart-related}}
{{^x-consumes-multipart-related}}
{{^bodyParams}}
{{>server-request-body-multipart-form}}
{{/bodyParams}}
{{/x-consumes-multipart-related}}
{{/x-consumes-multipart}}
{{^x-consumes-multipart}}
{{#bodyParams}}
{{>server-request-body-basic}}
{{/bodyParams}}
{{^bodyParams}}
{{>server-request-body-form}}
{{/bodyParams}}
{{/x-consumes-multipart}}
{{/vendorExtensions}}

View File

@ -0,0 +1,70 @@
let boundary = match swagger::multipart::form::boundary(&headers) {
Some(boundary) => boundary.to_string(),
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Couldn't find valid multipart body".to_string()))
.expect("Unable to create Bad Request response for incorrect boundary")),
};
use std::io::Read;
// Read Form Parameters from body
let mut entries = match Multipart::with_body(&body.to_vec()[..], boundary).save().temp() {
SaveResult::Full(entries) => {
entries
},
_ => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Unable to process all message parts".to_string()))
.expect("Unable to create Bad Request response due to failure to process all message"))
},
};
{{#formParams}}
let field_{{{paramName}}} = entries.fields.remove("{{{paramName}}}");
let param_{{{paramName}}} = match field_{{{paramName}}} {
Some(field) => {
let mut reader = field[0].data.readable().expect("Unable to read field for {{{paramName}}}");
{{^required}}
Some({
{{/required}}
{{#isByteArray}}
let mut data = vec![];
reader.read_to_end(&mut data).expect("Reading saved binary data should never fail");
swagger::ByteArray(data)
{{/isByteArray}}
{{^isByteArray}}
{{#jsonSchema}}
let mut data = String::new();
reader.read_to_string(&mut data).expect("Reading saved String should never fail");
let {{{paramName}}}_model: {{{dataType}}} = match serde_json::from_str(&data) {
Ok(model) => model,
Err(e) => {
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("{{{paramName}}} data does not match API definition : {}", e)))
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
}
};
{{{paramName}}}_model
{{/jsonSchema}}
{{/isByteArray}}
{{^required}}
})
{{/required}}
},
None => {
{{#required}}
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required form parameter {{{paramName}}}".to_string()))
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
{{/required}}
{{^required}}
None
{{/required}}
}
};
{{/formParams}}

View File

@ -0,0 +1,96 @@
// Get multipart chunks.
// Extract the top-level content type header.
let content_type_mime = headers
.get(CONTENT_TYPE)
.ok_or_else(|| "Missing content-type header".to_string())
.and_then(|v| v.to_str().map_err(|e| format!("Couldn't read content-type header value for {{operationId}}: {}", e)))
.and_then(|v| v.parse::<Mime2>().map_err(|_e| "Couldn't parse content-type header value for {{operationId}}".to_string()));
// Insert top-level content type header into a Headers object.
let mut multi_part_headers = Headers::new();
match content_type_mime {
Ok(content_type_mime) => {
multi_part_headers.set(ContentType(content_type_mime));
},
Err(e) => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(e))
.expect("Unable to create Bad Request response due to unable to read content-type header for {{operationId}}"));
}
}
// &*body expresses the body as a byteslice, &mut provides a
// mutable reference to that byteslice.
let nodes = match read_multipart_body(&mut&*body, &multi_part_headers, false) {
Ok(nodes) => nodes,
Err(e) => {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Could not read multipart body for {{operationId}}: {}", e)))
.expect("Unable to create Bad Request response due to unable to read multipart body for {{operationId}}"));
}
};
{{#formParams}}
let mut param_{{{paramName}}} = None;
{{/formParams}}
for node in nodes {
if let Node::Part(part) = node {
let content_type = part.content_type().map(|x| format!("{}",x));
match content_type.as_deref() {
{{#formParams}}
{{^isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
// Extract JSON part.
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in JSON part: {}", path);
unused_elements.push(path.to_string());
}) {
Ok(json_data) => json_data,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
.expect("Unable to create Bad Request response for invalid body parameter {{dataType}} due to schema"))
};
// Push JSON part to return object.
param_{{{paramName}}}.get_or_insert(json_data);
},
{{/isBinary}}
{{#isBinary}}
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
param_{{{paramName}}}.get_or_insert(swagger::ByteArray(part.body));
},
{{/isBinary}}
{{/formParams}}
Some(content_type) => {
warn!("Ignoring unexpected content type: {}", content_type);
unused_elements.push(content_type.to_string());
},
None => {
warn!("Missing content type");
},
}
} else {
unimplemented!("No support for handling unexpected parts");
// unused_elements.push();
}
}
{{#formParams}}
{{#-first}}
// Check that the required multipart chunks are present.
{{/-first}}
{{#required}}
let param_{{{paramName}}} = match param_{{{paramName}}} {
Some(x) => x,
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Missing required multipart/related parameter {{{paramName}}}".to_string()))
.expect("Unable to create Bad Request response for missing multipart/related parameter {{{paramName}}} due to schema"))
};
{{/required}}
{{/formParams}}

View File

@ -0,0 +1,50 @@
{{#dataType}}
{{#vendorExtensions}}
{{^x-produces-multipart-related}}
response.headers_mut().insert(
CONTENT_TYPE,
HeaderValue::from_str("{{{x-mime-type}}}")
.expect("Unable to create Content-Type header for {{{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}}
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");
{{/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 = body.0;
{{/x-produces-bytes}}
{{#x-produces-plain-text}}
// Plain text Body
let body = 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(body);
{{/dataType}}

View File

@ -423,6 +423,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes multipart/related body
// Construct the Body for a multipart/related request. The mime 0.2.6 library // Construct the Body for a multipart/related request. The mime 0.2.6 library
// does not parse quoted-string parameters correctly. The boundary doesn't // does not parse quoted-string parameters correctly. The boundary doesn't
// need to be a quoted string if it does not contain a '/', hence ensure // need to be a quoted string if it does not contain a '/', hence ensure
@ -433,7 +434,6 @@ impl<S, C> Api<C> for Client<S, C> where
*b = b'='; *b = b'=';
} }
} }
let mut body_parts = vec![]; let mut body_parts = vec![];
if let Some(object_field) = param_object_field { if let Some(object_field) = param_object_field {
@ -482,8 +482,6 @@ impl<S, C> Api<C> for Client<S, C> where
write_multipart(&mut body, &boundary, &body_parts) write_multipart(&mut body, &boundary, &body_parts)
.expect("Failed to write multipart body"); .expect("Failed to write multipart body");
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
let header = "multipart/related"; let header = "multipart/related";
request.headers_mut().insert(CONTENT_TYPE, request.headers_mut().insert(CONTENT_TYPE,
@ -494,6 +492,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -566,6 +567,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes multipart/form body
let (body_string, multipart_header) = { let (body_string, multipart_header) = {
let mut multipart = Multipart::new(); let mut multipart = Multipart::new();
@ -646,6 +648,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -716,6 +719,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes multipart/related body
// Construct the Body for a multipart/related request. The mime 0.2.6 library // Construct the Body for a multipart/related request. The mime 0.2.6 library
// does not parse quoted-string parameters correctly. The boundary doesn't // does not parse quoted-string parameters correctly. The boundary doesn't
// need to be a quoted string if it does not contain a '/', hence ensure // need to be a quoted string if it does not contain a '/', hence ensure
@ -726,7 +730,6 @@ impl<S, C> Api<C> for Client<S, C> where
*b = b'='; *b = b'=';
} }
} }
let mut body_parts = vec![]; let mut body_parts = vec![];
if let Some(binary1) = param_binary1 { if let Some(binary1) = param_binary1 {
@ -760,8 +763,6 @@ impl<S, C> Api<C> for Client<S, C> where
write_multipart(&mut body, &boundary, &body_parts) write_multipart(&mut body, &boundary, &body_parts)
.expect("Failed to write multipart body"); .expect("Failed to write multipart body");
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
let header = "multipart/related"; let header = "multipart/related";
request.headers_mut().insert(CONTENT_TYPE, request.headers_mut().insert(CONTENT_TYPE,
@ -772,6 +773,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
// Add the message body to the request object.
*request.body_mut() = Body::from(body);
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,

View File

@ -155,14 +155,13 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// MultipartRelatedRequestPost - POST /multipart_related_request // MultipartRelatedRequestPost - POST /multipart_related_request
hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => { hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw(); let result = body.into_raw().await;
match result.await { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements: Vec<String> = vec![]; let mut unused_elements : Vec<String> = vec![];
// Get multipart chunks. // Get multipart chunks.
// Extract the top-level content type header. // Extract the top-level content type header.
@ -251,6 +250,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing multipart/related parameter required_binary_field due to schema")) .expect("Unable to create Bad Request response for missing multipart/related parameter required_binary_field due to schema"))
}; };
let result = api_impl.multipart_related_request_post( let result = api_impl.multipart_related_request_post(
param_required_binary_field, param_required_binary_field,
param_object_field, param_object_field,
@ -263,11 +263,18 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str()) HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
.expect("Unable to create X-Span-ID header value")); .expect("Unable to create X-Span-ID header value"));
if !unused_elements.is_empty() {
response.headers_mut().insert(
HeaderName::from_static("warning"),
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value"));
}
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
MultipartRelatedRequestPostResponse::OK MultipartRelatedRequestPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -282,13 +289,19 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter Default: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter Default")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// MultipartRequestPost - POST /multipart_request // MultipartRequestPost - POST /multipart_request
hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => { hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => {
// Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
let result = body.into_raw().await;
match result {
Ok(body) => {
let boundary = match swagger::multipart::form::boundary(&headers) { let boundary = match swagger::multipart::form::boundary(&headers) {
Some(boundary) => boundary.to_string(), Some(boundary) => boundary.to_string(),
None => return Ok(Response::builder() None => return Ok(Response::builder()
@ -297,12 +310,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for incorrect boundary")), .expect("Unable to create Bad Request response for incorrect boundary")),
}; };
// Form Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
let result = body.into_raw();
match result.await {
Ok(body) => {
use std::io::Read; use std::io::Read;
// Read Form Parameters from body // Read Form Parameters from body
@ -407,6 +414,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request due to missing required form parameter binary_field")) .expect("Unable to create Bad Request due to missing required form parameter binary_field"))
} }
}; };
let result = api_impl.multipart_request_post( let result = api_impl.multipart_request_post(
param_string_field, param_string_field,
param_binary_field, param_binary_field,
@ -425,6 +434,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
MultipartRequestPostResponse::OK MultipartRequestPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -439,21 +449,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from("Couldn't read multipart body".to_string())) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable read multipart body")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types // MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types
hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => { hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw(); let result = body.into_raw().await;
match result.await { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements: Vec<String> = vec![]; let mut unused_elements : Vec<String> = vec![];
// Get multipart chunks. // Get multipart chunks.
// Extract the top-level content type header. // Extract the top-level content type header.
@ -518,6 +527,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// Check that the required multipart chunks are present. // Check that the required multipart chunks are present.
let result = api_impl.multiple_identical_mime_types_post( let result = api_impl.multiple_identical_mime_types_post(
param_binary1, param_binary1,
param_binary2, param_binary2,
@ -529,11 +539,18 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str()) HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
.expect("Unable to create X-Span-ID header value")); .expect("Unable to create X-Span-ID header value"));
if !unused_elements.is_empty() {
response.headers_mut().insert(
HeaderName::from_static("warning"),
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value"));
}
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
MultipleIdenticalMimeTypesPostResponse::OK MultipleIdenticalMimeTypesPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -548,8 +565,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter Default: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter Default")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },

View File

@ -414,9 +414,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = serde_json::to_string(&param_op_get_request).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_op_get_request).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";

View File

@ -144,15 +144,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// OpGet - GET /op // OpGet - GET /op
hyper::Method::GET if path.matched(paths::ID_OP) => { hyper::Method::GET if path.matched(paths::ID_OP) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_op_get_request: Option<models::OpGetRequest> = if !body.is_empty() { let param_op_get_request: Option<models::OpGetRequest> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body); let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path); warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string()); unused_elements.push(path.to_string());
@ -174,6 +174,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter OpGetRequest")), .expect("Unable to create Bad Request response for missing body parameter OpGetRequest")),
}; };
let result = api_impl.op_get( let result = api_impl.op_get(
param_op_get_request, param_op_get_request,
&context &context
@ -190,12 +191,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
OpGetResponse::OK OpGetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -210,8 +211,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter OpGetRequest: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter OpGetRequest")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },

View File

@ -204,6 +204,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
CallbackCallbackWithHeaderPostResponse::OK CallbackCallbackWithHeaderPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -244,6 +245,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
CallbackCallbackPostResponse::OK CallbackCallbackPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {

View File

@ -460,11 +460,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnyOfObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnyOfObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(AnyOfGetResponse::Success Ok(AnyOfGetResponse::Success
(body) (body)
) )
@ -474,11 +476,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Model12345AnyOfObject>(body).map_err(|e| { let body = serde_json::from_str::<models::Model12345AnyOfObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(AnyOfGetResponse::AlternateSuccess Ok(AnyOfGetResponse::AlternateSuccess
(body) (body)
) )
@ -488,11 +492,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnyOfGet202Response>(body).map_err(|e| { let body = serde_json::from_str::<models::AnyOfGet202Response>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(AnyOfGetResponse::AnyOfSuccess Ok(AnyOfGetResponse::AnyOfSuccess
(body) (body)
) )
@ -936,11 +942,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(MergePatchJsonGetResponse::Merge Ok(MergePatchJsonGetResponse::Merge
(body) (body)
) )
@ -1013,11 +1021,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(MultigetGetResponse::JSONRsp Ok(MultigetGetResponse::JSONRsp
(body) (body)
) )
@ -1027,12 +1037,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::MultigetGet201Response>(body) let body = serde_xml_rs::from_str::<models::MultigetGet201Response>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(MultigetGetResponse::XMLRsp Ok(MultigetGetResponse::XMLRsp
(body) (body)
) )
@ -1042,7 +1055,10 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = swagger::ByteArray(body.to_vec()); let body = swagger::ByteArray(body.to_vec());
Ok(MultigetGetResponse::OctetRsp Ok(MultigetGetResponse::OctetRsp
(body) (body)
) )
@ -1052,9 +1068,12 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = body.to_string(); let body = body.to_string();
Ok(MultigetGetResponse::StringRsp Ok(MultigetGetResponse::StringRsp
(body) (body)
) )
@ -1064,11 +1083,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText Ok(MultigetGetResponse::DuplicateResponseLongText
(body) (body)
) )
@ -1078,11 +1099,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText_2 Ok(MultigetGetResponse::DuplicateResponseLongText_2
(body) (body)
) )
@ -1092,11 +1115,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(MultigetGetResponse::DuplicateResponseLongText_3 Ok(MultigetGetResponse::DuplicateResponseLongText_3
(body) (body)
) )
@ -1256,11 +1281,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::OneOfGet200Response>(body).map_err(|e| { let body = serde_json::from_str::<models::OneOfGet200Response>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(OneOfGetResponse::Success Ok(OneOfGetResponse::Success
(body) (body)
) )
@ -1416,11 +1443,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AnotherXmlObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(ParamgetGetResponse::JSONRsp Ok(ParamgetGetResponse::JSONRsp
(body) (body)
) )
@ -1637,6 +1666,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = param_body.0; let body = param_body.0;
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -1645,6 +1676,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1770,11 +1802,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body).map_err(|e| { let body = serde_json::from_str::<String>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(ResponsesWithHeadersGetResponse::Success Ok(ResponsesWithHeadersGetResponse::Success
{ {
body, body,
@ -1889,11 +1923,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| { let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(Rfc7807GetResponse::OK Ok(Rfc7807GetResponse::OK
(body) (body)
) )
@ -1903,11 +1939,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| { let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(Rfc7807GetResponse::NotFound Ok(Rfc7807GetResponse::NotFound
(body) (body)
) )
@ -1917,12 +1955,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::ObjectWithArrayOfObjects>(body) let body = serde_xml_rs::from_str::<models::ObjectWithArrayOfObjects>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(Rfc7807GetResponse::NotAcceptable Ok(Rfc7807GetResponse::NotAcceptable
(body) (body)
) )
@ -1981,10 +2022,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_object_untyped_props.map(|ref body| { // Consumes basic body
serde_json::to_string(body).expect("impossible to fail to serialize") // Body parameter
}); if let Some(param_object_untyped_props) = param_object_untyped_props {
if let Some(body) = body { let body = serde_json::to_string(&param_object_untyped_props).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -1993,6 +2034,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2076,11 +2118,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<uuid::Uuid>(body).map_err(|e| { let body = serde_json::from_str::<uuid::Uuid>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(UuidGetResponse::DuplicateResponseLongText Ok(UuidGetResponse::DuplicateResponseLongText
(body) (body)
) )
@ -2139,10 +2183,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_duplicate_xml_object.map(|ref body| { // Consumes basic body
body.as_xml() // Body parameter
}); if let Some(param_duplicate_xml_object) = param_duplicate_xml_object {
if let Some(body) = body { let body = param_duplicate_xml_object.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -2151,6 +2195,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2225,10 +2270,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_another_xml_object.map(|ref body| { // Consumes basic body
body.as_xml() // Body parameter
}); if let Some(param_another_xml_object) = param_another_xml_object {
if let Some(body) = body { let body = param_another_xml_object.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -2237,6 +2282,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2252,12 +2298,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::AnotherXmlObject>(body) let body = serde_xml_rs::from_str::<models::AnotherXmlObject>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(XmlOtherPostResponse::OK Ok(XmlOtherPostResponse::OK
(body) (body)
) )
@ -2321,10 +2370,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_another_xml_array.map(|ref body| { // Consumes basic body
body.as_xml() // Body parameter
}); if let Some(param_another_xml_array) = param_another_xml_array {
if let Some(body) = body { let body = param_another_xml_array.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -2333,6 +2382,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2407,10 +2457,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_xml_array.map(|ref body| { // Consumes basic body
body.as_xml() // Body parameter
}); if let Some(param_xml_array) = param_xml_array {
if let Some(body) = body { let body = param_xml_array.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -2419,6 +2469,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2493,11 +2544,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_xml_object.map(|ref body| { // Consumes basic body
body.as_xml() // Body parameter
}); if let Some(param_xml_object) = param_xml_object {
let body = param_xml_object.as_xml();
if let Some(body) = body {
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -2581,6 +2631,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = serde_json::to_string(&param_object_param).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_object_param).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -2590,6 +2641,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2675,11 +2727,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body).map_err(|e| { let body = serde_json::from_str::<String>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(GetRepoInfoResponse::OK Ok(GetRepoInfoResponse::OK
(body) (body)
) )

View File

@ -259,9 +259,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for ANY_OF_GET_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
AnyOfGetResponse::AlternateSuccess AnyOfGetResponse::AlternateSuccess
(body) (body)
@ -270,9 +272,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for ANY_OF_GET_ALTERNATE_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
AnyOfGetResponse::AnyOfSuccess AnyOfGetResponse::AnyOfSuccess
(body) (body)
@ -281,9 +285,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for ANY_OF_GET_ANY_OF_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -341,6 +347,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
CallbackWithHeaderPostResponse::OK CallbackWithHeaderPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -382,6 +389,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
ComplexQueryParamGetResponse::Success ComplexQueryParamGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -435,6 +443,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
EnumInPathPathParamGetResponse::Success EnumInPathPathParamGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -485,6 +494,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
JsonComplexQueryParamGetResponse::Success JsonComplexQueryParamGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -538,6 +548,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
MandatoryRequestHeaderGetResponse::Success MandatoryRequestHeaderGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -571,9 +582,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/merge-patch+json") HeaderValue::from_str("application/merge-patch+json")
.expect("Unable to create Content-Type header for MERGE_PATCH_JSON_GET_MERGE")); .expect("Unable to create Content-Type header for application/merge-patch+json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -607,9 +620,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for MULTIGET_GET_JSON_RSP")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::XMLRsp MultigetGetResponse::XMLRsp
(body) (body)
@ -618,9 +633,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/xml") HeaderValue::from_str("application/xml")
.expect("Unable to create Content-Type header for MULTIGET_GET_XML_RSP")); .expect("Unable to create Content-Type header for application/xml"));
let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); // XML Body
*response.body_mut() = Body::from(body_content); let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::OctetRsp MultigetGetResponse::OctetRsp
(body) (body)
@ -629,9 +646,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/octet-stream") HeaderValue::from_str("application/octet-stream")
.expect("Unable to create Content-Type header for MULTIGET_GET_OCTET_RSP")); .expect("Unable to create Content-Type header for application/octet-stream"));
let body_content = body.0; // Binary Body
*response.body_mut() = Body::from(body_content); let body = body.0;
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::StringRsp MultigetGetResponse::StringRsp
(body) (body)
@ -640,9 +659,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("text/plain") HeaderValue::from_str("text/plain")
.expect("Unable to create Content-Type header for MULTIGET_GET_STRING_RSP")); .expect("Unable to create Content-Type header for text/plain"));
let body_content = body; // Plain text Body
*response.body_mut() = Body::from(body_content); let body = body;
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::DuplicateResponseLongText MultigetGetResponse::DuplicateResponseLongText
(body) (body)
@ -651,9 +672,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::DuplicateResponseLongText_2 MultigetGetResponse::DuplicateResponseLongText_2
(body) (body)
@ -662,9 +685,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_2")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
MultigetGetResponse::DuplicateResponseLongText_3 MultigetGetResponse::DuplicateResponseLongText_3
(body) (body)
@ -673,9 +698,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_3")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -735,6 +762,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
MultipleAuthSchemeGetResponse::CheckThatLimitingToMultipleRequiredAuthSchemesWorks MultipleAuthSchemeGetResponse::CheckThatLimitingToMultipleRequiredAuthSchemesWorks
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -768,9 +796,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for ONE_OF_GET_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -800,6 +830,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
OverrideServerGetResponse::Success OverrideServerGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -890,9 +921,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for PARAMGET_GET_JSON_RSP")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -951,6 +984,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
ReadonlyAuthSchemeGetResponse::CheckThatLimitingToASingleRequiredAuthSchemeWorks ReadonlyAuthSchemeGetResponse::CheckThatLimitingToASingleRequiredAuthSchemeWorks
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1008,6 +1042,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
RegisterCallbackPostResponse::OK RegisterCallbackPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1023,7 +1058,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// RequiredOctetStreamPut - PUT /required_octet_stream // RequiredOctetStreamPut - PUT /required_octet_stream
hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => { hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
@ -1042,6 +1077,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter body")), .expect("Unable to create Bad Request response for missing body parameter body")),
}; };
let result = api_impl.required_octet_stream_put( let result = api_impl.required_octet_stream_put(
param_body, param_body,
&context &context
@ -1057,6 +1093,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
RequiredOctetStreamPutResponse::OK RequiredOctetStreamPutResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1071,8 +1108,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter body: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter body")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
@ -1097,6 +1134,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
object_header object_header
} }
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
let success_info = match header::IntoHeaderValue(success_info).try_into() { let success_info = match header::IntoHeaderValue(success_info).try_into() {
Ok(val) => val, Ok(val) => val,
Err(e) => { Err(e) => {
@ -1111,6 +1150,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderName::from_static("success-info"), HeaderName::from_static("success-info"),
success_info success_info
); );
if let Some(bool_header) = bool_header { if let Some(bool_header) = bool_header {
let bool_header = match header::IntoHeaderValue(bool_header).try_into() { let bool_header = match header::IntoHeaderValue(bool_header).try_into() {
Ok(val) => val, Ok(val) => val,
@ -1127,6 +1167,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
bool_header bool_header
); );
} }
if let Some(object_header) = object_header { if let Some(object_header) = object_header {
let object_header = match header::IntoHeaderValue(object_header).try_into() { let object_header = match header::IntoHeaderValue(object_header).try_into() {
Ok(val) => val, Ok(val) => val,
@ -1143,13 +1184,14 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
object_header object_header
); );
} }
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for RESPONSES_WITH_HEADERS_GET_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
ResponsesWithHeadersGetResponse::PreconditionFailed ResponsesWithHeadersGetResponse::PreconditionFailed
{ {
@ -1157,6 +1199,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
failure_info failure_info
} }
=> { => {
*response.status_mut() = StatusCode::from_u16(412).expect("Unable to turn 412 into a StatusCode");
if let Some(further_info) = further_info { if let Some(further_info) = further_info {
let further_info = match header::IntoHeaderValue(further_info).try_into() { let further_info = match header::IntoHeaderValue(further_info).try_into() {
Ok(val) => val, Ok(val) => val,
@ -1173,6 +1217,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
further_info further_info
); );
} }
if let Some(failure_info) = failure_info { if let Some(failure_info) = failure_info {
let failure_info = match header::IntoHeaderValue(failure_info).try_into() { let failure_info = match header::IntoHeaderValue(failure_info).try_into() {
Ok(val) => val, Ok(val) => val,
@ -1189,7 +1234,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
failure_info failure_info
); );
} }
*response.status_mut() = StatusCode::from_u16(412).expect("Unable to turn 412 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1223,9 +1268,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for RFC7807_GET_OK")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
Rfc7807GetResponse::NotFound Rfc7807GetResponse::NotFound
(body) (body)
@ -1234,9 +1281,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/problem+json") HeaderValue::from_str("application/problem+json")
.expect("Unable to create Content-Type header for RFC7807_GET_NOT_FOUND")); .expect("Unable to create Content-Type header for application/problem+json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
Rfc7807GetResponse::NotAcceptable Rfc7807GetResponse::NotAcceptable
(body) (body)
@ -1245,9 +1294,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/problem+xml") HeaderValue::from_str("application/problem+xml")
.expect("Unable to create Content-Type header for RFC7807_GET_NOT_ACCEPTABLE")); .expect("Unable to create Content-Type header for application/problem+xml"));
let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); // XML Body
*response.body_mut() = Body::from(body_content); let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -1263,15 +1314,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// UntypedPropertyGet - GET /untyped_property // UntypedPropertyGet - GET /untyped_property
hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => { hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_object_untyped_props: Option<models::ObjectUntypedProps> = if !body.is_empty() { let param_object_untyped_props: Option<models::ObjectUntypedProps> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body); let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path); warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string()); unused_elements.push(path.to_string());
@ -1283,6 +1334,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.untyped_property_get( let result = api_impl.untyped_property_get(
param_object_untyped_props, param_object_untyped_props,
&context &context
@ -1299,12 +1351,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
UntypedPropertyGetResponse::CheckThatUntypedPropertiesWorks UntypedPropertyGetResponse::CheckThatUntypedPropertiesWorks
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1319,8 +1371,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter ObjectUntypedProps: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter ObjectUntypedProps")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
@ -1344,9 +1396,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -1362,13 +1416,13 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// XmlExtraPost - POST /xml_extra // XmlExtraPost - POST /xml_extra
hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => { hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() { let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
@ -1382,6 +1436,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.xml_extra_post( let result = api_impl.xml_extra_post(
param_duplicate_xml_object, param_duplicate_xml_object,
&context &context
@ -1398,16 +1453,17 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
XmlExtraPostResponse::OK XmlExtraPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
XmlExtraPostResponse::BadRequest XmlExtraPostResponse::BadRequest
=> { => {
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1422,20 +1478,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter DuplicateXmlObject: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter DuplicateXmlObject")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// XmlOtherPost - POST /xml_other // XmlOtherPost - POST /xml_other
hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => { hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() { let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
@ -1449,6 +1505,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.xml_other_post( let result = api_impl.xml_other_post(
param_another_xml_object, param_another_xml_object,
&context &context
@ -1465,7 +1522,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
XmlOtherPostResponse::OK XmlOtherPostResponse::OK
@ -1475,17 +1531,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("text/xml") HeaderValue::from_str("text/xml")
.expect("Unable to create Content-Type header for XML_OTHER_POST_OK")); .expect("Unable to create Content-Type header for text/xml"));
// XML Body
let mut namespaces = std::collections::BTreeMap::new(); let mut namespaces = std::collections::BTreeMap::new();
// An empty string is used to indicate a global namespace in xmltree. // An empty string is used to indicate a global namespace in xmltree.
namespaces.insert("".to_string(), models::AnotherXmlObject::NAMESPACE.to_string()); namespaces.insert("".to_string(), models::AnotherXmlObject::NAMESPACE.to_string());
let body_content = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body_content); *response.body_mut() = Body::from(body);
}, },
XmlOtherPostResponse::BadRequest XmlOtherPostResponse::BadRequest
=> { => {
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1500,20 +1559,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter AnotherXmlObject: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter AnotherXmlObject")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// XmlOtherPut - PUT /xml_other // XmlOtherPut - PUT /xml_other
hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => { hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_another_xml_array: Option<models::AnotherXmlArray> = if !body.is_empty() { let param_another_xml_array: Option<models::AnotherXmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
@ -1527,6 +1586,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.xml_other_put( let result = api_impl.xml_other_put(
param_another_xml_array, param_another_xml_array,
&context &context
@ -1543,16 +1603,17 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
XmlOtherPutResponse::OK XmlOtherPutResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
XmlOtherPutResponse::BadRequest XmlOtherPutResponse::BadRequest
=> { => {
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1567,20 +1628,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter AnotherXmlArray: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter AnotherXmlArray")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// XmlPost - POST /xml // XmlPost - POST /xml
hyper::Method::POST if path.matched(paths::ID_XML) => { hyper::Method::POST if path.matched(paths::ID_XML) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_xml_array: Option<models::XmlArray> = if !body.is_empty() { let param_xml_array: Option<models::XmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
@ -1594,6 +1655,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.xml_post( let result = api_impl.xml_post(
param_xml_array, param_xml_array,
&context &context
@ -1610,16 +1672,17 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
XmlPostResponse::OK XmlPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
XmlPostResponse::BadRequest XmlPostResponse::BadRequest
=> { => {
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1634,20 +1697,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter XmlArray: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter XmlArray")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// XmlPut - PUT /xml // XmlPut - PUT /xml
hyper::Method::PUT if path.matched(paths::ID_XML) => { hyper::Method::PUT if path.matched(paths::ID_XML) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_xml_object: Option<models::XmlObject> = if !body.is_empty() { let param_xml_object: Option<models::XmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body); let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
@ -1661,6 +1724,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
None None
}; };
let result = api_impl.xml_put( let result = api_impl.xml_put(
param_xml_object, param_xml_object,
&context &context
@ -1677,16 +1741,17 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
XmlPutResponse::OK XmlPutResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
XmlPutResponse::BadRequest XmlPutResponse::BadRequest
=> { => {
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1701,22 +1766,22 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter XmlObject: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter XmlObject")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// CreateRepo - POST /repos // CreateRepo - POST /repos
hyper::Method::POST if path.matched(paths::ID_REPOS) => { hyper::Method::POST if path.matched(paths::ID_REPOS) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_object_param: Option<models::ObjectParam> = if !body.is_empty() { let param_object_param: Option<models::ObjectParam> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body); let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path); warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string()); unused_elements.push(path.to_string());
@ -1738,6 +1803,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter ObjectParam")), .expect("Unable to create Bad Request response for missing body parameter ObjectParam")),
}; };
let result = api_impl.create_repo( let result = api_impl.create_repo(
param_object_param, param_object_param,
&context &context
@ -1754,12 +1820,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
CreateRepoResponse::Success CreateRepoResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1774,8 +1840,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter ObjectParam: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter ObjectParam")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
@ -1823,9 +1889,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for GET_REPO_INFO_OK")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {

View File

@ -266,6 +266,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op10GetResponse::OK Op10GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -295,6 +296,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op11GetResponse::OK Op11GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -324,6 +326,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op12GetResponse::OK Op12GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -353,6 +356,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op13GetResponse::OK Op13GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -382,6 +386,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op14GetResponse::OK Op14GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -411,6 +416,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op15GetResponse::OK Op15GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -440,6 +446,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op16GetResponse::OK Op16GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -469,6 +476,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op17GetResponse::OK Op17GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -498,6 +506,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op18GetResponse::OK Op18GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -527,6 +536,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op19GetResponse::OK Op19GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -556,6 +566,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op1GetResponse::OK Op1GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -585,6 +596,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op20GetResponse::OK Op20GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -614,6 +626,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op21GetResponse::OK Op21GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -643,6 +656,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op22GetResponse::OK Op22GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -672,6 +686,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op23GetResponse::OK Op23GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -701,6 +716,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op24GetResponse::OK Op24GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -730,6 +746,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op25GetResponse::OK Op25GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -759,6 +776,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op26GetResponse::OK Op26GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -788,6 +806,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op27GetResponse::OK Op27GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -817,6 +836,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op28GetResponse::OK Op28GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -846,6 +866,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op29GetResponse::OK Op29GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -875,6 +896,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op2GetResponse::OK Op2GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -904,6 +926,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op30GetResponse::OK Op30GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -933,6 +956,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op31GetResponse::OK Op31GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -962,6 +986,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op32GetResponse::OK Op32GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -991,6 +1016,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op33GetResponse::OK Op33GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1020,6 +1046,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op34GetResponse::OK Op34GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1049,6 +1076,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op35GetResponse::OK Op35GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1078,6 +1106,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op36GetResponse::OK Op36GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1107,6 +1136,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op37GetResponse::OK Op37GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1136,6 +1166,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op3GetResponse::OK Op3GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1165,6 +1196,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op4GetResponse::OK Op4GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1194,6 +1226,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op5GetResponse::OK Op5GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1223,6 +1256,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op6GetResponse::OK Op6GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1252,6 +1286,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op7GetResponse::OK Op7GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1281,6 +1316,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op8GetResponse::OK Op8GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -1310,6 +1346,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Op9GetResponse::OK Op9GetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {

View File

@ -451,9 +451,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";
@ -477,11 +477,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| { let body = serde_json::from_str::<models::Client>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(TestSpecialTagsResponse::SuccessfulOperation Ok(TestSpecialTagsResponse::SuccessfulOperation
(body) (body)
) )
@ -608,10 +610,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_body.map(|ref body| { // Consumes basic body
serde_json::to_string(body).expect("impossible to fail to serialize") // Body parameter
}); if let Some(param_body) = param_body {
if let Some(body) = body { let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -620,6 +622,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -635,11 +638,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<bool>(body).map_err(|e| { let body = serde_json::from_str::<bool>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(FakeOuterBooleanSerializeResponse::OutputBoolean Ok(FakeOuterBooleanSerializeResponse::OutputBoolean
(body) (body)
) )
@ -698,10 +703,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_body.map(|ref body| { // Consumes basic body
serde_json::to_string(body).expect("impossible to fail to serialize") // Body parameter
}); if let Some(param_body) = param_body {
if let Some(body) = body { let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -710,6 +715,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -725,11 +731,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::OuterComposite>(body).map_err(|e| { let body = serde_json::from_str::<models::OuterComposite>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(FakeOuterCompositeSerializeResponse::OutputComposite Ok(FakeOuterCompositeSerializeResponse::OutputComposite
(body) (body)
) )
@ -788,10 +796,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_body.map(|ref body| { // Consumes basic body
serde_json::to_string(body).expect("impossible to fail to serialize") // Body parameter
}); if let Some(param_body) = param_body {
if let Some(body) = body { let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -800,6 +808,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -815,11 +824,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<f64>(body).map_err(|e| { let body = serde_json::from_str::<f64>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(FakeOuterNumberSerializeResponse::OutputNumber Ok(FakeOuterNumberSerializeResponse::OutputNumber
(body) (body)
) )
@ -878,10 +889,10 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
let body = param_body.map(|ref body| { // Consumes basic body
serde_json::to_string(body).expect("impossible to fail to serialize") // Body parameter
}); if let Some(param_body) = param_body {
if let Some(body) = body { let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
} }
@ -890,6 +901,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -905,11 +917,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<String>(body).map_err(|e| { let body = serde_json::from_str::<String>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(FakeOuterStringSerializeResponse::OutputString Ok(FakeOuterStringSerializeResponse::OutputString
(body) (body)
) )
@ -1109,6 +1123,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -1117,6 +1133,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1186,6 +1203,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -1194,6 +1213,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1209,11 +1229,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| { let body = serde_json::from_str::<models::Client>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(TestClientModelResponse::SuccessfulOperation Ok(TestClientModelResponse::SuccessfulOperation
(body) (body)
) )
@ -1285,6 +1307,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes form body
let params = &[ let params = &[
("integer", param_integer.map(|param| format!("{:?}", param))), ("integer", param_integer.map(|param| format!("{:?}", param))),
("int32", param_int32.map(|param| format!("{:?}", param))), ("int32", param_int32.map(|param| format!("{:?}", param))),
@ -1303,12 +1326,14 @@ impl<S, C> Api<C> for Client<S, C> where
]; ];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize"); let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body.into_bytes());
let header = "application/x-www-form-urlencoded"; let header = "application/x-www-form-urlencoded";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) { request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
*request.body_mut() = Body::from(body.into_bytes());
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1424,17 +1449,20 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes form body
let params = &[ let params = &[
("enum_form_string", param_enum_form_string), ("enum_form_string", param_enum_form_string),
]; ];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize"); let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body.into_bytes());
let header = "application/x-www-form-urlencoded"; let header = "application/x-www-form-urlencoded";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) { request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
*request.body_mut() = Body::from(body.into_bytes());
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1544,6 +1572,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_param).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_param).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -1552,6 +1582,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1622,18 +1653,21 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes form body
let params = &[ let params = &[
("param", Some(param_param)), ("param", Some(param_param)),
("param2", Some(param_param2)), ("param2", Some(param_param2)),
]; ];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize"); let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body.into_bytes());
let header = "application/x-www-form-urlencoded"; let header = "application/x-www-form-urlencoded";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) { request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
*request.body_mut() = Body::from(body.into_bytes());
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -1706,9 +1740,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";
@ -1741,11 +1775,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::Client>(body).map_err(|e| { let body = serde_json::from_str::<models::Client>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(TestClassnameResponse::SuccessfulOperation Ok(TestClassnameResponse::SuccessfulOperation
(body) (body)
) )
@ -1804,6 +1840,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = param_body.as_xml(); let body = param_body.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -1813,6 +1850,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2045,12 +2083,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body) let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(FindPetsByStatusResponse::SuccessfulOperation Ok(FindPetsByStatusResponse::SuccessfulOperation
(body) (body)
) )
@ -2150,12 +2191,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body) let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(FindPetsByTagsResponse::SuccessfulOperation Ok(FindPetsByTagsResponse::SuccessfulOperation
(body) (body)
) )
@ -2244,12 +2288,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::Pet>(body) let body = serde_xml_rs::from_str::<models::Pet>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(GetPetByIdResponse::SuccessfulOperation Ok(GetPetByIdResponse::SuccessfulOperation
(body) (body)
) )
@ -2318,6 +2365,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = param_body.as_xml(); let body = param_body.as_xml();
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -2326,6 +2375,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2427,18 +2477,21 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes form body
let params = &[ let params = &[
("name", param_name), ("name", param_name),
("status", param_status), ("status", param_status),
]; ];
let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize"); let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body.into_bytes());
let header = "application/x-www-form-urlencoded"; let header = "application/x-www-form-urlencoded";
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) { request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
*request.body_mut() = Body::from(body.into_bytes());
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2530,6 +2583,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes multipart/form body
let (body_string, multipart_header) = { let (body_string, multipart_header) = {
let mut multipart = Multipart::new(); let mut multipart = Multipart::new();
@ -2585,6 +2639,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -2619,11 +2674,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::ApiResponse>(body).map_err(|e| { let body = serde_json::from_str::<models::ApiResponse>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(UploadFileResponse::SuccessfulOperation Ok(UploadFileResponse::SuccessfulOperation
(body) (body)
) )
@ -2780,11 +2837,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<std::collections::HashMap<String, i32>>(body).map_err(|e| { let body = serde_json::from_str::<std::collections::HashMap<String, i32>>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(GetInventoryResponse::SuccessfulOperation Ok(GetInventoryResponse::SuccessfulOperation
(body) (body)
) )
@ -2859,12 +2918,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::Order>(body) let body = serde_xml_rs::from_str::<models::Order>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(GetOrderByIdResponse::SuccessfulOperation Ok(GetOrderByIdResponse::SuccessfulOperation
(body) (body)
) )
@ -2933,8 +2995,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";
@ -2958,12 +3021,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::Order>(body) let body = serde_xml_rs::from_str::<models::Order>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(PlaceOrderResponse::SuccessfulOperation Ok(PlaceOrderResponse::SuccessfulOperation
(body) (body)
) )
@ -3027,6 +3093,7 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter // Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -3036,6 +3103,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -3105,6 +3173,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -3113,6 +3183,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -3182,6 +3253,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -3190,6 +3263,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -3350,12 +3424,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<models::User>(body) let body = serde_xml_rs::from_str::<models::User>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(GetUserByNameResponse::SuccessfulOperation Ok(GetUserByNameResponse::SuccessfulOperation
(body) (body)
) )
@ -3472,12 +3549,15 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
// ToDo: this will move to swagger-rs and become a standard From conversion trait // ToDo: this will move to swagger-rs and become a standard From conversion trait
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
let body = serde_xml_rs::from_str::<String>(body) let body = serde_xml_rs::from_str::<String>(body)
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
Ok(LoginUserResponse::SuccessfulOperation Ok(LoginUserResponse::SuccessfulOperation
{ {
body, body,
@ -3615,8 +3695,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";

View File

@ -168,6 +168,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
PingGetResponse::OK PingGetResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {

View File

@ -436,11 +436,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<models::AllOfObject>(body).map_err(|e| { let body = serde_json::from_str::<models::AllOfObject>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(AllOfGetResponse::OK Ok(AllOfGetResponse::OK
(body) (body)
) )
@ -567,6 +569,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_nested_response).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_nested_response).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -575,6 +579,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -658,11 +663,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<swagger::ByteArray>(body).map_err(|e| { let body = serde_json::from_str::<swagger::ByteArray>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(FileResponseGetResponse::Success Ok(FileResponseGetResponse::Success
(body) (body)
) )
@ -735,9 +742,12 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = body.to_string(); let body = body.to_string();
Ok(GetStructuredYamlResponse::OK Ok(GetStructuredYamlResponse::OK
(body) (body)
) )
@ -796,6 +806,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = param_body; let body = param_body;
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -804,6 +816,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -819,9 +832,12 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = body.to_string(); let body = body.to_string();
Ok(HtmlPostResponse::Success Ok(HtmlPostResponse::Success
(body) (body)
) )
@ -880,6 +896,8 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = param_value; let body = param_value;
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
@ -888,6 +906,7 @@ impl<S, C> Api<C> for Client<S, C> where
Ok(h) => h, Ok(h) => h,
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e))) Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
}); });
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str()); let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
Ok(h) => h, Ok(h) => h,
@ -971,11 +990,13 @@ impl<S, C> Api<C> for Client<S, C> where
let body = body let body = body
.into_raw() .into_raw()
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?; .map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
let body = str::from_utf8(&body) let body = str::from_utf8(&body)
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
let body = serde_json::from_str::<serde_json::Value>(body).map_err(|e| { let body = serde_json::from_str::<serde_json::Value>(body)
ApiError(format!("Response body did not match the schema: {}", e)) .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
})?;
Ok(RawJsonGetResponse::Success Ok(RawJsonGetResponse::Success
(body) (body)
) )
@ -1034,8 +1055,9 @@ impl<S, C> Api<C> for Client<S, C> where
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
}; };
// Consumes basic body
// Body parameter
let body = serde_json::to_string(&param_value).expect("impossible to fail to serialize"); let body = serde_json::to_string(&param_value).expect("impossible to fail to serialize");
*request.body_mut() = Body::from(body); *request.body_mut() = Body::from(body);
let header = "application/json"; let header = "application/json";

View File

@ -184,9 +184,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("*/*") HeaderValue::from_str("*/*")
.expect("Unable to create Content-Type header for ALL_OF_GET_OK")); .expect("Unable to create Content-Type header for */*"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -216,6 +218,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
DummyGetResponse::Success DummyGetResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -231,15 +234,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// DummyPut - PUT /dummy // DummyPut - PUT /dummy
hyper::Method::PUT if path.matched(paths::ID_DUMMY) => { hyper::Method::PUT if path.matched(paths::ID_DUMMY) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_nested_response: Option<models::DummyPutRequest> = if !body.is_empty() { let param_nested_response: Option<models::DummyPutRequest> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body); let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path); warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string()); unused_elements.push(path.to_string());
@ -261,6 +264,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter nested_response")), .expect("Unable to create Bad Request response for missing body parameter nested_response")),
}; };
let result = api_impl.dummy_put( let result = api_impl.dummy_put(
param_nested_response, param_nested_response,
&context &context
@ -277,12 +281,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
DummyPutResponse::Success DummyPutResponse::Success
=> { => {
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -297,8 +301,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter nested_response: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter nested_response")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
@ -322,9 +326,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/json") HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for FILE_RESPONSE_GET_SUCCESS")); .expect("Unable to create Content-Type header for application/json"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -358,9 +364,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("application/yaml") HeaderValue::from_str("application/yaml")
.expect("Unable to create Content-Type header for GET_STRUCTURED_YAML_OK")); .expect("Unable to create Content-Type header for application/yaml"));
let body_content = body; // Plain text Body
*response.body_mut() = Body::from(body_content); let body = body;
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -376,7 +384,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// HtmlPost - POST /html // HtmlPost - POST /html
hyper::Method::POST if path.matched(paths::ID_HTML) => { hyper::Method::POST if path.matched(paths::ID_HTML) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
@ -401,6 +409,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter body")), .expect("Unable to create Bad Request response for missing body parameter body")),
}; };
let result = api_impl.html_post( let result = api_impl.html_post(
param_body, param_body,
&context &context
@ -420,9 +429,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("text/html") HeaderValue::from_str("text/html")
.expect("Unable to create Content-Type header for HTML_POST_SUCCESS")); .expect("Unable to create Content-Type header for text/html"));
let body_content = body; // Plain text Body
*response.body_mut() = Body::from(body_content); let body = body;
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -437,14 +448,14 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter body: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter body")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
// PostYaml - POST /post-yaml // PostYaml - POST /post-yaml
hyper::Method::POST if path.matched(paths::ID_POST_YAML) => { hyper::Method::POST if path.matched(paths::ID_POST_YAML) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
@ -469,6 +480,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter value")), .expect("Unable to create Bad Request response for missing body parameter value")),
}; };
let result = api_impl.post_yaml( let result = api_impl.post_yaml(
param_value, param_value,
&context &context
@ -484,6 +496,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
PostYamlResponse::OK PostYamlResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -498,8 +511,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter value: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter value")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },
@ -523,9 +536,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
response.headers_mut().insert( response.headers_mut().insert(
CONTENT_TYPE, CONTENT_TYPE,
HeaderValue::from_str("*/*") HeaderValue::from_str("*/*")
.expect("Unable to create Content-Type header for RAW_JSON_GET_SUCCESS")); .expect("Unable to create Content-Type header for */*"));
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); // JSON Body
*response.body_mut() = Body::from(body_content); let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
}, },
}, },
Err(_) => { Err(_) => {
@ -541,15 +556,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
// SoloObjectPost - POST /solo-object // SoloObjectPost - POST /solo-object
hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => { hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => {
// Body parameters (note that non-required body parameters will ignore garbage // Handle body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for // values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields. // any unused fields.
let result = body.into_raw().await; let result = body.into_raw().await;
match result { match result {
Ok(body) => { Ok(body) => {
let mut unused_elements = Vec::new(); let mut unused_elements : Vec<String> = vec![];
let param_value: Option<serde_json::Value> = if !body.is_empty() { let param_value: Option<serde_json::Value> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body); let deserializer = &mut serde_json::Deserializer::from_slice(&*body);
match serde_ignored::deserialize(deserializer, |path| { match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path); warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string()); unused_elements.push(path.to_string());
@ -571,6 +586,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
.expect("Unable to create Bad Request response for missing body parameter value")), .expect("Unable to create Bad Request response for missing body parameter value")),
}; };
let result = api_impl.solo_object_post( let result = api_impl.solo_object_post(
param_value, param_value,
&context &context
@ -587,12 +603,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str()) HeaderValue::from_str(format!("Ignoring unknown fields in body: {:?}", unused_elements).as_str())
.expect("Unable to create Warning header value")); .expect("Unable to create Warning header value"));
} }
match result { match result {
Ok(rsp) => match rsp { Ok(rsp) => match rsp {
SoloObjectPostResponse::OK SoloObjectPostResponse::OK
=> { => {
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode"); *response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
}, },
}, },
Err(_) => { Err(_) => {
@ -607,8 +623,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
}, },
Err(e) => Ok(Response::builder() Err(e) => Ok(Response::builder()
.status(StatusCode::BAD_REQUEST) .status(StatusCode::BAD_REQUEST)
.body(Body::from(format!("Couldn't read body parameter value: {}", e))) .body(Body::from(format!("Unable to read body: {}", e)))
.expect("Unable to create Bad Request response due to unable to read body parameter value")), .expect("Unable to create Bad Request response due to unable to read body")),
} }
}, },