|
| 1 | +// This file is auto-generated by @hey-api/openapi-ts |
| 2 | + |
| 3 | +import { faker, type Faker } from '@faker-js/faker'; |
| 4 | + |
| 5 | +import type { Address, BoundedFloat, BoundedInt, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, Email, EmailWithLength, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, IPv4Address, IPv6Address, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NullableInt, NullableString, ObjectWithDefaultProp, Person, PersonList, ShortName, TagList, Team, UnconstrainedArray, UniqueId, UserProfile, Website, ZipCode } from '../types.gen'; |
| 6 | + |
| 7 | +export type Options = { |
| 8 | + faker?: Faker; |
| 9 | + includeOptional?: 'always' | 'random' | false; |
| 10 | + useDefault?: 'always' | 'random' | false; |
| 11 | +}; |
| 12 | + |
| 13 | +const resolveCondition = (condition: 'always' | 'random' | false, faker: Faker): boolean => condition === 'always' || condition === 'random' && faker.datatype.boolean(); |
| 14 | + |
| 15 | +const ensureFaker = (options?: Options): Faker => options?.faker ?? faker; |
| 16 | + |
| 17 | +export const fakeEmail = (options?: Options): Email => ensureFaker(options).internet.email(); |
| 18 | + |
| 19 | +export const fakeDateTime = (options?: Options): DateTime => ensureFaker(options).date.recent().toISOString(); |
| 20 | + |
| 21 | +export const fakeDateOnly = (options?: Options): DateOnly => ensureFaker(options).date.recent().toISOString().slice(0, 10); |
| 22 | + |
| 23 | +export const fakeUniqueId = (options?: Options): UniqueId => ensureFaker(options).string.uuid(); |
| 24 | + |
| 25 | +export const fakeWebsite = (options?: Options): Website => ensureFaker(options).internet.url(); |
| 26 | + |
| 27 | +export const fakeIPv4Address = (options?: Options): IPv4Address => ensureFaker(options).internet.ipv4(); |
| 28 | + |
| 29 | +export const fakeIPv6Address = (options?: Options): IPv6Address => ensureFaker(options).internet.ipv6(); |
| 30 | + |
| 31 | +export const fakeZipCode = (options?: Options): ZipCode => ensureFaker(options).helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); |
| 32 | + |
| 33 | +export const fakeShortName = (options?: Options): ShortName => ensureFaker(options).string.alpha({ length: { min: 2, max: 50 } }); |
| 34 | + |
| 35 | +export const fakeMinOnlyString = (options?: Options): MinOnlyString => ensureFaker(options).string.alpha({ length: { min: 10, max: 1000 } }); |
| 36 | + |
| 37 | +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => ensureFaker(options).string.alpha({ length: { min: 0, max: 5 } }); |
| 38 | + |
| 39 | +export const fakeEmailWithLength = (options?: Options): EmailWithLength => ensureFaker(options).internet.email(); |
| 40 | + |
| 41 | +export const fakeBoundedInt = (options?: Options): BoundedInt => ensureFaker(options).number.int({ min: 1, max: 100 }); |
| 42 | + |
| 43 | +export const fakeBoundedFloat = (options?: Options): BoundedFloat => ensureFaker(options).number.float({ min: 0, max: 1 }); |
| 44 | + |
| 45 | +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => ensureFaker(options).number.int({ min: 1, max: 9 }); |
| 46 | + |
| 47 | +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => ensureFaker(options).number.float({ min: 0 }); |
| 48 | + |
| 49 | +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => ensureFaker(options).number.int({ max: 999 }); |
| 50 | + |
| 51 | +export const fakeTagList = (options?: Options): TagList => ensureFaker(options).helpers.multiple(() => ensureFaker(options).string.sample(), { count: { min: 1, max: 10 } }); |
| 52 | + |
| 53 | +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => ensureFaker(options).helpers.multiple(() => ensureFaker(options).number.int(), { count: { min: 3, max: 1000 } }); |
| 54 | + |
| 55 | +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => ensureFaker(options).helpers.multiple(() => ensureFaker(options).string.sample(), { count: { min: 0, max: 5 } }); |
| 56 | + |
| 57 | +export const fakeUnconstrainedArray = (options?: Options): UnconstrainedArray => ensureFaker(options).helpers.multiple(() => ensureFaker(options).string.sample()); |
| 58 | + |
| 59 | +export const fakeDefaultString = (options?: Options): DefaultString => resolveCondition(options?.useDefault ?? false, ensureFaker(options)) ? 'unknown' : ensureFaker(options).string.sample(); |
| 60 | + |
| 61 | +export const fakeDefaultInt = (options?: Options): DefaultInt => resolveCondition(options?.useDefault ?? false, ensureFaker(options)) ? 0 : ensureFaker(options).number.int(); |
| 62 | + |
| 63 | +export const fakeDefaultBool = (options?: Options): DefaultBool => resolveCondition(options?.useDefault ?? false, ensureFaker(options)) ? true : ensureFaker(options).datatype.boolean(); |
| 64 | + |
| 65 | +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => resolveCondition(options?.useDefault ?? false, ensureFaker(options)) ? 42 : ensureFaker(options).number.int({ min: 1, max: 100 }); |
| 66 | + |
| 67 | +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => ensureFaker(options).number.float({ min: 0, max: 1 }); |
| 68 | + |
| 69 | +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => ensureFaker(options).number.float({ min: 10.1, max: 10.2 }); |
| 70 | + |
| 71 | +export const fakeNullableString = (options?: Options): NullableString => ensureFaker(options).datatype.boolean() ? ensureFaker(options).string.sample() : null; |
| 72 | + |
| 73 | +export const fakeNullableInt = (options?: Options): NullableInt => ensureFaker(options).datatype.boolean() ? ensureFaker(options).number.int() : null; |
| 74 | + |
| 75 | +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => ({ |
| 76 | + name: ensureFaker(options).string.sample(), |
| 77 | + ...!resolveCondition(options?.includeOptional ?? 'always', ensureFaker(options)) ? {} : { status: resolveCondition(options?.useDefault ?? false, ensureFaker(options)) ? 'active' : ensureFaker(options).string.sample() } |
| 78 | +}); |
| 79 | + |
| 80 | +export const fakeUserProfile = (options?: Options): UserProfile => ({ |
| 81 | + id: ensureFaker(options).number.int(), |
| 82 | + name: ensureFaker(options).string.sample(), |
| 83 | + ...!resolveCondition(options?.includeOptional ?? 'always', ensureFaker(options)) ? {} : { bio: ensureFaker(options).string.sample() }, |
| 84 | + ...!resolveCondition(options?.includeOptional ?? 'always', ensureFaker(options)) ? {} : { age: ensureFaker(options).number.int() } |
| 85 | +}); |
| 86 | + |
| 87 | +export const fakeAddress = (options?: Options): Address => ({ |
| 88 | + street: ensureFaker(options).string.alpha({ length: { min: 1, max: 200 } }), |
| 89 | + zip: fakeZipCode(options) |
| 90 | +}); |
| 91 | + |
| 92 | +export const fakePerson = (options?: Options): Person => ({ |
| 93 | + name: fakeShortName(options), |
| 94 | + email: fakeEmail(options), |
| 95 | + ...!resolveCondition(options?.includeOptional ?? 'always', ensureFaker(options)) ? {} : { address: fakeAddress(options) } |
| 96 | +}); |
| 97 | + |
| 98 | +export const fakePersonList = (options?: Options): PersonList => ensureFaker(options).helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); |
| 99 | + |
| 100 | +export const fakeTeam = (options?: Options): Team => ({ |
| 101 | + lead: fakePerson(options), |
| 102 | + config: fakeObjectWithDefaultProp(options) |
| 103 | +}); |
0 commit comments