typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
18 lines (17 loc) • 543 B
JavaScript
import { rootFake } from '../root';
import { EmptyRecursiveItem } from '../symbols';
/**
* Generates fake data for object schemas
*/
export const fakeObject = (schema, ctx, options) => {
const result = {};
// Break deep recursive processing
if (ctx.currentDepth >= options.maxDepth) {
return EmptyRecursiveItem;
}
// Generate fake data for each property
for (const [key, propSchema] of Object.entries(schema.properties)) {
result[key] = rootFake(propSchema, ctx, options);
}
return result;
};