if there are no defined responses, return a raw Response

This commit is contained in:
Joshua M. Clulow 2021-09-17 21:14:49 -07:00
parent 9ff59e812d
commit abf423f96c
1 changed files with 11 additions and 5 deletions

View File

@ -1221,9 +1221,7 @@ fn gen(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
a(&format!(" body: {},", bp)); a(&format!(" body: {},", bp));
} }
// println!("{:#?}", o.responses); let decode_response = if o.responses.responses.len() == 1 {
if o.responses.responses.len() == 1 {
let only = o.responses.responses.iter().next().unwrap(); let only = o.responses.responses.iter().next().unwrap();
match only.0 { match only.0 {
openapiv3::StatusCode::Code(n) => { openapiv3::StatusCode::Code(n) => {
@ -1276,9 +1274,13 @@ fn gen(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
bail!("too many response contents: {:#?}", i.content); bail!("too many response contents: {:#?}", i.content);
} }
} }
true
} else if o.responses.responses.is_empty() {
a(" ) -> Result<reqwest::Response> {");
false
} else { } else {
bail!("responses? {:#?}", o.responses); bail!("responses? {:#?}", o.responses);
} };
/* /*
* Generate the URL for the request. * Generate the URL for the request.
@ -1330,7 +1332,11 @@ fn gen(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
a(""); a("");
a(" Ok(res.json().await?)"); if decode_response {
a(" Ok(res.json().await?)");
} else {
a(" Ok(res)");
}
a(" }"); a(" }");
a(""); a("");