Skip to content

Commit f67ac2d

Browse files
committed
fix based on comments
1 parent 7b4810a commit f67ac2d

7 files changed

Lines changed: 43 additions & 9 deletions

File tree

docs/.vitepress/config/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default defineConfig({
194194
},
195195
{
196196
link: '/openapi-ts/plugins/faker',
197-
text: 'Faker <span data-badge>vote</span>',
197+
text: 'Faker',
198198
},
199199
{
200200
link: '/openapi-ts/plugins/falso',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup lang="ts">
2+
import VersionSwitcher from '@components/VersionSwitcher.vue';
3+
4+
const versions = [
5+
{
6+
label: 'Faker 10',
7+
short: 'v10',
8+
value: 'v10',
9+
},
10+
];
11+
</script>
12+
13+
<template>
14+
<VersionSwitcher :values="versions" default="v10" />
15+
</template>

docs/openapi-ts/plugins/faker.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2-
title: Faker
3-
description: Generate realistic mock data factories from OpenAPI with the Faker plugin for openapi-ts. Fully compatible with all core features.
2+
title: Faker v10 Plugin
3+
description: Generate realistic mock data factories from OpenAPI with the Faker v10 plugin for openapi-ts. Fully compatible with all core features.
44
---
55

66
<script setup lang="ts">
77
import Heading from '@components/Heading.vue';
8+
import FakerVersionSwitcher from '@versions/FakerVersionSwitcher.vue';
89
</script>
910

1011
<Heading>
11-
<h1>Faker</h1>
12+
<h1>Faker<span class="sr-only"> v10</span></h1>
13+
<FakerVersionSwitcher />
1214
</Heading>
1315

1416
### About
@@ -19,6 +21,7 @@ The Faker plugin for Hey API generates factory functions from your OpenAPI spec
1921

2022
## Features
2123

24+
- Faker v10 support
2225
- seamless integration with `@hey-api/openapi-ts` ecosystem
2326
- factory functions for reusable schema definitions and operation responses
2427
- smart property name inference for realistic data (e.g. `email` &rarr; `faker.internet.email()`)
@@ -211,14 +214,27 @@ export default {
211214

212215
See the [Faker localization guide](https://fakerjs.dev/guide/localization) for available locales.
213216

217+
## Deterministic Results
218+
219+
For snapshot testing or reproducible output, you can seed the faker instance and fix the reference date to ensure deterministic results.
220+
221+
```ts
222+
import { faker } from '@faker-js/faker';
223+
224+
faker.seed(42);
225+
faker.setDefaultRefDate('2026-01-01T00:00:00.000Z');
226+
227+
const data = fakeFoo({ faker });
228+
// always returns the same output
229+
```
230+
214231
## Custom Faker Instance
215232

216-
For runtime locale switching or seeded deterministic output, you can pass your own faker instance via the `faker` option.
233+
You can pass your own [faker instance](https://fakerjs.dev/api/faker.html) via the `faker` option for runtime locale switching or other customizations.
217234

218235
```ts
219236
import { faker } from '@faker-js/faker/locale/de';
220237

221-
faker.seed(42);
222238
const data = fakeFoo({ faker });
223239
```
224240

packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function arrayToExpression({
3838
// faker requires both min and max — fill in sensible defaults when only one is specified
3939
if (schema.minItems !== undefined || schema.maxItems !== undefined) {
4040
const min = schema.minItems ?? 0;
41-
const max = schema.maxItems ?? 1000;
41+
const max = schema.maxItems ?? 100;
4242
const countObj = $.object().prop('min', $.literal(min)).prop('max', $.literal(max));
4343
const options = $.object().prop('count', countObj);
4444
return fakerCtx.fakerAccessor.attr('helpers').attr('multiple').call(callback, options);

packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/enum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function enumToExpression(
1616
if (item.const === null || item.type === 'null') {
1717
members.push($.fromValue(null));
1818
} else if (item.const !== undefined) {
19-
members.push($.literal(item.const as string));
19+
members.push($.literal(item.const as string | number));
2020
}
2121
}
2222

packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/number.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export function numberToExpression(
2323
let min: number | undefined;
2424
let max: number | undefined;
2525

26+
// For floats, exclusive bounds are passed as-is to faker's min/max options,
27+
// which treats them as inclusive. This is technically not strictly exclusive,
28+
// but fine in practice since the chance of hitting the exact bound is negligible.
2629
if (schema.exclusiveMinimum !== undefined) {
2730
min = isInteger ? schema.exclusiveMinimum + 1 : schema.exclusiveMinimum;
2831
} else if (schema.minimum !== undefined) {

packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function stringToExpression(
3939
// faker requires both min and max — fill in sensible defaults when only one is specified
4040
if (schema.minLength !== undefined || schema.maxLength !== undefined) {
4141
const min = schema.minLength ?? 0;
42-
const max = schema.maxLength ?? 1000;
42+
const max = schema.maxLength ?? 100;
4343
const lengthObj = $.object().prop('min', $.literal(min)).prop('max', $.literal(max));
4444
return ctx.fakerAccessor
4545
.attr('string')

0 commit comments

Comments
 (0)