2018-11-01 13:42:27 +00:00
|
|
|
use crate::static_map::StaticMap;
|
2018-11-01 12:05:45 +00:00
|
|
|
|
2018-11-01 14:41:08 +00:00
|
|
|
pub type PropertyMap<'a> = StaticMap<'a, &'a str, Jss<'a>>;
|
2018-10-31 09:42:14 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub struct JssBoolean<'a> {
|
|
|
|
pub description: &'a str,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub optional: Option<bool>,
|
|
|
|
pub default: Option<bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub struct JssInteger<'a> {
|
|
|
|
pub description: &'a str,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub optional: Option<bool>,
|
|
|
|
pub minimum: Option<usize>,
|
|
|
|
pub maximum: Option<usize>,
|
|
|
|
pub default: Option<usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub struct JssString<'a> {
|
|
|
|
pub description: &'a str,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub optional: Option<bool>,
|
2018-11-01 13:16:41 +00:00
|
|
|
pub default: Option<&'a str>,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub min_length: Option<usize>,
|
|
|
|
pub max_length: Option<usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub struct JssArray<'a> {
|
|
|
|
pub description: &'a str,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub optional: Option<bool>,
|
2018-11-01 13:16:41 +00:00
|
|
|
pub items: &'a Jss<'a>,
|
2018-10-31 09:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub struct JssObject<'a> {
|
|
|
|
pub description: &'a str,
|
2018-10-31 09:42:14 +00:00
|
|
|
pub optional: Option<bool>,
|
|
|
|
pub additional_properties: Option<bool>,
|
2018-11-01 13:16:41 +00:00
|
|
|
pub properties: &'a PropertyMap<'a>,
|
2018-10-31 09:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-11-01 13:16:41 +00:00
|
|
|
pub enum Jss<'a> {
|
2018-10-31 09:42:14 +00:00
|
|
|
Null,
|
2018-11-01 13:16:41 +00:00
|
|
|
Boolean(JssBoolean<'a>),
|
|
|
|
Integer(JssInteger<'a>),
|
|
|
|
String(JssString<'a>),
|
|
|
|
Object(JssObject<'a>),
|
|
|
|
Array(JssArray<'a>),
|
|
|
|
Reference { reference: &'a Jss<'a> },
|
2018-10-31 09:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub static DEFAULTBOOL: JssBoolean = JssBoolean {
|
|
|
|
description: "",
|
|
|
|
optional: None,
|
|
|
|
default: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! Boolean {
|
|
|
|
($($name:ident => $e:expr),*) => {{
|
|
|
|
Jss::Boolean(JssBoolean { $($name: $e, )* ..DEFAULTBOOL})
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub static DEFAULTINTEGER: JssInteger = JssInteger {
|
|
|
|
description: "",
|
|
|
|
optional: None,
|
|
|
|
default: None,
|
|
|
|
minimum: None,
|
|
|
|
maximum: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! Integer {
|
|
|
|
($($name:ident => $e:expr),*) => {{
|
|
|
|
Jss::Integer(JssInteger { $($name: $e, )* ..DEFAULTINTEGER})
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub static DEFAULTSTRING: JssString = JssString {
|
|
|
|
description: "",
|
|
|
|
optional: None,
|
|
|
|
default: None,
|
|
|
|
min_length: None,
|
|
|
|
max_length: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! ApiString {
|
|
|
|
($($name:ident => $e:expr),*) => {{
|
|
|
|
Jss::String(JssString { $($name: $e, )* ..DEFAULTSTRING})
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub static DEFAULTARRAY: JssArray = JssArray {
|
|
|
|
description: "",
|
|
|
|
optional: None,
|
|
|
|
items: &Jss::Null, // is this a reasonable default??
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! Array {
|
|
|
|
($($name:ident => $e:expr),*) => {{
|
|
|
|
Jss::Array(JssArray { $($name: $e, )* ..DEFAULTARRAY})
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2018-11-01 13:16:41 +00:00
|
|
|
pub static EMPTYOBJECT: PropertyMap = PropertyMap { entries: &[] };
|
2018-10-31 09:42:14 +00:00
|
|
|
|
|
|
|
pub static DEFAULTOBJECT: JssObject = JssObject {
|
|
|
|
description: "",
|
|
|
|
optional: None,
|
|
|
|
additional_properties: None,
|
|
|
|
properties: &EMPTYOBJECT, // is this a reasonable default??
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! Object {
|
|
|
|
($($name:ident => $e:expr),*) => {{
|
|
|
|
Jss::Object(JssObject { $($name: $e, )* ..DEFAULTOBJECT})
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Option Definitions
|
|
|
|
pub static PVE_VMID: Jss = Integer!{
|
|
|
|
description => "The (unique) ID of the VM.",
|
|
|
|
minimum => Some(1)
|
|
|
|
};
|
2018-11-02 08:44:18 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! propertymap {
|
|
|
|
($($name:ident => $e:expr),*) => {
|
|
|
|
PropertyMap {
|
|
|
|
entries: &[
|
|
|
|
$( ( stringify!($name), $e), )*
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|