forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-request-body-basic.mustache
More file actions
63 lines (62 loc) · 3.94 KB
/
server-request-body-basic.mustache
File metadata and controls
63 lines (62 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{{#exts}}
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}}
{{#required}}
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {path}");
unused_elements.push(path.to_string());
}) {
Ok(param_{{{paramName}}}) => param_{{{paramName}}},
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(BoxBody::new(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}}
serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {path}");
unused_elements.push(path.to_string());
}).unwrap_or_default()
{{/required}}
{{/x-consumes-plain-text}}
{{#x-consumes-plain-text}}
{{#isBinary}}
Some(swagger::ByteArray(body.to_vec()))
{{/isBinary}}
{{#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(BoxBody::new(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}}
{{/exts}}
} else {
None
};
{{#required}}
let param_{{{paramName}}} = match param_{{{paramName}}} {
Some(param_{{{paramName}}}) => param_{{{paramName}}},
None => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(BoxBody::new("Missing required body parameter {{{baseName}}}".to_string()))
.expect("Unable to create Bad Request response for missing body parameter {{{baseName}}}")),
};
{{/required}}
{{#exts.x-can-validate}}
#[cfg(not(feature = "validate"))]
run_validation!(param_{{{paramName}}}, "{{{baseName}}}", validation);
{{/exts.x-can-validate}}