diff options
| author | Taylor Mullen <[email protected]> | 2025-04-17 18:06:21 -0400 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-04-17 15:29:34 -0700 |
| commit | cfc697a96d2e716a75e1c3b7f0f34fce81abaf1e (patch) | |
| tree | e06bcba67ca71a874048aa887b17457dbd409bdf /packages/cli/src/utils/schemaValidator.ts | |
| parent | 7928c1727f0b208ed34850cc89bbb36ea3dd23e5 (diff) | |
Run `npm run format`
- Also updated README.md accordingly.
Part of https://b.corp.google.com/issues/411384603
Diffstat (limited to 'packages/cli/src/utils/schemaValidator.ts')
| -rw-r--r-- | packages/cli/src/utils/schemaValidator.ts | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/packages/cli/src/utils/schemaValidator.ts b/packages/cli/src/utils/schemaValidator.ts index bbf7d4d1..d2dfdf1b 100644 --- a/packages/cli/src/utils/schemaValidator.ts +++ b/packages/cli/src/utils/schemaValidator.ts @@ -12,12 +12,12 @@ export class SchemaValidator { static validate(schema: Record<string, unknown>, data: unknown): boolean { // This is a simplified implementation // In a real application, you would use a library like Ajv for proper validation - + // Check for required fields if (schema.required && Array.isArray(schema.required)) { const required = schema.required as string[]; const dataObj = data as Record<string, unknown>; - + for (const field of required) { if (dataObj[field] === undefined) { console.error(`Missing required field: ${field}`); @@ -25,25 +25,29 @@ export class SchemaValidator { } } } - + // Check property types if properties are defined if (schema.properties && typeof schema.properties === 'object') { const properties = schema.properties as Record<string, { type?: string }>; const dataObj = data as Record<string, unknown>; - + for (const [key, prop] of Object.entries(properties)) { if (dataObj[key] !== undefined && prop.type) { const expectedType = prop.type; - const actualType = Array.isArray(dataObj[key]) ? 'array' : typeof dataObj[key]; - + const actualType = Array.isArray(dataObj[key]) + ? 'array' + : typeof dataObj[key]; + if (expectedType !== actualType) { - console.error(`Type mismatch for property "${key}": expected ${expectedType}, got ${actualType}`); + console.error( + `Type mismatch for property "${key}": expected ${expectedType}, got ${actualType}`, + ); return false; } } } } - + return true; } -}
\ No newline at end of file +} |
