2019-12-02 11:45:37 +01:00
use proxmox_api_macro ::api ;
2020-04-17 18:34:10 +02:00
use anyhow ::Error ;
2019-12-16 11:13:26 +01:00
use serde_json ::Value ;
2019-12-02 11:45:37 +01:00
#[ api(
input : {
properties : {
message : {
description : " The message to print " ,
}
}
}
) ]
/// Print the given message.
pub fn hello ( message : String ) -> Result < ( ) , Error > {
println! ( " Hello there. {} " , message ) ;
Ok ( ( ) )
}
2019-12-16 11:13:26 +01:00
#[ api(
input : {
properties : {
num : {
description : " The version to upgrade to " ,
} ,
} ,
} ,
) ]
/// Return the number...
pub async fn number ( num : u32 ) -> Result < u32 , Error > {
Ok ( num )
}
2019-12-16 12:11:52 +01:00
2020-01-08 11:01:55 +01:00
#[ test ]
fn number_schema_check ( ) {
2021-10-07 09:36:06 +02:00
const TEST_METHOD : ::proxmox_router ::ApiMethod = ::proxmox_router ::ApiMethod ::new (
& ::proxmox_router ::ApiHandler ::Async ( & api_function_number ) ,
& ::proxmox_schema ::ObjectSchema ::new (
2020-01-08 11:01:55 +01:00
" Return the number... " ,
& [ (
" num " ,
false ,
2021-10-07 09:36:06 +02:00
& ::proxmox_schema ::IntegerSchema ::new ( " The version to upgrade to " )
2020-03-06 11:57:15 +01:00
. minimum ( 0 )
. maximum ( 0xffffffff )
. schema ( ) ,
2020-01-08 11:01:55 +01:00
) ] ,
) ,
)
. protected ( false ) ;
assert_eq! ( TEST_METHOD , API_METHOD_NUMBER ) ;
}
2019-12-16 12:11:52 +01:00
#[ api(
input : {
properties : {
foo : {
type : String ,
description : " The great Foo " ,
} ,
bar : {
type : String ,
description : " The great Bar " ,
} ,
} ,
} ,
) ]
/// Return the number...
pub async fn more_async_params ( param : Value ) -> Result < ( ) , Error > {
let _ = param ;
Ok ( ( ) )
}
2020-01-08 11:01:55 +01:00
#[ test ]
fn more_async_params_schema_check ( ) {
2021-10-07 09:36:06 +02:00
const TEST_METHOD : ::proxmox_router ::ApiMethod = ::proxmox_router ::ApiMethod ::new (
& ::proxmox_router ::ApiHandler ::Async ( & api_function_more_async_params ) ,
& ::proxmox_schema ::ObjectSchema ::new (
2020-01-08 11:01:55 +01:00
" Return the number... " ,
& [
(
" bar " ,
false ,
2021-10-07 09:36:06 +02:00
& ::proxmox_schema ::StringSchema ::new ( " The great Bar " ) . schema ( ) ,
2020-01-08 11:01:55 +01:00
) ,
(
" foo " ,
false ,
2021-10-07 09:36:06 +02:00
& ::proxmox_schema ::StringSchema ::new ( " The great Foo " ) . schema ( ) ,
2020-01-08 11:01:55 +01:00
) ,
] ,
) ,
)
. protected ( false ) ;
assert_eq! ( TEST_METHOD , API_METHOD_MORE_ASYNC_PARAMS ) ;
}
2020-11-10 13:53:06 +01:00
#[ api(
input : {
properties : {
type : {
type : String ,
description : " The great Foo " ,
} ,
} ,
} ,
) ]
/// Returns nothing.
pub async fn keyword_named_parameters ( r#type : String ) -> Result < ( ) , Error > {
let _ = r#type ;
Ok ( ( ) )
}
#[ test ]
fn keyword_named_parameters_check ( ) {
2021-10-07 09:36:06 +02:00
const TEST_METHOD : ::proxmox_router ::ApiMethod = ::proxmox_router ::ApiMethod ::new (
& ::proxmox_router ::ApiHandler ::Async ( & api_function_keyword_named_parameters ) ,
& ::proxmox_schema ::ObjectSchema ::new (
2020-11-10 13:53:06 +01:00
" Returns nothing. " ,
2020-11-16 14:21:45 +01:00
& [ (
" type " ,
false ,
2021-10-07 09:36:06 +02:00
& ::proxmox_schema ::StringSchema ::new ( " The great Foo " ) . schema ( ) ,
2020-11-16 14:21:45 +01:00
) ] ,
2020-11-10 13:53:06 +01:00
) ,
)
. protected ( false ) ;
assert_eq! ( TEST_METHOD , API_METHOD_KEYWORD_NAMED_PARAMETERS ) ;
}