jss_core/schema/
mod.rs

1use std::fmt::{Debug, Display, Formatter};
2
3use indexmap::{map::Iter, IndexMap};
4
5use json_value::Number;
6
7mod traits;
8mod typing;
9mod value;
10
11/// The schema node
12#[derive(Clone)]
13pub struct JssSchema {
14    /// The kind of this node
15    pub kind: JssKind,
16    /// The name of the node
17    name: Option<String>,
18    /// The documentations of the node
19    description: String,
20    /// type definition
21    typing: JssType,
22    /// .key = value
23    property: IndexMap<String, JssSchema>,
24    /// Top level node only
25    /// ^key = value
26    definition: IndexMap<String, JssSchema>,
27    /// key = value
28    attribute: IndexMap<String, JssValue>,
29    // $key = value
30    // keywords: IndexMap<String, JssValue>,
31}
32
33#[derive(Copy, Clone, Debug, Eq, PartialEq)]
34pub enum JssKind {
35    Scheme,
36    Property,
37    PropertyTop,
38    Definition,
39}
40
41#[derive(Clone, Debug, PartialEq)]
42pub enum JssType {
43    Undefined,
44    Anything,
45    Nothing,
46    String,
47    Integer,
48    Number,
49    Array,
50    Object,
51    Reference(String),
52    Complex(Box<JssComplexType>),
53}
54
55#[derive(Clone, PartialEq)]
56pub struct JssComplexType {
57    /// Jss String
58    pub pattern: JssValue,
59}
60
61/// Represents any valid JSON value.
62///
63/// See the [`serde_json::value` module documentation](self) for usage examples.
64#[derive(Clone, Eq, PartialEq)]
65pub enum JssValue {
66    /// Represents a null value.
67    Null,
68
69    /// Represents a boolean.
70    Boolean(bool),
71
72    /// Represents a JSON number, whether integer or floating point.
73    Number(Number),
74
75    /// Represents a string.
76    String(String),
77    /// Represents a url.
78    Url(String),
79    /// Represents a regex.
80    Regex(String),
81    /// Represents an array.
82    Array(Vec<JssValue>),
83
84    /// Represents an object.
85    ///
86    /// By default the map is backed by a BTreeMap. Enable the `preserve_order`
87    /// feature of serde_json to use IndexMap instead, which preserves
88    /// entries in the order they are inserted into the map. In particular, this
89    /// allows JSON data to be deserialized into a Value and serialized to a
90    /// string while retaining the order of map keys in the input.
91    Object(IndexMap<String, JssValue>),
92}