UNPKG

typebox-schema-faker

Version:

Generate fake data from TypeBox schemas for testing, prototyping and development.

21 lines (20 loc) 582 B
import { TypeBoxError } from '@sinclair/typebox'; import { rootFake } from '../root'; import { unwrap } from '../unwrap'; /** * Generates fake data for recursive schemas */ export const fakeRecursive = (schema, ctx, options) => { const unwrapped = unwrap(schema); const id = unwrapped.$id; if (!id) { throw new TypeBoxError('TRecursive schema must contain $id'); } // Cache ref if (!ctx.refs.has(id)) { ctx.refs.set(id, unwrapped); } // Reset current depth ctx.currentDepth = 0; return rootFake(unwrapped, ctx, options); };