]> git.proxmox.com Git - proxmox-backup.git/blob - src/json_schema.rs
da292c9736fac862feed162e64def6b1c0c641ca
[proxmox-backup.git] / src / json_schema.rs
1 use crate::static_map::StaticMap;
2
3 pub type PropertyMap<'a> = StaticMap<'a, &'a str, Jss<'a>>;
4
5 #[derive(Debug)]
6 pub struct JssBoolean<'a> {
7 pub description: &'a str,
8 pub optional: Option<bool>,
9 pub default: Option<bool>,
10 }
11
12 #[derive(Debug)]
13 pub struct JssInteger<'a> {
14 pub description: &'a str,
15 pub optional: Option<bool>,
16 pub minimum: Option<usize>,
17 pub maximum: Option<usize>,
18 pub default: Option<usize>,
19 }
20
21 #[derive(Debug)]
22 pub struct JssString<'a> {
23 pub description: &'a str,
24 pub optional: Option<bool>,
25 pub default: Option<&'a str>,
26 pub min_length: Option<usize>,
27 pub max_length: Option<usize>,
28 }
29
30 #[derive(Debug)]
31 pub struct JssArray<'a> {
32 pub description: &'a str,
33 pub optional: Option<bool>,
34 pub items: &'a Jss<'a>,
35 }
36
37 #[derive(Debug)]
38 pub struct JssObject<'a> {
39 pub description: &'a str,
40 pub optional: Option<bool>,
41 pub additional_properties: Option<bool>,
42 pub properties: &'a PropertyMap<'a>,
43 }
44
45 #[derive(Debug)]
46 pub enum Jss<'a> {
47 Null,
48 Boolean(JssBoolean<'a>),
49 Integer(JssInteger<'a>),
50 String(JssString<'a>),
51 Object(JssObject<'a>),
52 Array(JssArray<'a>),
53 Reference { reference: &'a Jss<'a> },
54 }
55
56 pub static DEFAULTBOOL: JssBoolean = JssBoolean {
57 description: "",
58 optional: None,
59 default: None,
60 };
61
62 #[macro_export]
63 macro_rules! Boolean {
64 ($($name:ident => $e:expr),*) => {{
65 Jss::Boolean(JssBoolean { $($name: $e, )* ..DEFAULTBOOL})
66 }}
67 }
68
69 pub static DEFAULTINTEGER: JssInteger = JssInteger {
70 description: "",
71 optional: None,
72 default: None,
73 minimum: None,
74 maximum: None,
75 };
76
77 #[macro_export]
78 macro_rules! Integer {
79 ($($name:ident => $e:expr),*) => {{
80 Jss::Integer(JssInteger { $($name: $e, )* ..DEFAULTINTEGER})
81 }}
82 }
83
84 pub static DEFAULTSTRING: JssString = JssString {
85 description: "",
86 optional: None,
87 default: None,
88 min_length: None,
89 max_length: None,
90 };
91
92 #[macro_export]
93 macro_rules! ApiString {
94 ($($name:ident => $e:expr),*) => {{
95 Jss::String(JssString { $($name: $e, )* ..DEFAULTSTRING})
96 }}
97 }
98
99 pub static DEFAULTARRAY: JssArray = JssArray {
100 description: "",
101 optional: None,
102 items: &Jss::Null, // is this a reasonable default??
103 };
104
105 #[macro_export]
106 macro_rules! Array {
107 ($($name:ident => $e:expr),*) => {{
108 Jss::Array(JssArray { $($name: $e, )* ..DEFAULTARRAY})
109 }}
110 }
111
112 pub static EMPTYOBJECT: PropertyMap = PropertyMap { entries: &[] };
113
114 pub static DEFAULTOBJECT: JssObject = JssObject {
115 description: "",
116 optional: None,
117 additional_properties: None,
118 properties: &EMPTYOBJECT, // is this a reasonable default??
119 };
120
121 #[macro_export]
122 macro_rules! Object {
123 ($($name:ident => $e:expr),*) => {{
124 Jss::Object(JssObject { $($name: $e, )* ..DEFAULTOBJECT})
125 }}
126 }
127
128
129 // Standard Option Definitions
130 pub static PVE_VMID: Jss = Integer!{
131 description => "The (unique) ID of the VM.",
132 minimum => Some(1)
133 };