UNPKG

hey-api-builders

Version:

A custom plugin for @hey-api/openapi-ts that generates mock data builders with a lightweight custom runtime, Zod integration, or static mock generation.

69 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isEnum = isEnum; exports.isJsonValue = isJsonValue; exports.isObjectType = isObjectType; /** * Schema validation utilities */ /** * Checks if a schema represents an enum type * @param ir - Schema object to check * @returns True if schema is an enum */ function isEnum(ir) { if (!ir || typeof ir !== 'object') { return false; } const enumIr = ir; if (Array.isArray(enumIr.enum)) { return true; } if (enumIr.type === 'enum') { return true; } if (!enumIr.enum && Array.isArray(enumIr.items)) { const items = enumIr.items; if (items.length > 0 && items.every((it) => it && typeof it === 'object' && 'const' in it)) { return true; } } return false; } /** * Checks if a value is a valid JSON value * @param value - Value to check * @returns True if valid JSON value */ function isJsonValue(value) { if (value === null) { return true; } const type = typeof value; if (type === 'string' || type === 'number' || type === 'boolean') { return true; } if (Array.isArray(value)) { return value.every(isJsonValue); } if (type === 'object') { return Object.values(value).every(isJsonValue); } return false; } /** * Checks if a schema represents an object type * @param type - Schema type * @returns True if object type */ function isObjectType(type) { if (type === 'object') { return true; } if (Array.isArray(type) && type.includes('object')) { return true; } return false; } //# sourceMappingURL=schema-validators.js.map