rdx-schema-0.1.0-beta.2 has been yanked.
rdx-schema
Schema validation for RDX component ASTs. Define what components exist, what props they accept, and validate documents at build time.
Usage
use parse;
use ;
let schema = new
.strict
.component
.component;
let root = parse;
let diagnostics = validate;
for d in &diagnostics
What it validates
| Check | Severity |
|---|---|
| Missing required props | Error |
| Wrong prop type (e.g., string where object expected) | Error |
| Invalid enum value | Error |
| Children on a self-closing component | Error |
| Disallowed child components | Error |
| Unknown component (strict mode only) | Error |
| Unknown prop on a known component | Warning |
Variable attributes ({$path}) are accepted for any prop type since they resolve at runtime.
Schema definition
PropType
| Type | Matches |
|---|---|
String |
label="text" |
Number |
count={42} |
Boolean |
active={true} |
Enum |
String restricted to specific values |
Object |
config={{"key": "value"}} |
Array |
items={{[1, 2, 3]}} |
Variable |
title={$frontmatter.title} |
Any |
Accepts all value types |
Component constraints
new
.self_closing // must not have children
.allowed_children // restrict child components
.description
JSON schemas
Schema is Serialize + Deserialize, so schemas can be stored as JSON config files:
Design
rdx-schema depends only on rdx-ast, not rdx-parser. It validates any RdxRoot regardless of which parser produced it. This keeps schema validation parser-agnostic.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.