mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-17 20:05:16 +00:00
expose return schema as API_RETURN_SCHEMA_<methodname>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
9a281f6150
commit
2c7b786cef
@ -61,22 +61,27 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<T
|
|||||||
ts
|
ts
|
||||||
};
|
};
|
||||||
|
|
||||||
let returns_schema = {
|
|
||||||
let mut ts = TokenStream::new();
|
|
||||||
if let Some(schema) = returns_schema {
|
|
||||||
let mut inner = TokenStream::new();
|
|
||||||
schema.to_schema(&mut inner)?;
|
|
||||||
ts.extend(quote! { .returns(#inner) });
|
|
||||||
}
|
|
||||||
ts
|
|
||||||
};
|
|
||||||
|
|
||||||
let vis = &func.vis;
|
let vis = &func.vis;
|
||||||
let func_name = &func.sig.ident;
|
let func_name = &func.sig.ident;
|
||||||
let api_method_name = Ident::new(
|
let api_method_name = Ident::new(
|
||||||
&format!("API_METHOD_{}", func_name.to_string().to_uppercase()),
|
&format!("API_METHOD_{}", func_name.to_string().to_uppercase()),
|
||||||
func.sig.ident.span(),
|
func.sig.ident.span(),
|
||||||
);
|
);
|
||||||
|
let return_schema_name = Ident::new(
|
||||||
|
&format!("API_RETURN_SCHEMA_{}", func_name.to_string().to_uppercase()),
|
||||||
|
func.sig.ident.span(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut returns_schema_definition = TokenStream::new();
|
||||||
|
let mut returns_schema_setter = TokenStream::new();
|
||||||
|
if let Some(schema) = returns_schema {
|
||||||
|
let mut inner = TokenStream::new();
|
||||||
|
schema.to_schema(&mut inner)?;
|
||||||
|
returns_schema_definition = quote_spanned! { func.sig.span() =>
|
||||||
|
#vis const #return_schema_name: &'static ::proxmox::api::schema::Schema = (#inner);
|
||||||
|
};
|
||||||
|
returns_schema_setter = quote! { .returns(#return_schema_name) };
|
||||||
|
}
|
||||||
|
|
||||||
let api_handler = if is_async {
|
let api_handler = if is_async {
|
||||||
quote! { ::proxmox::api::ApiHandler::Async(&#api_func_name) }
|
quote! { ::proxmox::api::ApiHandler::Async(&#api_func_name) }
|
||||||
@ -85,14 +90,18 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<T
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(quote_spanned! { func.sig.span() =>
|
Ok(quote_spanned! { func.sig.span() =>
|
||||||
|
#returns_schema_definition
|
||||||
|
|
||||||
#vis const #api_method_name: ::proxmox::api::ApiMethod =
|
#vis const #api_method_name: ::proxmox::api::ApiMethod =
|
||||||
::proxmox::api::ApiMethod::new(
|
::proxmox::api::ApiMethod::new(
|
||||||
&#api_handler,
|
&#api_handler,
|
||||||
&#input_schema,
|
&#input_schema,
|
||||||
)
|
)
|
||||||
#returns_schema
|
#returns_schema_setter
|
||||||
.protected(#protected);
|
.protected(#protected);
|
||||||
|
|
||||||
#wrapper_ts
|
#wrapper_ts
|
||||||
|
|
||||||
#func
|
#func
|
||||||
})
|
})
|
||||||
//Ok(quote::quote!(#func))
|
//Ok(quote::quote!(#func))
|
||||||
|
Loading…
Reference in New Issue
Block a user