Add comments everywhere
This commit is contained in:
parent
cc05d65eb9
commit
960d4318ec
23
src/lib.rs
23
src/lib.rs
@ -29,28 +29,41 @@ fn expect_schema_object(s: &Schema) -> &SchemaObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of the schema
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum NodeType {
|
||||
/// NULL value
|
||||
Null,
|
||||
/// BOOLEAN value
|
||||
Boolean,
|
||||
/// Array value
|
||||
Array {
|
||||
/// Schema information about the children of the array
|
||||
item: Box<TreeNode>,
|
||||
},
|
||||
/// Object value
|
||||
Object {
|
||||
required: Option<Vec<String>>,
|
||||
/// Required filed for the object
|
||||
required: Option<Vec<String>>,*
|
||||
/// The children of the object
|
||||
children: Vec<TreeNode>,
|
||||
},
|
||||
/// String value
|
||||
String,
|
||||
/// Number value
|
||||
Number,
|
||||
/// Integer value
|
||||
Integer,
|
||||
}
|
||||
|
||||
impl NodeType {
|
||||
/// Specify if the type of the node allow children
|
||||
pub fn can_have_children(&self) -> bool {
|
||||
matches!(self, NodeType::Object { .. } | NodeType::Array { .. })
|
||||
}
|
||||
|
||||
/// Get a short symbol representing the type of value
|
||||
pub fn symbol(&self) -> &'static str {
|
||||
match self {
|
||||
NodeType::Null => "NULL",
|
||||
@ -64,20 +77,28 @@ impl NodeType {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parser schema structure node
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct TreeNode {
|
||||
/// The name of the schema
|
||||
pub name: String,
|
||||
/// The type of the schema
|
||||
#[serde(flatten)]
|
||||
pub r#type: NodeType,
|
||||
/// The description provided for the schema, if available
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
/// Examples values for the schema, if available
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub examples: Vec<String>,
|
||||
/// Discrete values of the schema, if specified
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#enum: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl TreeNode {
|
||||
/// Get the name of the schema, alongside with a symbol
|
||||
/// indicating its type
|
||||
pub fn print_name(&self) -> String {
|
||||
format!("{} {}", self.name, self.r#type.symbol())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user