proxmox/proxmox-api-macro/tests/ext-schema.rs
Wolfgang Bumiller d3ec63f26d api-macro: allow referencing external schemas in properties
Reference a predefined BACKUP_ARCHIVE_NAME StringSchema like
this:
    #[api(
        input: {
            properties: {
                archive: {
                    optional: true,
                    schema: BACKUP_ARCHIVE_NAME,
                },
            }
        }
    )]
    fn get_archive(archive: String) -> Result<(), Error> {
        ...
    }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:11:46 +01:00

27 lines
605 B
Rust

//! 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_macro::api;
use failure::Error;
pub const NAME_SCHEMA: schema::Schema = schema::StringSchema::new("Archive name.")
//.format(&FILENAME_FORMAT)
.schema();
#[api(
input: {
properties: {
name: {
schema: NAME_SCHEMA,
}
}
}
)]
/// Get an archive.
pub fn get_archive(name: String) -> Result<(), Error> {
let _ = name;
Ok(())
}