SchemaEditor - Validation
Property Name Validation
Section titled “Property Name Validation”Property names must:
- Be unique within the schema
- Not be empty
- Follow identifier conventions (recommended but not enforced)
- Start with letter or underscore
- Contain only letters, numbers, underscores
- Avoid JavaScript reserved words
Uniqueness Check
Section titled “Uniqueness Check”// ✅ Valid - unique names{ properties: { firstName: { type: 'string' }, lastName: { type: 'string' } }}
// ❌ Invalid - duplicate names{ properties: { name: { type: 'string' }, name: { type: 'number' } // Error: duplicate }}Visual Feedback
Section titled “Visual Feedback”- Green checkmark: Valid, unique name
- Red highlight: Duplicate or invalid name
- Tooltip: Error message explaining issue
Type Validation
Section titled “Type Validation”Type Compatibility
Section titled “Type Compatibility”Ensure selected type matches intended data:
// ✅ Compatible{ age: { type: 'integer' }, price: { type: 'number' }, name: { type: 'string' }}
// ⚠️ Type mismatch (functional but semantic issue){ age: { type: 'string' }, // Should be integer isActive: { type: 'string' } // Should be boolean}Format-Type Compatibility
Section titled “Format-Type Compatibility”Formats only apply to string types:
// ✅ Valid{ email: { type: 'string', format: 'email' }}
// ❌ Invalid - format ignored{ count: { type: 'integer', format: 'email' } // Format has no effect}SchemaEditor automatically:
- Clears format when changing from string to another type
- Enables format dropdown only for string types
Required Field Validation
Section titled “Required Field Validation”Required Array
Section titled “Required Array”The required array lists properties that must be present:
{ type: 'object', properties: { name: { type: 'string' }, email: { type: 'string' }, phone: { type: 'string' } }, required: ['name', 'email'] // name and email are required}Validation Rules
Section titled “Validation Rules”- Required properties must exist in
properties - Cannot remove required property without unmarking as required first
- Renaming a required property updates the
requiredarray
// Before renamerequired: ['oldName']
// After renaming 'oldName' to 'newName'required: ['newName'] // Automatically updatedSchema Structure Validation
Section titled “Schema Structure Validation”Object Type Requirements
Section titled “Object Type Requirements”Objects should have properties defined:
// ✅ Well-defined object{ type: 'object', properties: { id: { type: 'string' }, value: { type: 'number' } }}
// ⚠️ Empty object (valid but not useful){ type: 'object', properties: {}}Array Type Requirements
Section titled “Array Type Requirements”Arrays should have items schema defined:
// ✅ Well-defined array{ type: 'array', items: { type: 'string' }}
// ⚠️ Missing items schema{ type: 'array' // What type are the items?}SchemaEditor may:
- Prompt for items schema when creating array type
- Default to
{ type: 'string' }for items - Show warning for array without items definition
Constraint Validation
Section titled “Constraint Validation”Numeric Constraints
Section titled “Numeric Constraints”For number and integer types:
{ age: { type: 'integer', minimum: 0, maximum: 150 }, price: { type: 'number', minimum: 0, multipleOf: 0.01 // Two decimal places }}Validation checks:
minimum≤maximummultipleOf> 0exclusiveMinimum<exclusiveMaximum
String Constraints
Section titled “String Constraints”For string type:
{ username: { type: 'string', minLength: 3, maxLength: 20, pattern: '^[a-zA-Z0-9_]+$' }}Validation checks:
minLength≥ 0maxLength≥minLengthpatternis valid regex
Array Constraints
Section titled “Array Constraints”For array type:
{ tags: { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 10, uniqueItems: true }}Validation checks:
minItems≥ 0maxItems≥minItemsitemsschema is valid
Real-Time Validation
Section titled “Real-Time Validation”As you edit, SchemaEditor validates:
-
On property name change
- Check uniqueness
- Update required array if needed
-
On type change
- Clear incompatible format
- Remove incompatible constraints
- Prompt for type-specific requirements
-
On format change
- Verify format is valid for type
- Show format examples
-
On required toggle
- Add/remove from required array
- Update visual indicators
Validation Messages
Section titled “Validation Messages”Types of validation feedback:
Error (Red)
Section titled “Error (Red)”Prevents saving, must be fixed:
- Duplicate property name
- Empty property name
- Invalid schema structure
Warning (Yellow)
Section titled “Warning (Yellow)”Can save but may cause issues:
- Property name with special characters
- Missing items schema for array
- No properties defined for object
Info (Blue)
Section titled “Info (Blue)”Helpful suggestions:
- Recommended format for data type
- Common patterns for validation
- Best practices
External Validation
Section titled “External Validation”Validate generated schema against JSON Schema spec:
import Ajv from 'ajv';
const ajv = new Ajv();
const isValidSchema = ajv.validateSchema(schema);
if (!isValidSchema) { console.error('Schema validation errors:', ajv.errors);}Validation Best Practices
Section titled “Validation Best Practices”- Use required sparingly: Only mark truly required fields
- Choose appropriate types: Match data semantics
- Add constraints: Use min/max, patterns for data quality
- Test with data: Validate real data against schema
- Document expectations: Use descriptions for complex rules
- Version schemas: Track changes over time
- Validate early: Catch errors during editing, not at runtime