SchemaUtils

View as MarkdownOpen in Claude

SchemaUtils validates SWML documents against structural rules and provides schema-driven verb extraction and validation. Results are cached with an LRU-style eviction policy. Set SWML_SKIP_SCHEMA_VALIDATION=true to disable validation globally.

1import { SchemaUtils } from '@signalwire/sdk';
2
3const schema = new SchemaUtils();
4const result = schema.validate(swmlDocument);
5console.log(result.valid, result.errors);

Constructor

opts
object

Optional constructor configuration.

opts.skipValidation
boolean

Skip all validation checks. When omitted, defaults to true if the SWML_SKIP_SCHEMA_VALIDATION environment variable is "true", otherwise false.

opts.maxCacheSize
numberDefaults to 100

Maximum number of cached validation results before LRU eviction.

Methods

Example

1import { SchemaUtils } from '@signalwire/sdk';
2
3const schema = new SchemaUtils();
4
5// Validate a SWML document
6const result = schema.validate({
7 version: '1.0.0',
8 sections: { main: [{ answer: {} }, { hangup: {} }] },
9});
10console.log(result.valid); // true
11console.log(result.errors); // []