fsvalidator 0.3.0

A file structure validator
Documentation
//! # Raw Schema Types
//!
//! Defines the raw data structures used for parsing configuration files.
//!
//! This module contains the types used for deserializing TOML and JSON files into raw
//! configuration data, which is then processed into the validation model.

use std::collections::HashMap;

/// The root structure of a raw configuration file.
///
/// This is the top-level structure that contains all components of a validation definition.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RawRoot {
    /// The root node of the validation tree
    pub root: RawNode,
    /// A dictionary of template nodes that can be referenced
    pub template: HashMap<String, RawNode>,
    /// Optional configuration settings
    pub config: Option<RawConfig>,
    /// Optional global settings that apply to all nodes
    pub global: Option<RawGlobal>,
}

/// The type of a raw node in the configuration.
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RawNodeType {
    /// A directory node that can contain children
    Dir,
    /// A file node (leaf node)
    File,
    /// A reference to a template node
    Ref,
}

/// A raw node in the configuration.
///
/// This represents an unprocessed node from the configuration file, which will be
/// converted into a model node during loading.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RawNode {
    /// The type of node (dir, file, or ref)
    pub r#type: RawNodeType,
    /// The literal name of the node (mutually exclusive with pattern)
    pub name: Option<String>,
    /// A regex pattern for matching names (mutually exclusive with name)
    pub pattern: Option<String>,
    /// Child nodes (only valid for dir nodes)
    pub children: Option<Vec<RawNode>>,
    /// Template reference name (only valid for ref nodes)
    pub r#ref: Option<String>,
    /// Whether this node is required to exist
    pub required: Option<bool>,
    /// Whether only defined children are allowed (only valid for dir nodes)
    pub allow_defined_only: Option<bool>,
    /// List of patterns to exclude from validation
    pub excluded: Option<Vec<String>>,
}

/// Configuration settings for the validator.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RawConfig {
    /// Maximum depth for recursive validation
    pub max_recursive_depth: Option<usize>,
}

/// Global settings that apply to all nodes unless overridden.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RawGlobal {
    /// Default required flag for all nodes
    pub required: Option<bool>,
    /// Default allow_defined_only flag for directory nodes
    pub allow_defined_only: Option<bool>,
    /// Global patterns to exclude from validation
    pub excluded: Option<Vec<String>>,
}