typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
19 lines (18 loc) • 552 B
JavaScript
import { TypeBoxError } from '@sinclair/typebox';
import { rootFake } from '../root';
/**
* Generates fake data for This schemas
*/
export const fakeThis = (schema, ctx, options) => {
const ref = schema.$ref;
if (!ref) {
throw new TypeBoxError('TThis schema must contain $ref');
}
const refSchema = ctx.refs.get(ref);
if (!refSchema) {
throw new TypeBoxError(`$ref with id ${ref} does not exist`);
}
// Increment current depth usage
ctx.currentDepth++;
return rootFake(refSchema, ctx, options);
};