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

import { SchemaUtils } from '@signalwire/sdk';
const schema = new SchemaUtils();
const result = schema.validate({
version: '1.0.0',
sections: { main: [{ answer: {} }, { hangup: {} }] },
});
if (!result.valid) {
console.error('Validation errors:', result.errors);
}