A minimal schema validation engine in Rust, designed for cross-language behavioral parity with a JavaScript reference implementation.
- Type validation: string, number, boolean, object, array, null
- Required fields: Ensures mandatory properties are present
- Numeric constraints:
min,max - String constraints:
minLength,maxLength - Array validation:
items(recursive),minItems,maxItems - Nested objects: Recursive property validation with nested
required - Enum validation: Restrict values to an allowed set
- Pattern matching: Regex-based string validation
├── src/
│ ├── main.rs # CLI entry point
│ ├── lib.rs # Module declarations
│ ├── schema.rs # Schema types (SchemaType, PropertyRule, Schema)
│ └── validator.rs # Validation logic + unit tests
├── js/
│ ├── validate.js # JavaScript reference validator
│ └── package.json
├── tests/
│ ├── golden/ # Golden test cases (schema + input + expected)
│ └── golden_tests.rs # Integration test runner
├── scripts/
│ └── run_parity_tests.sh # Cross-language parity runner
├── Cargo.toml
└── README.md
cargo build --release
./target/release/rs-schema-validator schema.json input.jsonnode js/validate.js schema.json input.jsonBoth output VALID or INVALID: <error message> lines.
{
"type": "object",
"required": ["name", "age"],
"properties": {
"name": { "type": "string", "minLength": 2 },
"age": { "type": "number", "min": 18, "max": 120 },
"tags": {
"type": "array",
"items": { "type": "string" },
"minItems": 1
},
"status": {
"type": "string",
"enum": ["active", "inactive"]
}
}
}cargo testcargo test --test golden_tests./scripts/run_parity_tests.shRuns both Rust and JS validators against all golden test cases and verifies output parity.
- Deterministic errors: Validation errors follow a consistent format across both implementations.
- Recursive validation:
PropertyRuleis recursive (usingBox) to support nested objects and array items. - Struct update syntax: Tests use
..simple_rule()for concise PropertyRule construction. - No external schema standards: This is a custom, minimal schema format — not JSON Schema.
MIT License. See LICENSE.