Skip to main content

validate

Function validate 

Source
pub fn validate(root: &Root, schema: &Schema) -> Vec<Diagnostic>
Expand description

Validate an RDX AST against a schema. Returns a list of diagnostics.

An empty list means the document is valid.

ยงExample

use rdx_schema::{Schema, ComponentSchema, PropSchema, PropType, validate};
use rdx_parser::parse;

let schema = Schema::new()
    .strict(true)
    .component("Notice", ComponentSchema::new()
        .prop("type", PropSchema::enum_required(vec!["info", "warning", "error"]))
    );

let root = parse("<Notice type=\"info\">\nSome text.\n</Notice>\n");
let diagnostics = validate(&root, &schema);
assert!(diagnostics.is_empty());