From 960d4318ec0fc5679638503933d2722e0ce89a3e Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Fri, 3 Feb 2023 09:48:58 +0100 Subject: [PATCH] Add comments everywhere --- src/lib.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8da6f58..87aef17 100644 --- a/src/lib.rs +++ b/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, }, + /// Object value Object { - required: Option>, + /// Required filed for the object + required: Option>,* + /// The children of the object children: Vec, }, + /// 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, + /// Examples values for the schema, if available #[serde(skip_serializing_if = "Vec::is_empty")] pub examples: Vec, + /// Discrete values of the schema, if specified #[serde(skip_serializing_if = "Option::is_none")] pub r#enum: Option>, } 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()) }