-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
29 lines (26 loc) · 1.1 KB
/
index.ts
File metadata and controls
29 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {JSONSchemaFaker} from 'json-schema-faker'
import type { Schema} from 'json-schema-faker'
import type { BuilderOptions } from './types'
export interface JSFOptions {
useDefaultValue?: boolean
useExamplesValue?: boolean
alwaysFakeOptionals?: boolean
optionalsProbability?: number | false
omitNulls?: boolean
requiredOnly?: boolean
}
export function generateMock<T = unknown>(schema: unknown, options?: JSFOptions): T {
JSONSchemaFaker.option({
useDefaultValue: options?.useDefaultValue ?? false,
useExamplesValue: options?.useExamplesValue ?? false,
alwaysFakeOptionals: options?.alwaysFakeOptionals ?? false,
optionalsProbability: options?.optionalsProbability ?? 1,
omitNulls: options?.omitNulls ?? false,
requiredOnly: options?.requiredOnly ?? true,
})
return JSONSchemaFaker.generate(schema as Schema) as T
}
export { defaultConfig, defineConfig } from './config';
export { generateMockFromZodSchema } from './zod-generator';
export type { BuildersPlugin } from "./types";
export type { Schema as BuilderSchema, BuilderOptions };