mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-14 15:33:47 +00:00
macro: check function parameters
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
fe46b11152
commit
41884a622e
@ -80,6 +80,13 @@ fn handle_function(
|
|||||||
.transpose()?
|
.transpose()?
|
||||||
.map_or_else(|| quote! { ::hyper::Body }, |v| v.into_token_stream());
|
.map_or_else(|| quote! { ::hyper::Body }, |v| v.into_token_stream());
|
||||||
|
|
||||||
|
let mut parameters = definition
|
||||||
|
.remove("parameters")
|
||||||
|
.map(|v| v.expect_object())
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or_else(HashMap::new);
|
||||||
|
let mut parameter_tokens = TokenStream::new();
|
||||||
|
|
||||||
let vis = std::mem::replace(&mut item.vis, syn::Visibility::Inherited);
|
let vis = std::mem::replace(&mut item.vis, syn::Visibility::Inherited);
|
||||||
let span = item.ident.span();
|
let span = item.ident.span();
|
||||||
let name_str = item.ident.to_string();
|
let name_str = item.ident.to_string();
|
||||||
@ -124,6 +131,21 @@ fn handle_function(
|
|||||||
.unwrap_or(::serde_json::Value::Null)
|
.unwrap_or(::serde_json::Value::Null)
|
||||||
)?;
|
)?;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _info = parameters
|
||||||
|
.remove(&name_str)
|
||||||
|
.ok_or_else(|| format_err!("missing parameter '{}' in api defintion", name_str))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !parameters.is_empty() {
|
||||||
|
let mut list = String::new();
|
||||||
|
for param in parameters.keys() {
|
||||||
|
if !list.is_empty() {
|
||||||
|
list.push_str(", ");
|
||||||
|
}
|
||||||
|
list.push_str(¶m);
|
||||||
|
}
|
||||||
|
bail!("api definition contains parameters not found in function declaration: {}", list);
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
@ -55,7 +55,7 @@ async fn test_body() -> Result<&'static str, Error> {
|
|||||||
body: Bytes,
|
body: Bytes,
|
||||||
description: "Loopback the `input` parameter",
|
description: "Loopback the `input` parameter",
|
||||||
parameters: {
|
parameters: {
|
||||||
input: "the input",
|
param: "the input",
|
||||||
},
|
},
|
||||||
})]
|
})]
|
||||||
async fn get_loopback(param: String) -> Result<String, Error> {
|
async fn get_loopback(param: String) -> Result<String, Error> {
|
||||||
@ -66,7 +66,7 @@ async fn get_loopback(param: String) -> Result<String, Error> {
|
|||||||
body: Bytes,
|
body: Bytes,
|
||||||
description: "Loopback the `input` parameter",
|
description: "Loopback the `input` parameter",
|
||||||
parameters: {
|
parameters: {
|
||||||
input: "the input",
|
param: "the input",
|
||||||
},
|
},
|
||||||
returns: String
|
returns: String
|
||||||
})]
|
})]
|
||||||
|
Loading…
Reference in New Issue
Block a user