validate

View as MarkdownOpen in Claude

Validate a SWML document against structural rules. Checks for required top-level keys (version, sections), valid version strings, a main section, and correct AI verb structure. Results are cached.

Parameters

swml
string | Record<string, unknown>Required

The SWML document as a JSON string or parsed object.

Returns

ValidationResult — An object with valid: boolean and errors: string[].

Example

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