Skip to main content
Schema validation in JoyDoc ensures that documents conform to the expected structure and version compatibility. It validates the document’s JSON schema against the official JoyDoc schema definition and checks version compatibility.

Manual Schema Validation

You can also validate schemas manually:

Enabling/Disabling Schema Validation

Default Behavior

Schema validation is enabled by default in the JoyDoc component.

Enabling Schema Validation

Schema validation is enabled by default, but you can explicitly enable it:

Disabling Schema Validation

To disable schema validation, set features.validateSchema to false:

How Schema Validation Works

Basic Usage

Schema validation is automatically performed by the JoyDoc component when enabled:

Schema Validation Process

The validation process follows these steps:
  1. Version Compatibility Check: Verifies the document’s schema version is compatible with the current SDK
  2. JSON Schema Validation: Validates the document structure against the official JoyDoc schema
  3. Error Reporting: Returns detailed error information if validation fails

Validation Results

Success Case

When validation passes, the function returns undefined:

Error Cases

When validation fails, an error object is returned with the following structure:

Error Types

1. Schema Version Error

Code: ERROR_SCHEMA_VERSION Occurs when the document’s schema version is incompatible with the current SDK version.
Common causes:
  • Using an outdated document format
  • Document created with an older SDK version
  • Manual document editing with incorrect version

2. Schema Validation Error

Code: ERROR_SCHEMA_VALIDATION Occurs when the document structure doesn’t match the expected schema.
Common causes:
  • Missing required properties
  • Invalid field types
  • Malformed document structure
  • Corrupted document data

Error Handling

In JoyDoc Component

Handle schema validation errors using the onError callback:

Implementation Example

Key points:

  • Schema validation is enabled by default in JoyDoc components
  • Version compatibility is checked using major version numbers
  • Two types of errors: Schema version errors and schema validation errors
  • Always handle errors using the onError callback
  • Validate documents before processing to prevent runtime errors
  • Use manual validation for programmatic document validation