diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index a0a64903..d166c231 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -352,7 +352,7 @@ fn is_value_type(ty: &syn::Type) -> bool { fn create_wrapper_function( _input_schema: &Schema, - returns_schema: &Option, + _returns_schema: &Option, param_list: Vec<(FieldName, ParameterType)>, func: &syn::ItemFn, wrapper_ts: &mut TokenStream, @@ -364,7 +364,6 @@ fn create_wrapper_function( let mut body = TokenStream::new(); let mut args = TokenStream::new(); - let mut return_stmt = TokenStream::new(); for (name, param) in param_list { let span = name.span(); @@ -404,17 +403,6 @@ fn create_wrapper_function( } } - if returns_schema.is_some() { - return_stmt.extend(quote! { - Ok(::serde_json::to_value(output)?) - }); - } else { - return_stmt.extend(quote! { - let _ = output; - Ok(::serde_json::Value::Null) - }); - } - // build the wrapping function: let func_name = &func.sig.ident; wrapper_ts.extend(quote! { @@ -425,8 +413,7 @@ fn create_wrapper_function( ) -> Result<::serde_json::Value, ::failure::Error> { if let ::serde_json::Value::Object(ref mut input_map) = &mut input_params { #body - let output = #func_name(#args)?; - #return_stmt + Ok(::serde_json::to_value(#func_name(#args)?)?) } else { ::failure::bail!("api function wrapper called with a non-object json value"); } diff --git a/proxmox-api-macro/tests/ext-schema.rs b/proxmox-api-macro/tests/ext-schema.rs index 0d4bc084..dfda9fcc 100644 --- a/proxmox-api-macro/tests/ext-schema.rs +++ b/proxmox-api-macro/tests/ext-schema.rs @@ -1,10 +1,11 @@ //! This should test the usage of "external" schemas. If a property is declared with a path instead //! of an object, we expect the path to lead to a schema. -use proxmox::api::schema; +use proxmox::api::{schema, RpcEnvironment}; use proxmox_api_macro::api; use failure::Error; +use serde_json::{json, Value}; pub const NAME_SCHEMA: schema::Schema = schema::StringSchema::new("Archive name.") //.format(&FILENAME_FORMAT) @@ -24,3 +25,19 @@ pub fn get_archive(archive_name: String) -> Result<(), Error> { let _ = archive_name; Ok(()) } + +#[api( + input: { + properties: { + "archive-name": { + schema: NAME_SCHEMA, + } + } + } +)] +/// Get an archive. +pub fn get_archive_2(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let _ = param; + let _ = rpcenv; + Ok(json!("test")) +}