typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
16 lines (15 loc) • 522 B
JavaScript
import { rootFake } from '../root';
/**
* Generates fake data for intersect schemas
*/
export const fakeIntersect = (schema, ctx, options) => {
let result = {};
for (const subSchema of schema.allOf) {
const generated = rootFake(subSchema, ctx, options);
// Only merge if it's an object (intersect typically uses objects)
if (generated && typeof generated === 'object' && !Array.isArray(generated)) {
result = { ...result, ...generated };
}
}
return result;
};