forked from loafle/openapi-generator-original
[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:
parent
8f7354a2a2
commit
daf52229e3
@ -821,12 +821,15 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
} else if (isMimetypePlain(mediaType)) {
|
||||
consumesPlainText = true;
|
||||
} else if (isMimetypeWwwFormUrlEncoded(mediaType)) {
|
||||
op.vendorExtensions.put("x-consumes-form", true);
|
||||
additionalProperties.put("usesUrlEncodedForm", true);
|
||||
} else if (isMimetypeMultipartFormData(mediaType)) {
|
||||
op.vendorExtensions.put("x-consumes-multipart", true);
|
||||
op.vendorExtensions.put("x-consumes-multipart-form", true);
|
||||
additionalProperties.put("apiUsesMultipartFormData", true);
|
||||
additionalProperties.put("apiUsesMultipart", true);
|
||||
} else if (isMimetypeMultipartRelated(mediaType)) {
|
||||
op.vendorExtensions.put("x-consumes-multipart", true);
|
||||
op.vendorExtensions.put("x-consumes-multipart-related", true);
|
||||
additionalProperties.put("apiUsesMultipartRelated", 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);
|
||||
|
||||
if (op.bodyParam != null) {
|
||||
// Default to consuming json
|
||||
op.bodyParam.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId);
|
||||
if (consumesXml) {
|
||||
op.vendorExtensions.put("x-consumes-basic", true);
|
||||
op.bodyParam.vendorExtensions.put("x-consumes-xml", true);
|
||||
} else if (consumesPlainText) {
|
||||
op.vendorExtensions.put("x-consumes-basic", true);
|
||||
op.bodyParam.vendorExtensions.put("x-consumes-plain-text", true);
|
||||
} else {
|
||||
op.vendorExtensions.put("x-consumes-basic", 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
|
||||
if (consumesXml) {
|
||||
op.vendorExtensions.put("x-consumes-basic", true);
|
||||
param.vendorExtensions.put("x-consumes-xml", true);
|
||||
} else if (consumesPlainText) {
|
||||
op.vendorExtensions.put("x-consumes-basic", true);
|
||||
param.vendorExtensions.put("x-consumes-plain-text", true);
|
||||
} else {
|
||||
op.vendorExtensions.put("x-consumes-basic", true);
|
||||
param.vendorExtensions.put("x-consumes-json", true);
|
||||
}
|
||||
}
|
||||
|
@ -85,217 +85,7 @@
|
||||
Ok(req) => req,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
{{#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(¶m_{{{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(¶m_{{{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}}
|
||||
{{>client-request-body-instance}}
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -421,29 +211,9 @@
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
{{#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}}
|
||||
|
||||
{{>client-response-body-instance}}
|
||||
|
||||
Ok({{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
|
||||
{{^headers}}
|
||||
(body)
|
||||
|
84
modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache
vendored
Normal file
84
modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache
vendored
Normal 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(¶m_{{{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}}
|
@ -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(¶m_{{{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)))
|
||||
});
|
22
modules/openapi-generator/src/main/resources/rust-server/client-response-body-instance.mustache
vendored
Normal file
22
modules/openapi-generator/src/main/resources/rust-server/client-response-body-instance.mustache
vendored
Normal 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}}
|
@ -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}}
|
45
modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache
vendored
Normal file
45
modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache
vendored
Normal 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}}
|
@ -38,16 +38,6 @@
|
||||
|
||||
{{/hasAuthMethods}}
|
||||
{{#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}}
|
||||
// Path parameters
|
||||
let path: &str = uri.path();
|
||||
@ -202,278 +192,22 @@
|
||||
|
||||
{{/-last}}
|
||||
{{/queryParams}}
|
||||
{{#vendorExtensions}}
|
||||
{{^x-consumes-multipart}}
|
||||
{{#bodyParams}}
|
||||
{{#-first}}
|
||||
// Body parameters (note that non-required body parameters will ignore garbage
|
||||
{{#vendorExtensions.x-has-request-body}}
|
||||
// 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) => {
|
||||
{{#vendorExtensions}}
|
||||
{{^x-consumes-plain-text}}
|
||||
let mut unused_elements = Vec::new();
|
||||
{{/x-consumes-plain-text}}
|
||||
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}}
|
||||
{{/-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}}
|
||||
Ok(body) => {
|
||||
{{^vendorExtensions.x-consumes-multipart-form}}
|
||||
{{^vendorExtensions.x-consumes-form}}
|
||||
{{^bodyParam.vendorExtensions.x-consumes-plain-text}}
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
{{/bodyParam.vendorExtensions.x-consumes-plain-text}}
|
||||
{{/vendorExtensions.x-consumes-form}}
|
||||
{{/vendorExtensions.x-consumes-multipart-form}}
|
||||
{{>server-request-body-instance}}
|
||||
{{/vendorExtensions.x-has-request-body}}
|
||||
let result = api_impl.{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
||||
{{#vendorExtensions}}
|
||||
{{#x-callback-params}}
|
||||
@ -491,19 +225,20 @@
|
||||
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
|
||||
.expect("Unable to create X-Span-ID header value"));
|
||||
|
||||
{{#bodyParams}}
|
||||
{{#vendorExtensions}}
|
||||
{{^x-consumes-plain-text}}
|
||||
{{#vendorExtensions.x-has-request-body}}
|
||||
{{^vendorExtensions.x-consumes-multipart-form}}
|
||||
{{^vendorExtensions.x-consumes-form}}
|
||||
{{^bodyParam.vendorExtensions.x-consumes-plain-text}}
|
||||
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"));
|
||||
}
|
||||
|
||||
{{/x-consumes-plain-text}}
|
||||
{{/vendorExtensions}}
|
||||
{{/bodyParams}}
|
||||
{{/bodyParam.vendorExtensions.x-consumes-plain-text}}
|
||||
{{/vendorExtensions.x-consumes-form}}
|
||||
{{/vendorExtensions.x-consumes-multipart-form}}
|
||||
{{/vendorExtensions.x-has-request-body}}
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
{{#responses}}
|
||||
@ -535,7 +270,9 @@
|
||||
{{/headers}}
|
||||
{{/dataType}}
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16({{{code}}}).expect("Unable to turn {{{code}}} into a StatusCode");
|
||||
{{#headers}}
|
||||
|
||||
{{^required}}
|
||||
if let Some({{{name}}}) = {{{name}}} {
|
||||
{{/required}}
|
||||
@ -557,45 +294,7 @@
|
||||
}
|
||||
{{/required}}
|
||||
{{/headers}}
|
||||
*response.status_mut() = StatusCode::from_u16({{{code}}}).expect("Unable to turn {{{code}}} into a StatusCode");
|
||||
{{#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}}
|
||||
{{>server-response-body-instance}}
|
||||
},
|
||||
{{/responses}}
|
||||
},
|
||||
@ -608,44 +307,12 @@
|
||||
}
|
||||
|
||||
Ok(response)
|
||||
{{#vendorExtensions}}
|
||||
{{^x-consumes-multipart}}
|
||||
{{^bodyParams}}
|
||||
{{#vendorExtensions}}
|
||||
{{#x-consumes-multipart-related}}
|
||||
{{#vendorExtensions.x-has-request-body}}
|
||||
},
|
||||
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}}}")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
{{/x-consumes-multipart-related}}
|
||||
{{/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}}
|
||||
{{/vendorExtensions.x-has-request-body}}
|
||||
},
|
||||
|
52
modules/openapi-generator/src/main/resources/rust-server/server-request-body-basic.mustache
vendored
Normal file
52
modules/openapi-generator/src/main/resources/rust-server/server-request-body-basic.mustache
vendored
Normal 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}}
|
24
modules/openapi-generator/src/main/resources/rust-server/server-request-body-form.mustache
vendored
Normal file
24
modules/openapi-generator/src/main/resources/rust-server/server-request-body-form.mustache
vendored
Normal 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}}
|
20
modules/openapi-generator/src/main/resources/rust-server/server-request-body-instance.mustache
vendored
Normal file
20
modules/openapi-generator/src/main/resources/rust-server/server-request-body-instance.mustache
vendored
Normal 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}}
|
@ -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}}
|
@ -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}}
|
50
modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache
vendored
Normal file
50
modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache
vendored
Normal 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}}
|
@ -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)))
|
||||
};
|
||||
|
||||
// Consumes multipart/related body
|
||||
// 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
|
||||
@ -433,7 +434,6 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
*b = b'=';
|
||||
}
|
||||
}
|
||||
|
||||
let mut body_parts = vec![];
|
||||
|
||||
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)
|
||||
.expect("Failed to write multipart body");
|
||||
|
||||
// Add the message body to the request object.
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "multipart/related";
|
||||
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)))
|
||||
});
|
||||
|
||||
// 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());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes multipart/form body
|
||||
let (body_string, multipart_header) = {
|
||||
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)))
|
||||
});
|
||||
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes multipart/related body
|
||||
// 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
|
||||
@ -726,7 +730,6 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
*b = b'=';
|
||||
}
|
||||
}
|
||||
|
||||
let mut body_parts = vec![];
|
||||
|
||||
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)
|
||||
.expect("Failed to write multipart body");
|
||||
|
||||
// Add the message body to the request object.
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "multipart/related";
|
||||
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)))
|
||||
});
|
||||
|
||||
// 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());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
|
@ -155,14 +155,13 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// MultipartRelatedRequestPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw();
|
||||
match result.await {
|
||||
Ok(body) => {
|
||||
let mut unused_elements: Vec<String> = vec![];
|
||||
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
// Get multipart chunks.
|
||||
|
||||
// Extract the top-level content type header.
|
||||
@ -215,9 +214,9 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
}) {
|
||||
Ok(json_data) => json_data,
|
||||
Err(e) => return Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't parse body parameter models::MultipartRequestObjectField - doesn't match schema: {}", e)))
|
||||
.expect("Unable to create Bad Request response for invalid body parameter models::MultipartRequestObjectField due to schema"))
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't parse body parameter models::MultipartRequestObjectField - doesn't match schema: {}", e)))
|
||||
.expect("Unable to create Bad Request response for invalid body parameter models::MultipartRequestObjectField due to schema"))
|
||||
};
|
||||
// Push JSON part to return object.
|
||||
param_object_field.get_or_insert(json_data);
|
||||
@ -246,11 +245,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
let param_required_binary_field = 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 required_binary_field".to_string()))
|
||||
.expect("Unable to create Bad Request response for missing multipart/related parameter required_binary_field due to schema"))
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from("Missing required multipart/related parameter required_binary_field".to_string()))
|
||||
.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(
|
||||
param_required_binary_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())
|
||||
.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 {
|
||||
Ok(rsp) => match rsp {
|
||||
MultipartRelatedRequestPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -282,27 +289,27 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter Default: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter Default")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// MultipartRequestPost - POST /multipart_request
|
||||
hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => {
|
||||
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")),
|
||||
};
|
||||
|
||||
// Form 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
|
||||
// any unused fields.
|
||||
let result = body.into_raw();
|
||||
match result.await {
|
||||
Ok(body) => {
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
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
|
||||
@ -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"))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.multipart_request_post(
|
||||
param_string_field,
|
||||
param_binary_field,
|
||||
@ -425,6 +434,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
MultipartRequestPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -439,21 +449,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
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")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// MultipleIdenticalMimeTypesPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw();
|
||||
match result.await {
|
||||
Ok(body) => {
|
||||
let mut unused_elements: Vec<String> = vec![];
|
||||
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
// Get multipart chunks.
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
let result = api_impl.multiple_identical_mime_types_post(
|
||||
param_binary1,
|
||||
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())
|
||||
.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 {
|
||||
Ok(rsp) => match rsp {
|
||||
MultipleIdenticalMimeTypesPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -548,8 +565,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter Default: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter Default")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -414,10 +414,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_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";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
|
@ -144,15 +144,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// OpGet - GET /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
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| {
|
||||
warn!("Ignoring unknown field in body: {}", path);
|
||||
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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.op_get(
|
||||
param_op_get_request,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
OpGetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -210,8 +211,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter OpGetRequest: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter OpGetRequest")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -204,6 +204,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
CallbackCallbackWithHeaderPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -244,6 +245,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
CallbackCallbackPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
|
@ -460,11 +460,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnyOfObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnyOfObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(AnyOfGetResponse::Success
|
||||
(body)
|
||||
)
|
||||
@ -474,11 +476,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::Model12345AnyOfObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::Model12345AnyOfObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(AnyOfGetResponse::AlternateSuccess
|
||||
(body)
|
||||
)
|
||||
@ -488,11 +492,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnyOfGet202Response>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnyOfGet202Response>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(AnyOfGetResponse::AnyOfSuccess
|
||||
(body)
|
||||
)
|
||||
@ -936,11 +942,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MergePatchJsonGetResponse::Merge
|
||||
(body)
|
||||
)
|
||||
@ -1013,11 +1021,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::JSONRsp
|
||||
(body)
|
||||
)
|
||||
@ -1027,12 +1037,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::MultigetGet201Response>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::XMLRsp
|
||||
(body)
|
||||
)
|
||||
@ -1042,7 +1055,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = swagger::ByteArray(body.to_vec());
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::OctetRsp
|
||||
(body)
|
||||
)
|
||||
@ -1052,9 +1068,12 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = body.to_string();
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::StringRsp
|
||||
(body)
|
||||
)
|
||||
@ -1064,11 +1083,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::DuplicateResponseLongText
|
||||
(body)
|
||||
)
|
||||
@ -1078,11 +1099,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::DuplicateResponseLongText_2
|
||||
(body)
|
||||
)
|
||||
@ -1092,11 +1115,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(MultigetGetResponse::DuplicateResponseLongText_3
|
||||
(body)
|
||||
)
|
||||
@ -1256,11 +1281,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::OneOfGet200Response>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::OneOfGet200Response>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(OneOfGetResponse::Success
|
||||
(body)
|
||||
)
|
||||
@ -1416,11 +1443,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(ParamgetGetResponse::JSONRsp
|
||||
(body)
|
||||
)
|
||||
@ -1637,14 +1666,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = param_body.0;
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/octet-stream";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -1770,11 +1802,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<String>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<String>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(ResponsesWithHeadersGetResponse::Success
|
||||
{
|
||||
body,
|
||||
@ -1889,11 +1923,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(Rfc7807GetResponse::OK
|
||||
(body)
|
||||
)
|
||||
@ -1903,11 +1939,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::ObjectWithArrayOfObjects>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(Rfc7807GetResponse::NotFound
|
||||
(body)
|
||||
)
|
||||
@ -1917,12 +1955,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::ObjectWithArrayOfObjects>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(Rfc7807GetResponse::NotAcceptable
|
||||
(body)
|
||||
)
|
||||
@ -1981,11 +2022,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_object_untyped_props.map(|ref body| {
|
||||
serde_json::to_string(body).expect("impossible to fail to serialize")
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_object_untyped_props) = param_object_untyped_props {
|
||||
let body = serde_json::to_string(¶m_object_untyped_props).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/json";
|
||||
@ -1993,6 +2034,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2076,11 +2118,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<uuid::Uuid>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<uuid::Uuid>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(UuidGetResponse::DuplicateResponseLongText
|
||||
(body)
|
||||
)
|
||||
@ -2139,11 +2183,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_duplicate_xml_object.map(|ref body| {
|
||||
body.as_xml()
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_duplicate_xml_object) = param_duplicate_xml_object {
|
||||
let body = param_duplicate_xml_object.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/xml";
|
||||
@ -2151,6 +2195,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2225,11 +2270,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_another_xml_object.map(|ref body| {
|
||||
body.as_xml()
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_another_xml_object) = param_another_xml_object {
|
||||
let body = param_another_xml_object.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "text/xml";
|
||||
@ -2237,6 +2282,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2252,12 +2298,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::AnotherXmlObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(XmlOtherPostResponse::OK
|
||||
(body)
|
||||
)
|
||||
@ -2321,11 +2370,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_another_xml_array.map(|ref body| {
|
||||
body.as_xml()
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_another_xml_array) = param_another_xml_array {
|
||||
let body = param_another_xml_array.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/xml";
|
||||
@ -2333,6 +2382,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2407,11 +2457,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_xml_array.map(|ref body| {
|
||||
body.as_xml()
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_xml_array) = param_xml_array {
|
||||
let body = param_xml_array.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/xml";
|
||||
@ -2419,6 +2469,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2493,12 +2544,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_xml_object.map(|ref body| {
|
||||
body.as_xml()
|
||||
});
|
||||
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_xml_object) = param_xml_object {
|
||||
let body = param_xml_object.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/xml";
|
||||
@ -2581,15 +2631,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_object_param).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2675,11 +2727,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<String>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<String>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(GetRepoInfoResponse::OK
|
||||
(body)
|
||||
)
|
||||
|
@ -259,9 +259,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for ANY_OF_GET_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
AnyOfGetResponse::AlternateSuccess
|
||||
(body)
|
||||
@ -270,9 +272,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for ANY_OF_GET_ALTERNATE_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
AnyOfGetResponse::AnyOfSuccess
|
||||
(body)
|
||||
@ -281,9 +285,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for ANY_OF_GET_ANY_OF_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -341,6 +347,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
CallbackWithHeaderPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -382,6 +389,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
ComplexQueryParamGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -435,6 +443,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
EnumInPathPathParamGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -485,6 +494,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
JsonComplexQueryParamGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -538,6 +548,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
MandatoryRequestHeaderGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -571,9 +582,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/merge-patch+json")
|
||||
.expect("Unable to create Content-Type header for MERGE_PATCH_JSON_GET_MERGE"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/merge-patch+json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -607,9 +620,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_JSON_RSP"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::XMLRsp
|
||||
(body)
|
||||
@ -618,9 +633,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/xml")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_XML_RSP"));
|
||||
let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/xml"));
|
||||
// XML Body
|
||||
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::OctetRsp
|
||||
(body)
|
||||
@ -629,9 +646,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/octet-stream")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_OCTET_RSP"));
|
||||
let body_content = body.0;
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/octet-stream"));
|
||||
// Binary Body
|
||||
let body = body.0;
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::StringRsp
|
||||
(body)
|
||||
@ -640,9 +659,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("text/plain")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_STRING_RSP"));
|
||||
let body_content = body;
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for text/plain"));
|
||||
// Plain text Body
|
||||
let body = body;
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::DuplicateResponseLongText
|
||||
(body)
|
||||
@ -651,9 +672,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::DuplicateResponseLongText_2
|
||||
(body)
|
||||
@ -662,9 +685,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_2"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
MultigetGetResponse::DuplicateResponseLongText_3
|
||||
(body)
|
||||
@ -673,9 +698,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_3"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -735,6 +762,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
MultipleAuthSchemeGetResponse::CheckThatLimitingToMultipleRequiredAuthSchemesWorks
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -768,9 +796,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for ONE_OF_GET_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -800,6 +830,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
OverrideServerGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -890,9 +921,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for PARAMGET_GET_JSON_RSP"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -951,6 +984,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
ReadonlyAuthSchemeGetResponse::CheckThatLimitingToASingleRequiredAuthSchemeWorks
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1008,6 +1042,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
RegisterCallbackPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1023,12 +1058,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// RequiredOctetStreamPut - PUT /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
Ok(body) => {
|
||||
let param_body: Option<swagger::ByteArray> = if !body.is_empty() {
|
||||
Some(swagger::ByteArray(body.to_vec()))
|
||||
} else {
|
||||
@ -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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.required_octet_stream_put(
|
||||
param_body,
|
||||
&context
|
||||
@ -1057,6 +1093,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
RequiredOctetStreamPutResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1071,8 +1108,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter body")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.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
|
||||
}
|
||||
=> {
|
||||
*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() {
|
||||
Ok(val) => val,
|
||||
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"),
|
||||
success_info
|
||||
);
|
||||
|
||||
if let Some(bool_header) = bool_header {
|
||||
let bool_header = match header::IntoHeaderValue(bool_header).try_into() {
|
||||
Ok(val) => val,
|
||||
@ -1127,6 +1167,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
bool_header
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(object_header) = object_header {
|
||||
let object_header = match header::IntoHeaderValue(object_header).try_into() {
|
||||
Ok(val) => val,
|
||||
@ -1143,13 +1184,14 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
object_header
|
||||
);
|
||||
}
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for RESPONSES_WITH_HEADERS_GET_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
ResponsesWithHeadersGetResponse::PreconditionFailed
|
||||
{
|
||||
@ -1157,6 +1199,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
failure_info
|
||||
}
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(412).expect("Unable to turn 412 into a StatusCode");
|
||||
|
||||
if let Some(further_info) = further_info {
|
||||
let further_info = match header::IntoHeaderValue(further_info).try_into() {
|
||||
Ok(val) => val,
|
||||
@ -1173,6 +1217,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
further_info
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(failure_info) = failure_info {
|
||||
let failure_info = match header::IntoHeaderValue(failure_info).try_into() {
|
||||
Ok(val) => val,
|
||||
@ -1189,7 +1234,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
failure_info
|
||||
);
|
||||
}
|
||||
*response.status_mut() = StatusCode::from_u16(412).expect("Unable to turn 412 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1223,9 +1268,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for RFC7807_GET_OK"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
Rfc7807GetResponse::NotFound
|
||||
(body)
|
||||
@ -1234,9 +1281,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/problem+json")
|
||||
.expect("Unable to create Content-Type header for RFC7807_GET_NOT_FOUND"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/problem+json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
Rfc7807GetResponse::NotAcceptable
|
||||
(body)
|
||||
@ -1245,9 +1294,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/problem+xml")
|
||||
.expect("Unable to create Content-Type header for RFC7807_GET_NOT_ACCEPTABLE"));
|
||||
let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/problem+xml"));
|
||||
// XML Body
|
||||
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1263,15 +1314,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// UntypedPropertyGet - GET /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
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| {
|
||||
warn!("Ignoring unknown field in body: {}", path);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.untyped_property_get(
|
||||
param_object_untyped_props,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
UntypedPropertyGetResponse::CheckThatUntypedPropertiesWorks
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1319,8 +1371,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter ObjectUntypedProps: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter ObjectUntypedProps")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.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(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1362,13 +1416,13 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// XmlExtraPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() {
|
||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.xml_extra_post(
|
||||
param_duplicate_xml_object,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
XmlExtraPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
XmlExtraPostResponse::BadRequest
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1422,20 +1478,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter DuplicateXmlObject: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter DuplicateXmlObject")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// XmlOtherPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() {
|
||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.xml_other_post(
|
||||
param_another_xml_object,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
XmlOtherPostResponse::OK
|
||||
@ -1475,17 +1531,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
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();
|
||||
|
||||
// An empty string is used to indicate a global namespace in xmltree.
|
||||
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");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
XmlOtherPostResponse::BadRequest
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1500,20 +1559,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter AnotherXmlObject: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter AnotherXmlObject")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// XmlOtherPut - PUT /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
let param_another_xml_array: Option<models::AnotherXmlArray> = if !body.is_empty() {
|
||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.xml_other_put(
|
||||
param_another_xml_array,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
XmlOtherPutResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
XmlOtherPutResponse::BadRequest
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1567,20 +1628,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter AnotherXmlArray: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter AnotherXmlArray")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// XmlPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
let param_xml_array: Option<models::XmlArray> = if !body.is_empty() {
|
||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.xml_post(
|
||||
param_xml_array,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
XmlPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
XmlPostResponse::BadRequest
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1634,20 +1697,20 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter XmlArray: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter XmlArray")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// XmlPut - PUT /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
let param_xml_object: Option<models::XmlObject> = if !body.is_empty() {
|
||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.xml_put(
|
||||
param_xml_object,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
XmlPutResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
XmlPutResponse::BadRequest
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1701,22 +1766,22 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter XmlObject: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter XmlObject")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// CreateRepo - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
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| {
|
||||
warn!("Ignoring unknown field in body: {}", path);
|
||||
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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.create_repo(
|
||||
param_object_param,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
CreateRepoResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1774,8 +1840,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter ObjectParam: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter ObjectParam")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.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(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for GET_REPO_INFO_OK"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
|
@ -266,6 +266,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op10GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -295,6 +296,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op11GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -324,6 +326,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op12GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -353,6 +356,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op13GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -382,6 +386,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op14GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -411,6 +416,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op15GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -440,6 +446,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op16GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -469,6 +476,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op17GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -498,6 +506,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op18GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -527,6 +536,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op19GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -556,6 +566,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op1GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -585,6 +596,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op20GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -614,6 +626,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op21GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -643,6 +656,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op22GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -672,6 +686,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op23GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -701,6 +716,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op24GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -730,6 +746,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op25GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -759,6 +776,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op26GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -788,6 +806,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op27GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -817,6 +836,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op28GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -846,6 +866,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op29GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -875,6 +896,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op2GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -904,6 +926,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op30GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -933,6 +956,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op31GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -962,6 +986,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op32GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -991,6 +1016,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op33GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1020,6 +1046,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op34GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1049,6 +1076,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op35GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1078,6 +1106,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op36GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1107,6 +1136,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op37GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1136,6 +1166,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op3GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1165,6 +1196,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op4GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1194,6 +1226,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op5GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1223,6 +1256,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op6GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1252,6 +1286,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op7GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1281,6 +1316,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op8GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -1310,6 +1346,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
Op9GetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
|
@ -451,10 +451,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
@ -477,11 +477,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::Client>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(TestSpecialTagsResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -608,11 +610,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_body.map(|ref body| {
|
||||
serde_json::to_string(body).expect("impossible to fail to serialize")
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_body) = param_body {
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/json";
|
||||
@ -620,6 +622,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -635,11 +638,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<bool>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<bool>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FakeOuterBooleanSerializeResponse::OutputBoolean
|
||||
(body)
|
||||
)
|
||||
@ -698,11 +703,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_body.map(|ref body| {
|
||||
serde_json::to_string(body).expect("impossible to fail to serialize")
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_body) = param_body {
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/json";
|
||||
@ -710,6 +715,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -725,11 +731,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::OuterComposite>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::OuterComposite>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FakeOuterCompositeSerializeResponse::OutputComposite
|
||||
(body)
|
||||
)
|
||||
@ -788,11 +796,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_body.map(|ref body| {
|
||||
serde_json::to_string(body).expect("impossible to fail to serialize")
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_body) = param_body {
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/json";
|
||||
@ -800,6 +808,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -815,11 +824,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<f64>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<f64>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FakeOuterNumberSerializeResponse::OutputNumber
|
||||
(body)
|
||||
)
|
||||
@ -878,11 +889,11 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
let body = param_body.map(|ref body| {
|
||||
serde_json::to_string(body).expect("impossible to fail to serialize")
|
||||
});
|
||||
if let Some(body) = body {
|
||||
*request.body_mut() = Body::from(body);
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
if let Some(param_body) = param_body {
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
}
|
||||
|
||||
let header = "application/json";
|
||||
@ -890,6 +901,7 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Ok(h) => h,
|
||||
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -905,11 +917,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<String>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<String>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FakeOuterStringSerializeResponse::OutputString
|
||||
(body)
|
||||
)
|
||||
@ -1109,14 +1123,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -1186,14 +1203,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -1209,11 +1229,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::Client>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(TestClientModelResponse::SuccessfulOperation
|
||||
(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)))
|
||||
};
|
||||
|
||||
// Consumes form body
|
||||
let params = &[
|
||||
("integer", param_integer.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");
|
||||
|
||||
*request.body_mut() = Body::from(body.into_bytes());
|
||||
|
||||
let header = "application/x-www-form-urlencoded";
|
||||
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());
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes form body
|
||||
let params = &[
|
||||
("enum_form_string", param_enum_form_string),
|
||||
];
|
||||
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";
|
||||
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());
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -1544,14 +1572,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_param).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes form body
|
||||
let params = &[
|
||||
("param", Some(param_param)),
|
||||
("param2", Some(param_param2)),
|
||||
];
|
||||
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";
|
||||
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());
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -1706,10 +1740,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
@ -1741,11 +1775,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::Client>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::Client>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(TestClassnameResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -1804,15 +1840,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = param_body.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2045,12 +2083,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FindPetsByStatusResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2150,12 +2191,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<Vec<models::Pet>>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FindPetsByTagsResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2244,12 +2288,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::Pet>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(GetPetByIdResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2318,14 +2365,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = param_body.as_xml();
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes form body
|
||||
let params = &[
|
||||
("name", param_name),
|
||||
("status", param_status),
|
||||
];
|
||||
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";
|
||||
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());
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
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)))
|
||||
};
|
||||
|
||||
// Consumes multipart/form body
|
||||
let (body_string, multipart_header) = {
|
||||
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)))
|
||||
});
|
||||
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -2619,11 +2674,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::ApiResponse>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::ApiResponse>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(UploadFileResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2780,11 +2837,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<std::collections::HashMap<String, i32>>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(GetInventoryResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2859,12 +2918,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::Order>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(GetOrderByIdResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -2933,9 +2995,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
@ -2958,12 +3021,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::Order>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(PlaceOrderResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -3027,15 +3093,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -3105,14 +3173,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -3182,14 +3253,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -3350,12 +3424,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<models::User>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(GetUserByNameResponse::SuccessfulOperation
|
||||
(body)
|
||||
)
|
||||
@ -3472,12 +3549,15 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.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
|
||||
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
|
||||
let body = serde_xml_rs::from_str::<String>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(LoginUserResponse::SuccessfulOperation
|
||||
{
|
||||
body,
|
||||
@ -3615,9 +3695,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize");
|
||||
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -168,6 +168,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
PingGetResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
|
@ -436,11 +436,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<models::AllOfObject>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<models::AllOfObject>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(AllOfGetResponse::OK
|
||||
(body)
|
||||
)
|
||||
@ -567,14 +569,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_nested_response).expect("impossible to fail to serialize");
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -658,11 +663,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<swagger::ByteArray>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<swagger::ByteArray>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(FileResponseGetResponse::Success
|
||||
(body)
|
||||
)
|
||||
@ -735,9 +742,12 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = body.to_string();
|
||||
|
||||
|
||||
Ok(GetStructuredYamlResponse::OK
|
||||
(body)
|
||||
)
|
||||
@ -796,14 +806,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = param_body;
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "text/html";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -819,9 +832,12 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = body.to_string();
|
||||
|
||||
|
||||
Ok(HtmlPostResponse::Success
|
||||
(body)
|
||||
)
|
||||
@ -880,14 +896,17 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = param_value;
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/yaml";
|
||||
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)))
|
||||
});
|
||||
|
||||
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
|
||||
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
|
||||
Ok(h) => h,
|
||||
@ -971,11 +990,13 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
let body = body
|
||||
.into_raw()
|
||||
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
|
||||
|
||||
let body = str::from_utf8(&body)
|
||||
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
|
||||
let body = serde_json::from_str::<serde_json::Value>(body).map_err(|e| {
|
||||
ApiError(format!("Response body did not match the schema: {}", e))
|
||||
})?;
|
||||
let body = serde_json::from_str::<serde_json::Value>(body)
|
||||
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
|
||||
|
||||
|
||||
Ok(RawJsonGetResponse::Success
|
||||
(body)
|
||||
)
|
||||
@ -1034,9 +1055,10 @@ impl<S, C> Api<C> for Client<S, C> where
|
||||
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
|
||||
};
|
||||
|
||||
// Consumes basic body
|
||||
// Body parameter
|
||||
let body = serde_json::to_string(¶m_value).expect("impossible to fail to serialize");
|
||||
|
||||
*request.body_mut() = Body::from(body);
|
||||
*request.body_mut() = Body::from(body);
|
||||
|
||||
let header = "application/json";
|
||||
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
|
||||
|
@ -184,9 +184,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("*/*")
|
||||
.expect("Unable to create Content-Type header for ALL_OF_GET_OK"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for */*"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -216,6 +218,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
DummyGetResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -231,15 +234,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// DummyPut - PUT /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
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| {
|
||||
warn!("Ignoring unknown field in body: {}", path);
|
||||
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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.dummy_put(
|
||||
param_nested_response,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
DummyPutResponse::Success
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -297,8 +301,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter nested_response: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter nested_response")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.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(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/json")
|
||||
.expect("Unable to create Content-Type header for FILE_RESPONSE_GET_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/json"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -358,9 +364,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("application/yaml")
|
||||
.expect("Unable to create Content-Type header for GET_STRUCTURED_YAML_OK"));
|
||||
let body_content = body;
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for application/yaml"));
|
||||
// Plain text Body
|
||||
let body = body;
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -376,12 +384,12 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// HtmlPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
Ok(body) => {
|
||||
let param_body: Option<String> = if !body.is_empty() {
|
||||
match String::from_utf8(body.to_vec()) {
|
||||
Ok(param_body) => Some(param_body),
|
||||
@ -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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.html_post(
|
||||
param_body,
|
||||
&context
|
||||
@ -420,9 +429,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("text/html")
|
||||
.expect("Unable to create Content-Type header for HTML_POST_SUCCESS"));
|
||||
let body_content = body;
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for text/html"));
|
||||
// Plain text Body
|
||||
let body = body;
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -437,19 +448,19 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter body")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
// PostYaml - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
Ok(body) => {
|
||||
let param_value: Option<String> = if !body.is_empty() {
|
||||
match String::from_utf8(body.to_vec()) {
|
||||
Ok(param_value) => Some(param_value),
|
||||
@ -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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.post_yaml(
|
||||
param_value,
|
||||
&context
|
||||
@ -484,6 +496,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
PostYamlResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -498,8 +511,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter value: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter value")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.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(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str("*/*")
|
||||
.expect("Unable to create Content-Type header for RAW_JSON_GET_SUCCESS"));
|
||||
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body_content);
|
||||
.expect("Unable to create Content-Type header for */*"));
|
||||
// JSON Body
|
||||
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
|
||||
*response.body_mut() = Body::from(body);
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -541,15 +556,15 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
|
||||
// SoloObjectPost - POST /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
|
||||
// any unused fields.
|
||||
let result = body.into_raw().await;
|
||||
match result {
|
||||
Ok(body) => {
|
||||
let mut unused_elements = Vec::new();
|
||||
Ok(body) => {
|
||||
let mut unused_elements : Vec<String> = vec![];
|
||||
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| {
|
||||
warn!("Ignoring unknown field in body: {}", path);
|
||||
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")),
|
||||
};
|
||||
|
||||
|
||||
let result = api_impl.solo_object_post(
|
||||
param_value,
|
||||
&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())
|
||||
.expect("Unable to create Warning header value"));
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(rsp) => match rsp {
|
||||
SoloObjectPostResponse::OK
|
||||
=> {
|
||||
*response.status_mut() = StatusCode::from_u16(204).expect("Unable to turn 204 into a StatusCode");
|
||||
|
||||
},
|
||||
},
|
||||
Err(_) => {
|
||||
@ -607,8 +623,8 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
|
||||
},
|
||||
Err(e) => Ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Couldn't read body parameter value: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body parameter value")),
|
||||
.body(Body::from(format!("Unable to read body: {}", e)))
|
||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user