mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-16 13:35:33 +00:00
api-macro: convert function output to a json value
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
6e98ae0dd3
commit
0bf354e437
@ -450,10 +450,6 @@ fn handle_function_signature(
|
|||||||
|
|
||||||
let mut param_list = Vec::<(SimpleIdent, ParameterType)>::new();
|
let mut param_list = Vec::<(SimpleIdent, ParameterType)>::new();
|
||||||
|
|
||||||
// Go through the function signature to figure out whether we need to create an internal
|
|
||||||
// wrapping function.
|
|
||||||
//
|
|
||||||
// First: go through the parameters:
|
|
||||||
for input in sig.inputs.iter() {
|
for input in sig.inputs.iter() {
|
||||||
// `self` types are not supported:
|
// `self` types are not supported:
|
||||||
let pat_type = match input {
|
let pat_type = match input {
|
||||||
@ -522,16 +518,24 @@ fn handle_function_signature(
|
|||||||
param_list.push((pat.ident.clone().into(), param_type));
|
param_list.push((pat.ident.clone().into(), param_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If our function has the correct signature we may not even need a wrapper:
|
/*
|
||||||
if (
|
* Doing this is actually unreliable, since we cannot support aliased Result types, or all
|
||||||
param_list.len(),
|
* poassible combinations of paths like `result::Result<>` or `std::result::Result<>` or
|
||||||
value_param,
|
* `ApiResult`.
|
||||||
api_method_param,
|
|
||||||
rpc_env_param,
|
// Secondly, take a look at the return type, and then decide what to do:
|
||||||
) == (3, Some(0), Some(1), Some(2))
|
// If our function has the correct signature we may not even need a wrapper.
|
||||||
|
if is_default_return_type(&sig.output)
|
||||||
|
&& (
|
||||||
|
param_list.len(),
|
||||||
|
value_param,
|
||||||
|
api_method_param,
|
||||||
|
rpc_env_param,
|
||||||
|
) == (3, Some(0), Some(1), Some(2))
|
||||||
{
|
{
|
||||||
return Ok(sig.ident.clone());
|
return Ok(sig.ident.clone());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
create_wrapper_function(input_schema, returns_schema, param_list, func, wrapper_ts)
|
create_wrapper_function(input_schema, returns_schema, param_list, func, wrapper_ts)
|
||||||
}
|
}
|
||||||
@ -642,10 +646,9 @@ fn create_wrapper_function(
|
|||||||
api_method_param: &::proxmox::api::ApiMethod,
|
api_method_param: &::proxmox::api::ApiMethod,
|
||||||
rpc_env_param: &mut dyn ::proxmox::api::RpcEnvironment,
|
rpc_env_param: &mut dyn ::proxmox::api::RpcEnvironment,
|
||||||
) -> Result<::serde_json::Value, ::failure::Error> {
|
) -> Result<::serde_json::Value, ::failure::Error> {
|
||||||
#[allow(unused_variables)]
|
|
||||||
if let Value::Object(ref mut input_map) = &mut input_params {
|
if let Value::Object(ref mut input_map) = &mut input_params {
|
||||||
#body
|
#body
|
||||||
#func_name(#args)
|
Ok(serde_json::to_value(#func_name(#args)?)?)
|
||||||
} else {
|
} else {
|
||||||
::failure::bail!("api function wrapper called with a non-object json value");
|
::failure::bail!("api function wrapper called with a non-object json value");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user