diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index b60697788a..c8267118e1 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -198,7 +198,7 @@ export default defineConfig({ }, { link: '/openapi-ts/plugins/faker', - text: 'Faker vote', + text: 'Faker', }, { link: '/openapi-ts/plugins/falso', diff --git a/docs/openapi-ts/plugins/faker.md b/docs/openapi-ts/plugins/faker.md index d014d4a572..6dc4ec9111 100644 --- a/docs/openapi-ts/plugins/faker.md +++ b/docs/openapi-ts/plugins/faker.md @@ -1,18 +1,369 @@ --- -title: Faker -description: Faker plugin for Hey API. Compatible with all our features. +title: Faker Plugin +description: Generate realistic mock data factories from OpenAPI with the Faker plugin for openapi-ts. Compatible with Faker v9 and v10. --- -# Faker vote - - + +

Faker v9 & v10

+
### About [Faker](https://fakerjs.dev) is a popular library that generates fake (but reasonable) data that can be used for things such as unit testing, performance testing, building demos, and working without a completed backend. +The Faker plugin for Hey API generates factory functions from your OpenAPI spec that return realistic mock data using `@faker-js/faker`. + +## Features + +- Faker v9 and v10 support +- seamless integration with `@hey-api/openapi-ts` ecosystem +- factory functions for reusable schema definitions, operation requests, and operation responses +- smart property name inference for realistic data (e.g. `email` → `faker.internet.email()`) +- constraint and format awareness (min/max, string formats, array bounds) +- optional property and default value handling +- dependency injection for custom faker instances (locale, seed) +- minimal learning curve thanks to extending the underlying technology + +## Installation + +In your [configuration](/openapi-ts/get-started), add `@faker-js/faker` to your plugins and you'll be ready to generate faker factories. :tada: + +```js +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + '@faker-js/faker', // [!code ++] + ], +}; +``` + +## Output + +The Faker plugin will generate the following artifacts, depending on the input specification. + +## Definitions + +A factory function is generated for every reusable definition from your input. + +::: code-group + +```ts [example] +import { faker, type Faker } from '@faker-js/faker'; + +import type { Bar, Foo } from '../types.gen'; + +export const fakeFoo = (options?: Options): Foo => ({ + name: ensureFaker(options).string.sample(), + age: ensureFaker(options).number.int({ min: 1, max: 120 }), +}); + +export const fakeBar = (options?: Options): Bar => + ensureFaker(options).helpers.arrayElement(['baz', 'qux']); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@faker-js/faker', + definitions: true, // [!code ++] + }, + ], +}; +``` + +::: + +You can customize the naming and casing pattern for `definitions` factories using the `.name` and `.case` options. + +## Requests + +A single factory function is generated per operation for request data. It combines the request body, path parameters, query parameters, and headers into one object. Only keys with actual data are included. + +::: code-group + +```ts [example] +// body + path + query combined into one factory +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + tag: fakeTag(options), + }, + path: { + id: f.string.uuid(), + }, + query: { + dryRun: f.datatype.boolean(), + }, + }; +}; + +// body only +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + }, + }; +}; +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@faker-js/faker', + requests: true, // [!code ++] + }, + ], +}; +``` + +::: + +You can customize the naming and casing pattern for `requests` factories using the `.name` and `.case` options. + +## Responses + +A factory function is generated for operation responses. When an operation has a single success response, the factory is unsuffixed. When multiple responses exist, each factory is suffixed with the status code. + +::: code-group + +```ts [example] +// single success response — unsuffixed +export const fakeCreatePetResponse = (options?: Options): CreatePetResponse => fakePet(options); + +// multiple responses — suffixed with status code +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@faker-js/faker', + responses: true, // [!code ++] + }, + ], +}; +``` + +::: + +You can customize the naming and casing pattern for `responses` factories using the `.name` and `.case` options. + +## Smart Inference + +The plugin infers semantically appropriate faker methods from property names, producing more realistic mock data without requiring explicit schema formats or annotations. + +```ts +// property name "email" → faker.internet.email() +// property name "firstName" → faker.person.firstName() +// property name "city" → faker.location.city() +// property name "id" → faker.string.uuid() +// property name "age" → faker.number.int({ min: 1, max: 120 }) +``` + +Ancestor context is also used for disambiguation. For example, `name` under a `User` schema produces `faker.person.fullName()`, while `name` under a `Company` schema produces `faker.company.name()`. + +Explicit schema annotations (format, pattern, constraints) always take priority over name-based inference. + +### Name Rules + +You can extend or override the built-in name inference with custom `nameRules`. Rules are defined per schema type (`string` or `number`) and map property names to specific faker methods. + +::: code-group + +```ts [output] +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.word.words({ count: 4 }), + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.database.mongodbObjectId(), + _id: f.database.mongodbObjectId(), + }; +}; +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@faker-js/faker', + nameRules: { + // [!code ++] + string: { + // [!code ++] + // compound rule: "message" inside an "error" schema // [!code ++] + 'error.message': { + // [!code ++] + fakerPath: ['word', 'words'], // [!code ++] + defaultArgs: { count: 4 }, // [!code ++] + }, // [!code ++] + // suffix rule: any property ending with "id" // [!code ++] + id: { + // [!code ++] + fakerPath: ['database', 'mongodbObjectId'], // [!code ++] + suffixMatch: true, // [!code ++] + }, // [!code ++] + }, // [!code ++] + }, // [!code ++] + }, + ], +}; +``` + +::: + +Each rule requires a `fakerPath` — a tuple of `[module, method]` corresponding to a faker method (e.g. `['database', 'mongodbObjectId']` for `faker.database.mongodbObjectId()`). You can optionally provide `defaultArgs` to pass default arguments to the faker method. + +**Matching strategies:** + +- **Exact match** — `'email'` matches a property named `email` +- **Compound match** — `'error.message'` matches a property named `message` inside an ancestor named `error` +- **Suffix match** — `'id'` with `suffixMatch: true` matches any property ending with `id` (e.g. `userId`, `_id`) + +User-provided rules take priority over built-in rules. Property names are normalized (lowercased, separators removed) before matching. + +## Formats and Constraints + +The plugin respects OpenAPI schema formats and constraints to generate appropriately bounded data. + +**String formats:** + +- `email` → `faker.internet.email()` +- `date-time` → `faker.date.recent().toISOString()` +- `date` → `faker.date.recent().toISOString().slice(0, 10)` +- `uuid` → `faker.string.uuid()` +- `uri` / `url` → `faker.internet.url()` +- `ipv4` → `faker.internet.ipv4()` +- `ipv6` → `faker.internet.ipv6()` +- `pattern` → `faker.helpers.fromRegExp(pattern)` + +**Numeric constraints:** + +- `minimum` / `maximum` → `faker.number.int({ min, max })` +- `exclusiveMinimum` / `exclusiveMaximum` → adjusted bounds + +**String constraints:** + +- `minLength` / `maxLength` → `faker.string.alpha({ length: { min, max } })` + +**Array constraints:** + +- `minItems` / `maxItems` → controls count in `faker.helpers.multiple()` + +## Optional Properties + +Required properties are always included. Optional properties are controlled by the `includeOptional` option at runtime. + +```ts +const user = fakeFoo(); // includes optional properties by default +const user = fakeFoo({ includeOptional: false }); // excludes optional properties +const user = fakeFoo({ includeOptional: 0.5 }); // 50% probability per optional property +``` + +## Default Values + +When a schema defines default values, you can control whether to use them instead of generating fake data via the `useDefault` option. + +```ts +const data = fakeFoo(); // always generates fake data +const data = fakeFoo({ useDefault: true }); // uses schema defaults when available +const data = fakeFoo({ useDefault: 0.5 }); // 50% probability of using defaults +``` + +## Circular References + +Schemas with circular references are automatically detected, whether self-referencing (a schema that refers to itself) or mutually recursive (two or more schemas that refer to each other). The generated factories use a depth counter to prevent infinite recursion, returning empty arrays or omitting optional properties once the limit is reached. + +The maximum depth defaults to `10` and can be configured via the `maxCallDepth` option. + +## Locale + +You can configure the locale for generated faker factories. When set, the generated code imports the faker instance from the locale-specific build of `@faker-js/faker`. + +::: code-group + +```ts [output] +import { faker } from '@faker-js/faker/locale/de'; +import type { Faker } from '@faker-js/faker'; +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@faker-js/faker', + locale: 'de', // [!code ++] + }, + ], +}; +``` + +::: + +See the [Faker localization guide](https://fakerjs.dev/guide/localization) for available locales. + +## Deterministic Results + +For snapshot testing or reproducible output, you can seed the faker instance and fix the reference date to ensure deterministic results. + +```ts +import { faker } from '@faker-js/faker'; + +faker.seed(42); +faker.setDefaultRefDate('2026-01-01T00:00:00.000Z'); + +const data = fakeFoo(); +// always returns the same output +``` + +## Custom Faker Instance + +You can pass your own [faker instance](https://fakerjs.dev/api/faker.html) via the `faker` option for runtime locale switching or other customizations. + +```ts +import { faker } from '@faker-js/faker/locale/de'; + +const data = fakeFoo({ faker }); +``` + +## API + +You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@faker-js/faker/types.ts) interface. + diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..6a90383bde --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/@faker-js/faker.gen.ts @@ -0,0 +1,88 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Comment, Department, Employee, Member, Org, Project, TreeNode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakeTreeNode = (options: Options = {}, _callDepth = 0): TreeNode => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + value: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { children: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeTreeNode(options, _callDepth + 1)) } + }; +}; + +export const fakeComment = (options: Options = {}, _callDepth = 0): Comment => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + text: f.string.sample(), + parent: _callDepth > MAX_CALL_DEPTH ? null : f.datatype.boolean() ? fakeComment(options, _callDepth + 1) : null + }; +}; + +export const fakeOrg = (options: Options = {}, _callDepth = 0): Org => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { members: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeMember(options, _callDepth + 1)) } + }; +}; + +export const fakeMember = (options: Options = {}, _callDepth = 0): Member => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { org: fakeOrg(options, _callDepth + 1) } + }; +}; + +export const fakeDepartment = (options: Options = {}, _callDepth = 0): Department => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { employees: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeEmployee(options, _callDepth + 1)) } + }; +}; + +export const fakeEmployee = (options: Options = {}, _callDepth = 0): Employee => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.person.fullName(), + projects: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeProject(options, _callDepth + 1)) + }; +}; + +export const fakeProject = (options: Options = {}, _callDepth = 0): Project => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { department: fakeDepartment(options, _callDepth + 1) } + }; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/index.ts new file mode 100644 index 0000000000..c9f13ff070 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { ClientOptions, Comment, Department, Employee, Member, Org, Project, TreeNode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/types.gen.ts new file mode 100644 index 0000000000..362929ff7b --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-circular/types.gen.ts @@ -0,0 +1,47 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: string; +}; + +export type TreeNode = { + id: string; + value: string; + children?: Array; +}; + +export type Org = { + id: string; + name: string; + members?: Array; +}; + +export type Member = { + id: string; + name: string; + org?: Org; +}; + +export type Department = { + id: string; + name: string; + employees?: Array; +}; + +export type Employee = { + id: string; + name: string; + projects: Array; +}; + +export type Project = { + id: string; + name: string; + department?: Department; +}; + +export type Comment = { + id: string; + text: string; + parent: Comment | null; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..ed86938689 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/@faker-js/faker.gen.ts @@ -0,0 +1,782 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithParametersData, CallWithResponseAndNoContentResponseResponses, CallWithResponseResponse, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, Date, Default, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithReference, DictionaryWithString, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithStrings, ExternalRefA, ExternalRefB, ExternalSharedModel, FailureFailure, ModelThatExtends, ModelThatExtendsExtends, ModelWithArray, ModelWithBoolean, ModelWithCircularReference, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithInteger, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableString, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiStringæøåÆøÅöôêÊ字符串, ParameterActivityParams, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponses, ResponsePostActivityResponse, SimpleBoolean, SimpleFile, SimpleInteger, SimpleReference, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakeCommentWithBreaks = (options?: Options): CommentWithBreaks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticks = (options?: Options): CommentWithBackticks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticksAndQuotes = (options?: Options): CommentWithBackticksAndQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithSlashes = (options?: Options): CommentWithSlashes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithExpressionPlaceholders = (options?: Options): CommentWithExpressionPlaceholders => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithQuotes = (options?: Options): CommentWithQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithReservedCharacters = (options?: Options): CommentWithReservedCharacters => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleInteger = (options?: Options): SimpleInteger => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleBoolean = (options?: Options): SimpleBoolean => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeSimpleString = (options?: Options): SimpleString => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeNonAsciiStringæøåÆøÅöôêÊ字符串 = (options?: Options): NonAsciiStringæøåÆøÅöôêÊ字符串 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeSimpleFile = (options?: Options): SimpleFile => { + const f = options?.faker ?? faker; + return new Blob([f.image.dataUri()]); +}; + +export const fakeSimpleStringWithPattern = (options?: Options): SimpleStringWithPattern => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'); +}; + +export const fakeEnumWithStrings = (options?: Options): EnumWithStrings => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + '\'Single Quote\'', + '"Double Quotes"', + 'Non-ascii: øæåôöØÆÅÔÖ字符串' + ]); +}; + +export const fakeEnumWithNumbers = (options?: Options): EnumWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3, + 1.1, + 1.2, + 1.3, + 100, + 200, + 300, + -100, + -200, + -300, + -1.1, + -1.2, + -1.3 + ]); +}; + +export const fakeEnumFromDescription = (options?: Options): EnumFromDescription => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeEnumWithExtensions = (options?: Options): EnumWithExtensions => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 200, + 400, + 500 + ]); +}; + +export const fakeArrayWithNumbers = (options?: Options): ArrayWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int()); +}; + +export const fakeArrayWithBooleans = (options?: Options): ArrayWithBooleans => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.datatype.boolean()); +}; + +export const fakeArrayWithStrings = (options?: Options): ArrayWithStrings => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeArrayWithProperties = (options?: Options): ArrayWithProperties => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => ({ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + })); +}; + +export const fakeDictionaryWithString = (options?: Options): DictionaryWithString => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeDictionaryWithDictionary = (options?: Options): DictionaryWithDictionary => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } + }; +}; + +export const fakeDictionaryWithProperties = (options?: Options): DictionaryWithProperties => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + } + }; +}; + +export const fakeDate = (options?: Options): Date => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithInteger = (options?: Options): ModelWithInteger => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.number.int() } + }; +}; + +export const fakeModelWithBoolean = (options?: Options): ModelWithBoolean => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.datatype.boolean() } + }; +}; + +export const fakeModelWithString = (options?: Options): ModelWithString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeSimpleReference = (options?: Options): SimpleReference => fakeModelWithString(options); + +export const fakeArrayWithReferences = (options?: Options): ArrayWithReferences => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeArrayWithArray = (options?: Options): ArrayWithArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.multiple(() => fakeModelWithString(options))); +}; + +export const fakeDictionaryWithReference = (options?: Options): DictionaryWithReference => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: fakeModelWithString(options) + }; +}; + +export const fakeDictionaryWithArray = (options?: Options): DictionaryWithArray => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => fakeModelWithString(options)) + }; +}; + +export const fakeModelWithStringError = (options?: Options): ModelWithStringError => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeModelWithNullableString = (options?: Options): ModelWithNullableString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableProp: f.datatype.boolean() ? f.string.sample() : null }, + nullableRequiredProp: f.datatype.boolean() ? f.string.sample() : null + }; +}; + +export const fakeModelWithEnum = (options?: Options): ModelWithEnum => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { test: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { statusCode: f.helpers.arrayElement([ + '100', + '200 FOO', + '300 FOO_BAR', + '400 foo-bar', + '500 foo.bar', + '600 foo&bar' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bool: true } + }; +}; + +export const fakeModelWithEnumFromDescription = (options?: Options): ModelWithEnumFromDescription => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { test: f.number.int() } + }; +}; + +export const fakeModelWithNestedEnums = (options?: Options): ModelWithNestedEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnum: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnumFromDescription: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.number.int() + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithEnum: f.helpers.multiple(() => f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithDescription: f.helpers.multiple(() => f.number.int()) } + }; +}; + +export const fakeModelWithArray = (options?: Options): ModelWithArray => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithString(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithDictionary = (options?: Options): ModelWithDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } } + }; +}; + +export const fakeModelWithCircularReference = (options: Options = {}, _callDepth = 0): ModelWithCircularReference => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithCircularReference(options, _callDepth + 1) } + }; +}; + +export const fakeModelWithProperties = (options?: Options): ModelWithProperties => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + requiredAndReadOnly: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() } + }; +}; + +export const fakeModelWithReference = (options?: Options): ModelWithReference => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithProperties(options) } + }; +}; + +export const fakeModelWithNestedProperties = (options?: Options): ModelWithNestedProperties => { + const f = options?.faker ?? faker; + return { + first: { + second: { + third: f.string.sample() + } + } + }; +}; + +export const fakeModelWithDuplicateProperties = (options?: Options): ModelWithDuplicateProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithString(options) } + }; +}; + +export const fakeModelWithOrderedProperties = (options?: Options): ModelWithOrderedProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { zebra: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { apple: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hawaii: f.string.sample() } + }; +}; + +export const fakeModelWithDuplicateImports = (options?: Options): ModelWithDuplicateImports => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propB: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propC: fakeModelWithString(options) } + }; +}; + +export const fakeModelThatExtends = (options?: Options): ModelThatExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsA: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsB: fakeModelWithString(options) } + }); +}; + +export const fakeModelThatExtendsExtends = (options?: Options): ModelThatExtendsExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), fakeModelThatExtends(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsC: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsD: fakeModelWithString(options) } + }); +}; + +export const fakeDefault = (options?: Options): Default => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakeModelWithPattern = (options?: Options): ModelWithPattern => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { enabled: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { modified: f.date.recent().toISOString() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakeParameterActivityParams = (options?: Options): ParameterActivityParams => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { graduate_id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { organization_id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parent_activity: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { post_id: f.number.int() } + }; +}; + +export const fakeResponsePostActivityResponse = (options?: Options): ResponsePostActivityResponse => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { graduate_id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { organization_id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parent_activity_id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { post_id: f.number.int() } + }; +}; + +export const fakeFailureFailure = (options?: Options): FailureFailure => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { message: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference_code: f.string.sample() } + }; +}; + +export const fakeExternalSharedModel = (options?: Options): ExternalSharedModel => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakeExternalRefA = (options?: Options): ExternalRefA => fakeExternalSharedModel(options); + +export const fakeExternalRefB = (options?: Options): ExternalRefB => fakeExternalSharedModel(options); + +export const fakeModelWithPropertiesWritable = (options?: Options): ModelWithPropertiesWritable => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() } + }; +}; + +export const fakeModelWithReferenceWritable = (options?: Options): ModelWithReferenceWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithPropertiesWritable(options) } + }; +}; + +export const fakeModelWithPatternWritable = (options?: Options): ModelWithPatternWritable => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakePatchApiVbyApiVersionNoTagResponse = () => undefined; + +export const fakeFooWowResponse = () => undefined; + +export const fakeCallWithDescriptionsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBreaks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBackticks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithSlashes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithExpressionPlaceholders: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithQuotes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithReservedCharacters: f.string.sample() } + } + }; +}; + +export const fakeCallWithParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + headers: { + parameterHeader: f.string.sample() + }, + path: { + parameterPath: f.string.sample(), + 'api-version': f.string.sample() + }, + query: { + parameterQuery: f.string.sample() + } + }; +}; + +export const fakeCallWithWeirdParameterNamesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.string.sample(), + headers: { + 'parameter.header': f.string.sample() + }, + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter.path.1': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter-path-2': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'PARAMETER-PATH-3': f.string.sample() }, + 'api-version': f.string.sample() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + 'parameter-query': f.string.sample() + } + }; +}; + +export const fakeCallWithDefaultParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterString: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample(), + parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float(), + parameterBoolean: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(), + parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]), + parameterModel: resolveCondition(options?.useDefault ?? false, f) ? { prop: 'Hello World!' } : { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + } + } + }; +}; + +export const fakeCallWithDefaultOptionalParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterString: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterBoolean: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) } + } + }; +}; + +export const fakeCallToTestOrderOfParamsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithNoDefault: f.string.sample() }, + parameterStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample(), + parameterStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample(), + parameterStringWithNoDefault: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithNoDefault: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithDefault: f.datatype.boolean() ? f.string.sample() : null } + } + }; +}; + +export const fakeCallWithNoContentResponseResponse = () => undefined; + +export const fakeCallWithResponseAndNoContentResponseResponse200 = (options?: Options): CallWithResponseAndNoContentResponseResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeCallWithResponseAndNoContentResponseResponse204 = (): CallWithResponseAndNoContentResponseResponses[204] => undefined; + +export const fakeDummyAResponse = () => undefined; + +export const fakeDummyBResponse = () => undefined; + +export const fakeCallWithResponseResponse = (options?: Options): CallWithResponseResponse => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse201 = (options?: Options): CallWithDuplicateResponsesResponses[201] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse202 = (options?: Options): CallWithDuplicateResponsesResponses[202] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse500 = (options?: Options): CallWithDuplicateResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse501 = (options?: Options): CallWithDuplicateResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse502 = (options?: Options): CallWithDuplicateResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponsedefault = (options?: Options): CallWithDuplicateResponsesErrors['default'] => fakeModelWithString(options); + +export const fakeCallWithResponsesResponse200 = (options?: Options): CallWithResponsesResponses[200] => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { value: f.helpers.multiple(() => fakeModelWithString(options)) } + }; +}; + +export const fakeCallWithResponsesResponse201 = (options?: Options): CallWithResponsesResponses[201] => fakeModelThatExtends(options); + +export const fakeCallWithResponsesResponse202 = (options?: Options): CallWithResponsesResponses[202] => fakeModelThatExtendsExtends(options); + +export const fakeCallWithResponsesResponse500 = (options?: Options): CallWithResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse501 = (options?: Options): CallWithResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse502 = (options?: Options): CallWithResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponsedefault = (options?: Options): CallWithResponsesErrors['default'] => fakeModelWithString(options); + +export const fakeCollectionFormatRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterArrayCSV: f.helpers.multiple(() => f.string.sample()), + parameterArraySSV: f.helpers.multiple(() => f.string.sample()), + parameterArrayTSV: f.helpers.multiple(() => f.string.sample()), + parameterArrayPipes: f.helpers.multiple(() => f.string.sample()), + parameterArrayMulti: f.helpers.multiple(() => f.string.sample()) + } + }; +}; + +export const fakeTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.number.int() } + }, + query: { + parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float(), + parameterString: resolveCondition(options?.useDefault ?? false, f) ? 'default' : f.string.sample(), + parameterBoolean: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(), + parameterArray: f.helpers.multiple(() => f.string.sample()), + parameterDictionary: {}, + parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) + } + }; +}; + +export const fakeTypesResponse200 = (options?: Options): TypesResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeTypesResponse201 = (options?: Options): TypesResponses[201] => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeTypesResponse202 = (options?: Options): TypesResponses[202] => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeTypesResponse203 = (): TypesResponses[203] => ({}); + +export const fakeComplexTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterObject: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { first: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { second: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { third: f.string.sample() } + } } + } } + }, + parameterReference: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + } + } + }; +}; + +export const fakeComplexTypesResponse200 = (options?: Options): ComplexTypesResponses[200] => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeComplexTypesResponse400 = (): ComplexTypesErrors[400] => undefined; + +export const fakeComplexTypesResponse500 = (): ComplexTypesErrors[500] => undefined; + +export const fakeCallWithResultFromHeaderResponse200 = (): CallWithResultFromHeaderResponses[200] => undefined; + +export const fakeCallWithResultFromHeaderResponse400 = (): CallWithResultFromHeaderErrors[400] => undefined; + +export const fakeCallWithResultFromHeaderResponse500 = (): CallWithResultFromHeaderErrors[500] => undefined; + +export const fakeTestErrorCodeRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + status: f.string.sample() + } + }; +}; + +export const fakeTestErrorCodeResponse200 = (): TestErrorCodeResponses[200] => undefined; + +export const fakeTestErrorCodeResponse500 = (): TestErrorCodeErrors[500] => undefined; + +export const fakeTestErrorCodeResponse501 = (): TestErrorCodeErrors[501] => undefined; + +export const fakeTestErrorCodeResponse502 = (): TestErrorCodeErrors[502] => undefined; + +export const fakeTestErrorCodeResponse503 = (): TestErrorCodeErrors[503] => undefined; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Request = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + nonAsciiParamæøåÆØÅöôêÊ: f.number.int() + } + }; +}; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Response = (options?: Options): NonAsciiæøåÆøÅöôêÊ字符串Response => fakeNonAsciiStringæøåÆøÅöôêÊ字符串(options); + +export const fakePostApiVbyApiVersionBodyRequest = (options?: Options): Omit => ({ + body: fakeParameterActivityParams(options) +}); + +export const fakePostApiVbyApiVersionBodyResponse200 = (options?: Options): PostApiVbyApiVersionBodyResponses[200] => fakeResponsePostActivityResponse(options); + +export const fakePostApiVbyApiVersionBodyResponse400 = (options?: Options): PostApiVbyApiVersionBodyErrors[400] => fakeFailureFailure(options); + +export const fakePostApiVbyApiVersionBodyResponse500 = (options?: Options): PostApiVbyApiVersionBodyErrors[500] => fakeFailureFailure(options); diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/index.ts new file mode 100644 index 0000000000..c42215da06 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, Date, Default, DeleteCallWithoutParametersAndResponseData, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithStrings, ExternalRefA, ExternalRefB, ExternalSharedModel, FailureFailure, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ModelThatExtends, ModelThatExtendsExtends, ModelWithArray, ModelWithBoolean, ModelWithCircularReference, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithInteger, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableString, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, OptionsCallWithoutParametersAndResponseData, ParameterActivityParams, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponse, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ResponsePostActivityResponse, ServiceWithEmptyTagData, SimpleBoolean, SimpleFile, SimpleInteger, SimpleReference, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/types.gen.ts new file mode 100644 index 0000000000..d69b074040 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-full/types.gen.ts @@ -0,0 +1,1190 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string; + bar?: string; +}>; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a type-only model that defines Date as a string + */ +export type Date = string; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp: string | null; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string; + }; + }; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +export type Default = { + name?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ParameterActivityParams = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity?: number; + post_id?: number; +}; + +export type ResponsePostActivityResponse = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity_id?: number; + post_id?: number; +}; + +export type FailureFailure = { + error?: string; + message?: string; + reference_code?: string; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ServiceWithEmptyTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions/'; +}; + +export type CallWithParametersData = { + body?: never; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that is sent as request body + */ + body: string; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query: { + /** + * This is a simple string with default value + */ + parameterString: string; + /** + * This is a simple number with default value + */ + parameterNumber: number; + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a model with one string property + */ + parameterModel: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean; + /** + * This is an array parameter + */ + parameterArray: Array; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + }; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * This is a model with one string property + */ + parameterReference: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: string; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: NonAsciiStringæøåÆøÅöôêÊ字符串; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PostApiVbyApiVersionBodyData = { + /** + * Body should not be unknown + */ + body: ParameterActivityParams; + path?: never; + query?: never; + url: '/api/v{api-version}/body'; +}; + +export type PostApiVbyApiVersionBodyErrors = { + /** + * Bad Request + */ + 400: FailureFailure; + /** + * Internal Server Error + */ + 500: FailureFailure; +}; + +export type PostApiVbyApiVersionBodyError = PostApiVbyApiVersionBodyErrors[keyof PostApiVbyApiVersionBodyErrors]; + +export type PostApiVbyApiVersionBodyResponses = { + /** + * OK + */ + 200: ResponsePostActivityResponse; +}; + +export type PostApiVbyApiVersionBodyResponse = PostApiVbyApiVersionBodyResponses[keyof PostApiVbyApiVersionBodyResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-locale/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-locale/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..0c48bdb708 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-locale/@faker-js/faker.gen.ts @@ -0,0 +1,417 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Faker } from '@faker-js/faker'; +import { faker } from '@faker-js/faker/locale/de'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse201 = (options?: Options) => fakePet(options); + +export const fakeCreatePetResponse204 = () => undefined; + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse204 = () => undefined; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..b6e60488c1 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/@faker-js/faker.gen.ts @@ -0,0 +1,418 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, BoundedFloat, BoundedInt, Company, Config, CreatePetData, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, DeletePetResponses, Document, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NullableInt, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetWithOwner, Price, Quantity, ShortName, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.word.words({ count: 4 }) + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse201 = (options?: Options): CreatePetResponses[201] => fakePet(options); + +export const fakeCreatePetResponse204 = (): CreatePetResponses[204] => undefined; + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse204 = (): DeletePetResponses[204] => undefined; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/index.ts new file mode 100644 index 0000000000..9edc7226d9 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, BoundedFloat, BoundedInt, ClientOptions, Company, Config, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponses, Document, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, NullableInt, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetWithOwner, Price, Quantity, ShortName, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/types.gen.ts new file mode 100644 index 0000000000..8991c09719 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-name-rules/types.gen.ts @@ -0,0 +1,312 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'https://localhost/' | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: unknown; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: unknown; +}; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..29685ed37e --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/@faker-js/faker.gen.ts @@ -0,0 +1,418 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, BoundedFloat, BoundedInt, Company, Config, CreatePetData, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, DeletePetResponses, Document, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NullableInt, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetWithOwner, Price, Quantity, ShortName, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse201 = (options?: Options): CreatePetResponses[201] => fakePet(options); + +export const fakeCreatePetResponse204 = (): CreatePetResponses[204] => undefined; + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse204 = (): DeletePetResponses[204] => undefined; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/index.ts new file mode 100644 index 0000000000..9edc7226d9 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, BoundedFloat, BoundedInt, ClientOptions, Company, Config, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponses, Document, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, NullableInt, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetWithOwner, Price, Quantity, ShortName, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/types.gen.ts new file mode 100644 index 0000000000..8991c09719 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker-typed/types.gen.ts @@ -0,0 +1,312 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'https://localhost/' | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: unknown; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: unknown; +}; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..05a48909f3 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/2.0.x/faker/@faker-js/faker.gen.ts @@ -0,0 +1,416 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse201 = (options?: Options) => fakePet(options); + +export const fakeCreatePetResponse204 = () => undefined; + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse204 = () => undefined; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..d865e27631 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/@faker-js/faker.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Bar, Baz, Comment, Corge, Department, Employee, Foo, Member, Org, Project, Quux, Qux, TreeNode, Wrapper } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakeTreeNode = (options: Options = {}, _callDepth = 0): TreeNode => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + value: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { children: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeTreeNode(options, _callDepth + 1)) } + }; +}; + +export const fakeWrapper = (options?: Options): Wrapper => { + const f = options?.faker ?? faker; + return { + label: f.string.sample(), + tree: fakeTreeNode(options) + }; +}; + +export const fakeComment = (options: Options = {}, _callDepth = 0): Comment => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + text: f.string.sample(), + parent: _callDepth > MAX_CALL_DEPTH ? null : f.datatype.boolean() ? fakeComment(options, _callDepth + 1) : null + }; +}; + +export const fakeFoo = (options: Options = {}, _callDepth = 0): Foo => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { quux: fakeQuux(options, _callDepth + 1) } + }; +}; + +export const fakeBar = (options: Options = {}, _callDepth = 0): Bar => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: fakeBar(options, _callDepth + 1) }, + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { baz: fakeBaz(options, _callDepth + 1) } + }; +}; + +export const fakeBaz = (options: Options = {}, _callDepth = 0): Baz => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { quux: fakeQuux(options, _callDepth + 1) } + }; +}; + +export const fakeQux = (options: Options = {}, _callDepth = 0): Qux => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCorge(options, _callDepth + 1)), + type: 'struct' as const + }, { + ...Object.assign({}, fakeFoo(options, _callDepth + 1)), + type: 'array' as const + }]); +}; + +export const fakeQuux = (options: Options = {}, _callDepth = 0): Quux => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { qux: fakeQux(options, _callDepth + 1) } + }; +}; + +export const fakeCorge = (options: Options = {}, _callDepth = 0): Corge => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { baz: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeBaz(options, _callDepth + 1)) } + }; +}; + +export const fakeOrg = (options: Options = {}, _callDepth = 0): Org => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { members: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeMember(options, _callDepth + 1)) } + }; +}; + +export const fakeMember = (options: Options = {}, _callDepth = 0): Member => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { org: fakeOrg(options, _callDepth + 1) } + }; +}; + +export const fakeDepartment = (options: Options = {}, _callDepth = 0): Department => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { employees: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeEmployee(options, _callDepth + 1)) } + }; +}; + +export const fakeEmployee = (options: Options = {}, _callDepth = 0): Employee => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.person.fullName(), + projects: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeProject(options, _callDepth + 1)) + }; +}; + +export const fakeProject = (options: Options = {}, _callDepth = 0): Project => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { department: fakeDepartment(options, _callDepth + 1) } + }; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/index.ts new file mode 100644 index 0000000000..dfdbfa829b --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Bar, Baz, ClientOptions, Comment, Corge, Department, Employee, Foo, Member, Org, Project, Quux, Qux, TreeNode, Wrapper } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/types.gen.ts new file mode 100644 index 0000000000..cdca11642c --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-circular/types.gen.ts @@ -0,0 +1,79 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type Foo = { + quux?: Quux; +}; + +export type Bar = { + bar?: Bar; + baz?: Baz; +}; + +export type Baz = { + quux?: Quux; +}; + +export type Qux = ({ + type: 'struct'; +} & Corge) | ({ + type: 'array'; +} & Foo); + +export type Quux = { + qux?: Qux; +}; + +export type Corge = { + baz?: Array; +}; + +export type TreeNode = { + id: string; + value: string; + children?: Array; +}; + +export type Org = { + id: string; + name: string; + members?: Array; +}; + +export type Member = { + id: string; + name: string; + org?: Org; +}; + +export type Department = { + id: string; + name: string; + employees?: Array; +}; + +export type Employee = { + id: string; + name: string; + projects: Array; +}; + +export type Project = { + id: string; + name: string; + department?: Department; +}; + +export type Wrapper = { + label: string; + tree: TreeNode; +}; + +export type Comment = { + id: string; + text: string; + parent: Comment | null; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..11c23562a2 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/@faker-js/faker.gen.ts @@ -0,0 +1,1616 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountResponse, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithParametersData, CallWithResponseAndNoContentResponseResponse, CallWithResponseResponse, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAResponse, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileWritable, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, Import, ImportData, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseResponse, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, Pageable, ParameterSimpleParameterUnused, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponse, XFooBar } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fake400 = (options?: Options): _400 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeCamelCaseCommentWithBreaks = (options?: Options): CamelCaseCommentWithBreaks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBreaks = (options?: Options): CommentWithBreaks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticks = (options?: Options): CommentWithBackticks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticksAndQuotes = (options?: Options): CommentWithBackticksAndQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithSlashes = (options?: Options): CommentWithSlashes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithExpressionPlaceholders = (options?: Options): CommentWithExpressionPlaceholders => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithQuotes = (options?: Options): CommentWithQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithReservedCharacters = (options?: Options): CommentWithReservedCharacters => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleInteger = (options?: Options): SimpleInteger => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleBoolean = (options?: Options): SimpleBoolean => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeSimpleString = (options?: Options): SimpleString => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeNonAsciiStringæøåÆøÅöôêÊ字符串 = (options?: Options): NonAsciiStringæøåÆøÅöôêÊ字符串 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeSimpleFile = (options?: Options): SimpleFile => { + const f = options?.faker ?? faker; + return new Blob([f.image.dataUri()]); +}; + +export const fakeSimpleStringWithPattern = (options?: Options): SimpleStringWithPattern => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.helpers.fromRegExp('^[a-zA-Z0-9_]*$') : null; +}; + +export const fakeEnumWithStrings = (options?: Options): EnumWithStrings => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + '\'Single Quote\'', + '"Double Quotes"', + 'Non-ascii: øæåôöØÆÅÔÖ字符串' + ]); +}; + +export const fakeEnumWithReplacedCharacters = (options?: Options): EnumWithReplacedCharacters => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + '\'Single Quote\'', + '"Double Quotes"', + 'øæåôöØÆÅÔÖ字符串', + 3.1, + '' + ]); +}; + +export const fakeEnumWithNumbers = (options?: Options): EnumWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3, + 1.1, + 1.2, + 1.3, + 100, + 200, + 300, + -100, + -200, + -300, + -1.1, + -1.2, + -1.3 + ]); +}; + +export const fakeEnumFromDescription = (options?: Options): EnumFromDescription => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeEnumWithExtensions = (options?: Options): EnumWithExtensions => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 200, + 400, + 500 + ]); +}; + +export const fakeEnumWithXEnumNames = (options?: Options): EnumWithXEnumNames => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 0, + 1, + 2 + ]); +}; + +export const fakeArrayWithNumbers = (options?: Options): ArrayWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int()); +}; + +export const fakeArrayWithBooleans = (options?: Options): ArrayWithBooleans => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.datatype.boolean()); +}; + +export const fakeArrayWithStrings = (options?: Options): ArrayWithStrings => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? ['test'] : f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeArrayWithProperties = (options?: Options): ArrayWithProperties => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => ({ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '16x16': fakeCamelCaseCommentWithBreaks(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + })); +}; + +export const fakeArrayWithAnyOfProperties = (options?: Options): ArrayWithAnyOfProperties => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.arrayElement([{ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: resolveCondition(options?.useDefault ?? false, f) ? 'test' : f.string.sample() } + }, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + }])); +}; + +export const fakeAnyOfAnyAndNull = (options?: Options): AnyOfAnyAndNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: undefined } + }; +}; + +export const fakeAnyOfArrays = (options?: Options): AnyOfArrays => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { results: f.helpers.multiple(() => f.helpers.arrayElement([{ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() } + }, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + }])) } + }; +}; + +export const fakeDictionaryWithString = (options?: Options): DictionaryWithString => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeDictionaryWithPropertiesAndAdditionalProperties = (options?: Options): DictionaryWithPropertiesAndAdditionalProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.datatype.boolean() } + }; +}; + +export const fakeDictionaryWithDictionary = (options?: Options): DictionaryWithDictionary => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } + }; +}; + +export const fakeDictionaryWithProperties = (options?: Options): DictionaryWithProperties => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + } + }; +}; + +export const fakeModelWithInteger = (options?: Options): ModelWithInteger => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.number.int() } + }; +}; + +export const fakeModelWithBoolean = (options?: Options): ModelWithBoolean => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.datatype.boolean() } + }; +}; + +export const fakeModelWithString = (options?: Options): ModelWithString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeSimpleReference = (options?: Options): SimpleReference => fakeModelWithString(options); + +export const fakeArrayWithReferences = (options?: Options): ArrayWithReferences => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeArrayWithArray = (options?: Options): ArrayWithArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.multiple(() => fakeModelWithString(options))); +}; + +export const fakeDictionaryWithReference = (options?: Options): DictionaryWithReference => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: fakeModelWithString(options) + }; +}; + +export const fakeDictionaryWithArray = (options?: Options): DictionaryWithArray => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => fakeModelWithString(options)) + }; +}; + +export const fakeModelWithStringError = (options?: Options): ModelWithStringError => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeModelFromZendesk = (options?: Options): ModelFromZendesk => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithNullableString = (options?: Options): ModelWithNullableString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableProp1: f.datatype.boolean() ? f.string.sample() : null }, + nullableRequiredProp1: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableProp2: f.datatype.boolean() ? f.string.sample() : null }, + nullableRequiredProp2: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) } + }; +}; + +export const fakeModelWithEnum = (options?: Options): ModelWithEnum => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { statusCode: f.helpers.arrayElement([ + '100', + '200 FOO', + '300 FOO_BAR', + '400 foo-bar', + '500 foo.bar', + '600 foo&bar' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bool: true } + }; +}; + +export const fakeModelWithEnumWithHyphen = (options?: Options): ModelWithEnumWithHyphen => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo-bar-baz-qux': '3.0' } + }; +}; + +export const fakeModelWithEnumFromDescription = (options?: Options): ModelWithEnumFromDescription => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { test: f.number.int() } + }; +}; + +export const fakeModelWithNestedEnums = (options?: Options): ModelWithNestedEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnum: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnumFromDescription: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.number.int() + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithEnum: f.helpers.multiple(() => f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithDescription: f.helpers.multiple(() => f.number.int()) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) } + }; +}; + +export const fakeModelWithArray = (options?: Options): ModelWithArray => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithString(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithDictionary = (options?: Options): ModelWithDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } } + }; +}; + +export const fakeDeprecatedModel = (options?: Options): DeprecatedModel => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeModelWithCircularReference = (options: Options = {}, _callDepth = 0): ModelWithCircularReference => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithCircularReference(options, _callDepth + 1) } + }; +}; + +export const fakeCompositionWithOneOf = (options?: Options): CompositionWithOneOf => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]) } + }; +}; + +export const fakeCompositionWithOneOfAnonymous = (options?: Options): CompositionWithOneOfAnonymous => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.string.sample() } + }, + f.string.sample(), + f.number.int() + ]) } + }; +}; + +export const fakeModelCircle = (options?: Options): ModelCircle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { radius: f.number.float() } + }; +}; + +export const fakeModelSquare = (options?: Options): ModelSquare => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { sideLength: f.number.float() } + }; +}; + +export const fakeCompositionWithOneOfDiscriminator = (options?: Options): CompositionWithOneOfDiscriminator => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeModelCircle(options)), + kind: 'circle' as const + }, { + ...Object.assign({}, fakeModelSquare(options)), + kind: 'square' as const + }]); +}; + +export const fakeCompositionWithAnyOf = (options?: Options): CompositionWithAnyOf => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]) } + }; +}; + +export const fakeCompositionWithAnyOfAnonymous = (options?: Options): CompositionWithAnyOfAnonymous => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.string.sample() } + }, + f.string.sample(), + f.number.int() + ]) } + }; +}; + +export const fakeCompositionWithNestedAnyAndTypeNull = (options?: Options): CompositionWithNestedAnyAndTypeNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.helpers.multiple(() => f.datatype.boolean() ? fakeModelWithDictionary(options) : null), f.helpers.multiple(() => f.datatype.boolean() ? fakeModelWithArray(options) : null)]) } + }; +}; + +export const fake3eNum1Период = (options?: Options): _3eNum1Период => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['Bird', 'Dog']); +}; + +export const fakeConstValue = (): ConstValue => 'ConstValue'; + +export const fakeCompositionWithNestedAnyOfAndNull = (options?: Options): CompositionWithNestedAnyOfAndNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.datatype.boolean() ? f.helpers.multiple(() => f.helpers.arrayElement([fake3eNum1Период(options), fakeConstValue()])) : null } + }; +}; + +export const fakeCompositionWithOneOfAndNullable = (options?: Options): CompositionWithOneOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options), + null + ]) } + }; +}; + +export const fakeCompositionWithOneOfAndSimpleDictionary = (options?: Options): CompositionWithOneOfAndSimpleDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.number.float() + }]) } + }; +}; + +export const fakeCompositionWithOneOfAndSimpleArrayDictionary = (options?: Options): CompositionWithOneOfAndSimpleArrayDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => f.datatype.boolean()) + }]) } + }; +}; + +export const fakeCompositionWithOneOfAndComplexArrayDictionary = (options?: Options): CompositionWithOneOfAndComplexArrayDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => f.helpers.arrayElement([f.number.float(), f.string.sample()])) + }]) } + }; +}; + +export const fakeCompositionWithAllOfAndNullable = (options?: Options): CompositionWithAllOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.datatype.boolean() ? Object.assign({}, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, fakeModelWithEnum(options), fakeModelWithArray(options), fakeModelWithDictionary(options)) : null } + }; +}; + +export const fakeCompositionWithAnyOfAndNullable = (options?: Options): CompositionWithAnyOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options), + null + ]) } + }; +}; + +export const fakeCompositionBaseModel = (options?: Options): CompositionBaseModel => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { firstName: f.person.firstName() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { lastname: f.person.lastName() } + }; +}; + +export const fakeCompositionExtendedModel = (options?: Options): CompositionExtendedModel => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeCompositionBaseModel(options), { + age: f.number.int({ max: 120, min: 1 }), + firstName: f.person.firstName(), + lastname: f.person.lastName() + }); +}; + +export const fakeModelWithProperties = (options?: Options): ModelWithProperties => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + requiredAndReadOnly: f.string.sample(), + requiredAndNullable: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() } + }; +}; + +export const fakeModelWithReference = (options?: Options): ModelWithReference => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithProperties(options) } + }; +}; + +export const fakeModelWithNestedProperties = (options?: Options): ModelWithNestedProperties => { + const f = options?.faker ?? faker; + return { + first: f.datatype.boolean() ? { + second: f.datatype.boolean() ? { + third: f.datatype.boolean() ? f.string.sample() : null + } : null + } : null + }; +}; + +export const fakeModelWithDuplicateProperties = (options?: Options): ModelWithDuplicateProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithString(options) } + }; +}; + +export const fakeModelWithOrderedProperties = (options?: Options): ModelWithOrderedProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { zebra: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { apple: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hawaii: f.string.sample() } + }; +}; + +export const fakeModelWithDuplicateImports = (options?: Options): ModelWithDuplicateImports => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propB: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propC: fakeModelWithString(options) } + }; +}; + +export const fakeModelThatExtends = (options?: Options): ModelThatExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsA: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsB: fakeModelWithString(options) } + }); +}; + +export const fakeModelThatExtendsExtends = (options?: Options): ModelThatExtendsExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), fakeModelThatExtends(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsC: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsD: fakeModelWithString(options) } + }); +}; + +export const fakeModelWithPattern = (options?: Options): ModelWithPattern => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { enabled: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { modified: f.date.recent().toISOString() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakeFile = (options?: Options): File => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.string.uuid() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { updated_at: f.date.recent().toISOString() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { created_at: f.date.recent().toISOString() }, + mime: f.string.alpha({ length: { min: 1, max: 24 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { file: f.internet.url() } + }; +}; + +export const fakeDefault = (options?: Options): Default => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakePageable = (options?: Options): Pageable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { page: resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int({ min: 0 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { size: f.number.int({ min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { sort: f.helpers.multiple(() => f.string.sample()) } + }; +}; + +export const fakeFreeFormObjectWithoutAdditionalProperties = (): FreeFormObjectWithoutAdditionalProperties => ({}); + +export const fakeFreeFormObjectWithAdditionalPropertiesEqTrue = (): FreeFormObjectWithAdditionalPropertiesEqTrue => ({}); + +export const fakeFreeFormObjectWithAdditionalPropertiesEqEmptyObject = (): FreeFormObjectWithAdditionalPropertiesEqEmptyObject => ({}); + +export const fakeModelWithConst = (options?: Options): ModelWithConst => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { String: 'String' }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: 0 }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { null: undefined }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { withType: 'Some string' } + }; +}; + +export const fakeModelWithAdditionalPropertiesEqTrue = (options?: Options): ModelWithAdditionalPropertiesEqTrue => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeNestedAnyOfArraysNullable = (options?: Options): NestedAnyOfArraysNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableArray: f.datatype.boolean() ? f.helpers.multiple(() => f.helpers.arrayElement([f.string.sample(), f.datatype.boolean()])) : null } + }; +}; + +export const fakeNullableObject = (options?: Options): NullableObject => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() } + } : null; +}; + +export const fakeCharactersInDescription = (options?: Options): CharactersInDescription => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithNullableObject = (options?: Options): ModelWithNullableObject => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: fakeNullableObject(options) } + }; +}; + +export const fakeModelWithAdditionalPropertiesRef = (options?: Options): ModelWithAdditionalPropertiesRef => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.datatype.boolean() ? fakeNullableObject(options) : null + }; +}; + +export const fakeModelWithOneOfEnum = (options?: Options): ModelWithOneOfEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + { + foo: 'Bar' + }, + { + foo: 'Baz' + }, + { + foo: 'Qux' + }, + { + content: f.date.recent().toISOString(), + foo: 'Quux' + }, + { + content: [f.date.recent().toISOString(), f.date.recent().toISOString()], + foo: 'Corge' + } + ]); +}; + +export const fakeModelWithNestedArrayEnumsDataFoo = (options?: Options): ModelWithNestedArrayEnumsDataFoo => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['foo', 'bar']); +}; + +export const fakeModelWithNestedArrayEnumsDataBar = (options?: Options): ModelWithNestedArrayEnumsDataBar => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['baz', 'qux']); +}; + +export const fakeModelWithNestedArrayEnumsData = (options?: Options): ModelWithNestedArrayEnumsData => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.helpers.multiple(() => fakeModelWithNestedArrayEnumsDataFoo(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.helpers.multiple(() => fakeModelWithNestedArrayEnumsDataBar(options)) } + }; +}; + +export const fakeModelWithNestedArrayEnums = (options?: Options): ModelWithNestedArrayEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { array_strings: f.helpers.multiple(() => f.string.sample()) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: fakeModelWithNestedArrayEnumsData(options) } + }; +}; + +export const fakeModelWithNestedCompositionEnums = (options?: Options): ModelWithNestedCompositionEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: fakeModelWithNestedArrayEnumsDataFoo(options) } + }; +}; + +export const fakeModelWithReadOnlyAndWriteOnly = (options?: Options): ModelWithReadOnlyAndWriteOnly => { + const f = options?.faker ?? faker; + return { + foo: f.string.sample(), + bar: f.string.sample() + }; +}; + +export const fakeModelWithArrayReadOnlyAndWriteOnly = (options?: Options): ModelWithArrayReadOnlyAndWriteOnly => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithReadOnlyAndWriteOnly(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithConstantSizeArray = (options?: Options): ModelWithConstantSizeArray => { + const f = options?.faker ?? faker; + return [f.number.float(), f.number.float()]; +}; + +export const fakeModelWithAnyOfConstantSizeArray = (options?: Options): ModelWithAnyOfConstantSizeArray => { + const f = options?.faker ?? faker; + return [ + f.helpers.arrayElement([f.number.float(), f.string.sample()]), + f.helpers.arrayElement([f.number.float(), f.string.sample()]), + f.helpers.arrayElement([f.number.float(), f.string.sample()]) + ]; +}; + +export const fakeModelWithPrefixItemsConstantSizeArray = (options?: Options): ModelWithPrefixItemsConstantSizeArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.arrayElement([ + fakeModelWithInteger(options), + f.number.float(), + f.string.sample() + ])); +}; + +export const fakeModelWithAnyOfConstantSizeArrayNullable = (options?: Options): ModelWithAnyOfConstantSizeArrayNullable => { + const f = options?.faker ?? faker; + return [ + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]), + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]), + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]) + ]; +}; + +export const fakeModelWithNumericEnumUnion = (options?: Options): ModelWithNumericEnumUnion => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { value: f.helpers.arrayElement([ + -10, + -1, + 0, + 1, + 3, + 6, + 12 + ]) } + }; +}; + +export const fakeModelWithBackticksInDescription = (options?: Options): ModelWithBackticksInDescription => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { template: f.string.sample() } + }; +}; + +export const fakeParameterSimpleParameterUnused = (options?: Options): ParameterSimpleParameterUnused => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakePostServiceWithEmptyTagResponse = (options?: Options): PostServiceWithEmptyTagResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakePostServiceWithEmptyTagResponse2 = (options?: Options): PostServiceWithEmptyTagResponse2 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeDeleteFooData = (options?: Options): DeleteFooData => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeDeleteFooData2 = (options?: Options): DeleteFooData2 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeImport = (options?: Options): Import => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = (options?: Options): ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions => { + const f = options?.faker ?? faker; + return [f.helpers.arrayElement([f.number.float(), fakeImport(options)]), f.helpers.arrayElement([f.number.float(), fakeImport(options)])]; +}; + +export const fakeSchemaWithFormRestrictedKeys = (options?: Options): SchemaWithFormRestrictedKeys => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { object: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() } + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { array: f.helpers.multiple(() => ({ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() } + })) } + }; +}; + +export const fakeIoK8sApimachineryPkgApisMetaV1Preconditions = (options?: Options): IoK8sApimachineryPkgApisMetaV1Preconditions => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { resourceVersion: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { uid: f.string.sample() } + }; +}; + +export const fakeIoK8sApimachineryPkgApisMetaV1DeleteOptions = (options?: Options): IoK8sApimachineryPkgApisMetaV1DeleteOptions => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { preconditions: fakeIoK8sApimachineryPkgApisMetaV1Preconditions(options) } + }; +}; + +export const fakeAdditionalPropertiesUnknownIssue = (options?: Options): AdditionalPropertiesUnknownIssue => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeAdditionalPropertiesUnknownIssue2 = (options?: Options): AdditionalPropertiesUnknownIssue2 => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeAdditionalPropertiesIntegerIssue = (options?: Options): AdditionalPropertiesIntegerIssue => { + const f = options?.faker ?? faker; + return { + value: f.number.int() + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemBoolean = (options?: Options): GenericSchemaDuplicateIssue1SystemBoolean => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hasError: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: {} } + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemString = (options?: Options): GenericSchemaDuplicateIssue1SystemString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hasError: f.datatype.boolean() } + }; +}; + +export const fakeOneOfAllOfIssue = (options?: Options): OneOfAllOfIssue => fakeGenericSchemaDuplicateIssue1SystemString(options); + +export const fakeExternalSharedModel = (options?: Options): ExternalSharedModel => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakeExternalRefA = (options?: Options): ExternalRefA => fakeExternalSharedModel(options); + +export const fakeExternalRefB = (options?: Options): ExternalRefB => fakeExternalSharedModel(options); + +export const fakeModelWithPropertiesWritable = (options?: Options): ModelWithPropertiesWritable => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + requiredAndNullable: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() } + }; +}; + +export const fakeModelWithReferenceWritable = (options?: Options): ModelWithReferenceWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithPropertiesWritable(options) } + }; +}; + +export const fakeModelWithPatternWritable = (options?: Options): ModelWithPatternWritable => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakeFileWritable = (options?: Options): FileWritable => { + const f = options?.faker ?? faker; + return { + mime: f.string.alpha({ length: { min: 1, max: 24 } }) + }; +}; + +export const fakeModelWithReadOnlyAndWriteOnlyWritable = (options?: Options): ModelWithReadOnlyAndWriteOnlyWritable => { + const f = options?.faker ?? faker; + return { + foo: f.string.sample(), + baz: f.string.sample() + }; +}; + +export const fakeModelWithArrayReadOnlyAndWriteOnlyWritable = (options?: Options): ModelWithArrayReadOnlyAndWriteOnlyWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithReadOnlyAndWriteOnlyWritable(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = (options?: Options): ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable => { + const f = options?.faker ?? faker; + return [f.helpers.arrayElement([f.number.float(), fakeImport(options)]), f.helpers.arrayElement([f.number.float(), fakeImport(options)])]; +}; + +export const fakeAdditionalPropertiesUnknownIssueWritable = (options?: Options): AdditionalPropertiesUnknownIssueWritable => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeOneOfAllOfIssueWritable = (options?: Options): OneOfAllOfIssueWritable => fakeGenericSchemaDuplicateIssue1SystemString(options); + +export const fakeGenericSchemaDuplicateIssue1SystemBooleanWritable = (options?: Options): GenericSchemaDuplicateIssue1SystemBooleanWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: {} } + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemStringWritable = (options?: Options): GenericSchemaDuplicateIssue1SystemStringWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null } + }; +}; + +export const fakeSimpleParameter = (options?: Options): SimpleParameter => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeCompositionWithOneOfAndProperties = (options?: Options): CompositionWithOneOfAndProperties => { + const f = options?.faker ?? faker; + return Object.assign({}, f.helpers.arrayElement([{ + foo: fakeSimpleParameter(options) + }, { + bar: fakeNonAsciiStringæøåÆøÅöôêÊ字符串(options) + }]), { + baz: f.datatype.boolean() ? f.number.int({ min: 0 }) : null, + qux: f.number.int({ min: 0 }) + }); +}; + +export const fakeXFooBar = (options?: Options): XFooBar => fakeModelWithString(options); + +export const fakeSimpleRequestBody = (options?: Options): SimpleRequestBody => fakeModelWithString(options); + +export const fakeSimpleFormData = (options?: Options): SimpleFormData => fakeModelWithString(options); + +export const fakePatchApiVbyApiVersionNoTagResponse = () => undefined; + +export const fakeImportRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.helpers.arrayElement([fakeModelWithReadOnlyAndWriteOnlyWritable(options), fakeModelWithArrayReadOnlyAndWriteOnlyWritable(options)]) + }; +}; + +export const fakeImportResponse200 = (options?: Options): ImportResponses[200] => fakeModelFromZendesk(options); + +export const fakeImportResponsedefault = (options?: Options): ImportResponses['default'] => fakeModelWithReadOnlyAndWriteOnly(options); + +export const fakeFooWowResponse = () => undefined; + +export const fakeApiVVersionODataControllerCountResponse = (options?: Options): ApiVVersionODataControllerCountResponse => fakeModelFromZendesk(options); + +export const fakeGetApiVbyApiVersionSimpleOperationRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + foo_param: f.string.sample() + } + }; +}; + +export const fakeGetApiVbyApiVersionSimpleOperationResponse200 = (options?: Options): GetApiVbyApiVersionSimpleOperationResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeGetApiVbyApiVersionSimpleOperationResponsedefault = (options?: Options): GetApiVbyApiVersionSimpleOperationErrors['default'] => fakeModelWithBoolean(options); + +export const fakeDeleteFooRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + headers: { + 'x-Foo-Bar': fakeModelWithString(options) + }, + path: { + foo_param: f.string.sample(), + BarParam: f.string.sample() + } + }; +}; + +export const fakeCallWithDescriptionsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBreaks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBackticks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithSlashes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithExpressionPlaceholders: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithQuotes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithReservedCharacters: f.string.sample() } + } + }; +}; + +export const fakeDeprecatedCallRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + headers: { + parameter: f.datatype.boolean() ? fakeDeprecatedModel(options) : null + } + }; +}; + +export const fakeCallWithParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.datatype.boolean() ? {} : null, + headers: { + parameterHeader: f.datatype.boolean() ? f.string.sample() : null + }, + path: { + parameterPath: f.datatype.boolean() ? f.string.sample() : null, + 'api-version': f.datatype.boolean() ? f.string.sample() : null + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo_ref_enum: fakeModelWithNestedArrayEnumsDataFoo(options) }, + foo_all_of_enum: fakeModelWithNestedArrayEnumsDataFoo(options), + cursor: f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeCallWithWeirdParameterNamesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.datatype.boolean() ? fakeModelWithString(options) : null, + headers: { + 'parameter.header': f.datatype.boolean() ? f.string.sample() : null + }, + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter.path.1': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter-path-2': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'PARAMETER-PATH-3': f.string.sample() }, + 'api-version': f.datatype.boolean() ? f.string.sample() : null + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + 'parameter-query': f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeGetCallWithOptionalParamRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeModelWithOneOfEnum(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { page: f.number.float() } + } + }; +}; + +export const fakePostCallWithOptionalParamRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { offset: f.datatype.boolean() ? f.number.float() : null } + }, + query: { + parameter: fakePageable(options) + } + }; +}; + +export const fakePostCallWithOptionalParamResponse = (options?: Options): PostCallWithOptionalParamResponse => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakePostApiVbyApiVersionRequestBodyRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeSimpleRequestBody(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameter: f.string.sample() } + } + }; +}; + +export const fakePostApiVbyApiVersionFormDataRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeSimpleFormData(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameter: f.string.sample() } + } + }; +}; + +export const fakeCallWithDefaultParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterString: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterNumber: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterBoolean: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterModel: f.datatype.boolean() ? fakeModelWithString(options) : null } + } + }; +}; + +export const fakeCallWithDefaultOptionalParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterString: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterBoolean: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterModel: fakeModelWithString(options) } + } + }; +}; + +export const fakeCallToTestOrderOfParamsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithNoDefault: f.string.sample() }, + parameterStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample(), + parameterStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample(), + parameterStringWithNoDefault: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithNoDefault: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithDefault: f.datatype.boolean() ? f.string.sample() : null } + } + }; +}; + +export const fakeCallWithResponseAndNoContentResponseResponse = (options?: Options): CallWithResponseAndNoContentResponseResponse => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeDummyAResponse = (options?: Options): DummyAResponse => fake400(options); + +export const fakeCallWithResponseResponse = (options?: Options): CallWithResponseResponse => fakeImport(options); + +export const fakeCallWithDuplicateResponsesResponse200 = (options?: Options): CallWithDuplicateResponsesResponses[200] => Object.assign({}, fakeModelWithBoolean(options), fakeModelWithInteger(options)); + +export const fakeCallWithDuplicateResponsesResponse201 = (options?: Options): CallWithDuplicateResponsesResponses[201] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse202 = (options?: Options): CallWithDuplicateResponsesResponses[202] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse500 = (options?: Options): CallWithDuplicateResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse501 = (options?: Options): CallWithDuplicateResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse502 = (options?: Options): CallWithDuplicateResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse4Xx = (options?: Options): CallWithDuplicateResponsesErrors['4XX'] => fakeDictionaryWithArray(options); + +export const fakeCallWithDuplicateResponsesResponsedefault = (options?: Options): CallWithDuplicateResponsesErrors['default'] => fakeModelWithBoolean(options); + +export const fakeCallWithResponsesResponse200 = (options?: Options): CallWithResponsesResponses[200] => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { value: f.helpers.multiple(() => fakeModelWithString(options)) } + }; +}; + +export const fakeCallWithResponsesResponse201 = (options?: Options): CallWithResponsesResponses[201] => fakeModelThatExtends(options); + +export const fakeCallWithResponsesResponse202 = (options?: Options): CallWithResponsesResponses[202] => fakeModelThatExtendsExtends(options); + +export const fakeCallWithResponsesResponse500 = (options?: Options): CallWithResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse501 = (options?: Options): CallWithResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse502 = (options?: Options): CallWithResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponsedefault = (options?: Options): CallWithResponsesErrors['default'] => fakeModelWithStringError(options); + +export const fakeCollectionFormatRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterArrayCSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArraySSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayTSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayPipes: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayMulti: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null + } + }; +}; + +export const fakeTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.number.int() } + }, + query: { + parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float(), + parameterString: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 'default' : f.string.sample() : null, + parameterBoolean: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() : null, + parameterObject: f.datatype.boolean() ? {} : null, + parameterArray: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterDictionary: f.datatype.boolean() ? {} : null, + parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) + } + }; +}; + +export const fakeTypesResponse200 = (options?: Options): TypesResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeTypesResponse201 = (options?: Options): TypesResponses[201] => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeTypesResponse202 = (options?: Options): TypesResponses[202] => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeTypesResponse203 = (): TypesResponses[203] => ({}); + +export const fakeUploadFileRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: new Blob([f.image.dataUri()]), + path: { + 'api-version': f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeUploadFileResponse = (options?: Options): UploadFileResponse => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeFileResponseRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid(), + 'api-version': f.string.sample() + } + }; +}; + +export const fakeFileResponseResponse = (options?: Options): FileResponseResponse => { + const f = options?.faker ?? faker; + return new Blob([f.image.dataUri()]); +}; + +export const fakeComplexTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterObject: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { first: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { second: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { third: f.string.sample() } + } } + } } + }, + parameterReference: fakeModelWithString(options) + } + }; +}; + +export const fakeComplexTypesResponse200 = (options?: Options): ComplexTypesResponses[200] => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeComplexTypesResponse400 = (): ComplexTypesErrors[400] => undefined; + +export const fakeComplexTypesResponse500 = (): ComplexTypesErrors[500] => undefined; + +export const fakeMultipartResponseResponse = (options?: Options): MultipartResponseResponse => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { file: new Blob([f.image.dataUri()]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { metadata: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + } } + }; +}; + +export const fakeMultipartRequestRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { content: new Blob([f.image.dataUri()]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: f.datatype.boolean() ? fakeModelWithString(options) : null } + } + }; +}; + +export const fakeComplexParamsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + key: f.datatype.boolean() ? f.helpers.fromRegExp('^[a-zA-Z0-9_]*$') : null, + name: f.datatype.boolean() ? f.string.alpha({ length: { min: 0, max: 255 } }) : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { enabled: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() }, + type: f.helpers.arrayElement([ + 'Monkey', + 'Horse', + 'Bird' + ]), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { listOfModels: f.datatype.boolean() ? f.helpers.multiple(() => fakeModelWithString(options)) : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { listOfStrings: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null }, + parameters: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { user: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.datatype.boolean() ? f.person.fullName() : null } + } } + }, + path: { + id: f.number.int(), + 'api-version': f.string.sample() + } + }; +}; + +export const fakeComplexParamsResponse = (options?: Options): ComplexParamsResponse => fakeModelWithString(options); + +export const fakeCallWithResultFromHeaderResponse200 = (): CallWithResultFromHeaderResponses[200] => undefined; + +export const fakeCallWithResultFromHeaderResponse400 = (): CallWithResultFromHeaderErrors[400] => undefined; + +export const fakeCallWithResultFromHeaderResponse500 = (): CallWithResultFromHeaderErrors[500] => undefined; + +export const fakeTestErrorCodeRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + status: f.number.int() + } + }; +}; + +export const fakeTestErrorCodeResponse200 = (): TestErrorCodeResponses[200] => undefined; + +export const fakeTestErrorCodeResponse500 = (): TestErrorCodeErrors[500] => undefined; + +export const fakeTestErrorCodeResponse501 = (): TestErrorCodeErrors[501] => undefined; + +export const fakeTestErrorCodeResponse502 = (): TestErrorCodeErrors[502] => undefined; + +export const fakeTestErrorCodeResponse503 = (): TestErrorCodeErrors[503] => undefined; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Request = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + nonAsciiParamæøåÆØÅöôêÊ: f.number.int() + } + }; +}; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Response = (options?: Options): NonAsciiæøåÆøÅöôêÊ字符串Response => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeNonAsciiStringæøåÆøÅöôêÊ字符串(options)); +}; + +export const fakePutWithFormUrlEncodedRequest = (options?: Options): Omit => ({ + body: fakeArrayWithStrings(options) +}); diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/index.ts new file mode 100644 index 0000000000..2ef59c1f0c --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/types.gen.ts new file mode 100644 index 0000000000..3287ee8737 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-full/types.gen.ts @@ -0,0 +1,2081 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: unknown; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = Array; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-locale/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-locale/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..44d096176c --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-locale/@faker-js/faker.gen.ts @@ -0,0 +1,501 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Faker } from '@faker-js/faker'; +import { faker } from '@faker-js/faker/locale/de'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeAnything = () => undefined; + +export const fakeStatusWithNull = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options) => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options) => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..c5ef22034f --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/@faker-js/faker.gen.ts @@ -0,0 +1,502 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, Company, Config, CreateJobErrors, CreateJobResponses, CreatePetData, CreatePetResponse, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeAnything = (): Anything => undefined; + +export const fakeStatusWithNull = (options?: Options): StatusWithNull => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.word.words({ count: 4 }) + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options): PetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options): StringOrNumber => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options): NullablePetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options): Circle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options): Square => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options): Shape => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options): Dog => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options): Cat => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options): Animal => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options): CreatePetResponse => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options): CreateJobResponses['2XX'] => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options): CreateJobErrors['4XX'] => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/index.ts new file mode 100644 index 0000000000..bbd64f9a01 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, ClientOptions, Company, Config, CreateJobData, CreateJobError, CreateJobErrors, CreateJobResponse, CreateJobResponses, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponse, DeletePetResponses, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/types.gen.ts new file mode 100644 index 0000000000..5035a69599 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-name-rules/types.gen.ts @@ -0,0 +1,381 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type Anything = unknown; + +export type StatusWithNull = 'active' | 'inactive' | null; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetOrTag = Pet | Tag; + +export type StringOrNumber = string | number; + +export type NullablePetOrTag = Pet | Tag | null; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type Circle = { + kind: string; + radius: number; +}; + +export type Square = { + kind: string; + side: number; +}; + +export type Shape = ({ + kind: 'Circle'; +} & Circle) | ({ + kind: 'Square'; +} & Square); + +export type Dog = { + type: string; + bark: boolean; +}; + +export type Cat = { + type: string; + purr: boolean; +}; + +export type Animal = ({ + type: 'dog'; +} & Dog) | ({ + type: 'cat'; +} & Cat); + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: void; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: void; +}; + +export type DeletePetResponse = DeletePetResponses[keyof DeletePetResponses]; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type CreateJobData = { + body?: never; + path?: never; + query?: never; + url: '/jobs'; +}; + +export type CreateJobErrors = { + /** + * Client error + */ + '4XX': Error; +}; + +export type CreateJobError = CreateJobErrors[keyof CreateJobErrors]; + +export type CreateJobResponses = { + /** + * Job accepted + */ + '2XX': Pet; +}; + +export type CreateJobResponse = CreateJobResponses[keyof CreateJobResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..729152753f --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/@faker-js/faker.gen.ts @@ -0,0 +1,502 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, Company, Config, CreateJobErrors, CreateJobResponses, CreatePetData, CreatePetResponse, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeAnything = (): Anything => undefined; + +export const fakeStatusWithNull = (options?: Options): StatusWithNull => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options): PetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options): StringOrNumber => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options): NullablePetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options): Circle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options): Square => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options): Shape => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options): Dog => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options): Cat => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options): Animal => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options): CreatePetResponse => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options): CreateJobResponses['2XX'] => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options): CreateJobErrors['4XX'] => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/index.ts new file mode 100644 index 0000000000..bbd64f9a01 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, ClientOptions, Company, Config, CreateJobData, CreateJobError, CreateJobErrors, CreateJobResponse, CreateJobResponses, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponse, DeletePetResponses, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/types.gen.ts new file mode 100644 index 0000000000..5035a69599 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker-typed/types.gen.ts @@ -0,0 +1,381 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type Anything = unknown; + +export type StatusWithNull = 'active' | 'inactive' | null; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetOrTag = Pet | Tag; + +export type StringOrNumber = string | number; + +export type NullablePetOrTag = Pet | Tag | null; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type Circle = { + kind: string; + radius: number; +}; + +export type Square = { + kind: string; + side: number; +}; + +export type Shape = ({ + kind: 'Circle'; +} & Circle) | ({ + kind: 'Square'; +} & Square); + +export type Dog = { + type: string; + bark: boolean; +}; + +export type Cat = { + type: string; + purr: boolean; +}; + +export type Animal = ({ + type: 'dog'; +} & Dog) | ({ + type: 'cat'; +} & Cat); + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: void; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: void; +}; + +export type DeletePetResponse = DeletePetResponses[keyof DeletePetResponses]; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type CreateJobData = { + body?: never; + path?: never; + query?: never; + url: '/jobs'; +}; + +export type CreateJobErrors = { + /** + * Client error + */ + '4XX': Error; +}; + +export type CreateJobError = CreateJobErrors[keyof CreateJobErrors]; + +export type CreateJobResponses = { + /** + * Job accepted + */ + '2XX': Pet; +}; + +export type CreateJobResponse = CreateJobResponses[keyof CreateJobResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..8fa5bebd3f --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.0.x/faker/@faker-js/faker.gen.ts @@ -0,0 +1,500 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeAnything = () => undefined; + +export const fakeStatusWithNull = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options) => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options) => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..dd5878d330 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/@faker-js/faker.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Comment, Department, Employee, Member, Org, Pair, Project, TreeNode, Wrapper } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakeTreeNode = (options: Options = {}, _callDepth = 0): TreeNode => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + value: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { children: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeTreeNode(options, _callDepth + 1)) } + }; +}; + +export const fakeWrapper = (options?: Options): Wrapper => { + const f = options?.faker ?? faker; + return { + label: f.string.sample(), + tree: fakeTreeNode(options) + }; +}; + +export const fakePair = (options?: Options): Pair => ({ + nodes: [fakeTreeNode(options), fakeTreeNode(options)] +}); + +export const fakeComment = (options: Options = {}, _callDepth = 0): Comment => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + text: f.string.sample(), + parent: _callDepth > MAX_CALL_DEPTH ? null : f.datatype.boolean() ? fakeComment(options, _callDepth + 1) : null + }; +}; + +export const fakeOrg = (options: Options = {}, _callDepth = 0): Org => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { members: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeMember(options, _callDepth + 1)) } + }; +}; + +export const fakeMember = (options: Options = {}, _callDepth = 0): Member => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { org: fakeOrg(options, _callDepth + 1) } + }; +}; + +export const fakeDepartment = (options: Options = {}, _callDepth = 0): Department => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { employees: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeEmployee(options, _callDepth + 1)) } + }; +}; + +export const fakeEmployee = (options: Options = {}, _callDepth = 0): Employee => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.person.fullName(), + projects: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(() => fakeProject(options, _callDepth + 1)) + }; +}; + +export const fakeProject = (options: Options = {}, _callDepth = 0): Project => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { department: fakeDepartment(options, _callDepth + 1) } + }; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/index.ts new file mode 100644 index 0000000000..e5979c33bb --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { ClientOptions, Comment, Department, Employee, Member, Org, Pair, Project, TreeNode, Wrapper } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/types.gen.ts new file mode 100644 index 0000000000..418558bafe --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-circular/types.gen.ts @@ -0,0 +1,59 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type TreeNode = { + id: string; + value: string; + children?: Array; +}; + +export type Org = { + id: string; + name: string; + members?: Array; +}; + +export type Member = { + id: string; + name: string; + org?: Org; +}; + +export type Department = { + id: string; + name: string; + employees?: Array; +}; + +export type Employee = { + id: string; + name: string; + projects: Array; +}; + +export type Project = { + id: string; + name: string; + department?: Department; +}; + +export type Wrapper = { + label: string; + tree: TreeNode; +}; + +export type Pair = { + nodes: [ + TreeNode, + TreeNode + ]; +}; + +export type Comment = { + id: string; + text: string; + parent: Comment | null; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..dee95747d0 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/@faker-js/faker.gen.ts @@ -0,0 +1,1617 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountResponse, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithParametersData, CallWithResponseAndNoContentResponseResponse, CallWithResponseResponse, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAResponse, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileWritable, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, Import, ImportData, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseResponse, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, Pageable, ParameterSimpleParameterUnused, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponse, XFooBar } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const MAX_CALL_DEPTH = 10; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fake400 = (options?: Options): _400 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeCamelCaseCommentWithBreaks = (options?: Options): CamelCaseCommentWithBreaks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBreaks = (options?: Options): CommentWithBreaks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticks = (options?: Options): CommentWithBackticks => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithBackticksAndQuotes = (options?: Options): CommentWithBackticksAndQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithSlashes = (options?: Options): CommentWithSlashes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithExpressionPlaceholders = (options?: Options): CommentWithExpressionPlaceholders => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithQuotes = (options?: Options): CommentWithQuotes => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeCommentWithReservedCharacters = (options?: Options): CommentWithReservedCharacters => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleInteger = (options?: Options): SimpleInteger => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeSimpleBoolean = (options?: Options): SimpleBoolean => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeSimpleString = (options?: Options): SimpleString => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeNonAsciiStringæøåÆøÅöôêÊ字符串 = (options?: Options): NonAsciiStringæøåÆøÅöôêÊ字符串 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeSimpleFile = (options?: Options): SimpleFile => { + const f = options?.faker ?? faker; + return new Blob([f.image.dataUri()]); +}; + +export const fakeSimpleStringWithPattern = (options?: Options): SimpleStringWithPattern => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.helpers.fromRegExp('^[a-zA-Z0-9_]*$') : null; +}; + +export const fakeEnumWithStrings = (options?: Options): EnumWithStrings => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + '\'Single Quote\'', + '"Double Quotes"', + 'Non-ascii: øæåôöØÆÅÔÖ字符串' + ]); +}; + +export const fakeEnumWithReplacedCharacters = (options?: Options): EnumWithReplacedCharacters => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + '\'Single Quote\'', + '"Double Quotes"', + 'øæåôöØÆÅÔÖ字符串', + 3.1, + '' + ]); +}; + +export const fakeEnumWithNumbers = (options?: Options): EnumWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3, + 1.1, + 1.2, + 1.3, + 100, + 200, + 300, + -100, + -200, + -300, + -1.1, + -1.2, + -1.3 + ]); +}; + +export const fakeEnumFromDescription = (options?: Options): EnumFromDescription => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeEnumWithExtensions = (options?: Options): EnumWithExtensions => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 200, + 400, + 500 + ]); +}; + +export const fakeEnumWithXEnumNames = (options?: Options): EnumWithXEnumNames => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 0, + 1, + 2 + ]); +}; + +export const fakeArrayWithNumbers = (options?: Options): ArrayWithNumbers => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int()); +}; + +export const fakeArrayWithBooleans = (options?: Options): ArrayWithBooleans => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.datatype.boolean()); +}; + +export const fakeArrayWithStrings = (options?: Options): ArrayWithStrings => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? ['test'] : f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeArrayWithProperties = (options?: Options): ArrayWithProperties => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => ({ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '16x16': fakeCamelCaseCommentWithBreaks(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + })); +}; + +export const fakeArrayWithAnyOfProperties = (options?: Options): ArrayWithAnyOfProperties => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.arrayElement([{ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: resolveCondition(options?.useDefault ?? false, f) ? 'test' : f.string.sample() } + }, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + }])); +}; + +export const fakeAnyOfAnyAndNull = (options?: Options): AnyOfAnyAndNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: f.datatype.boolean() ? undefined : null } + }; +}; + +export const fakeAnyOfArrays = (options?: Options): AnyOfArrays => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { results: f.helpers.multiple(() => f.helpers.arrayElement([{ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() } + }, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + }])) } + }; +}; + +export const fakeDictionaryWithString = (options?: Options): DictionaryWithString => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeDictionaryWithPropertiesAndAdditionalProperties = (options?: Options): DictionaryWithPropertiesAndAdditionalProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.datatype.boolean() } + }; +}; + +export const fakeDictionaryWithDictionary = (options?: Options): DictionaryWithDictionary => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } + }; +}; + +export const fakeDictionaryWithProperties = (options?: Options): DictionaryWithProperties => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + } + }; +}; + +export const fakeModelWithInteger = (options?: Options): ModelWithInteger => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.number.int() } + }; +}; + +export const fakeModelWithBoolean = (options?: Options): ModelWithBoolean => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.datatype.boolean() } + }; +}; + +export const fakeModelWithString = (options?: Options): ModelWithString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeSimpleReference = (options?: Options): SimpleReference => fakeModelWithString(options); + +export const fakeArrayWithReferences = (options?: Options): ArrayWithReferences => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeArrayWithArray = (options?: Options): ArrayWithArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.helpers.multiple(() => fakeModelWithString(options))); +}; + +export const fakeDictionaryWithReference = (options?: Options): DictionaryWithReference => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: fakeModelWithString(options) + }; +}; + +export const fakeDictionaryWithArray = (options?: Options): DictionaryWithArray => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => fakeModelWithString(options)) + }; +}; + +export const fakeModelWithStringError = (options?: Options): ModelWithStringError => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeModelFromZendesk = (options?: Options): ModelFromZendesk => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithNullableString = (options?: Options): ModelWithNullableString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableProp1: f.datatype.boolean() ? f.string.sample() : null }, + nullableRequiredProp1: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableProp2: f.datatype.boolean() ? f.string.sample() : null }, + nullableRequiredProp2: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) } + }; +}; + +export const fakeModelWithEnum = (options?: Options): ModelWithEnum => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { statusCode: f.helpers.arrayElement([ + '100', + '200 FOO', + '300 FOO_BAR', + '400 foo-bar', + '500 foo.bar', + '600 foo&bar' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bool: true } + }; +}; + +export const fakeModelWithEnumWithHyphen = (options?: Options): ModelWithEnumWithHyphen => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo-bar-baz-qux': '3.0' } + }; +}; + +export const fakeModelWithEnumFromDescription = (options?: Options): ModelWithEnumFromDescription => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { test: f.number.int() } + }; +}; + +export const fakeModelWithNestedEnums = (options?: Options): ModelWithNestedEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnum: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dictionaryWithEnumFromDescription: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.number.int() + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithEnum: f.helpers.multiple(() => f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { arrayWithDescription: f.helpers.multiple(() => f.number.int()) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'foo_bar-enum': f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + 'ØÆÅ字符串' + ]) } + }; +}; + +export const fakeModelWithArray = (options?: Options): ModelWithArray => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithString(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithDictionary = (options?: Options): ModelWithDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + } } + }; +}; + +export const fakeDeprecatedModel = (options?: Options): DeprecatedModel => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeModelWithCircularReference = (options: Options = {}, _callDepth = 0): ModelWithCircularReference => { + const f = options?.faker ?? faker; + return { + ..._callDepth > MAX_CALL_DEPTH || !resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithCircularReference(options, _callDepth + 1) } + }; +}; + +export const fakeCompositionWithOneOf = (options?: Options): CompositionWithOneOf => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]) } + }; +}; + +export const fakeCompositionWithOneOfAnonymous = (options?: Options): CompositionWithOneOfAnonymous => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.string.sample() } + }, + f.string.sample(), + f.number.int() + ]) } + }; +}; + +export const fakeModelCircle = (options?: Options): ModelCircle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { radius: f.number.float() } + }; +}; + +export const fakeModelSquare = (options?: Options): ModelSquare => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { sideLength: f.number.float() } + }; +}; + +export const fakeCompositionWithOneOfDiscriminator = (options?: Options): CompositionWithOneOfDiscriminator => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeModelCircle(options)), + kind: 'circle' as const + }, { + ...Object.assign({}, fakeModelSquare(options)), + kind: 'square' as const + }]); +}; + +export const fakeCompositionWithAnyOf = (options?: Options): CompositionWithAnyOf => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]) } + }; +}; + +export const fakeCompositionWithAnyOfAnonymous = (options?: Options): CompositionWithAnyOfAnonymous => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.string.sample() } + }, + f.string.sample(), + f.number.int() + ]) } + }; +}; + +export const fakeCompositionWithNestedAnyAndTypeNull = (options?: Options): CompositionWithNestedAnyAndTypeNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.helpers.multiple(() => f.datatype.boolean() ? fakeModelWithDictionary(options) : null), f.helpers.multiple(() => f.datatype.boolean() ? fakeModelWithArray(options) : null)]) } + }; +}; + +export const fake3eNum1Период = (options?: Options): _3eNum1Период => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['Bird', 'Dog']); +}; + +export const fakeConstValue = (): ConstValue => 'ConstValue'; + +export const fakeCompositionWithNestedAnyOfAndNull = (options?: Options): CompositionWithNestedAnyOfAndNull => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.datatype.boolean() ? f.helpers.multiple(() => f.helpers.arrayElement([fake3eNum1Период(options), fakeConstValue()])) : null } + }; +}; + +export const fakeCompositionWithOneOfAndNullable = (options?: Options): CompositionWithOneOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options), + null + ]) } + }; +}; + +export const fakeCompositionWithOneOfAndSimpleDictionary = (options?: Options): CompositionWithOneOfAndSimpleDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.number.float() + }]) } + }; +}; + +export const fakeCompositionWithOneOfAndSimpleArrayDictionary = (options?: Options): CompositionWithOneOfAndSimpleArrayDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => f.datatype.boolean()) + }]) } + }; +}; + +export const fakeCompositionWithOneOfAndComplexArrayDictionary = (options?: Options): CompositionWithOneOfAndComplexArrayDictionary => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([f.datatype.boolean(), !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.multiple(() => f.helpers.arrayElement([f.number.float(), f.string.sample()])) + }]) } + }; +}; + +export const fakeCompositionWithAllOfAndNullable = (options?: Options): CompositionWithAllOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.datatype.boolean() ? Object.assign({}, { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, fakeModelWithEnum(options), fakeModelWithArray(options), fakeModelWithDictionary(options)) : null } + }; +}; + +export const fakeCompositionWithAnyOfAndNullable = (options?: Options): CompositionWithAnyOfAndNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: f.helpers.arrayElement([ + { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() } + }, + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options), + null + ]) } + }; +}; + +export const fakeCompositionBaseModel = (options?: Options): CompositionBaseModel => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { firstName: f.person.firstName() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { lastname: f.person.lastName() } + }; +}; + +export const fakeCompositionExtendedModel = (options?: Options): CompositionExtendedModel => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeCompositionBaseModel(options), { + age: f.number.int({ max: 120, min: 1 }), + firstName: f.person.firstName(), + lastname: f.person.lastName() + }); +}; + +export const fakeModelWithProperties = (options?: Options): ModelWithProperties => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + requiredAndReadOnly: f.string.sample(), + requiredAndNullable: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() } + }; +}; + +export const fakeModelWithReference = (options?: Options): ModelWithReference => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithProperties(options) } + }; +}; + +export const fakeModelWithNestedProperties = (options?: Options): ModelWithNestedProperties => { + const f = options?.faker ?? faker; + return { + first: f.datatype.boolean() ? { + second: f.datatype.boolean() ? { + third: f.datatype.boolean() ? f.string.sample() : null + } : null + } : null + }; +}; + +export const fakeModelWithDuplicateProperties = (options?: Options): ModelWithDuplicateProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithString(options) } + }; +}; + +export const fakeModelWithOrderedProperties = (options?: Options): ModelWithOrderedProperties => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { zebra: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { apple: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hawaii: f.string.sample() } + }; +}; + +export const fakeModelWithDuplicateImports = (options?: Options): ModelWithDuplicateImports => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propA: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propB: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propC: fakeModelWithString(options) } + }; +}; + +export const fakeModelThatExtends = (options?: Options): ModelThatExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsA: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsB: fakeModelWithString(options) } + }); +}; + +export const fakeModelThatExtendsExtends = (options?: Options): ModelThatExtendsExtends => { + const f = options?.faker ?? faker; + return Object.assign({}, fakeModelWithString(options), fakeModelThatExtends(options), { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsC: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propExtendsD: fakeModelWithString(options) } + }); +}; + +export const fakeModelWithPattern = (options?: Options): ModelWithPattern => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { enabled: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { modified: f.date.recent().toISOString() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakeFile = (options?: Options): File => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.string.uuid() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { updated_at: f.date.recent().toISOString() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { created_at: f.date.recent().toISOString() }, + mime: f.string.alpha({ length: { min: 1, max: 24 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { file: f.internet.url() } + }; +}; + +export const fakeDefault = (options?: Options): Default => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakePageable = (options?: Options): Pageable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { page: resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int({ min: 0 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { size: f.number.int({ min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { sort: f.helpers.multiple(() => f.string.sample()) } + }; +}; + +export const fakeFreeFormObjectWithoutAdditionalProperties = (): FreeFormObjectWithoutAdditionalProperties => ({}); + +export const fakeFreeFormObjectWithAdditionalPropertiesEqTrue = (): FreeFormObjectWithAdditionalPropertiesEqTrue => ({}); + +export const fakeFreeFormObjectWithAdditionalPropertiesEqEmptyObject = (): FreeFormObjectWithAdditionalPropertiesEqEmptyObject => ({}); + +export const fakeModelWithConst = (options?: Options): ModelWithConst => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { String: 'String' }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: 0 }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { null: null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { withType: 'Some string' } + }; +}; + +export const fakeModelWithAdditionalPropertiesEqTrue = (options?: Options): ModelWithAdditionalPropertiesEqTrue => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.string.sample() } + }; +}; + +export const fakeNestedAnyOfArraysNullable = (options?: Options): NestedAnyOfArraysNullable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { nullableArray: f.datatype.boolean() ? f.helpers.multiple(() => f.helpers.arrayElement([f.string.sample(), f.datatype.boolean()])) : null } + }; +}; + +export const fakeNullableObject = (options?: Options): NullableObject => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() } + } : null; +}; + +export const fakeCharactersInDescription = (options?: Options): CharactersInDescription => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithNullableObject = (options?: Options): ModelWithNullableObject => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: fakeNullableObject(options) } + }; +}; + +export const fakeModelWithAdditionalPropertiesRef = (options?: Options): ModelWithAdditionalPropertiesRef => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.datatype.boolean() ? fakeNullableObject(options) : null + }; +}; + +export const fakeModelWithOneOfEnum = (options?: Options): ModelWithOneOfEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + { + foo: 'Bar' + }, + { + foo: 'Baz' + }, + { + foo: 'Qux' + }, + { + content: f.date.recent().toISOString(), + foo: 'Quux' + }, + { + content: [f.date.recent().toISOString(), f.string.sample()], + foo: 'Corge' + } + ]); +}; + +export const fakeModelWithNestedArrayEnumsDataFoo = (options?: Options): ModelWithNestedArrayEnumsDataFoo => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['foo', 'bar']); +}; + +export const fakeModelWithNestedArrayEnumsDataBar = (options?: Options): ModelWithNestedArrayEnumsDataBar => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement(['baz', 'qux']); +}; + +export const fakeModelWithNestedArrayEnumsData = (options?: Options): ModelWithNestedArrayEnumsData => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.helpers.multiple(() => fakeModelWithNestedArrayEnumsDataFoo(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.helpers.multiple(() => fakeModelWithNestedArrayEnumsDataBar(options)) } + }; +}; + +export const fakeModelWithNestedArrayEnums = (options?: Options): ModelWithNestedArrayEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { array_strings: f.helpers.multiple(() => f.string.sample()) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: fakeModelWithNestedArrayEnumsData(options) } + }; +}; + +export const fakeModelWithNestedCompositionEnums = (options?: Options): ModelWithNestedCompositionEnums => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: fakeModelWithNestedArrayEnumsDataFoo(options) } + }; +}; + +export const fakeModelWithReadOnlyAndWriteOnly = (options?: Options): ModelWithReadOnlyAndWriteOnly => { + const f = options?.faker ?? faker; + return { + foo: f.string.sample(), + bar: f.string.sample() + }; +}; + +export const fakeModelWithArrayReadOnlyAndWriteOnly = (options?: Options): ModelWithArrayReadOnlyAndWriteOnly => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithReadOnlyAndWriteOnly(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithConstantSizeArray = (options?: Options): ModelWithConstantSizeArray => { + const f = options?.faker ?? faker; + return [f.number.float(), f.number.float()]; +}; + +export const fakeModelWithAnyOfConstantSizeArray = (options?: Options): ModelWithAnyOfConstantSizeArray => { + const f = options?.faker ?? faker; + return [ + f.helpers.arrayElement([f.number.float(), f.string.sample()]), + f.helpers.arrayElement([f.number.float(), f.string.sample()]), + f.helpers.arrayElement([f.number.float(), f.string.sample()]) + ]; +}; + +export const fakeModelWithPrefixItemsConstantSizeArray = (options?: Options): ModelWithPrefixItemsConstantSizeArray => { + const f = options?.faker ?? faker; + return [ + fakeModelWithInteger(options), + f.helpers.arrayElement([f.number.float(), f.string.sample()]), + f.string.sample() + ]; +}; + +export const fakeModelWithAnyOfConstantSizeArrayNullable = (options?: Options): ModelWithAnyOfConstantSizeArrayNullable => { + const f = options?.faker ?? faker; + return [ + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]), + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]), + f.helpers.arrayElement([ + f.number.float(), + f.string.sample(), + null + ]) + ]; +}; + +export const fakeModelWithNumericEnumUnion = (options?: Options): ModelWithNumericEnumUnion => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { value: f.helpers.arrayElement([ + -10, + -1, + 0, + 1, + 3, + 6, + 12 + ]) } + }; +}; + +export const fakeModelWithBackticksInDescription = (options?: Options): ModelWithBackticksInDescription => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { template: f.string.sample() } + }; +}; + +export const fakeParameterSimpleParameterUnused = (options?: Options): ParameterSimpleParameterUnused => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakePostServiceWithEmptyTagResponse = (options?: Options): PostServiceWithEmptyTagResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakePostServiceWithEmptyTagResponse2 = (options?: Options): PostServiceWithEmptyTagResponse2 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeDeleteFooData = (options?: Options): DeleteFooData => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeDeleteFooData2 = (options?: Options): DeleteFooData2 => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeImport = (options?: Options): Import => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = (options?: Options): ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions => { + const f = options?.faker ?? faker; + return [f.helpers.arrayElement([f.number.float(), fakeImport(options)]), f.helpers.arrayElement([f.number.float(), fakeImport(options)])]; +}; + +export const fakeSchemaWithFormRestrictedKeys = (options?: Options): SchemaWithFormRestrictedKeys => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { object: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() } + } }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { array: f.helpers.multiple(() => ({ + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { description: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-descriptions': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enum-varnames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'x-enumNames': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { title: f.lorem.words() } + })) } + }; +}; + +export const fakeIoK8sApimachineryPkgApisMetaV1Preconditions = (options?: Options): IoK8sApimachineryPkgApisMetaV1Preconditions => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { resourceVersion: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { uid: f.string.sample() } + }; +}; + +export const fakeIoK8sApimachineryPkgApisMetaV1DeleteOptions = (options?: Options): IoK8sApimachineryPkgApisMetaV1DeleteOptions => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { preconditions: fakeIoK8sApimachineryPkgApisMetaV1Preconditions(options) } + }; +}; + +export const fakeAdditionalPropertiesUnknownIssue = (options?: Options): AdditionalPropertiesUnknownIssue => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeAdditionalPropertiesUnknownIssue2 = (options?: Options): AdditionalPropertiesUnknownIssue2 => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeAdditionalPropertiesIntegerIssue = (options?: Options): AdditionalPropertiesIntegerIssue => { + const f = options?.faker ?? faker; + return { + value: f.number.int() + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemBoolean = (options?: Options): GenericSchemaDuplicateIssue1SystemBoolean => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hasError: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: {} } + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemString = (options?: Options): GenericSchemaDuplicateIssue1SystemString => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { hasError: f.datatype.boolean() } + }; +}; + +export const fakeOneOfAllOfIssue = (options?: Options): OneOfAllOfIssue => fakeGenericSchemaDuplicateIssue1SystemString(options); + +export const fakeExternalSharedModel = (options?: Options): ExternalSharedModel => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.string.sample() } + }; +}; + +export const fakeExternalRefA = (options?: Options): ExternalRefA => fakeExternalSharedModel(options); + +export const fakeExternalRefB = (options?: Options): ExternalRefB => fakeExternalSharedModel(options); + +export const fakeModelWithPropertiesWritable = (options?: Options): ModelWithPropertiesWritable => { + const f = options?.faker ?? faker; + return { + required: f.string.sample(), + requiredAndNullable: f.datatype.boolean() ? f.string.sample() : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { string: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { number: f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { boolean: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { reference: fakeModelWithString(options) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'property with space': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { try: f.string.sample() } + }; +}; + +export const fakeModelWithReferenceWritable = (options?: Options): ModelWithReferenceWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: fakeModelWithPropertiesWritable(options) } + }; +}; + +export const fakeModelWithPatternWritable = (options?: Options): ModelWithPatternWritable => { + const f = options?.faker ?? faker; + return { + key: f.helpers.fromRegExp('^[a-zA-Z0-9_]*$'), + name: f.string.alpha({ length: { min: 0, max: 255 } }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.helpers.fromRegExp('^\\d{2}-\\d{3}-\\d{4}$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { text: f.helpers.fromRegExp('^\\w+$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithSingleQuotes: f.helpers.fromRegExp('^[a-zA-Z0-9\']*$') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithNewline: f.helpers.fromRegExp('aaa\\nbbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithBacktick: f.helpers.fromRegExp('aaa`bbb') }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { patternWithUnicode: f.helpers.fromRegExp('^\\p{L}+$') } + }; +}; + +export const fakeFileWritable = (options?: Options): FileWritable => { + const f = options?.faker ?? faker; + return { + mime: f.string.alpha({ length: { min: 1, max: 24 } }) + }; +}; + +export const fakeModelWithReadOnlyAndWriteOnlyWritable = (options?: Options): ModelWithReadOnlyAndWriteOnlyWritable => { + const f = options?.faker ?? faker; + return { + foo: f.string.sample(), + baz: f.string.sample() + }; +}; + +export const fakeModelWithArrayReadOnlyAndWriteOnlyWritable = (options?: Options): ModelWithArrayReadOnlyAndWriteOnlyWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { prop: f.helpers.multiple(() => fakeModelWithReadOnlyAndWriteOnlyWritable(options)) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithFile: f.helpers.multiple(() => new Blob([f.image.dataUri()])) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { propWithNumber: f.helpers.multiple(() => f.number.float()) } + }; +}; + +export const fakeModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = (options?: Options): ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable => { + const f = options?.faker ?? faker; + return [f.helpers.arrayElement([f.number.float(), fakeImport(options)]), f.helpers.arrayElement([f.number.float(), fakeImport(options)])]; +}; + +export const fakeAdditionalPropertiesUnknownIssueWritable = (options?: Options): AdditionalPropertiesUnknownIssueWritable => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.helpers.arrayElement([f.string.sample(), f.number.float()]) + }; +}; + +export const fakeOneOfAllOfIssueWritable = (options?: Options): OneOfAllOfIssueWritable => fakeGenericSchemaDuplicateIssue1SystemString(options); + +export const fakeGenericSchemaDuplicateIssue1SystemBooleanWritable = (options?: Options): GenericSchemaDuplicateIssue1SystemBooleanWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: {} } + }; +}; + +export const fakeGenericSchemaDuplicateIssue1SystemStringWritable = (options?: Options): GenericSchemaDuplicateIssue1SystemStringWritable => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { item: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { error: f.datatype.boolean() ? f.string.sample() : null } + }; +}; + +export const fakeSimpleParameter = (options?: Options): SimpleParameter => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeCompositionWithOneOfAndProperties = (options?: Options): CompositionWithOneOfAndProperties => { + const f = options?.faker ?? faker; + return Object.assign({}, f.helpers.arrayElement([{ + foo: fakeSimpleParameter(options) + }, { + bar: fakeNonAsciiStringæøåÆøÅöôêÊ字符串(options) + }]), { + baz: f.datatype.boolean() ? f.number.int({ min: 0 }) : null, + qux: f.number.int({ min: 0 }) + }); +}; + +export const fakeXFooBar = (options?: Options): XFooBar => fakeModelWithString(options); + +export const fakeSimpleRequestBody = (options?: Options): SimpleRequestBody => fakeModelWithString(options); + +export const fakeSimpleFormData = (options?: Options): SimpleFormData => fakeModelWithString(options); + +export const fakePatchApiVbyApiVersionNoTagResponse = () => undefined; + +export const fakeImportRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.helpers.arrayElement([fakeModelWithReadOnlyAndWriteOnlyWritable(options), fakeModelWithArrayReadOnlyAndWriteOnlyWritable(options)]) + }; +}; + +export const fakeImportResponse200 = (options?: Options): ImportResponses[200] => fakeModelFromZendesk(options); + +export const fakeImportResponsedefault = (options?: Options): ImportResponses['default'] => fakeModelWithReadOnlyAndWriteOnly(options); + +export const fakeFooWowResponse = () => undefined; + +export const fakeApiVVersionODataControllerCountResponse = (options?: Options): ApiVVersionODataControllerCountResponse => fakeModelFromZendesk(options); + +export const fakeGetApiVbyApiVersionSimpleOperationRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + foo_param: f.helpers.arrayElement([f.string.sample(), f.string.uuid()]) + } + }; +}; + +export const fakeGetApiVbyApiVersionSimpleOperationResponse200 = (options?: Options): GetApiVbyApiVersionSimpleOperationResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeGetApiVbyApiVersionSimpleOperationResponsedefault = (options?: Options): GetApiVbyApiVersionSimpleOperationErrors['default'] => fakeModelWithBoolean(options); + +export const fakeDeleteFooRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + headers: { + 'x-Foo-Bar': fakeModelWithString(options) + }, + path: { + foo_param: f.string.sample(), + BarParam: f.string.sample() + } + }; +}; + +export const fakeCallWithDescriptionsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBreaks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithBackticks: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithSlashes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithExpressionPlaceholders: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithQuotes: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterWithReservedCharacters: f.string.sample() } + } + }; +}; + +export const fakeDeprecatedCallRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + headers: { + parameter: f.datatype.boolean() ? fakeDeprecatedModel(options) : null + } + }; +}; + +export const fakeCallWithParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.datatype.boolean() ? {} : null, + headers: { + parameterHeader: f.datatype.boolean() ? f.string.sample() : null + }, + path: { + parameterPath: f.datatype.boolean() ? f.string.sample() : null, + 'api-version': f.datatype.boolean() ? f.string.sample() : null + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo_ref_enum: fakeModelWithNestedArrayEnumsDataFoo(options) }, + foo_all_of_enum: fakeModelWithNestedArrayEnumsDataFoo(options), + cursor: f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeCallWithWeirdParameterNamesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: f.datatype.boolean() ? fakeModelWithString(options) : null, + headers: { + 'parameter.header': f.datatype.boolean() ? f.string.sample() : null + }, + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter.path.1': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'parameter-path-2': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { 'PARAMETER-PATH-3': f.string.sample() }, + 'api-version': f.datatype.boolean() ? f.string.sample() : null + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { default: f.string.sample() }, + 'parameter-query': f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeGetCallWithOptionalParamRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeModelWithOneOfEnum(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { page: f.number.float() } + } + }; +}; + +export const fakePostCallWithOptionalParamRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { offset: f.datatype.boolean() ? f.number.float() : null } + }, + query: { + parameter: fakePageable(options) + } + }; +}; + +export const fakePostCallWithOptionalParamResponse = (options?: Options): PostCallWithOptionalParamResponse => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakePostApiVbyApiVersionRequestBodyRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeSimpleRequestBody(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameter: f.string.sample() } + } + }; +}; + +export const fakePostApiVbyApiVersionFormDataRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: fakeSimpleFormData(options), + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameter: f.string.sample() } + } + }; +}; + +export const fakeCallWithDefaultParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterString: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterNumber: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterBoolean: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterModel: f.datatype.boolean() ? fakeModelWithString(options) : null } + } + }; +}; + +export const fakeCallWithDefaultOptionalParametersRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterString: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterBoolean: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error' + ]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterModel: fakeModelWithString(options) } + } + }; +}; + +export const fakeCallToTestOrderOfParamsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterOptionalStringWithNoDefault: f.string.sample() }, + parameterStringWithDefault: resolveCondition(options?.useDefault ?? false, f) ? 'Hello World!' : f.string.sample(), + parameterStringWithEmptyDefault: resolveCondition(options?.useDefault ?? false, f) ? '' : f.string.sample(), + parameterStringWithNoDefault: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithNoDefault: f.datatype.boolean() ? f.string.sample() : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { parameterStringNullableWithDefault: f.datatype.boolean() ? f.string.sample() : null } + } + }; +}; + +export const fakeCallWithResponseAndNoContentResponseResponse = (options?: Options): CallWithResponseAndNoContentResponseResponse => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeDummyAResponse = (options?: Options): DummyAResponse => fake400(options); + +export const fakeCallWithResponseResponse = (options?: Options): CallWithResponseResponse => fakeImport(options); + +export const fakeCallWithDuplicateResponsesResponse200 = (options?: Options): CallWithDuplicateResponsesResponses[200] => Object.assign({}, fakeModelWithBoolean(options), fakeModelWithInteger(options)); + +export const fakeCallWithDuplicateResponsesResponse201 = (options?: Options): CallWithDuplicateResponsesResponses[201] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse202 = (options?: Options): CallWithDuplicateResponsesResponses[202] => fakeModelWithString(options); + +export const fakeCallWithDuplicateResponsesResponse500 = (options?: Options): CallWithDuplicateResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse501 = (options?: Options): CallWithDuplicateResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse502 = (options?: Options): CallWithDuplicateResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithDuplicateResponsesResponse4Xx = (options?: Options): CallWithDuplicateResponsesErrors['4XX'] => fakeDictionaryWithArray(options); + +export const fakeCallWithDuplicateResponsesResponsedefault = (options?: Options): CallWithDuplicateResponsesErrors['default'] => fakeModelWithBoolean(options); + +export const fakeCallWithResponsesResponse200 = (options?: Options): CallWithResponsesResponses[200] => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.string': f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { '@namespace.integer': f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { value: f.helpers.multiple(() => fakeModelWithString(options)) } + }; +}; + +export const fakeCallWithResponsesResponse201 = (options?: Options): CallWithResponsesResponses[201] => fakeModelThatExtends(options); + +export const fakeCallWithResponsesResponse202 = (options?: Options): CallWithResponsesResponses[202] => fakeModelThatExtendsExtends(options); + +export const fakeCallWithResponsesResponse500 = (options?: Options): CallWithResponsesErrors[500] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse501 = (options?: Options): CallWithResponsesErrors[501] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponse502 = (options?: Options): CallWithResponsesErrors[502] => fakeModelWithStringError(options); + +export const fakeCallWithResponsesResponsedefault = (options?: Options): CallWithResponsesErrors['default'] => fakeModelWithStringError(options); + +export const fakeCollectionFormatRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterArrayCSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArraySSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayTSV: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayPipes: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterArrayMulti: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null + } + }; +}; + +export const fakeTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.number.int() } + }, + query: { + parameterNumber: resolveCondition(options?.useDefault ?? false, f) ? 123 : f.number.float(), + parameterString: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? 'default' : f.string.sample() : null, + parameterBoolean: f.datatype.boolean() ? resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() : null, + parameterObject: f.datatype.boolean() ? {} : null, + parameterArray: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null, + parameterDictionary: f.datatype.boolean() ? {} : null, + parameterEnum: f.helpers.arrayElement([ + 'Success', + 'Warning', + 'Error', + null + ]) + } + }; +}; + +export const fakeTypesResponse200 = (options?: Options): TypesResponses[200] => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeTypesResponse201 = (options?: Options): TypesResponses[201] => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; + +export const fakeTypesResponse202 = (options?: Options): TypesResponses[202] => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeTypesResponse203 = (): TypesResponses[203] => ({}); + +export const fakeUploadFileRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: new Blob([f.image.dataUri()]), + path: { + 'api-version': f.datatype.boolean() ? f.string.sample() : null + } + }; +}; + +export const fakeUploadFileResponse = (options?: Options): UploadFileResponse => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeFileResponseRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid(), + 'api-version': f.string.sample() + } + }; +}; + +export const fakeFileResponseResponse = (options?: Options): FileResponseResponse => { + const f = options?.faker ?? faker; + return new Blob([f.image.dataUri()]); +}; + +export const fakeComplexTypesRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + parameterObject: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { first: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { second: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { third: f.string.sample() } + } } + } } + }, + parameterReference: fakeModelWithString(options) + } + }; +}; + +export const fakeComplexTypesResponse200 = (options?: Options): ComplexTypesResponses[200] => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeModelWithString(options)); +}; + +export const fakeComplexTypesResponse400 = (): ComplexTypesErrors[400] => undefined; + +export const fakeComplexTypesResponse500 = (): ComplexTypesErrors[500] => undefined; + +export const fakeMultipartResponseResponse = (options?: Options): MultipartResponseResponse => { + const f = options?.faker ?? faker; + return { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { file: new Blob([f.image.dataUri()]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { metadata: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { foo: f.string.sample() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bar: f.string.sample() } + } } + }; +}; + +export const fakeMultipartRequestRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { content: new Blob([f.image.dataUri()]) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { data: f.datatype.boolean() ? fakeModelWithString(options) : null } + } + }; +}; + +export const fakeComplexParamsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + key: f.datatype.boolean() ? f.helpers.fromRegExp('^[a-zA-Z0-9_]*$') : null, + name: f.datatype.boolean() ? f.string.alpha({ length: { min: 0, max: 255 } }) : null, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { enabled: resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean() }, + type: f.helpers.arrayElement([ + 'Monkey', + 'Horse', + 'Bird' + ]), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { listOfModels: f.datatype.boolean() ? f.helpers.multiple(() => fakeModelWithString(options)) : null }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { listOfStrings: f.datatype.boolean() ? f.helpers.multiple(() => f.string.sample()) : null }, + parameters: f.helpers.arrayElement([ + fakeModelWithString(options), + fakeModelWithEnum(options), + fakeModelWithArray(options), + fakeModelWithDictionary(options) + ]), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { user: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { id: f.number.int() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { name: f.datatype.boolean() ? f.person.fullName() : null } + } } + }, + path: { + id: f.number.int(), + 'api-version': f.string.sample() + } + }; +}; + +export const fakeComplexParamsResponse = (options?: Options): ComplexParamsResponse => fakeModelWithString(options); + +export const fakeCallWithResultFromHeaderResponse200 = (): CallWithResultFromHeaderResponses[200] => undefined; + +export const fakeCallWithResultFromHeaderResponse400 = (): CallWithResultFromHeaderErrors[400] => undefined; + +export const fakeCallWithResultFromHeaderResponse500 = (): CallWithResultFromHeaderErrors[500] => undefined; + +export const fakeTestErrorCodeRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + status: f.number.int() + } + }; +}; + +export const fakeTestErrorCodeResponse200 = (): TestErrorCodeResponses[200] => undefined; + +export const fakeTestErrorCodeResponse500 = (): TestErrorCodeErrors[500] => undefined; + +export const fakeTestErrorCodeResponse501 = (): TestErrorCodeErrors[501] => undefined; + +export const fakeTestErrorCodeResponse502 = (): TestErrorCodeErrors[502] => undefined; + +export const fakeTestErrorCodeResponse503 = (): TestErrorCodeErrors[503] => undefined; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Request = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + nonAsciiParamæøåÆØÅöôêÊ: f.number.int() + } + }; +}; + +export const fakeNonAsciiæøåÆøÅöôêÊ字符串Response = (options?: Options): NonAsciiæøåÆøÅöôêÊ字符串Response => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakeNonAsciiStringæøåÆøÅöôêÊ字符串(options)); +}; + +export const fakePutWithFormUrlEncodedRequest = (options?: Options): Omit => ({ + body: fakeArrayWithStrings(options) +}); diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/index.ts new file mode 100644 index 0000000000..2ef59c1f0c --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/types.gen.ts new file mode 100644 index 0000000000..d819316644 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-full/types.gen.ts @@ -0,0 +1,2100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * External ref to shared model (A) + */ +export type ExternalRefA = ExternalSharedModel; + +/** + * External ref to shared model (B) + */ +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + /** + * Scopes + */ + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null (anyOf ref + null) + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = [ + ModelWithInteger, + number | string, + string +]; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-locale/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-locale/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..b16676e78c --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-locale/@faker-js/faker.gen.ts @@ -0,0 +1,511 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Faker } from '@faker-js/faker'; +import { faker } from '@faker-js/faker/locale/de'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNothing = () => null; + +export const fakeAnything = () => undefined; + +export const fakeStatusWithNull = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeDictionaryObject = (options?: Options) => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + homePhone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options) => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options) => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..f88936ac61 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/@faker-js/faker.gen.ts @@ -0,0 +1,512 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, Company, Config, CreateJobErrors, CreateJobResponses, CreatePetData, CreatePetResponse, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, DictionaryObject, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, Nothing, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNothing = (): Nothing => null; + +export const fakeAnything = (): Anything => undefined; + +export const fakeStatusWithNull = (options?: Options): StatusWithNull => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeDictionaryObject = (options?: Options): DictionaryObject => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.word.words({ count: 4 }) + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options): PetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options): StringOrNumber => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options): NullablePetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options): Circle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options): Square => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options): Shape => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options): Dog => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options): Cat => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options): Animal => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + homePhone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options): CreatePetResponse => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options): CreateJobResponses['2XX'] => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options): CreateJobErrors['4XX'] => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/index.ts new file mode 100644 index 0000000000..0543fb7fba --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, ClientOptions, Company, Config, CreateJobData, CreateJobError, CreateJobErrors, CreateJobResponse, CreateJobResponses, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponse, DeletePetResponses, DictionaryObject, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, Nothing, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/types.gen.ts new file mode 100644 index 0000000000..17825ee3ff --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-name-rules/types.gen.ts @@ -0,0 +1,391 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type Nothing = null; + +export type Anything = unknown; + +export type StatusWithNull = 'active' | 'inactive' | null; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +/** + * This is a dictionary object + */ +export type DictionaryObject = { + [key: string]: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetOrTag = Pet | Tag; + +export type StringOrNumber = string | number; + +export type NullablePetOrTag = Pet | Tag | null; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type Circle = { + kind: string; + radius: number; +}; + +export type Square = { + kind: string; + side: number; +}; + +export type Shape = ({ + kind: 'Circle'; +} & Circle) | ({ + kind: 'Square'; +} & Square); + +export type Dog = { + type: string; + bark: boolean; +}; + +export type Cat = { + type: string; + purr: boolean; +}; + +export type Animal = ({ + type: 'dog'; +} & Dog) | ({ + type: 'cat'; +} & Cat); + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + homePhone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: void; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: void; +}; + +export type DeletePetResponse = DeletePetResponses[keyof DeletePetResponses]; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type CreateJobData = { + body?: never; + path?: never; + query?: never; + url: '/jobs'; +}; + +export type CreateJobErrors = { + /** + * Client error + */ + '4XX': Error; +}; + +export type CreateJobError = CreateJobErrors[keyof CreateJobErrors]; + +export type CreateJobResponses = { + /** + * Job accepted + */ + '2XX': Pet; +}; + +export type CreateJobResponse = CreateJobResponses[keyof CreateJobResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..dd1a61012f --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/@faker-js/faker.gen.ts @@ -0,0 +1,512 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +import type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, Company, Config, CreateJobErrors, CreateJobResponses, CreatePetData, CreatePetResponse, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetErrors, DictionaryObject, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetErrors, GetPetResponses, HealthCheckResponse, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, Nothing, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, User, UserProfile, Website, ZipCode } from '../types.gen'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options): Price => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options): Quantity => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options): Active => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNothing = (): Nothing => null; + +export const fakeAnything = (): Anything => undefined; + +export const fakeStatusWithNull = (options?: Options): StatusWithNull => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options): NumericEnum => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options): Email => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options): DateTime => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options): DateOnly => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options): UniqueId => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options): Website => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options): IPv4Address => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options): IPv6Address => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options): ZipCode => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options): ShortName => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options): MinOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options): MaxOnlyString => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options): EmailWithLength => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options): BoundedInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options): BoundedFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options): ExclusiveInt => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options): MinOnlyNumber => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options): MaxOnlyInt => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options): ExclusiveFloat => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options): ExclusiveFloatNarrow => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options): Tags => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options): TagList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options): MinOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options): MaxOnlyArray => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options): DefaultString => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options): DefaultInt => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options): DefaultBool => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options): DefaultOverridesConstraints => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options): NullableString => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options): NullableInt => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options): ObjectWithDefaultProp => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeDictionaryObject = (options?: Options): DictionaryObject => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeUserProfile = (options?: Options): UserProfile => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options): Tag => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options): Pet => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options): Error => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options): Address => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options): Person => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options): PersonList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options): PetList => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options): Team => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options): PetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options): StringOrNumber => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options): NullablePetOrTag => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options): PetWithOwner => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options): Circle => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options): Square => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options): Shape => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options): Dog => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options): Cat => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options): Animal => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options): PersonProfile => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + homePhone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options): PersonWithConstraints => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options): User => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options): Company => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options): Config => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = (): NeverArray => []; + +export const fakeObjectWithOptionalNever = (options?: Options): ObjectWithOptionalNever => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options): Document => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options): ListPetsResponse => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options): CreatePetResponse => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options): DeletePetErrors[404] => fakeError(options); + +export const fakeGetPetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options): GetPetResponses[200] => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options): GetPetErrors[404] => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options): Omit => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options): UpdatePetResponse => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options): CreateJobResponses['2XX'] => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options): CreateJobErrors['4XX'] => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options): HealthCheckResponse => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/index.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/index.ts new file mode 100644 index 0000000000..0543fb7fba --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/index.ts @@ -0,0 +1,3 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Active, Address, Animal, Anything, BoundedFloat, BoundedInt, Cat, Circle, ClientOptions, Company, Config, CreateJobData, CreateJobError, CreateJobErrors, CreateJobResponse, CreateJobResponses, CreatePetData, CreatePetResponse, CreatePetResponses, DateOnly, DateTime, DefaultBool, DefaultInt, DefaultOverridesConstraints, DefaultString, DeletePetData, DeletePetError, DeletePetErrors, DeletePetResponse, DeletePetResponses, DictionaryObject, Document, Dog, Email, EmailWithLength, Error, ExclusiveFloat, ExclusiveFloatNarrow, ExclusiveInt, GetPetData, GetPetError, GetPetErrors, GetPetResponse, GetPetResponses, HealthCheckData, HealthCheckResponse, HealthCheckResponses, IPv4Address, IPv6Address, ListPetsData, ListPetsResponse, ListPetsResponses, MaxOnlyArray, MaxOnlyInt, MaxOnlyString, MinOnlyArray, MinOnlyNumber, MinOnlyString, NeverArray, NeverTuple, Nothing, NullableInt, NullablePetOrTag, NullableString, NumericEnum, ObjectWithDefaultProp, ObjectWithOptionalNever, ObjectWithRequiredNever, Person, PersonList, PersonProfile, PersonWithConstraints, Pet, PetList, PetOrTag, PetWithOwner, Price, Quantity, Shape, ShortName, Square, StatusWithNull, StringOrNumber, Tag, TagList, Tags, Team, UniqueId, UpdatePetData, UpdatePetResponse, UpdatePetResponses, User, UserProfile, Website, ZipCode } from './types.gen'; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/types.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/types.gen.ts new file mode 100644 index 0000000000..17825ee3ff --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker-typed/types.gen.ts @@ -0,0 +1,391 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type Price = number; + +export type Quantity = number; + +export type Active = boolean; + +export type Nothing = null; + +export type Anything = unknown; + +export type StatusWithNull = 'active' | 'inactive' | null; + +export type NumericEnum = 1 | 2 | 3; + +export type Email = string; + +export type DateTime = string; + +export type DateOnly = string; + +export type UniqueId = string; + +export type Website = string; + +export type IPv4Address = string; + +export type IPv6Address = string; + +export type ZipCode = string; + +export type ShortName = string; + +export type MinOnlyString = string; + +export type MaxOnlyString = string; + +export type EmailWithLength = string; + +export type BoundedInt = number; + +export type BoundedFloat = number; + +export type ExclusiveInt = number; + +export type MinOnlyNumber = number; + +export type MaxOnlyInt = number; + +export type ExclusiveFloat = number; + +export type ExclusiveFloatNarrow = number; + +export type Tags = Array; + +export type TagList = Array; + +export type MinOnlyArray = Array; + +export type MaxOnlyArray = Array; + +export type DefaultString = string; + +export type DefaultInt = number; + +export type DefaultBool = boolean; + +export type DefaultOverridesConstraints = number; + +export type NullableString = string | null; + +export type NullableInt = number | null; + +export type ObjectWithDefaultProp = { + name: string; + status?: string; +}; + +/** + * This is a dictionary object + */ +export type DictionaryObject = { + [key: string]: string; +}; + +export type UserProfile = { + id: number; + name: string; + bio?: string; + age?: number; +}; + +export type Pet = { + id: string; + name: string; + age?: number; + tag?: Tag; +}; + +export type Tag = { + id: number; + label: string; +}; + +export type Error = { + code: number; + message: string; +}; + +export type Address = { + street: string; + zip: ZipCode; +}; + +export type Person = { + name: ShortName; + email: Email; + address?: Address; +}; + +export type PersonList = Array; + +export type PetList = Array; + +export type Team = { + lead: Person; + config: ObjectWithDefaultProp; +}; + +export type PetOrTag = Pet | Tag; + +export type StringOrNumber = string | number; + +export type NullablePetOrTag = Pet | Tag | null; + +export type PetWithOwner = Pet & { + owner: string; +}; + +export type Circle = { + kind: string; + radius: number; +}; + +export type Square = { + kind: string; + side: number; +}; + +export type Shape = ({ + kind: 'Circle'; +} & Circle) | ({ + kind: 'Square'; +} & Square); + +export type Dog = { + type: string; + bark: boolean; +}; + +export type Cat = { + type: string; + purr: boolean; +}; + +export type Animal = ({ + type: 'dog'; +} & Dog) | ({ + type: 'cat'; +} & Cat); + +export type PersonProfile = { + firstName: string; + last_name: string; + email: string; + phone: string; + homePhone: string; + age: number; + city: string; + postalCode: string; + bio: string; + website: string; + zipCode: string; + username: string; + someRandomField: string; +}; + +export type PersonWithConstraints = { + age: number; + seniorAge?: number; +}; + +export type User = { + name: string; + email: string; +}; + +export type Company = { + name: string; +}; + +export type Config = { + name: string; +}; + +export type NeverTuple = [ + number & string, + number & string +]; + +export type NeverArray = Array; + +export type ObjectWithRequiredNever = { + id: number; + impossible: number & string; +}; + +export type ObjectWithOptionalNever = { + id: number; + impossible?: number & string; +}; + +export type Document = { + id: string; + _id: string; + numericId: number; +}; + +export type ListPetsData = { + body?: never; + path?: never; + query?: { + limit?: number; + }; + url: '/pets'; +}; + +export type ListPetsResponses = { + /** + * A list of pets + */ + 200: Array; +}; + +export type ListPetsResponse = ListPetsResponses[keyof ListPetsResponses]; + +export type CreatePetData = { + body: { + name: string; + tag?: string; + }; + path?: never; + query?: never; + url: '/pets'; +}; + +export type CreatePetResponses = { + /** + * Pet created + */ + 201: Pet; + /** + * No content + */ + 204: void; +}; + +export type CreatePetResponse = CreatePetResponses[keyof CreatePetResponses]; + +export type DeletePetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type DeletePetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type DeletePetError = DeletePetErrors[keyof DeletePetErrors]; + +export type DeletePetResponses = { + /** + * Deleted + */ + 204: void; +}; + +export type DeletePetResponse = DeletePetResponses[keyof DeletePetResponses]; + +export type GetPetData = { + body?: never; + path: { + id: string; + }; + query?: never; + url: '/pets/{id}'; +}; + +export type GetPetErrors = { + /** + * Not found + */ + 404: Error; +}; + +export type GetPetError = GetPetErrors[keyof GetPetErrors]; + +export type GetPetResponses = { + /** + * A pet + */ + 200: Pet; +}; + +export type GetPetResponse = GetPetResponses[keyof GetPetResponses]; + +export type UpdatePetData = { + body: { + name: string; + tag?: Tag; + }; + path: { + id: string; + }; + query?: { + dryRun?: boolean; + }; + url: '/pets/{id}'; +}; + +export type UpdatePetResponses = { + /** + * Updated pet + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type CreateJobData = { + body?: never; + path?: never; + query?: never; + url: '/jobs'; +}; + +export type CreateJobErrors = { + /** + * Client error + */ + '4XX': Error; +}; + +export type CreateJobError = CreateJobErrors[keyof CreateJobErrors]; + +export type CreateJobResponses = { + /** + * Job accepted + */ + '2XX': Pet; +}; + +export type CreateJobResponse = CreateJobResponses[keyof CreateJobResponses]; + +export type HealthCheckData = { + body?: never; + path?: never; + query?: never; + url: '/health'; +}; + +export type HealthCheckResponses = { + /** + * OK + */ + 200: string; +}; + +export type HealthCheckResponse = HealthCheckResponses[keyof HealthCheckResponses]; diff --git a/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker/@faker-js/faker.gen.ts b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker/@faker-js/faker.gen.ts new file mode 100644 index 0000000000..8b1b27b8aa --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/__snapshots__/3.1.x/faker/@faker-js/faker.gen.ts @@ -0,0 +1,510 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { faker, type Faker } from '@faker-js/faker'; + +export type Options = { + faker?: Faker; + /** + * Whether to include optional properties, including add property to record object. + * Provide a number between 0 and 1 to randomly include based on that probability. + * @default true + */ + includeOptional?: boolean | number; + /** + * Whether to use schema default values instead of generating fake data. + * Provide a number between 0 and 1 to randomly use defaults based on that probability. + * @default false + */ + useDefault?: boolean | number; +}; + +const resolveCondition = (condition: boolean | number, faker: Faker): boolean => condition === true || typeof condition === 'number' && faker.datatype.boolean({ probability: condition }); + +export const fakePrice = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float(); +}; + +export const fakeQuantity = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int(); +}; + +export const fakeActive = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean(); +}; + +export const fakeNothing = () => null; + +export const fakeAnything = () => undefined; + +export const fakeStatusWithNull = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 'active', + 'inactive', + null + ]); +}; + +export const fakeNumericEnum = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + 1, + 2, + 3 + ]); +}; + +export const fakeEmail = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeDateTime = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString(); +}; + +export const fakeDateOnly = (options?: Options) => { + const f = options?.faker ?? faker; + return f.date.recent().toISOString().slice(0, 10); +}; + +export const fakeUniqueId = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.uuid(); +}; + +export const fakeWebsite = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.url(); +}; + +export const fakeIPv4Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv4(); +}; + +export const fakeIPv6Address = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.ipv6(); +}; + +export const fakeZipCode = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.fromRegExp('^\\d{5}(-\\d{4})?$'); +}; + +export const fakeShortName = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 2, max: 50 } }); +}; + +export const fakeMinOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 10, max: 100 } }); +}; + +export const fakeMaxOnlyString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.alpha({ length: { min: 0, max: 5 } }); +}; + +export const fakeEmailWithLength = (options?: Options) => { + const f = options?.faker ?? faker; + return f.internet.email(); +}; + +export const fakeBoundedInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 100 }); +}; + +export const fakeBoundedFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ min: 1, max: 9 }); +}; + +export const fakeMinOnlyNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0 }); +}; + +export const fakeMaxOnlyInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.int({ max: 999 }); +}; + +export const fakeExclusiveFloat = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 0, max: 1 }); +}; + +export const fakeExclusiveFloatNarrow = (options?: Options) => { + const f = options?.faker ?? faker; + return f.number.float({ min: 10.1, max: 10.2 }); +}; + +export const fakeTags = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample()); +}; + +export const fakeTagList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 1, max: 10 } }); +}; + +export const fakeMinOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.number.int(), { count: { min: 3, max: 100 } }); +}; + +export const fakeMaxOnlyArray = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => f.string.sample(), { count: { min: 0, max: 5 } }); +}; + +export const fakeDefaultString = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 'unknown' : f.string.sample(); +}; + +export const fakeDefaultInt = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 0 : f.number.int(); +}; + +export const fakeDefaultBool = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? true : f.datatype.boolean(); +}; + +export const fakeDefaultOverridesConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return resolveCondition(options?.useDefault ?? false, f) ? 42 : f.number.int({ min: 1, max: 100 }); +}; + +export const fakeNullableString = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.string.sample() : null; +}; + +export const fakeNullableInt = (options?: Options) => { + const f = options?.faker ?? faker; + return f.datatype.boolean() ? f.number.int() : null; +}; + +export const fakeObjectWithDefaultProp = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { status: resolveCondition(options?.useDefault ?? false, f) ? 'active' : f.string.sample() } + }; +}; + +export const fakeDictionaryObject = (options?: Options) => { + const f = options?.faker ?? faker; + return !resolveCondition(options?.includeOptional ?? true, f) ? {} as {} : { + additionalProp: f.string.sample() + }; +}; + +export const fakeUserProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { bio: f.lorem.sentence() }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) } + }; +}; + +export const fakeTag = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int(), + label: f.string.sample() + }; +}; + +export const fakePet = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { age: f.number.int({ max: 120, min: 1 }) }, + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }; +}; + +export const fakeError = (options?: Options) => { + const f = options?.faker ?? faker; + return { + code: f.number.int(), + message: f.string.sample() + }; +}; + +export const fakeAddress = (options?: Options) => { + const f = options?.faker ?? faker; + return { + street: f.location.streetAddress(), + zip: fakeZipCode(options) + }; +}; + +export const fakePerson = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: fakeShortName(options), + email: fakeEmail(options), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { address: fakeAddress(options) } + }; +}; + +export const fakePersonList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePerson(options), { count: { min: 1, max: 20 } }); +}; + +export const fakePetList = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeTeam = (options?: Options) => ({ + lead: fakePerson(options), + config: fakeObjectWithDefaultProp(options) +}); + +export const fakePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([fakePet(options), fakeTag(options)]); +}; + +export const fakeStringOrNumber = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([f.string.sample(), f.number.float()]); +}; + +export const fakeNullablePetOrTag = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([ + fakePet(options), + fakeTag(options), + null + ]); +}; + +export const fakePetWithOwner = (options?: Options) => { + const f = options?.faker ?? faker; + return Object.assign({}, fakePet(options), { + owner: f.string.sample() + }); +}; + +export const fakeCircle = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + radius: f.number.float() + }; +}; + +export const fakeSquare = (options?: Options) => { + const f = options?.faker ?? faker; + return { + kind: f.string.sample(), + side: f.number.float() + }; +}; + +export const fakeShape = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeCircle(options)), + kind: 'Circle' as const + }, { + ...Object.assign({}, fakeSquare(options)), + kind: 'Square' as const + }]); +}; + +export const fakeDog = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + bark: f.datatype.boolean() + }; +}; + +export const fakeCat = (options?: Options) => { + const f = options?.faker ?? faker; + return { + type: f.string.sample(), + purr: f.datatype.boolean() + }; +}; + +export const fakeAnimal = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.arrayElement([{ + ...Object.assign({}, fakeDog(options)), + type: 'dog' as const + }, { + ...Object.assign({}, fakeCat(options)), + type: 'cat' as const + }]); +}; + +export const fakePersonProfile = (options?: Options) => { + const f = options?.faker ?? faker; + return { + firstName: f.person.firstName(), + last_name: f.person.lastName(), + email: f.internet.email(), + phone: f.phone.number(), + homePhone: f.phone.number(), + age: f.number.int({ max: 120, min: 1 }), + city: f.location.city(), + postalCode: f.location.zipCode(), + bio: f.lorem.sentence(), + website: f.internet.url(), + zipCode: f.helpers.fromRegExp('^\\d{5}$'), + username: f.internet.username(), + someRandomField: f.string.sample() + }; +}; + +export const fakePersonWithConstraints = (options?: Options) => { + const f = options?.faker ?? faker; + return { + age: f.number.int({ max: 120, min: 18 }), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { seniorAge: f.number.int({ min: 65, max: 100 }) } + }; +}; + +export const fakeUser = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.person.fullName(), + email: f.internet.email() + }; +}; + +export const fakeCompany = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.company.name() + }; +}; + +export const fakeConfig = (options?: Options) => { + const f = options?.faker ?? faker; + return { + name: f.string.sample() + }; +}; + +export const fakeNeverArray = () => []; + +export const fakeObjectWithOptionalNever = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.number.int() + }; +}; + +export const fakeDocument = (options?: Options) => { + const f = options?.faker ?? faker; + return { + id: f.string.uuid(), + _id: f.string.uuid(), + numericId: f.number.int() + }; +}; + +export const fakeListPetsRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { limit: f.number.int({ min: 1, max: 100 }) } + } + }; +}; + +export const fakeListPetsResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.helpers.multiple(() => fakePet(options)); +}; + +export const fakeCreatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: f.string.sample() } + } + }; +}; + +export const fakeCreatePetResponse = (options?: Options) => fakePet(options); + +export const fakeDeletePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeDeletePetResponse404 = (options?: Options) => fakeError(options); + +export const fakeGetPetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + path: { + id: f.string.uuid() + } + }; +}; + +export const fakeGetPetResponse200 = (options?: Options) => fakePet(options); + +export const fakeGetPetResponse404 = (options?: Options) => fakeError(options); + +export const fakeUpdatePetRequest = (options?: Options) => { + const f = options?.faker ?? faker; + return { + body: { + name: f.string.sample(), + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { tag: fakeTag(options) } + }, + path: { + id: f.string.uuid() + }, + query: { + ...!resolveCondition(options?.includeOptional ?? true, f) ? {} : { dryRun: f.datatype.boolean() } + } + }; +}; + +export const fakeUpdatePetResponse = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse2Xx = (options?: Options) => fakePet(options); + +export const fakeCreateJobResponse4Xx = (options?: Options) => fakeError(options); + +export const fakeHealthCheckResponse = (options?: Options) => { + const f = options?.faker ?? faker; + return f.string.sample(); +}; diff --git a/packages/openapi-ts-tests/faker/v10/package.json b/packages/openapi-ts-tests/faker/v10/package.json new file mode 100644 index 0000000000..8daba95fc0 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/package.json @@ -0,0 +1,17 @@ +{ + "name": "@test/openapi-ts-faker-v10", + "version": "0.0.0", + "private": true, + "type": "module", + "scripts": { + "typecheck": "tsgo --noEmit" + }, + "devDependencies": { + "@faker-js/faker": "^10.4.0", + "@hey-api/openapi-ts": "workspace:*", + "typescript": "5.9.3" + }, + "engines": { + "node": ">=18.0.0" + } +} diff --git a/packages/openapi-ts-tests/faker/v10/test/constants.ts b/packages/openapi-ts-tests/faker/v10/test/constants.ts new file mode 100644 index 0000000000..e72988d8bb --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/test/constants.ts @@ -0,0 +1,4 @@ +import path from 'node:path'; + +export const snapshotsDir = path.join(__dirname, '..', '__snapshots__'); +export const tmpDir = path.join(__dirname, '..', '.tmp'); diff --git a/packages/openapi-ts-tests/faker/v10/test/faker.test.ts b/packages/openapi-ts-tests/faker/v10/test/faker.test.ts new file mode 100644 index 0000000000..7735e8e0fd --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/test/faker.test.ts @@ -0,0 +1,98 @@ +import fs from 'node:fs'; +import path from 'node:path'; + +import { createClient } from '@hey-api/openapi-ts'; + +import { getFilePaths } from '../../../utils'; +import { snapshotsDir, tmpDir } from './constants'; +import { createConfigFactory } from './utils'; + +const versions = ['2.0.x', '3.0.x', '3.1.x'] as const; + +describe.each(versions)('OpenAPI %s', (version) => { + const outputDir = path.join(tmpDir, version); + const createConfig = createConfigFactory({ openApiVersion: version, outputDir }); + + const scenarios = [ + { + config: createConfig({ + input: 'faker.yaml', + output: 'faker', + }), + description: 'generates faker factories without type annotations', + }, + { + config: createConfig({ + input: 'faker.yaml', + output: 'faker-locale', + plugins: [{ locale: 'de', name: '@faker-js/faker' }], + }), + description: 'generates faker factories with locale-specific import', + }, + { + config: createConfig({ + input: 'faker.yaml', + output: 'faker-typed', + plugins: ['@hey-api/typescript', '@faker-js/faker'], + }), + description: 'generates typed faker factories when typescript plugin is active', + }, + { + config: createConfig({ + input: 'circular.yaml', + output: 'faker-circular', + plugins: ['@hey-api/typescript', '@faker-js/faker'], + }), + description: 'generates faker factories with schemas with circular references', + }, + { + config: createConfig({ + input: 'faker.yaml', + output: 'faker-name-rules', + plugins: [ + '@hey-api/typescript', + { + name: '@faker-js/faker', + nameRules: { + string: { + 'error.message': { + defaultArgs: { count: 4 }, + fakerPath: ['word', 'words'], + }, + id: { + fakerPath: ['database', 'mongodbObjectId'], + suffixMatch: true, + }, + }, + }, + }, + ], + }), + description: 'generates faker factories with name rules', + }, + { + config: createConfig({ + input: 'full.yaml', + output: 'faker-full', + plugins: ['@hey-api/typescript', { compatibilityVersion: 9, name: '@faker-js/faker' }], + }), + description: 'generates faker factories', + }, + ]; + + it.each(scenarios)('$description', async ({ config }) => { + await createClient(config); + + const outputString = config.output as string; + const filePaths = getFilePaths(outputString); + + await Promise.all( + filePaths.map(async (filePath) => { + const fileContent = fs.readFileSync(filePath, 'utf-8'); + await expect(fileContent).toMatchFileSnapshot( + path.join(snapshotsDir, version, filePath.slice(outputDir.length + 1)), + ); + }), + ); + }); +}); diff --git a/packages/openapi-ts-tests/faker/v10/test/globalTeardown.ts b/packages/openapi-ts-tests/faker/v10/test/globalTeardown.ts new file mode 100644 index 0000000000..7c8712f70f --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/test/globalTeardown.ts @@ -0,0 +1,7 @@ +import fs from 'node:fs'; + +import { tmpDir } from './constants'; + +export function teardown() { + fs.rmSync(tmpDir, { force: true, recursive: true }); +} diff --git a/packages/openapi-ts-tests/faker/v10/test/utils.ts b/packages/openapi-ts-tests/faker/v10/test/utils.ts new file mode 100644 index 0000000000..3a9e9530cc --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/test/utils.ts @@ -0,0 +1,37 @@ +import path from 'node:path'; + +import type { UserConfig } from '@hey-api/openapi-ts'; + +import { getSpecsPath } from '../../../utils'; + +export function createConfigFactory({ + openApiVersion, + outputDir, +}: { + openApiVersion: string; + outputDir: string; +}) { + return (userConfig: UserConfig) => { + const input = userConfig.input instanceof Array ? userConfig.input[0]! : userConfig.input; + const inputPath = path.join( + getSpecsPath(), + openApiVersion, + typeof input === 'string' ? input : (input.path as string), + ); + const output = userConfig.output instanceof Array ? userConfig.output[0]! : userConfig.output; + const outputPath = typeof output === 'string' ? output : (output?.path ?? ''); + return { + plugins: ['@faker-js/faker'], + ...userConfig, + input: + typeof userConfig.input === 'string' + ? inputPath + : { + ...userConfig.input, + path: inputPath, + }, + logs: { level: 'silent', path: './logs' }, + output: path.join(outputDir, outputPath), + } as UserConfig; + }; +} diff --git a/packages/openapi-ts-tests/faker/v10/tsconfig.json b/packages/openapi-ts-tests/faker/v10/tsconfig.json new file mode 100644 index 0000000000..e7572df83d --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["test/**/*", "__snapshots__/**/*"], + "references": [{ "path": "../../../openapi-ts" }] +} diff --git a/packages/openapi-ts-tests/faker/v10/turbo.json b/packages/openapi-ts-tests/faker/v10/turbo.json new file mode 100644 index 0000000000..f25a4152d3 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/turbo.json @@ -0,0 +1,10 @@ +{ + "$schema": "../../../../node_modules/turbo/schema.json", + "extends": ["//"], + "tasks": { + "build": { + "dependsOn": [], + "outputs": ["dist/**"] + } + } +} diff --git a/packages/openapi-ts-tests/faker/v10/vitest.setup.ts b/packages/openapi-ts-tests/faker/v10/vitest.setup.ts new file mode 100644 index 0000000000..c6178ba405 --- /dev/null +++ b/packages/openapi-ts-tests/faker/v10/vitest.setup.ts @@ -0,0 +1,7 @@ +import { fileURLToPath } from 'node:url'; + +import { beforeAll } from 'vitest'; + +beforeAll(() => { + process.chdir(fileURLToPath(new URL('.', import.meta.url))); +}); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts index a6c351d2d5..5684171a21 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -2,6 +2,23 @@ import * as z from 'zod/v4-mini'; +export const zTreeNode = z.object({ + id: z.string(), + value: z.string(), + children: z.optional(z.array(z.lazy((): any => zTreeNode))) +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment = z.object({ + id: z.string(), + text: z.string(), + parent: z.nullable(z.lazy((): any => zComment)) +}); + export const zFoo = z.object({ quux: z.optional(z.lazy((): any => zQuux)) }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.optional(z.array(zBaz)) }); + +export const zOrg = z.object({ + id: z.string(), + name: z.string(), + members: z.optional(z.array(z.lazy((): any => zMember))) +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: z.optional(zOrg) +}); + +export const zDepartment = z.object({ + id: z.string(), + name: z.string(), + employees: z.optional(z.array(z.lazy((): any => zEmployee))) +}); + +export const zEmployee = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy((): any => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: z.optional(zDepartment) +}); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 4caa3fbd4e..9d4261c7f9 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -2,6 +2,23 @@ import { z } from 'zod'; +export const zTreeNode: z.AnyZodObject = z.object({ + id: z.string(), + value: z.string(), + children: z.array(z.lazy(() => zTreeNode)).optional() +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment: z.AnyZodObject = z.object({ + id: z.string(), + text: z.string(), + parent: z.lazy(() => zComment).nullable() +}); + export const zFoo: z.AnyZodObject = z.object({ quux: z.lazy(() => zQuux).optional() }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.array(zBaz).optional() }); + +export const zOrg: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + members: z.array(z.lazy(() => zMember)).optional() +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: zOrg.optional() +}); + +export const zDepartment: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + employees: z.array(z.lazy(() => zEmployee)).optional() +}); + +export const zEmployee: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy(() => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: zDepartment.optional() +}); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts index f17d721509..5355958677 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -2,6 +2,23 @@ import * as z from 'zod/v4'; +export const zTreeNode = z.object({ + id: z.string(), + value: z.string(), + children: z.array(z.lazy((): any => zTreeNode)).optional() +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment = z.object({ + id: z.string(), + text: z.string(), + parent: z.lazy((): any => zComment).nullable() +}); + export const zFoo = z.object({ quux: z.lazy((): any => zQuux).optional() }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.array(zBaz).optional() }); + +export const zOrg = z.object({ + id: z.string(), + name: z.string(), + members: z.array(z.lazy((): any => zMember)).optional() +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: zOrg.optional() +}); + +export const zDepartment = z.object({ + id: z.string(), + name: z.string(), + employees: z.array(z.lazy((): any => zEmployee)).optional() +}); + +export const zEmployee = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy((): any => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: zDepartment.optional() +}); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts index c9bffc9233..1cd37f838f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -2,6 +2,23 @@ import * as z from 'zod/mini'; +export const zTreeNode = z.object({ + id: z.string(), + value: z.string(), + children: z.optional(z.array(z.lazy((): any => zTreeNode))) +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment = z.object({ + id: z.string(), + text: z.string(), + parent: z.nullable(z.lazy((): any => zComment)) +}); + export const zFoo = z.object({ quux: z.optional(z.lazy((): any => zQuux)) }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.optional(z.array(zBaz)) }); + +export const zOrg = z.object({ + id: z.string(), + name: z.string(), + members: z.optional(z.array(z.lazy((): any => zMember))) +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: z.optional(zOrg) +}); + +export const zDepartment = z.object({ + id: z.string(), + name: z.string(), + employees: z.optional(z.array(z.lazy((): any => zEmployee))) +}); + +export const zEmployee = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy((): any => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: z.optional(zDepartment) +}); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 89c43bbd9d..98964d2027 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -2,6 +2,23 @@ import { z } from 'zod/v3'; +export const zTreeNode: z.AnyZodObject = z.object({ + id: z.string(), + value: z.string(), + children: z.array(z.lazy(() => zTreeNode)).optional() +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment: z.AnyZodObject = z.object({ + id: z.string(), + text: z.string(), + parent: z.lazy(() => zComment).nullable() +}); + export const zFoo: z.AnyZodObject = z.object({ quux: z.lazy(() => zQuux).optional() }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.array(zBaz).optional() }); + +export const zOrg: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + members: z.array(z.lazy(() => zMember)).optional() +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: zOrg.optional() +}); + +export const zDepartment: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + employees: z.array(z.lazy(() => zEmployee)).optional() +}); + +export const zEmployee: z.AnyZodObject = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy(() => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: zDepartment.optional() +}); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 6fdddaf323..6f2e3f0f1b 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -2,6 +2,23 @@ import * as z from 'zod'; +export const zTreeNode = z.object({ + id: z.string(), + value: z.string(), + children: z.array(z.lazy((): any => zTreeNode)).optional() +}); + +export const zWrapper = z.object({ + label: z.string(), + tree: zTreeNode +}); + +export const zComment = z.object({ + id: z.string(), + text: z.string(), + parent: z.lazy((): any => zComment).nullable() +}); + export const zFoo = z.object({ quux: z.lazy((): any => zQuux).optional() }); @@ -31,3 +48,33 @@ export const zQuux = z.object({ export const zCorge = z.object({ baz: z.array(zBaz).optional() }); + +export const zOrg = z.object({ + id: z.string(), + name: z.string(), + members: z.array(z.lazy((): any => zMember)).optional() +}); + +export const zMember = z.object({ + id: z.string(), + name: z.string(), + org: zOrg.optional() +}); + +export const zDepartment = z.object({ + id: z.string(), + name: z.string(), + employees: z.array(z.lazy((): any => zEmployee)).optional() +}); + +export const zEmployee = z.object({ + id: z.string(), + name: z.string(), + projects: z.array(z.lazy((): any => zProject)) +}); + +export const zProject = z.object({ + id: z.string(), + name: z.string(), + department: zDepartment.optional() +}); diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/api.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/api.ts index 5c568d68c3..eac357bf1a 100644 --- a/packages/openapi-ts/src/plugins/@faker-js/faker/api.ts +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/api.ts @@ -1,45 +1,61 @@ import type { IR } from '@hey-api/shared'; -import type { $ } from '../../../ts-dsl'; - -type Expression = ReturnType; +import type { Expression } from './shared/types'; +import type { FakerJsFakerPlugin } from './types'; +import { toNodeRefV10, toNodeV10 } from './v10/api'; export type IApi = { /** - * Generate a Faker expression for a schema. + * Generate an inline Faker expression for a schema. * * Returns an expression that produces a valid instance when executed. - * Use when you need one-off generation without referencing shared artifacts. + * The returned expression may reference faker symbols (`ensureFaker`, + * `options`) — cross-plugin references resolve imports automatically. * * @example * ```ts + * // For { type: 'object', properties: { name: string, email: string } }: * { - * name: faker.person.fullName(), - * email: faker.internet.email() + * name: ensureFaker(options).person.fullName(), + * email: ensureFaker(options).internet.email() * } * ``` */ - toNode(schema: IR.SchemaObject): Expression; + toNode(args: { plugin: FakerJsFakerPlugin['Instance']; schema: IR.SchemaObject }): Expression; /** - * Get a reference to a generated Faker expression for a schema. + * Get a reference to an existing Faker factory for a schema. * - * Returns a call expression referencing the shared artifact. - * If the artifact doesn't exist, it will be created. + * For `$ref` schemas, looks up the registered factory symbol via + * `referenceSymbol` and returns a call expression (e.g. `fakeUser(options)`). + * For non-`$ref` schemas, falls back to an inline expression via `toNode`. * * @example - * // Returns: fakeUser() + * ```ts + * // For { $ref: '#/components/schemas/User' }: + * fakeUser(options) + * ``` */ - toNodeRef(schema: IR.SchemaObject): Expression; + toNodeRef(args: { plugin: FakerJsFakerPlugin['Instance']; schema: IR.SchemaObject }): Expression; }; export class Api implements IApi { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - toNode(_schema: IR.SchemaObject): Expression { - return undefined as any; + toNode(args: { plugin: FakerJsFakerPlugin['Instance']; schema: IR.SchemaObject }): Expression { + const { plugin } = args; + switch (plugin.config.compatibilityVersion) { + case 9: + case 10: + default: + return toNodeV10(args); + } } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - toNodeRef(_schema: IR.SchemaObject): Expression { - return undefined as any; + toNodeRef(args: { plugin: FakerJsFakerPlugin['Instance']; schema: IR.SchemaObject }): Expression { + const { plugin } = args; + switch (plugin.config.compatibilityVersion) { + case 9: + case 10: + default: + return toNodeRefV10(args); + } } } diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/config.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/config.ts index 50ba6576a8..4767d61c30 100644 --- a/packages/openapi-ts/src/plugins/@faker-js/faker/config.ts +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/config.ts @@ -1,7 +1,7 @@ import { definePluginConfig, mappers } from '@hey-api/shared'; import { Api } from './api'; -// import { handler } from './plugin'; +import { handler } from './plugin'; import type { FakerJsFakerPlugin } from './types'; export const defaultConfig: FakerJsFakerPlugin['Config'] = { @@ -9,20 +9,48 @@ export const defaultConfig: FakerJsFakerPlugin['Config'] = { config: { case: 'camelCase', includeInEntry: false, + nameRules: {}, }, - // handler, - handler: () => {}, + handler, name: '@faker-js/faker', resolveConfig: (plugin, context) => { + if (!plugin.config.compatibilityVersion) { + const version = context.package.getVersion('@faker-js/faker'); + plugin.config.compatibilityVersion = + version && (version.major === 9 || version.major === 10) ? (version.major as 9 | 10) : 9; + } + + plugin.config.maxCallDepth = plugin.config.maxCallDepth ?? 10; + plugin.config.definitions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - name: 'v{{name}}', + name: 'fake{{name}}', }, mappers, value: plugin.config.definitions, }); + + plugin.config.requests = context.valueToObject({ + defaultValue: { + case: plugin.config.case ?? 'camelCase', + enabled: true, + name: 'fake{{name}}Request', + }, + mappers, + value: plugin.config.requests, + }); + + plugin.config.responses = context.valueToObject({ + defaultValue: { + case: plugin.config.case ?? 'camelCase', + enabled: true, + name: 'fake{{name}}Response', + }, + mappers, + value: plugin.config.responses, + }); }, tags: ['mocker'], }; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/plugin.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/plugin.ts new file mode 100644 index 0000000000..d9c3c2f581 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/plugin.ts @@ -0,0 +1,12 @@ +import type { FakerJsFakerPlugin } from './types'; +import { handlerV10 } from './v10/plugin'; + +export const handler: FakerJsFakerPlugin['Handler'] = (args) => { + const { plugin } = args; + switch (plugin.config.compatibilityVersion) { + case 9: + case 10: + default: + return handlerV10(args); + } +}; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/export.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/export.ts new file mode 100644 index 0000000000..84c1553524 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/export.ts @@ -0,0 +1,84 @@ +import { log } from '@hey-api/codegen-core'; +import { buildSymbolIn, pathToName } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import { getFakerPackagePath } from './helpers'; +import type { ProcessorContext } from './processor'; +import type { FakerResult } from './types'; + +export function exportAst({ + final, + isCircularSchema, + meta, + naming, + namingAnchor, + path, + plugin, + schema, + tags, +}: ProcessorContext & { + final: FakerResult; + isCircularSchema?: boolean; +}): void { + const name = pathToName(path, { anchor: namingAnchor }); + const symbolIn = buildSymbolIn({ + meta: { + category: 'schema', + path, + tags, + tool: 'faker', + ...meta, + }, + name, + naming, + plugin, + schema, + }); + + if (final.resultType === 'never') { + log.warn( + `[${plugin.name}] ${symbolIn.name} not generated because we can't produce data that fits its schema.`, + ); + return; + } + + const symbol = plugin.registerSymbol(symbolIn); + + // Look up the TypeScript type for this schema (e.g. Foo, Bar, or PostFooResponse) + const typeSymbol = plugin.querySymbol({ + category: 'type', + resource: meta.resource, + resourceId: meta.resourceId, + tool: 'typescript', + ...(meta.role ? { role: meta.role } : undefined), + }); + + // Build arrow function, only adding options param when the expression uses faker. + // When usesAccessor is true, emit a block body: const f = options?.faker ?? faker; return ; + const arrowFn = $.func() + .arrow() + .$if(final.usesFaker, (f) => { + if (isCircularSchema) { + return f + .param('options', (p) => p.type('Options').assign($.object())) + .param('_callDepth', (p) => p.assign($.literal(0))); + } + return f.param('options', (p) => p.optional().type('Options')); + }) + .$if(typeSymbol, (f) => f.returns($.type(typeSymbol!))) + .$if( + final.usesAccessor, + (f) => { + const fakerSymbol = plugin.external(`${getFakerPackagePath(plugin.config.locale)}.faker`); + const fDecl = $.const('f').assign( + $.binary($('options').attr('faker').optional(), '??', $(fakerSymbol)), + ); + return f.do(fDecl, $.return(final.expression)); + }, + (f) => f.do($.return(final.expression)), + ); + + const statement = $.const(symbol).export().assign(arrowFn); + + plugin.node(statement); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/faker-expr.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/faker-expr.ts new file mode 100644 index 0000000000..69441d8942 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/faker-expr.ts @@ -0,0 +1,66 @@ +import { $ } from '../../../../ts-dsl'; +import { normalizeName } from './helpers'; +import type { + EmitTracking, + FakerWalkerContext, + NameRule, + NameRulesOverrides, + ResolvedNameRules, +} from './types'; + +/** + * Creates the shared walker context with the faker accessor expression. + * + * The accessor is `f` — a local variable declared in each function body + * as `const f = options?.faker ?? faker`. + */ +export function createFakerWalkerContext( + tracking: EmitTracking, + circularPointers: Set, + isCircularSchema: boolean, + nameRules: + | { + number?: NameRulesOverrides; + string?: NameRulesOverrides; + } + | undefined, +): FakerWalkerContext { + const optionsId = $('options'); + const fakerAccessor = $('f'); + + return { + circularPointers, + fakerAccessor, + isCircularSchema, + nameRulesByType: { + number: nameRules?.number && mapRules(nameRules.number), + string: nameRules?.string && mapRules(nameRules.string), + }, + optionsId, + tracking, + }; +} + +function mapRules(overrides: NameRulesOverrides): ResolvedNameRules { + const compoundRules: Record = {}; + const exactMatchRules: Record = {}; + const suffixRules: Array<{ rule: NameRule; suffix: string }> = []; + + Object.entries(overrides).forEach(([key, { suffixMatch, ...rule }]) => { + if (key.includes('.')) { + compoundRules[normalizeName(key)] = rule; + } else if (suffixMatch) { + suffixRules.push({ + rule, + suffix: normalizeName(key), + }); + } else { + exactMatchRules[normalizeName(key)] = rule; + } + }); + return { + ...(Object.keys(compoundRules).length > 0 ? { compoundRules } : {}), + ...(Object.keys(exactMatchRules).length > 0 ? { exactMatchRules } : {}), + ...(suffixRules.length > 0 ? { suffixRules } : {}), + }; +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/helpers.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/helpers.ts new file mode 100644 index 0000000000..3a6bbafba5 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/helpers.ts @@ -0,0 +1,5 @@ +/** Strip underscores/hyphens and lowercase for case-insensitive matching. */ +export const normalizeName = (name: string) => name.replace(/[-_]/g, '').toLowerCase(); + +export const getFakerPackagePath = (maybeLocale: string | undefined) => + maybeLocale ? `@faker-js/faker/locale/${maybeLocale}` : '@faker-js/faker'; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation-request.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation-request.ts new file mode 100644 index 0000000000..a29a2e617d --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation-request.ts @@ -0,0 +1,175 @@ +import type { IR } from '@hey-api/shared'; +import { buildSymbolIn, pathToName } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import type { FakerJsFakerPlugin } from '../types'; +import { getFakerPackagePath } from './helpers'; +import type { ProcessorResult } from './processor'; +import type { FakerResult } from './types'; + +interface RequestPart { + key: string; + result: FakerResult; +} + +/** + * Convert a record of IR parameters into an IR object schema. + * Follows the same pattern as valibot's `buildOperationSchema`. + */ +function irParametersToIrSchema( + params: Record, +): IR.SchemaObject | undefined { + const properties: Record = {}; + const required: Array = []; + + for (const key in params) { + const parameter = params[key]!; + properties[parameter.name] = parameter.schema; + if (parameter.required) { + required.push(parameter.name); + } + } + + if (!Object.keys(properties).length) return undefined; + + return { properties, required, type: 'object' }; +} + +/** + * Collect the non-void request parts from an operation. + * Returns an array of { key, schema } entries for body, headers, path, query. + */ +function collectRequestParts( + operation: IR.OperationObject, +): ReadonlyArray<{ key: string; schema: IR.SchemaObject }> { + const parts: Array<{ key: string; schema: IR.SchemaObject }> = []; + + if (operation.body) { + parts.push({ key: 'body', schema: operation.body.schema }); + } + + if (operation.parameters) { + for (const location of ['header', 'path', 'query'] satisfies ReadonlyArray< + keyof typeof operation.parameters + >) { + const params = operation.parameters[location]; + if (!params) continue; + + const propKey = location === 'header' ? 'headers' : location; + const schema = irParametersToIrSchema(params); + if (schema) { + parts.push({ key: propKey, schema }); + } + } + } + + return parts; +} + +/** + * Generate a single request factory per operation that combines + * body, path params, query params, and headers into one object. + */ +export function irOperationRequestToAst({ + operation, + path, + plugin, + processor, + tags, +}: { + operation: IR.OperationObject; + path: ReadonlyArray; + plugin: FakerJsFakerPlugin['Instance']; + processor: ProcessorResult; + tags?: ReadonlyArray; +}): void { + if (!plugin.config.requests.enabled) return; + + const parts = collectRequestParts(operation); + if (parts.length === 0) return; + + // Process each part independently through the processor + const processedParts: Array = []; + let usesFaker = false; + let usesAccessor = false; + + for (const part of parts) { + const result = processor.process({ + export: false, + meta: { + resource: 'operation', + resourceId: operation.id, + role: 'request', + }, + naming: plugin.config.requests, + namingAnchor: operation.id, + path: [...path, 'request', part.key], + plugin, + schema: part.schema, + tags, + }) as FakerResult | void; + + if (!result) continue; + + processedParts.push({ key: part.key, result }); + usesFaker = usesFaker || result.usesFaker; + usesAccessor = usesAccessor || result.usesAccessor; + } + + if (processedParts.length === 0) return; + + // Build combined object expression + let obj = $.object().pretty(); + for (const { key, result } of processedParts) { + obj = obj.prop(key, result.expression); + } + + const name = pathToName([...path, 'request'], { anchor: operation.id }); + + const symbol = plugin.registerSymbol( + buildSymbolIn({ + meta: { + category: 'schema', + path: [...path, 'request'], + resource: 'operation', + resourceId: operation.id, + role: 'request', + tags, + tool: 'faker', + }, + name, + naming: plugin.config.requests, + plugin, + schema: { type: 'object' }, + }), + ); + + // Look up TypeScript Data type for return type annotation + const typeSymbol = plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: 'data', + tool: 'typescript', + }); + + const arrowFn = $.func() + .arrow() + .$if(usesFaker, (f) => f.param('options', (p) => p.optional().type('Options'))) + .$if(typeSymbol, (f) => + f.returns($.type.expr('Omit').generic($.type(typeSymbol!)).generic($.type.literal('url'))), + ) + .$if( + usesAccessor, + (f) => { + const fakerSymbol = plugin.external(`${getFakerPackagePath(plugin.config.locale)}.faker`); + const fDecl = $.const('f').assign( + $.binary($('options').attr('faker').optional(), '??', $(fakerSymbol)), + ); + return f.do(fDecl, $.return(obj)); + }, + (f) => f.do($.return(obj)), + ); + + plugin.node($.const(symbol).export().assign(arrowFn)); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation.ts new file mode 100644 index 0000000000..4eada96070 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/operation.ts @@ -0,0 +1,304 @@ +import type { IR, NamingConfig } from '@hey-api/shared'; +import { buildSymbolIn, operationResponsesMap, pathToName } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import type { FakerJsFakerPlugin } from '../types'; +import { getFakerPackagePath } from './helpers'; +import type { ProcessorResult } from './processor'; +import type { FakerResult } from './types'; + +type ResponseGroup = 'errors' | 'responses'; + +interface MeaningfulResponse { + group: ResponseGroup; + schema: IR.SchemaObject; + statusCode: string; +} + +function isVoidSchema(schema: IR.SchemaObject): boolean { + return schema.type === 'void' || schema.type === 'never'; +} + +function collectMeaningfulResponses( + responses: IR.SchemaObject | undefined, + errors: IR.SchemaObject | undefined, +): ReadonlyArray { + const result: Array = []; + + if (responses?.properties) { + for (const [code, schema] of Object.entries(responses.properties)) { + if (!isVoidSchema(schema)) { + result.push({ group: 'responses', schema, statusCode: code }); + } + } + } + + if (errors?.properties) { + for (const [code, schema] of Object.entries(errors.properties)) { + if (!isVoidSchema(schema)) { + result.push({ group: 'errors', schema, statusCode: code }); + } + } + } + + return result; +} + +/** + * Build a naming config with the status code appended to the template. + * + * For template `'fake{{name}}Response'` and status `'200'`, + * produces `'fake{{name}}Response200'` which resolves to e.g. `fakeGetPetResponse200`. + */ +function suffixedNaming(naming: NamingConfig, statusCode: string): NamingConfig { + return { + ...naming, + name: + typeof naming.name === 'function' + ? (n: string) => (naming.name as (n: string) => string)(n) + statusCode + : (naming.name ?? '') + statusCode, + }; +} + +/** + * Export a per-status-code operation response factory. + * Bypasses the standard `exportAst` pipeline to handle suffixed naming + * and indexed access return types. + */ +function exportOperationResponse({ + group, + naming, + operation, + path, + plugin, + processor, + schema, + statusCode, + tags, +}: { + group: ResponseGroup; + naming: NamingConfig; + operation: IR.OperationObject; + path: ReadonlyArray; + plugin: FakerJsFakerPlugin['Instance']; + processor: ProcessorResult; + schema: IR.SchemaObject; + statusCode: string; + tags?: ReadonlyArray; +}): void { + // Process schema but don't export — we handle export manually + const result = processor.process({ + export: false, + meta: { + resource: 'operation', + resourceId: operation.id, + role: group, + }, + naming, + namingAnchor: operation.id, + path: [...path, group, statusCode], + plugin, + schema, + tags, + }) as FakerResult | void; + + if (!result) return; + + const name = pathToName([...path, 'responses'], { anchor: operation.id }); + + const symbol = plugin.registerSymbol( + buildSymbolIn({ + meta: { + category: 'schema', + path: [...path, group, statusCode], + resource: 'operation', + resourceId: operation.id, + role: 'response', + statusCode, + tags, + tool: 'faker', + }, + name, + naming: suffixedNaming(naming, statusCode), + plugin, + schema, + }), + ); + + // Look up TypeScript type for indexed access return type + // 2XX codes → responses (plural), 4XX/5XX → errors (plural) + const typeSymbol = plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: group, + tool: 'typescript', + }); + + // Use number literal for numeric codes (200), string literal for wildcards (2XX) + const statusLiteral = /^\d+$/.test(statusCode) + ? $.type.literal(Number(statusCode)) + : $.type.literal(statusCode); + + const arrowFn = $.func() + .arrow() + .$if(result.usesFaker, (f) => f.param('options', (p) => p.optional().type('Options'))) + .$if(typeSymbol, (f) => f.returns($.type(typeSymbol!).idx(statusLiteral))) + .$if( + result.usesAccessor, + (f) => { + const fakerSymbol = plugin.external(`${getFakerPackagePath(plugin.config.locale)}.faker`); + const fDecl = $.const('f').assign( + $.binary($('options').attr('faker').optional(), '??', $(fakerSymbol)), + ); + return f.do(fDecl, $.return(result.expression)); + }, + (f) => f.do($.return(result.expression)), + ); + + plugin.node($.const(symbol).export().assign(arrowFn)); +} + +/** + * Export an unsuffixed operation response factory (single meaningful 2XX, no errors). + * Uses manual export with consistent metadata (role: 'response', statusCode). + */ +function exportUnsuffixedResponse({ + naming, + operation, + path, + plugin, + processor, + schema, + statusCode, + tags, +}: { + naming: NamingConfig; + operation: IR.OperationObject; + path: ReadonlyArray; + plugin: FakerJsFakerPlugin['Instance']; + processor: ProcessorResult; + schema: IR.SchemaObject; + statusCode: string; + tags?: ReadonlyArray; +}): void { + const result = processor.process({ + export: false, + meta: { + resource: 'operation', + resourceId: operation.id, + role: 'response', + }, + naming, + namingAnchor: operation.id, + path: [...path, 'responses'], + plugin, + schema, + tags, + }) as FakerResult | void; + + if (!result) return; + + const name = pathToName([...path, 'responses'], { anchor: operation.id }); + + const symbol = plugin.registerSymbol( + buildSymbolIn({ + meta: { + category: 'schema', + path: [...path, 'responses'], + resource: 'operation', + resourceId: operation.id, + role: 'response', + statusCode, + tags, + tool: 'faker', + }, + name, + naming, + plugin, + schema, + }), + ); + + // Look up TypeScript type (singular 'response' role) + const typeSymbol = plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: 'response', + tool: 'typescript', + }); + + const arrowFn = $.func() + .arrow() + .$if(result.usesFaker, (f) => f.param('options', (p) => p.optional().type('Options'))) + .$if(typeSymbol, (f) => f.returns($.type(typeSymbol!))) + .$if( + result.usesAccessor, + (f) => { + const fakerPackagePath = plugin.config.locale + ? `@faker-js/faker/locale/${plugin.config.locale}` + : '@faker-js/faker'; + const fakerSymbol = plugin.external(`${fakerPackagePath}.faker`); + const fDecl = $.const('f').assign( + $.binary($('options').attr('faker').optional(), '??', $(fakerSymbol)), + ); + return f.do(fDecl, $.return(result.expression)); + }, + (f) => f.do($.return(result.expression)), + ); + + plugin.node($.const(symbol).export().assign(arrowFn)); +} + +export function irOperationToAst({ + operation, + path, + plugin, + processor, + tags, +}: { + operation: IR.OperationObject; + path: ReadonlyArray; + plugin: FakerJsFakerPlugin['Instance']; + processor: ProcessorResult; + tags?: ReadonlyArray; +}): void { + if (!plugin.config.responses.enabled || !operation.responses) return; + + const { errors, responses } = operationResponsesMap(operation); + + const meaningful = collectMeaningfulResponses(responses, errors); + if (meaningful.length === 0) return; + + // No suffix only when: exactly 1 useful 2XX response and no useful error responses + const useSuffix = !(meaningful.length === 1 && meaningful[0]!.group === 'responses'); + + if (!useSuffix) { + const entry = meaningful[0]!; + exportUnsuffixedResponse({ + naming: plugin.config.responses, + operation, + path, + plugin, + processor, + schema: entry.schema, + statusCode: entry.statusCode, + tags, + }); + } else { + for (const entry of meaningful) { + exportOperationResponse({ + group: entry.group, + naming: plugin.config.responses, + operation, + path, + plugin, + processor, + schema: entry.schema, + statusCode: entry.statusCode, + tags, + }); + } + } +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/processor.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/processor.ts new file mode 100644 index 0000000000..17ae04cc33 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/processor.ts @@ -0,0 +1,17 @@ +import type { IR, NamingConfig, SchemaProcessorContext } from '@hey-api/shared'; + +import type { FakerJsFakerPlugin } from '../types'; +import type { FakerResult } from './types'; + +export type ProcessorContext = SchemaProcessorContext & { + /** Whether to export the result (default: true) */ + export?: boolean; + naming: NamingConfig; + /** The plugin instance. */ + plugin: FakerJsFakerPlugin['Instance']; + schema: IR.SchemaObject; +}; + +export type ProcessorResult = { + process: (ctx: ProcessorContext) => FakerResult | void; +}; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/shared/types.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/types.ts new file mode 100644 index 0000000000..9f51ad86c8 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/shared/types.ts @@ -0,0 +1,114 @@ +import type ts from 'typescript'; + +import type { $ } from '../../../../ts-dsl'; +import type { MaybeTsDsl } from '../../../../ts-dsl/base'; + +/** + * Any DSL node or raw TS node that represents an expression. + * Broad enough to accept ExprTsDsl, CallTsDsl, ObjectTsDsl, LiteralTsDsl, etc. + */ +export type Expression = MaybeTsDsl; + +/** + * Result from walking a schema node. + */ +export interface FakerResult { + expression: Expression; + /** Whether the expression contains a reference to a circular schema. */ + hasCircularRef?: boolean; + /** Whether the expression produces an object-like value that can be spread. */ + isObjectLike?: boolean; + /** The type of the result - for special handling */ + resultType?: 'never' | 'unknown'; + /** Whether the expression directly references the local `f` accessor. */ + usesAccessor: boolean; + /** Whether the expression depends on the `options` parameter (faker accessor or $ref call). */ + usesFaker: boolean; +} + +/** + * Mutable tracking of which helpers are actually referenced in the generated output. + * Used to conditionally emit helper declarations only when needed. + */ +export interface EmitTracking { + /** + * Tracks whether each exported schema function returns an object-like value + * that can be spread in an intersection. Keyed by JSON pointer (resourceId). + */ + isObjectByRef: Map; + needsMaxCallDepth: boolean; + needsResolveCondition: boolean; + /** + * Tracks whether each exported schema function accepts `options`. + * Keyed by JSON pointer (resourceId). Populated during processing so that + * later `$ref` call sites can omit the argument when the target function + * does not need it (e.g. const-only schemas). + */ + usesFakerByRef: Map; +} + +/** + * Context carried through the walker for building faker expressions. + */ +export interface FakerWalkerContext { + /** Set of JSON pointers that are involved in circular references. */ + circularPointers: Set; + /** + * The `f` identifier — a local variable declared in each function body + * as `const f = options?.faker ?? faker`. + * All leaf nodes chain `.attr()` / `.call()` on this. + */ + fakerAccessor: ReturnType; + /** Whether the current top-level schema being processed is itself circular. */ + isCircularSchema: boolean; + nameRulesByType: { + number?: ResolvedNameRules; + string?: ResolvedNameRules; + }; + /** + * The `options` identifier, used when calling referenced factories. + */ + optionsId: ReturnType; + /** Shared tracking object for conditional helper emission. */ + tracking: EmitTracking; +} + +export interface NameRule { + /** + * Default args for the faker method. Schema constraints merge with these: + * schema values override defaults. + */ + defaultArgs?: string | Record; + /** Faker method path segments, e.g., ['person', 'firstName']. */ + fakerPath: Readonly<[fakeModule: string, fakeFunction: string]>; +} + +/** + * A map of properties and the desired faker methods. + * + * Add `suffixMatch` so the configured rule will be applied as long as + * the property name ends with the provided key. + * + * Supports matching with property ancestor with the pattern + * `.`. + * + * @example + * + * ```ts + * { + * // property matching 'country' exactly -> `faker.location.countryCode('alpha-3')` + * country: { fakerPath: ['location', 'countryCode'], defaultArgs: 'alpha-3' }, + * // property ends with 'id' -> `faker.database.mongodbObjectId()` + * id: { fakerPath: ['database', 'mongodbObjectId'], suffixMatch: true }, + * // property name wih role as ancestor -> `faker.person.jobTitle()` + * 'role.name': { fakerPath: ['person', 'jobTitle'] } + * } + * ``` + */ +export type NameRulesOverrides = Record; + +export type ResolvedNameRules = { + compoundRules?: Record; + exactMatchRules?: Record; + suffixRules?: Array<{ rule: NameRule; suffix: string }>; +}; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/types.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/types.ts index f317f3a3de..0a0b82a092 100644 --- a/packages/openapi-ts/src/plugins/@faker-js/faker/types.ts +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/types.ts @@ -2,6 +2,7 @@ import type { Casing, FeatureToggle, NameTransformer, NamingOptions } from '@hey import type { DefinePlugin, Plugin } from '@hey-api/shared'; import type { IApi } from './api'; +import type { NameRulesOverrides } from './shared/types'; export type UserConfig = Plugin.Name<'@faker-js/faker'> & Plugin.Hooks & @@ -13,6 +14,18 @@ export type UserConfig = Plugin.Name<'@faker-js/faker'> & * @default 'camelCase' */ case?: Casing; + /** + * The compatibility version to target for generated output. + * + * Can be: + * - `9`: [@faker-js/faker v9](https://www.npmjs.com/package/@faker-js/faker/v/9) (default). Requires Node >= 18. + * - `10`: [@faker-js/faker v10](https://www.npmjs.com/package/@faker-js/faker/v/10). Requires Node ^20.19.0. + * + * Both versions produce identical output. + * + * @default 9 + */ + compatibilityVersion?: 9 | 10; /** * Configuration for reusable schema definitions. * @@ -45,16 +58,92 @@ export type UserConfig = Plugin.Name<'@faker-js/faker'> & name?: NameTransformer; }; /** - * Faker locale for generated data. + * Locale for `@faker-js/faker`. When set, the generated import for the + * faker instance will use `@faker-js/faker/locale/{locale}` instead of + * `@faker-js/faker`. * - * @default 'en' + * @see https://fakerjs.dev/guide/localization */ locale?: string; /** - * Seed for deterministic output. When set, Faker will produce - * the same values across runs. + * Maximum recursion depth for circular schema references. + * When the call depth exceeds this value, circular references + * will return empty arrays or be omitted for optional properties. + * + * @default 10 + */ + maxCallDepth?: number; + /** + * Customize the faker method based on property names. + */ + nameRules?: { + /** Name rules for number schema type */ + number?: NameRulesOverrides; + /** Name rules for string schema type */ + string?: NameRulesOverrides; + }; + /** + * Configuration for operation request factories. + * + * Can be: + * - `boolean`: Shorthand for `{ enabled: boolean }` + * - `string` or `function`: Shorthand for `{ name: string | function }` + * - `object`: Full configuration object + */ + requests?: + | boolean + | NameTransformer + | { + /** + * Casing convention for generated names. + * + * @default 'camelCase' + */ + case?: Casing; + /** + * Whether this feature is enabled. + * + * @default true + */ + enabled?: boolean; + /** + * Naming pattern for generated names. + * + * @default 'fake{{name}}Request' + */ + name?: NameTransformer; + }; + /** + * Configuration for operation response factories. + * + * Can be: + * - `boolean`: Shorthand for `{ enabled: boolean }` + * - `string` or `function`: Shorthand for `{ name: string | function }` + * - `object`: Full configuration object */ - seed?: number; + responses?: + | boolean + | NameTransformer + | { + /** + * Casing convention for generated names. + * + * @default 'camelCase' + */ + case?: Casing; + /** + * Whether this feature is enabled. + * + * @default true + */ + enabled?: boolean; + /** + * Naming pattern for generated names. + * + * @default 'fake{{name}}Response' + */ + name?: NameTransformer; + }; }; export type Config = Plugin.Name<'@faker-js/faker'> & @@ -63,12 +152,23 @@ export type Config = Plugin.Name<'@faker-js/faker'> & // Resolvers & { /** Casing convention for generated names. */ case: Casing; + /** The compatibility version to target for generated output. */ + compatibilityVersion: 9 | 10; /** Configuration for reusable schema definitions. */ definitions: NamingOptions & FeatureToggle; - /** Faker locale for generated data. */ - locale: string; - /** Seed for deterministic output. */ - seed?: number; + /** Locale for `@faker-js/faker`. */ + locale?: string; + /** Maximum recursion depth for circular schema references. */ + maxCallDepth: number; + /** Faker method customization based on property name */ + nameRules: { + number?: NameRulesOverrides; + string?: NameRulesOverrides; + }; + /** Configuration for operation request factories. */ + requests: NamingOptions & FeatureToggle; + /** Configuration for operation response factories. */ + responses: NamingOptions & FeatureToggle; }; export type FakerJsFakerPlugin = DefinePlugin; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/api.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/api.ts new file mode 100644 index 0000000000..114f72b150 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/api.ts @@ -0,0 +1,52 @@ +import { ref } from '@hey-api/codegen-core'; +import type { IR } from '@hey-api/shared'; +import { createSchemaWalker } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import type { EmitTracking, Expression, FakerResult } from '../shared/types'; +import type { FakerJsFakerPlugin } from '../types'; +import { createVisitor } from './walker'; + +export function toNodeV10({ + plugin, + schema, +}: { + plugin: FakerJsFakerPlugin['Instance']; + schema: IR.SchemaObject; +}): Expression { + const tracking: EmitTracking = { + isObjectByRef: new Map(), + needsMaxCallDepth: false, + needsResolveCondition: false, + usesFakerByRef: new Map(), + }; + const visitor = createVisitor({ + circularPointers: new Set(), + isCircularSchema: false, + plugin, + tracking, + }); + const walk = createSchemaWalker(visitor); + const result = walk(schema, { path: ref([]), plugin }); + const final = visitor.applyModifiers(result, { path: ref([]), plugin }) as FakerResult; + return final.expression; +} + +export function toNodeRefV10({ + plugin, + schema, +}: { + plugin: FakerJsFakerPlugin['Instance']; + schema: IR.SchemaObject; +}): Expression { + if (schema.$ref) { + const symbol = plugin.referenceSymbol({ + category: 'schema', + resource: 'definition', + resourceId: schema.$ref, + tool: 'faker', + }); + return $(symbol).call($('options')); + } + return toNodeV10({ plugin, schema }); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/plugin.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/plugin.ts new file mode 100644 index 0000000000..e5aed50628 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/plugin.ts @@ -0,0 +1,179 @@ +import { pathToJsonPointer } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import { getFakerPackagePath } from '../shared/helpers'; +import { irOperationToAst } from '../shared/operation'; +import { irOperationRequestToAst } from '../shared/operation-request'; +import type { EmitTracking } from '../shared/types'; +import type { FakerJsFakerPlugin } from '../types'; +import { createProcessor } from './processor'; + +export const handlerV10: FakerJsFakerPlugin['Handler'] = ({ plugin }) => { + plugin.symbol('faker', { + external: getFakerPackagePath(plugin.config.locale), + importKind: 'named', + }); + + plugin.symbol('Faker', { + external: '@faker-js/faker', + kind: 'type', + }); + + // Emit shared Options type + const fakerTypeSymbol = plugin.external('@faker-js/faker.Faker'); + const optionsSymbol = plugin.symbol('Options', { kind: 'type' }); + const optionsType = $.type + .object() + .prop('faker', (p) => p.optional().type($.type(fakerTypeSymbol))) + .prop('includeOptional', (p) => + p + .doc([ + 'Whether to include optional properties, including add property to record object.', + 'Provide a number between 0 and 1 to randomly include based on that probability.', + '@default true', + ]) + .optional() + .type($.type.or($.type('boolean'), $.type('number'))), + ) + .prop('useDefault', (p) => + p + .doc([ + 'Whether to use schema default values instead of generating fake data.', + 'Provide a number between 0 and 1 to randomly use defaults based on that probability.', + '@default false', + ]) + .optional() + .type($.type.or($.type('boolean'), $.type('number'))), + ); + plugin.node($.type.alias(optionsSymbol).export().type(optionsType)); + + // Compute circular schema pointers from the dependency graph + const circularPointers = new Set(); + const graph = plugin.context.graph; + if (graph) { + for (const [pointer, deps] of graph.transitiveDependencies) { + if (deps.has(pointer)) { + circularPointers.add(pointer); + continue; + } + for (const dep of deps) { + if (graph.transitiveDependencies.get(dep)?.has(pointer)) { + circularPointers.add(pointer); + circularPointers.add(dep); + break; + } + } + } + } + + // Reserve slots for conditional helpers — only filled if actually referenced + const maxCallDepthSlot = plugin.node(null); + const resolveConditionSlot = plugin.node(null); + + const tracking: EmitTracking = { + isObjectByRef: new Map(), + needsMaxCallDepth: false, + needsResolveCondition: false, + usesFakerByRef: new Map(), + }; + const processor = createProcessor(plugin, tracking, circularPointers); + + plugin.forEach('operation', 'parameter', 'requestBody', 'schema', (event) => { + switch (event.type) { + case 'operation': + irOperationRequestToAst({ + operation: event.operation, + path: event._path, + plugin, + processor, + tags: event.tags, + }); + irOperationToAst({ + operation: event.operation, + path: event._path, + plugin, + processor, + tags: event.tags, + }); + break; + case 'parameter': + processor.process({ + meta: { + resource: 'definition', + resourceId: pathToJsonPointer(event._path), + }, + naming: plugin.config.definitions, + path: event._path, + plugin, + schema: event.parameter.schema, + tags: event.tags, + }); + break; + case 'requestBody': + processor.process({ + meta: { + resource: 'definition', + resourceId: pathToJsonPointer(event._path), + }, + naming: plugin.config.definitions, + path: event._path, + plugin, + schema: event.requestBody.schema, + tags: event.tags, + }); + break; + case 'schema': + processor.process({ + meta: { + resource: 'definition', + resourceId: pathToJsonPointer(event._path), + }, + naming: plugin.config.definitions, + path: event._path, + plugin, + schema: event.schema, + tags: event.tags, + }); + break; + } + }); + + // Conditionally emit MAX_CALL_DEPTH constant only when circular schemas exist + if (tracking.needsMaxCallDepth) { + const maxCallDepthSymbol = plugin.symbol('MAX_CALL_DEPTH'); + plugin.node( + $.const(maxCallDepthSymbol).assign($.literal(plugin.config.maxCallDepth)), + maxCallDepthSlot, + ); + } + + // Conditionally emit resolveCondition helper only when referenced + if (tracking.needsResolveCondition) { + const conditionParamType = $.type.or($.type('boolean'), $.type('number')); + const resolveConditionFn = $.func() + .arrow() + .param('condition', (p) => p.type(conditionParamType)) + .param('faker', (p) => p.type($.type(fakerTypeSymbol))) + .returns('boolean') + .do( + $.return( + $.binary( + $('condition').eq($.literal(true)), + '||', + $( + $.binary( + $('condition').typeofExpr().eq($.literal('number')), + '&&', + $('faker') + .attr('datatype') + .attr('boolean') + .call($.object().prop('probability', $('condition'))), + ), + ), + ), + ), + ); + const resolveConditionSymbol = plugin.symbol('resolveCondition'); + plugin.node($.const(resolveConditionSymbol).assign(resolveConditionFn), resolveConditionSlot); + } +}; diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/processor.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/processor.ts new file mode 100644 index 0000000000..08fa39c8d3 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/processor.ts @@ -0,0 +1,86 @@ +import { ref } from '@hey-api/codegen-core'; +import type { Hooks, IR } from '@hey-api/shared'; +import { createSchemaProcessor, createSchemaWalker, pathToJsonPointer } from '@hey-api/shared'; + +import { exportAst } from '../shared/export'; +import type { ProcessorContext, ProcessorResult } from '../shared/processor'; +import type { EmitTracking, FakerResult } from '../shared/types'; +import type { FakerJsFakerPlugin } from '../types'; +import { createVisitor } from './walker'; + +export function createProcessor( + plugin: FakerJsFakerPlugin['Instance'], + tracking: EmitTracking, + circularPointers: Set, +): ProcessorResult { + const processor = createSchemaProcessor(); + + const extractorHooks: ReadonlyArray['shouldExtract']> = [ + plugin.config['~hooks']?.schemas?.shouldExtract, + plugin.context.config.parser.hooks.schemas?.shouldExtract, + ]; + + function extractor(ctx: ProcessorContext): IR.SchemaObject { + if (processor.hasEmitted(ctx.path)) { + return ctx.schema; + } + + for (const hook of extractorHooks) { + const result = typeof hook === 'function' ? hook(ctx) : hook; + if (result) { + process({ + namingAnchor: processor.context.anchor, + tags: processor.context.tags, + ...ctx, + }); + return { $ref: pathToJsonPointer(ctx.path) }; + } + } + + return ctx.schema; + } + + function process(ctx: ProcessorContext): FakerResult | void { + if (!processor.markEmitted(ctx.path)) return; + + const shouldExport = ctx.export !== false; + const isCircularSchema = circularPointers.has(ctx.meta.resourceId); + + return processor.withContext({ anchor: ctx.namingAnchor, tags: ctx.tags }, () => { + const visitor = createVisitor({ + circularPointers, + isCircularSchema, + plugin, + schemaExtractor: extractor, + tracking, + }); + const walk = createSchemaWalker(visitor); + + const result = walk(ctx.schema, { + path: ref(ctx.path), + plugin, + }); + + const final = visitor.applyModifiers(result, { + path: ref(ctx.path), + plugin, + }) as FakerResult; + + // Track whether this schema's function accepts options, so that + // later $ref call sites can omit the argument when not needed. + tracking.usesFakerByRef.set(ctx.meta.resourceId, final.usesFaker); + // Track whether this schema produces an object-like value, + // so that intersection handlers know if the result can be spread. + tracking.isObjectByRef.set(ctx.meta.resourceId, !!final.isObjectLike); + + if (shouldExport) { + exportAst({ ...ctx, final, isCircularSchema, plugin }); + return; + } + + return final; + }); + } + + return { process }; +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/array.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/array.ts new file mode 100644 index 0000000000..c24d10baff --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/array.ts @@ -0,0 +1,69 @@ +import type { SchemaVisitorContext, SchemaWithType, Walker } from '@hey-api/shared'; +import { childContext, deduplicateSchema } from '@hey-api/shared'; + +import { $ } from '../../../../../ts-dsl'; +import type { Expression, FakerResult, FakerWalkerContext } from '../../shared/types'; +import type { FakerJsFakerPlugin } from '../../types'; + +/** + * Generates `(options?.faker ?? faker).helpers.multiple(() => )`. + */ +export function arrayToExpression({ + fakerCtx, + schema, + walk, + walkerCtx, +}: { + fakerCtx: FakerWalkerContext; + schema: SchemaWithType<'array'>; + walk: Walker; + walkerCtx: SchemaVisitorContext; +}): { expression: Expression; hasCircularRef: boolean; usesFaker: boolean } { + let normalizedSchema: SchemaWithType<'array'> = schema; + if (normalizedSchema.items) { + normalizedSchema = deduplicateSchema({ schema: normalizedSchema }) as SchemaWithType<'array'>; + } + + let itemExpr: Expression; + let hasCircularRef = false; + + if (normalizedSchema.items && normalizedSchema.items.length > 0) { + // When the array has multiple items with a logicalOperator (e.g. allOf/anyOf on array items), + // construct a wrapper schema so the walker dispatches to intersection/union properly. + const itemSchema = + normalizedSchema.items.length > 1 + ? { items: normalizedSchema.items, logicalOperator: normalizedSchema.logicalOperator } + : normalizedSchema.items[0]!; + const result = walk(itemSchema, childContext(walkerCtx, 'items', 0)); + if (result.resultType === 'never') { + return { expression: $.array(), hasCircularRef: false, usesFaker: false }; + } + itemExpr = result.expression; + hasCircularRef = result.hasCircularRef ?? false; + } else { + itemExpr = $('undefined'); + } + + const callback = $.func().arrow().do($.return(itemExpr)); + + let arrayExpr: Expression; + // faker requires both min and max — fill in sensible defaults when only one is specified + if (schema.minItems !== undefined || schema.maxItems !== undefined) { + const min = schema.minItems ?? 0; + const max = schema.maxItems ?? 100; + const countObj = $.object().prop('min', $.literal(min)).prop('max', $.literal(max)); + const options = $.object().prop('count', countObj); + arrayExpr = fakerCtx.fakerAccessor.attr('helpers').attr('multiple').call(callback, options); + } else { + arrayExpr = fakerCtx.fakerAccessor.attr('helpers').attr('multiple').call(callback); + } + + // For circular refs, guard with depth check: _callDepth > MAX_CALL_DEPTH ? [] : f.helpers.multiple(...) + if (hasCircularRef) { + fakerCtx.tracking.needsMaxCallDepth = true; + const depthExceeded = $('_callDepth').gt($('MAX_CALL_DEPTH')); + arrayExpr = $.ternary(depthExceeded).do($.array()).otherwise(arrayExpr); + } + + return { expression: arrayExpr, hasCircularRef, usesFaker: true }; +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/boolean.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/boolean.ts new file mode 100644 index 0000000000..66e5ef1dc2 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/boolean.ts @@ -0,0 +1,8 @@ +import type { Expression, FakerWalkerContext } from '../../shared/types'; + +/** + * Generates `(options?.faker ?? faker).datatype.boolean()`. + */ +export function booleanToExpression(ctx: FakerWalkerContext): Expression { + return ctx.fakerAccessor.attr('datatype').attr('boolean').call(); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/enum.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/enum.ts new file mode 100644 index 0000000000..824b420395 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/enum.ts @@ -0,0 +1,35 @@ +import type { SchemaWithType } from '@hey-api/shared'; + +import { $ } from '../../../../../ts-dsl'; +import type { Expression, FakerWalkerContext } from '../../shared/types'; + +/** + * Generates `(options?.faker ?? faker).helpers.arrayElement([...values])`. + */ +export function enumToExpression( + ctx: FakerWalkerContext, + schema: SchemaWithType<'enum'>, +): Expression { + const members: Array> = []; + + for (const item of schema.items ?? []) { + if (item.const === null || item.type === 'null') { + members.push($.fromValue(null)); + } else if (item.const !== undefined) { + members.push($.literal(item.const as string | number)); + } + } + + if (!members.length) { + return $('undefined'); + } + + if (members.length === 1 && members[0]) { + return members[0]; + } + + return ctx.fakerAccessor + .attr('helpers') + .attr('arrayElement') + .call($.array(...members)); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/nameRules.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/nameRules.ts new file mode 100644 index 0000000000..e078fbf365 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/nameRules.ts @@ -0,0 +1,315 @@ +import { $ } from '../../../../../ts-dsl'; +import { normalizeName } from '../../shared/helpers'; +import type { Expression, FakerWalkerContext, ResolvedNameRules } from '../../shared/types'; +import type { NameRule } from '../../shared/types'; + +/** + * Property name context extracted from the schema visitor path. + */ +export interface PropertyNameInfo { + name: string; + parent?: string; +} + +// --------------------------------------------------------------------------- +// String name rules (standalone). +// Keys are normalized: lowercase with separators removed, sorted alphabetically. +// --------------------------------------------------------------------------- +const STRING_NAME_RULES: Record = { + accountnumber: { fakerPath: ['finance', 'accountNumber'] }, + address: { fakerPath: ['location', 'streetAddress'] }, + avatar: { fakerPath: ['image', 'avatar'] }, + avatarurl: { fakerPath: ['image', 'avatar'] }, + bio: { fakerPath: ['lorem', 'sentence'] }, + cardnumber: { fakerPath: ['finance', 'creditCardNumber'] }, + city: { fakerPath: ['location', 'city'] }, + color: { fakerPath: ['color', 'human'] }, + colour: { fakerPath: ['color', 'human'] }, + company: { fakerPath: ['company', 'name'] }, + companyname: { fakerPath: ['company', 'name'] }, + contenttype: { fakerPath: ['system', 'mimeType'] }, + country: { fakerPath: ['location', 'country'] }, + countrycode: { fakerPath: ['location', 'countryCode'] }, + creditcard: { fakerPath: ['finance', 'creditCardNumber'] }, + creditcardnumber: { fakerPath: ['finance', 'creditCardNumber'] }, + currency: { fakerPath: ['finance', 'currencyCode'] }, + currencycode: { fakerPath: ['finance', 'currencyCode'] }, + currencyname: { fakerPath: ['finance', 'currencyName'] }, + currencysymbol: { fakerPath: ['finance', 'currencySymbol'] }, + description: { fakerPath: ['lorem', 'sentence'] }, + domain: { fakerPath: ['internet', 'domainName'] }, + domainname: { fakerPath: ['internet', 'domainName'] }, + email: { fakerPath: ['internet', 'email'] }, + emailaddress: { fakerPath: ['internet', 'email'] }, + filename: { fakerPath: ['system', 'fileName'] }, + filepath: { fakerPath: ['system', 'filePath'] }, + firstname: { fakerPath: ['person', 'firstName'] }, + fullname: { fakerPath: ['person', 'fullName'] }, + homepage: { fakerPath: ['internet', 'url'] }, + hostname: { fakerPath: ['internet', 'domainName'] }, + iban: { fakerPath: ['finance', 'iban'] }, + id: { fakerPath: ['string', 'uuid'] }, + imageurl: { fakerPath: ['image', 'url'] }, + ip: { fakerPath: ['internet', 'ip'] }, + ipaddress: { fakerPath: ['internet', 'ip'] }, + isbn: { fakerPath: ['commerce', 'isbn'] }, + jobtitle: { fakerPath: ['person', 'jobTitle'] }, + jwt: { fakerPath: ['internet', 'jwt'] }, + lastname: { fakerPath: ['person', 'lastName'] }, + latitude: { fakerPath: ['location', 'latitude'] }, + longitude: { fakerPath: ['location', 'longitude'] }, + mac: { fakerPath: ['internet', 'mac'] }, + macaddress: { fakerPath: ['internet', 'mac'] }, + middlename: { fakerPath: ['person', 'middleName'] }, + mimetype: { fakerPath: ['system', 'mimeType'] }, + password: { fakerPath: ['internet', 'password'] }, + phone: { fakerPath: ['phone', 'number'] }, + phonenumber: { fakerPath: ['phone', 'number'] }, + postalcode: { fakerPath: ['location', 'zipCode'] }, + productname: { fakerPath: ['commerce', 'productName'] }, + profileimage: { fakerPath: ['image', 'avatar'] }, + semver: { fakerPath: ['system', 'semver'] }, + slug: { fakerPath: ['lorem', 'slug'] }, + state: { fakerPath: ['location', 'state'] }, + street: { fakerPath: ['location', 'street'] }, + streetaddress: { fakerPath: ['location', 'streetAddress'] }, + summary: { fakerPath: ['lorem', 'sentence'] }, + surname: { fakerPath: ['person', 'lastName'] }, + timezone: { fakerPath: ['location', 'timeZone'] }, + title: { fakerPath: ['lorem', 'words'] }, + token: { fakerPath: ['internet', 'jwt'] }, + url: { fakerPath: ['internet', 'url'] }, + useragent: { fakerPath: ['internet', 'userAgent'] }, + username: { fakerPath: ['internet', 'username'] }, + uuid: { fakerPath: ['string', 'uuid'] }, + version: { fakerPath: ['system', 'semver'] }, + website: { fakerPath: ['internet', 'url'] }, + zipcode: { fakerPath: ['location', 'zipCode'] }, +}; + +// --------------------------------------------------------------------------- +// String compound rules (ancestor.property) for ambiguous names. +// Looked up before standalone rules. Keys are "normalizedParent.normalizedProp". +// --------------------------------------------------------------------------- +const STRING_COMPOUND_RULES: Record = { + 'address.city': { fakerPath: ['location', 'city'] }, + 'address.country': { fakerPath: ['location', 'country'] }, + 'address.state': { fakerPath: ['location', 'state'] }, + 'address.street': { fakerPath: ['location', 'streetAddress'] }, + 'author.name': { fakerPath: ['person', 'fullName'] }, + 'book.title': { fakerPath: ['book', 'title'] }, + 'company.name': { fakerPath: ['company', 'name'] }, + 'customer.name': { fakerPath: ['person', 'fullName'] }, + 'employee.name': { fakerPath: ['person', 'fullName'] }, + 'organization.name': { fakerPath: ['company', 'name'] }, + 'owner.name': { fakerPath: ['person', 'fullName'] }, + 'person.name': { fakerPath: ['person', 'fullName'] }, + 'product.description': { fakerPath: ['commerce', 'productDescription'] }, + 'product.name': { fakerPath: ['commerce', 'productName'] }, + 'user.name': { fakerPath: ['person', 'fullName'] }, +}; + +// --------------------------------------------------------------------------- +// String suffix rules — checked after exact/compound matches. +// Order matters: first match wins. Suffixes are matched against normalized names. +// --------------------------------------------------------------------------- +const STRING_SUFFIX_RULES: Array<{ rule: NameRule; suffix: string }> = [ + { rule: { fakerPath: ['string', 'uuid'] }, suffix: 'Id' }, + { rule: { fakerPath: ['internet', 'email'] }, suffix: 'Email' }, + { rule: { fakerPath: ['internet', 'url'] }, suffix: 'Url' }, + { rule: { fakerPath: ['phone', 'number'] }, suffix: 'Phone' }, +]; + +// --------------------------------------------------------------------------- +// Integer / number name rules (standalone). +// --------------------------------------------------------------------------- +const NUMBER_NAME_RULES: Record = { + age: { defaultArgs: { max: 120, min: 1 }, fakerPath: ['number', 'int'] }, + amount: { defaultArgs: { max: 10000, min: 0 }, fakerPath: ['number', 'float'] }, + count: { defaultArgs: { max: 1000, min: 0 }, fakerPath: ['number', 'int'] }, + port: { fakerPath: ['internet', 'port'] }, + price: { defaultArgs: { max: 10000, min: 0 }, fakerPath: ['number', 'float'] }, + quantity: { defaultArgs: { max: 100, min: 1 }, fakerPath: ['number', 'int'] }, +}; + +// --------------------------------------------------------------------------- +// Helpers +// --------------------------------------------------------------------------- + +/** + * Extract the property name and its parent context from a schema visitor path. + * + * Path examples: + * - `['components', 'schemas', 'User', 'properties', 'name']` + * -> `{ name: 'name', parent: 'User' }` + * - `['...', 'properties', 'address', 'properties', 'street']` + * -> `{ name: 'street', parent: 'address' }` + */ +export function propertyNameFromPath( + path: ReadonlyArray, +): PropertyNameInfo | undefined { + for (let i = path.length - 1; i >= 1; i--) { + if (path[i - 1] === 'properties' && typeof path[i] === 'string') { + const name = path[i] as string; + // The segment before the 'properties' keyword is the parent + const parentSegment = i >= 2 ? path[i - 2] : undefined; + const parent = + typeof parentSegment === 'string' && parentSegment !== 'properties' + ? parentSegment + : undefined; + return { name, parent }; + } + } + return undefined; +} + +/** + * Build a faker expression from a data-driven {@link NameRule}. + * Optionally merges schema numeric constraints with rule defaults. + */ +function buildFromRule( + ctx: FakerWalkerContext, + rule: NameRule, + schemaArgs?: { max?: number; min?: number }, +): Expression { + const fakerMethod = ctx.fakerAccessor.attr(rule.fakerPath[0]).attr(rule.fakerPath[1]); + + // Merge: schema constraints override rule defaults + const merged = + (rule.defaultArgs || schemaArgs) && typeof rule.defaultArgs === 'object' + ? { ...rule.defaultArgs, ...schemaArgs } + : rule.defaultArgs || schemaArgs; + + if (merged) { + return $(fakerMethod).call($.fromValue(merged)); + } + + return $(fakerMethod).call(); +} + +interface RuleLookupResult { + /** + * Whether this rule came from user-provided `nameRules` config. + * User overrides are treated as intentional and complete — schema constraints + * (like min/max from the OpenAPI spec) are NOT merged into their `defaultArgs`. + * Built-in rules use `defaultArgs` as sensible defaults that schema constraints + * can refine (e.g. `age` defaults to min:1/max:120, but schema `minimum: 18` + * narrows it). + */ + isUserOverride: boolean; + rule: NameRule; +} + +/** Look up compound key first, then standalone key. User overrides take priority. */ +function lookupRule( + nameInfo: PropertyNameInfo, + standaloneMap: Record, + compoundMap: Record, + nameRuleOverrides: ResolvedNameRules | undefined, +): RuleLookupResult | undefined { + const normalizedProp = normalizeName(nameInfo.name); + + if (nameInfo.parent) { + const compoundKey = `${normalizeName(nameInfo.parent)}.${normalizedProp}`; + + if (nameRuleOverrides?.compoundRules) { + const computeRuleOverride = nameRuleOverrides.compoundRules[compoundKey]; + + if (computeRuleOverride) { + return { isUserOverride: true, rule: computeRuleOverride }; + } + } + + const compoundRule = compoundMap[compoundKey]; + if (compoundRule) { + return { isUserOverride: false, rule: compoundRule }; + } + } + + const ruleOverride = nameRuleOverrides?.exactMatchRules?.[normalizedProp]; + + if (ruleOverride) { + return { isUserOverride: true, rule: ruleOverride }; + } + + const standaloneRule = standaloneMap[normalizedProp]; + if (standaloneRule) { + return { isUserOverride: false, rule: standaloneRule }; + } + + return undefined; +} + +/** + * Attempt to resolve a string faker expression from the property name. + * Returns `undefined` when no rule matches. + * + * String name rules don't receive schema constraints (minLength/maxLength) because + * each faker method has its own concept of "length" (characters, words, sentences). + * We trust that name-matched methods produce reasonable output by default. + */ +export function stringNameToExpression( + ctx: FakerWalkerContext, + nameInfo: PropertyNameInfo, +): Expression | undefined { + const nameRuleOverrides = ctx.nameRulesByType.string; + const result = lookupRule(nameInfo, STRING_NAME_RULES, STRING_COMPOUND_RULES, nameRuleOverrides); + if (result) { + return buildFromRule(ctx, result.rule); + } + + if (nameRuleOverrides?.suffixRules) { + const suffixRuleOverride = nameRuleOverrides.suffixRules.find((r) => + nameInfo.name.endsWith(r.suffix), + ); + + if (suffixRuleOverride) { + return buildFromRule(ctx, suffixRuleOverride.rule); + } + } + + const suffixRule = STRING_SUFFIX_RULES.find((r) => nameInfo.name.endsWith(r.suffix)); + if (suffixRule) { + return buildFromRule(ctx, suffixRule.rule); + } + + return undefined; +} + +/** + * Attempt to resolve a number/integer faker expression from the property name. + * + * For built-in rules, schema constraints (min/max from the OpenAPI spec) are merged + * with rule defaults — schema values override defaults. For user-provided overrides + * via `nameRules` config, `defaultArgs` are used as-is because the user intentionally + * chose both the faker method and its arguments. + * + * Returns `undefined` when no rule matches. + */ +export function numberNameToExpression( + ctx: FakerWalkerContext, + nameInfo: PropertyNameInfo, + schemaArgs?: { max?: number; min?: number }, +): Expression | undefined { + const nameRuleOverrides = ctx.nameRulesByType.number; + const result = lookupRule(nameInfo, NUMBER_NAME_RULES, {}, nameRuleOverrides); + + if (result) { + // Only merge schema constraints for built-in rules. User overrides are intentional + // and complete — their defaultArgs should not be overridden by schema constraints. + return buildFromRule(ctx, result.rule, result.isUserOverride ? undefined : schemaArgs); + } + + if (nameRuleOverrides?.suffixRules) { + const suffixRuleOverride = nameRuleOverrides.suffixRules.find((r) => + nameInfo.name.endsWith(r.suffix), + ); + + if (suffixRuleOverride) { + // Suffix overrides are always user-provided — don't merge schema constraints + return buildFromRule(ctx, suffixRuleOverride.rule); + } + } + + return undefined; +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/number.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/number.ts new file mode 100644 index 0000000000..b28dedbf93 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/number.ts @@ -0,0 +1,69 @@ +import type { SchemaWithType } from '@hey-api/shared'; + +import { $ } from '../../../../../ts-dsl'; +import type { Expression, FakerWalkerContext } from '../../shared/types'; +import type { PropertyNameInfo } from './nameRules'; +import { numberNameToExpression } from './nameRules'; + +/** + * Generates `(options?.faker ?? faker).number.int()` or `.float()`, + * with optional `{ min, max }` constraints and property-name inference. + * + * For number types, schema constraints and name-based defaults are **merged**: + * schema values override rule defaults. + */ +export function numberToExpression( + ctx: FakerWalkerContext, + schema: SchemaWithType<'integer' | 'number'>, + nameInfo?: PropertyNameInfo, +): Expression { + const isInteger = schema.type === 'integer'; + const method = isInteger ? 'int' : 'float'; + + let min: number | undefined; + let max: number | undefined; + + // For floats, exclusive bounds are passed as-is to faker's min/max options, + // which treats them as inclusive. This is technically not strictly exclusive, + // but fine in practice since the chance of hitting the exact bound is negligible. + if (schema.exclusiveMinimum !== undefined) { + min = isInteger ? schema.exclusiveMinimum + 1 : schema.exclusiveMinimum; + } else if (schema.minimum !== undefined) { + min = schema.minimum; + } + + if (schema.exclusiveMaximum !== undefined) { + max = isInteger ? schema.exclusiveMaximum - 1 : schema.exclusiveMaximum; + } else if (schema.maximum !== undefined) { + max = schema.maximum; + } + + // Try property-name-based inference with merged constraints + if (nameInfo) { + const schemaArgs: { max?: number; min?: number } = {}; + if (min !== undefined) { + schemaArgs.min = min; + } + if (max !== undefined) { + schemaArgs.max = max; + } + const nameExpr = numberNameToExpression(ctx, nameInfo, schemaArgs); + if (nameExpr) { + return nameExpr; + } + } + + // Existing constraint-based logic + if (min !== undefined || max !== undefined) { + const options = $.object(); + if (min !== undefined) { + options.prop('min', $.literal(min)); + } + if (max !== undefined) { + options.prop('max', $.literal(max)); + } + return ctx.fakerAccessor.attr('number').attr(method).call(options); + } + + return ctx.fakerAccessor.attr('number').attr(method).call(); +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/object.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/object.ts new file mode 100644 index 0000000000..6286021438 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/object.ts @@ -0,0 +1,125 @@ +import type { SchemaVisitorContext, SchemaWithType, Walker } from '@hey-api/shared'; +import { childContext } from '@hey-api/shared'; + +import { $ } from '../../../../../ts-dsl'; +import type { Expression, FakerResult, FakerWalkerContext } from '../../shared/types'; +import type { FakerJsFakerPlugin } from '../../types'; + +/** + * Generates an object literal `{ prop: , ... }`. + * + * Required properties are always included. Optional properties are + * conditionally included based on `options.includeOptional`: + * - `true` or `undefined` (default) — always included + * - number (0.0-1.0) — included with that probability + * - `false` — omitted entirely + */ +export function objectToExpression({ + fakerCtx, + schema, + walk, + walkerCtx, +}: { + fakerCtx: FakerWalkerContext; + schema: SchemaWithType<'object'>; + walk: Walker; + walkerCtx: SchemaVisitorContext; +}): FakerResult { + const obj = $.object().pretty(); + const requiredSet = new Set(schema.required ?? []); + let usesAccessor = false; + let hasCircularRef = false; + let hasEmittedProperty = false; + + for (const name in schema.properties) { + const property = schema.properties[name]!; + const result = walk(property, childContext(walkerCtx, 'properties', name)); + if (result.hasCircularRef) hasCircularRef = true; + + if (requiredSet.has(name)) { + if (result.resultType === 'never') { + return { + expression: $('undefined'), + hasCircularRef: false, + isObjectLike: false, + resultType: 'never', + usesAccessor: false, + usesFaker: false, + }; + } + hasEmittedProperty = true; + obj.prop(name, result.expression); + if (result.usesAccessor) usesAccessor = true; + } else if (result.resultType === 'never') { + // Optional property that can never be satisfied — skip entirely + continue; + } else { + // Optional property: conditionally spread based on options.includeOptional + hasEmittedProperty = true; + fakerCtx.tracking.needsResolveCondition = true; + usesAccessor = true; + const includeCondition = $('resolveCondition').call( + $.binary($(fakerCtx.optionsId).attr('includeOptional').optional(), '??', $.literal(true)), + fakerCtx.fakerAccessor, + ); + + // For circular refs, add depth guard: _callDepth > MAX_CALL_DEPTH || !resolveCondition(...) + let skipCondition: Expression; + if (result.hasCircularRef) { + fakerCtx.tracking.needsMaxCallDepth = true; + const depthExceeded = $('_callDepth').gt($('MAX_CALL_DEPTH')); + skipCondition = $.binary(depthExceeded, '||', $.prefix(includeCondition).not()); + } else { + skipCondition = $.prefix(includeCondition).not(); + } + + const propObj = $.object().prop(name, result.expression); + obj.spread($.ternary(skipCondition).do($.object()).otherwise(propObj)); + } + } + + let expression: Expression = obj; + + let hasAdditionalPropertyExpression = false; + + if (!hasEmittedProperty && schema.additionalProperties) { + const extraProperty = schema.additionalProperties; + const result = walk(extraProperty, childContext(walkerCtx, 'additionalProperties')); + + // If we can't produce meaningful data for dictionary object, just skip it + if (result.resultType !== 'never' && result.resultType !== 'unknown') { + hasAdditionalPropertyExpression = true; + if (result.hasCircularRef) hasCircularRef = true; + + // Because dictionary can be empty, so we add `includeOptional` check + fakerCtx.tracking.needsResolveCondition = true; + usesAccessor = true; + const includeCondition = $('resolveCondition').call( + $.binary($(fakerCtx.optionsId).attr('includeOptional').optional(), '??', $.literal(true)), + fakerCtx.fakerAccessor, + ); + + let skipCondition: Expression; + if (result.hasCircularRef) { + fakerCtx.tracking.needsMaxCallDepth = true; + const depthExceeded = $('_callDepth').gt($('MAX_CALL_DEPTH')); + skipCondition = $.binary(depthExceeded, '||', $.prefix(includeCondition).not()); + } else { + skipCondition = $.prefix(includeCondition).not(); + } + + expression = $.ternary(skipCondition) + .do($.object().as('{}')) + // Hardcode to additionalProp property - unless we want to extend object DSL + .otherwise($.object().pretty().prop('additionalProp', result.expression)); + } + } + + return { + expression, + hasCircularRef, + isObjectLike: true, + usesAccessor, + usesFaker: hasEmittedProperty || hasAdditionalPropertyExpression, + }; +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/string.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/string.ts new file mode 100644 index 0000000000..96dd6df91e --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/toAst/string.ts @@ -0,0 +1,86 @@ +import type { SchemaWithType } from '@hey-api/shared'; + +import { $ } from '../../../../../ts-dsl'; +import type { Expression, FakerWalkerContext } from '../../shared/types'; +import type { PropertyNameInfo } from './nameRules'; +import { stringNameToExpression } from './nameRules'; + +/** + * Generates a faker expression for a string schema, respecting format, + * pattern, property name, and length constraints. + * + * Priority: format > pattern > property name > length constraints > fallback. + */ +export function stringToExpression( + ctx: FakerWalkerContext, + schema: SchemaWithType<'string'>, + nameInfo?: PropertyNameInfo, +): Expression { + // 1. Format-specific faker methods + const formatExpr = formatToExpression(ctx, schema.format); + if (formatExpr) { + return formatExpr; + } + + // 2. Pattern → faker.helpers.fromRegExp(pattern) + if (schema.pattern) { + return ctx.fakerAccessor.attr('helpers').attr('fromRegExp').call($.literal(schema.pattern)); + } + + // 3. Property name inference → semantic faker helpers + if (nameInfo) { + const nameExpr = stringNameToExpression(ctx, nameInfo); + if (nameExpr) { + return nameExpr; + } + } + + // 4. Length constraints → faker.string.alpha({ length: { min, max } }) + // faker requires both min and max — fill in sensible defaults when only one is specified + if (schema.minLength !== undefined || schema.maxLength !== undefined) { + const min = schema.minLength ?? 0; + const max = schema.maxLength ?? 100; + const lengthObj = $.object().prop('min', $.literal(min)).prop('max', $.literal(max)); + return ctx.fakerAccessor + .attr('string') + .attr('alpha') + .call($.object().prop('length', lengthObj)); + } + + // 5. Fallback + return ctx.fakerAccessor.attr('string').attr('sample').call(); +} + +function formatToExpression( + ctx: FakerWalkerContext, + format: string | undefined, +): Expression | undefined { + switch (format) { + case 'date': + return ctx.fakerAccessor + .attr('date') + .attr('recent') + .call() + .attr('toISOString') + .call() + .attr('slice') + .call($.literal(0), $.literal(10)); + case 'date-time': + return ctx.fakerAccessor.attr('date').attr('recent').call().attr('toISOString').call(); + case 'email': + return ctx.fakerAccessor.attr('internet').attr('email').call(); + case 'ipv4': + return ctx.fakerAccessor.attr('internet').attr('ipv4').call(); + case 'ipv6': + return ctx.fakerAccessor.attr('internet').attr('ipv6').call(); + case 'uri': + case 'url': + return ctx.fakerAccessor.attr('internet').attr('url').call(); + case 'uuid': + return ctx.fakerAccessor.attr('string').attr('uuid').call(); + case 'binary': + return $.new('Blob').arg($.array(ctx.fakerAccessor.attr('image').attr('dataUri').call())); + default: + return undefined; + } +} diff --git a/packages/openapi-ts/src/plugins/@faker-js/faker/v10/walker.ts b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/walker.ts new file mode 100644 index 0000000000..39aaf4be04 --- /dev/null +++ b/packages/openapi-ts/src/plugins/@faker-js/faker/v10/walker.ts @@ -0,0 +1,426 @@ +import type { SymbolMeta } from '@hey-api/codegen-core'; +import { fromRef } from '@hey-api/codegen-core'; +import type { IR, SchemaExtractor, SchemaVisitor } from '@hey-api/shared'; +import { childContext, pathToJsonPointer } from '@hey-api/shared'; + +import { $ } from '../../../../ts-dsl'; +import { createFakerWalkerContext } from '../shared/faker-expr'; +import type { ProcessorContext } from '../shared/processor'; +import type { EmitTracking, Expression, FakerResult, FakerWalkerContext } from '../shared/types'; +import type { FakerJsFakerPlugin } from '../types'; +import { arrayToExpression } from './toAst/array'; +import { booleanToExpression } from './toAst/boolean'; +import { enumToExpression } from './toAst/enum'; +import { propertyNameFromPath } from './toAst/nameRules'; +import { numberToExpression } from './toAst/number'; +import { objectToExpression } from './toAst/object'; +import { stringToExpression } from './toAst/string'; + +export interface VisitorConfig { + /** Set of JSON pointers involved in circular references. */ + circularPointers: Set; + /** Whether the current top-level schema is itself circular. */ + isCircularSchema: boolean; + plugin: FakerJsFakerPlugin['Instance']; + /** Optional schema extractor function. */ + schemaExtractor?: SchemaExtractor; + /** Shared tracking for conditional helper emission. */ + tracking: EmitTracking; +} + +const FALLBACK_UNDEFINED: FakerResult = { + expression: $('undefined'), + isObjectLike: false, + usesAccessor: false, + usesFaker: false, +}; + +/** + * Detect discriminator constraint schemas: objects where every property has a `const` value. + * These are generated by the IR parser for discriminated unions. + */ +function isDiscriminatorConstraint(schema: IR.SchemaObject): boolean { + if (schema.type !== 'object' || !schema.properties) return false; + const props = schema.properties; + return Object.keys(props).every((key) => props[key]!.const !== undefined); +} + +export function createVisitor( + config: VisitorConfig, +): SchemaVisitor { + const { circularPointers, isCircularSchema, plugin, schemaExtractor, tracking } = config; + const fakerCtx: FakerWalkerContext = createFakerWalkerContext( + tracking, + circularPointers, + isCircularSchema, + plugin.config.nameRules, + ); + + return { + applyModifiers(result) { + return result; + }, + array(schema, ctx, walk) { + const result = arrayToExpression({ fakerCtx, schema, walk, walkerCtx: ctx }); + return { + expression: result.expression, + hasCircularRef: result.hasCircularRef, + isObjectLike: false, + usesAccessor: result.usesFaker, + usesFaker: result.usesFaker, + }; + }, + boolean() { + return { + expression: booleanToExpression(fakerCtx), + isObjectLike: false, + usesAccessor: true, + usesFaker: true, + }; + }, + enum(schema) { + const expression = enumToExpression(fakerCtx, schema); + // Count valid enum members — only multi-member enums use faker.helpers.arrayElement. + // Single-member enums (e.g. OpenAPI 3.0 const via `enum: [value]`) resolve to a + // plain literal and don't need faker. + const memberCount = + schema.items?.filter((item) => item.const !== undefined || item.type === 'null').length ?? + 0; + const needsFaker = memberCount > 1; + return { + expression, + isObjectLike: false, + usesAccessor: needsFaker, + usesFaker: needsFaker, + }; + }, + integer(schema, ctx) { + const nameInfo = propertyNameFromPath(fromRef(ctx.path)); + return { + expression: numberToExpression(fakerCtx, schema, nameInfo), + isObjectLike: false, + usesAccessor: true, + usesFaker: true, + }; + }, + intercept(schema, ctx, walk) { + // const values are always emitted as literals + if (schema.const !== undefined) { + return { + expression: $.fromValue(schema.const), + isObjectLike: typeof schema.const === 'object' && schema.const !== null, + usesAccessor: false, + usesFaker: false, + }; + } + + if (schemaExtractor && !schema.$ref) { + const extracted = schemaExtractor({ + meta: { + resource: 'definition', + resourceId: pathToJsonPointer(fromRef(ctx.path)), + }, + naming: ctx.plugin.config.definitions, + path: fromRef(ctx.path), + plugin: ctx.plugin, + schema, + }); + + if (extracted !== schema) { + return walk(extracted, ctx); + } + } + }, + intersection(items, schemas) { + if (items.length === 0) { + return FALLBACK_UNDEFINED; + } + if (items.length === 1 && items[0]) { + return items[0]; + } + + // Check if all items produce object-like values that can be spread. + // Uses the walked results rather than schema structure, since $ref and + // union schemas may resolve to non-object types at runtime. + const allSpreadable = items.every((item) => item.isObjectLike); + + if (!allSpreadable) { + // Detect impossible intersections where types can never be satisfied. + // Collect the distinct "kind" of each schema: primitive type name, 'object' for objects/$refs, + // or 'composite' for nested logical operators. + const kinds = new Set( + schemas.map((s) => { + if (s.$ref || s.type === 'object') { + return 'object'; + } + if (s.items && s.logicalOperator) { + return 'composite'; + } + return s.type; // primitive type: 'string', 'number', 'boolean', 'array' + }), + ); + // More than one kind means incompatible types (e.g. string & object, number & string) + if (kinds.size > 1) { + return { + ...FALLBACK_UNDEFINED, + resultType: 'never', + }; + } + return items[0]!; + } + + // Reorder so discriminator constraint objects (all-const properties) are spread last + const indexed = items.map((item, i) => ({ item, schema: schemas[i]! })); + const regular: typeof indexed = []; + const discriminators: typeof indexed = []; + + for (const entry of indexed) { + if (isDiscriminatorConstraint(entry.schema)) { + discriminators.push(entry); + } else { + regular.push(entry); + } + } + + // Use Object.assign({}, ...items) instead of spread to merge regular items + const assignCall = $('Object') + .attr('assign') + .call($.object(), ...regular.map(({ item }) => item.expression)); + + let expression: Expression; + if (discriminators.length > 0) { + // Wrap with spread and emit discriminator constraint properties with `as const` + const obj = $.object().pretty(); + obj.spread(assignCall); + for (const { schema } of discriminators) { + for (const key of Object.keys(schema.properties!)) { + obj.prop(key, $($.fromValue(schema.properties![key]!.const)).as('const')); + } + } + expression = obj; + } else { + expression = assignCall; + } + + return { + expression, + hasCircularRef: items.some((item) => item.hasCircularRef), + isObjectLike: true, + usesAccessor: items.some((item) => item.usesAccessor), + usesFaker: items.some((item) => item.usesFaker), + }; + }, + never() { + // Skip never expression + return { + ...FALLBACK_UNDEFINED, + resultType: 'never', + }; + }, + null() { + return { + expression: $.fromValue(null), + isObjectLike: false, + usesAccessor: false, + usesFaker: false, + }; + }, + number(schema, ctx) { + const nameInfo = propertyNameFromPath(fromRef(ctx.path)); + return { + expression: numberToExpression(fakerCtx, schema, nameInfo), + isObjectLike: false, + usesAccessor: true, + usesFaker: true, + }; + }, + object(schema, ctx, walk) { + return objectToExpression({ fakerCtx, schema, walk, walkerCtx: ctx }); + }, + postProcess(result, schema) { + // resolveCondition(options?.useDefault ?? false, f) ? : + if (schema.default !== undefined && result.usesFaker) { + tracking.needsResolveCondition = true; + const condition = $('resolveCondition').call( + $.binary($(fakerCtx.optionsId).attr('useDefault').optional(), '??', $.literal(false)), + fakerCtx.fakerAccessor, + ); + const defaultExpr = $.fromValue(schema.default); + return { + expression: $.ternary(condition).do(defaultExpr).otherwise(result.expression), + hasCircularRef: result.hasCircularRef, + usesAccessor: true, + usesFaker: true, + }; + } + return result; + }, + reference($ref, _schema, ctx) { + const query: SymbolMeta = { + category: 'schema', + resource: 'definition', + resourceId: $ref, + tool: 'faker', + }; + + const refSymbol = ctx.plugin.referenceSymbol(query); + // Only emit depth-aware call sites when the enclosing schema is itself + // circular — `_callDepth` is only declared as a parameter for circular + // schemas. Non-circular schemas that reference a circular one just call + // it normally; the circular schema starts its own depth tracking from 0. + const isCircularRef = fakerCtx.isCircularSchema && fakerCtx.circularPointers.has($ref); + // Look up whether the referenced function accepts options. + // Schemas are walked in dependency order, so the target is already processed. + // For circular references (A→B→A or A→A) the target may not be in the map + // yet; we fall back to true which is safe since options is always optional. + const refUsesFaker = fakerCtx.tracking.usesFakerByRef.get($ref) ?? true; + // Look up whether the referenced function returns an object-like value. + // For circular references, fall back to true (circular schemas are typically objects). + const refIsObjectLike = fakerCtx.tracking.isObjectByRef.get($ref) ?? true; + + return { + expression: isCircularRef + ? $(refSymbol).call(fakerCtx.optionsId, $('_callDepth').plus($.literal(1))) + : refUsesFaker + ? $(refSymbol).call(fakerCtx.optionsId) + : $(refSymbol).call(), + hasCircularRef: isCircularRef, + isObjectLike: refIsObjectLike, + usesAccessor: false, + usesFaker: refUsesFaker, + }; + }, + string(schema, ctx) { + const nameInfo = propertyNameFromPath(fromRef(ctx.path)); + return { + expression: stringToExpression(fakerCtx, schema, nameInfo), + isObjectLike: false, + usesAccessor: true, + usesFaker: true, + }; + }, + tuple(schema, ctx, walk) { + const elements: Array = []; + let anyChildUsesFaker = false; + let anyChildUsesAccessor = false; + let anyChildHasCircularRef = false; + for (let i = 0; i < (schema.items?.length ?? 0); i++) { + const item = schema.items![i]!; + const result = walk(item, childContext(ctx, 'items', i)); + if (result.resultType === 'never') { + return { + ...FALLBACK_UNDEFINED, + resultType: 'never' as const, + }; + } + elements.push(result.expression); + if (result.usesFaker) anyChildUsesFaker = true; + if (result.usesAccessor) anyChildUsesAccessor = true; + if (result.hasCircularRef) anyChildHasCircularRef = true; + } + return { + expression: $.array(...elements), + hasCircularRef: anyChildHasCircularRef, + isObjectLike: false, + usesAccessor: anyChildUsesAccessor, + usesFaker: anyChildUsesFaker, + }; + }, + undefined() { + return FALLBACK_UNDEFINED; + }, + union(items, schemas) { + // Discard impossible branches (e.g. allOf that resolved to never) + const viableItems = items.filter((item) => item.resultType !== 'never'); + + if (viableItems.length === 0) { + return { + ...FALLBACK_UNDEFINED, + resultType: 'never', + }; + } + if (viableItems.length === 1 && viableItems[0]) { + return viableItems[0]; + } + + const viableSchemas = schemas.filter((_, i) => items[i]?.resultType !== 'never'); + const nullIndex = viableSchemas.findIndex((s) => s.type === 'null'); + const hasNull = nullIndex !== -1; + const nonNullItems = hasNull ? viableItems.filter((_, i) => i !== nullIndex) : viableItems; + + if (nonNullItems.length === 0) { + return { + expression: $.fromValue(null), + isObjectLike: false, + usesAccessor: false, + usesFaker: false, + }; + } + + // Nullable union with exactly one non-null variant: simple ternary + if (hasNull && nonNullItems.length === 1) { + let expression = $.ternary(fakerCtx.fakerAccessor.attr('datatype').attr('boolean').call()) + .do(nonNullItems[0]!.expression) + .otherwise($.fromValue(null)); + + // Depth guard: _callDepth > MAX_CALL_DEPTH ? null : (ternary) + if (nonNullItems[0]!.hasCircularRef) { + fakerCtx.tracking.needsMaxCallDepth = true; + expression = $.ternary($('_callDepth').gt($('MAX_CALL_DEPTH'))) + .do($.fromValue(null)) + .otherwise(expression); + } + + return { + expression, + hasCircularRef: nonNullItems[0]!.hasCircularRef, + isObjectLike: nonNullItems[0]!.isObjectLike, + usesAccessor: true, + usesFaker: true, + }; + } + + const possibleValues = nonNullItems.map((item) => item.expression); + if (hasNull) { + possibleValues.push($.fromValue(null)); + } + + // faker.helpers.arrayElement([v1(), v2(), ...]) + let expression: Expression = $( + fakerCtx.fakerAccessor + .attr('helpers') + .attr('arrayElement') + .call($.array(...possibleValues)), + ); + + const hasCircularRef = items.some((item) => item.hasCircularRef); + + // Depth guard for nullable unions with circular refs + if (hasNull && hasCircularRef) { + fakerCtx.tracking.needsMaxCallDepth = true; + expression = $.ternary($('_callDepth').gt($('MAX_CALL_DEPTH'))) + .do($.fromValue(null)) + .otherwise(expression); + } + + return { + expression, + hasCircularRef, + // Union is object-like only if all non-null items are object-like + isObjectLike: nonNullItems.every((item) => item.isObjectLike), + usesAccessor: true, + usesFaker: true, + }; + }, + unknown() { + return { + ...FALLBACK_UNDEFINED, + resultType: 'unknown', + }; + }, + + void() { + return FALLBACK_UNDEFINED; + }, + }; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea39f5886e..a07887eca5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1327,7 +1327,7 @@ importers: version: 1.8.0 nuxt: specifier: '>=3.0.0' - version: 3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.4)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.9.2)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@3.29.5)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue-tsc@3.2.4(typescript@5.9.3)) + version: 3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.2)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.7.0)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@3.29.5)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue-tsc@3.2.4(typescript@5.9.3)) vue: specifier: '>=3.5.13' version: 3.5.13(typescript@5.9.3) @@ -1465,7 +1465,7 @@ importers: version: 1.14.3 nuxt: specifier: 3.14.1592 - version: 3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.2)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.7.0)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@4.56.0)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue-tsc@3.2.4(typescript@5.9.3)) + version: 3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.4)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.9.2)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@4.56.0)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue-tsc@3.2.4(typescript@5.9.3)) ofetch: specifier: 1.5.1 version: 1.5.1 @@ -1485,6 +1485,18 @@ importers: specifier: 0.16.0 version: 0.16.0 + packages/openapi-ts-tests/faker/v10: + devDependencies: + '@faker-js/faker': + specifier: ^10.4.0 + version: 10.4.0 + '@hey-api/openapi-ts': + specifier: workspace:* + version: link:../../../openapi-ts + typescript: + specifier: 5.9.3 + version: 5.9.3 + packages/openapi-ts-tests/main: devDependencies: '@angular-devkit/build-angular': @@ -3894,6 +3906,10 @@ packages: '@noble/hashes': optional: true + '@faker-js/faker@10.4.0': + resolution: {integrity: sha512-sDBWI3yLy8EcDzgobvJTWq1MJYzAkQdpjXuPukga9wXonhpMRvd1Izuo2Qgwey2OiEoRIBr35RMU9HJRoOHzpw==} + engines: {node: ^20.19.0 || ^22.13.0 || ^23.5.0 || >=24.0.0, npm: '>=10'} + '@faker-js/faker@8.4.1': resolution: {integrity: sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0, npm: '>=6.14.13'} @@ -18656,6 +18672,8 @@ snapshots: '@exodus/bytes@1.15.0': {} + '@faker-js/faker@10.4.0': {} + '@faker-js/faker@8.4.1': {} '@fastify/ajv-compiler@4.0.5': @@ -19871,15 +19889,6 @@ snapshots: '@nuxt/devalue@2.0.2': {} - '@nuxt/devtools-kit@1.7.0(magicast@0.3.5)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))': - dependencies: - '@nuxt/kit': 3.21.0(magicast@0.3.5) - '@nuxt/schema': 3.16.2 - execa: 7.2.0 - vite: 5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1) - transitivePeerDependencies: - - magicast - '@nuxt/devtools-kit@1.7.0(magicast@0.3.5)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))': dependencies: '@nuxt/kit': 3.21.0(magicast@0.3.5) @@ -19976,53 +19985,6 @@ snapshots: - utf-8-validate - vue - '@nuxt/devtools@1.7.0(rollup@4.56.0)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue@3.5.25(typescript@5.9.3))': - dependencies: - '@antfu/utils': 0.7.10 - '@nuxt/devtools-kit': 1.7.0(magicast@0.3.5)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)) - '@nuxt/devtools-wizard': 1.7.0 - '@nuxt/kit': 3.21.0(magicast@0.3.5) - '@vue/devtools-core': 7.6.8(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue@3.5.25(typescript@5.9.3)) - '@vue/devtools-kit': 7.6.8 - birpc: 0.2.19 - consola: 3.4.2 - cronstrue: 2.59.0 - destr: 2.0.5 - error-stack-parser-es: 0.1.5 - execa: 7.2.0 - fast-npm-meta: 0.2.2 - flatted: 3.3.3 - get-port-please: 3.2.0 - hookable: 5.5.3 - image-meta: 0.2.1 - is-installed-globally: 1.0.0 - launch-editor: 2.11.1 - local-pkg: 0.5.1 - magicast: 0.3.5 - nypm: 0.4.1 - ohash: 1.1.6 - pathe: 1.1.2 - perfect-debounce: 1.0.0 - pkg-types: 1.3.1 - rc9: 2.1.2 - scule: 1.3.0 - semver: 7.7.3 - simple-git: 3.28.0 - sirv: 3.0.2 - tinyglobby: 0.2.15 - unimport: 3.14.6(rollup@4.56.0) - vite: 5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1) - vite-plugin-inspect: 0.8.9(@nuxt/kit@3.21.0(magicast@0.3.5))(rollup@4.56.0)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)) - vite-plugin-vue-inspector: 5.3.2(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)) - which: 3.0.1 - ws: 8.18.3 - transitivePeerDependencies: - - bufferutil - - rollup - - supports-color - - utf-8-validate - - vue - '@nuxt/devtools@1.7.0(rollup@4.56.0)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))': dependencies: '@antfu/utils': 0.7.10 @@ -23666,18 +23628,6 @@ snapshots: dependencies: '@vue/devtools-kit': 8.0.5 - '@vue/devtools-core@7.6.8(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue@3.5.25(typescript@5.9.3))': - dependencies: - '@vue/devtools-kit': 7.7.7 - '@vue/devtools-shared': 7.7.7 - mitt: 3.0.1 - nanoid: 5.1.5 - pathe: 1.1.2 - vite-hot-client: 0.2.4(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)) - vue: 3.5.25(typescript@5.9.3) - transitivePeerDependencies: - - vite - '@vue/devtools-core@7.6.8(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))': dependencies: '@vue/devtools-kit': 7.7.7 @@ -25890,7 +25840,7 @@ snapshots: eslint: 9.39.2(jiti@2.6.1) eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)) - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.2(jiti@2.6.1)) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)) eslint-plugin-jsx-a11y: 6.10.2(eslint@9.39.2(jiti@2.6.1)) eslint-plugin-react: 7.37.5(eslint@9.39.2(jiti@2.6.1)) eslint-plugin-react-hooks: 5.2.0(eslint@9.39.2(jiti@2.6.1)) @@ -25920,7 +25870,7 @@ snapshots: tinyglobby: 0.2.15 unrs-resolver: 1.11.1 optionalDependencies: - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.2(jiti@2.6.1)) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)) transitivePeerDependencies: - supports-color @@ -25935,7 +25885,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.2(jiti@2.6.1)): + eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.29.1(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)))(eslint@9.39.2(jiti@2.6.1)): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.9 @@ -29021,128 +28971,7 @@ snapshots: nuxi@3.28.0: {} - nuxt@3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.2)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.7.0)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@4.56.0)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue-tsc@3.2.4(typescript@5.9.3)): - dependencies: - '@nuxt/devalue': 2.0.2 - '@nuxt/devtools': 1.7.0(rollup@4.56.0)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1))(vue@3.5.25(typescript@5.9.3)) - '@nuxt/kit': 3.14.1592(magicast@0.3.5)(rollup@4.56.0) - '@nuxt/schema': 3.14.1592(magicast@0.3.5)(rollup@4.56.0) - '@nuxt/telemetry': 2.6.6(magicast@0.3.5) - '@nuxt/vite-builder': 3.14.1592(@types/node@25.2.1)(eslint@9.39.2(jiti@2.6.1))(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@4.56.0)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vue-tsc@3.2.4(typescript@5.9.3))(vue@3.5.25(typescript@5.9.3)) - '@unhead/dom': 1.11.20 - '@unhead/shared': 1.11.20 - '@unhead/ssr': 1.11.20 - '@unhead/vue': 1.11.20(vue@3.5.25(typescript@5.9.3)) - '@vue/shared': 3.5.25 - acorn: 8.14.0 - c12: 2.0.1(magicast@0.3.5) - chokidar: 4.0.3 - compatx: 0.1.8 - consola: 3.4.2 - cookie-es: 1.2.2 - defu: 6.1.4 - destr: 2.0.5 - devalue: 5.3.2 - errx: 0.1.0 - esbuild: 0.24.2 - escape-string-regexp: 5.0.0 - estree-walker: 3.0.3 - globby: 14.1.0 - h3: 1.15.4 - hookable: 5.5.3 - ignore: 6.0.2 - impound: 0.2.2(rollup@4.56.0) - jiti: 2.6.1 - klona: 2.0.6 - knitwork: 1.3.0 - magic-string: 0.30.21 - mlly: 1.8.0 - nanotar: 0.1.1 - nitropack: 2.12.4(@netlify/blobs@9.1.2)(encoding@0.1.13)(rolldown@1.0.0-rc.12) - nuxi: 3.28.0 - nypm: 0.3.12 - ofetch: 1.5.1 - ohash: 1.1.6 - pathe: 1.1.2 - perfect-debounce: 1.0.0 - pkg-types: 1.3.1 - radix3: 1.1.2 - scule: 1.3.0 - semver: 7.7.3 - std-env: 3.10.0 - strip-literal: 2.1.1 - tinyglobby: 0.2.10 - ufo: 1.6.1 - ultrahtml: 1.6.0 - uncrypto: 0.1.3 - unctx: 2.4.1 - unenv: 1.10.0 - unhead: 1.11.20 - unimport: 3.14.6(rollup@4.56.0) - unplugin: 1.16.1 - unplugin-vue-router: 0.10.9(rollup@4.56.0)(vue-router@4.5.0(vue@3.5.25(typescript@5.9.3)))(vue@3.5.25(typescript@5.9.3)) - unstorage: 1.17.0(@netlify/blobs@9.1.2)(db0@0.3.2)(ioredis@5.7.0) - untyped: 1.5.2 - vue: 3.5.25(typescript@5.9.3) - vue-bundle-renderer: 2.1.2 - vue-devtools-stub: 0.1.0 - vue-router: 4.5.0(vue@3.5.25(typescript@5.9.3)) - optionalDependencies: - '@parcel/watcher': 2.5.1 - '@types/node': 25.2.1 - transitivePeerDependencies: - - '@azure/app-configuration' - - '@azure/cosmos' - - '@azure/data-tables' - - '@azure/identity' - - '@azure/keyvault-secrets' - - '@azure/storage-blob' - - '@biomejs/biome' - - '@capacitor/preferences' - - '@deno/kv' - - '@electric-sql/pglite' - - '@libsql/client' - - '@netlify/blobs' - - '@planetscale/database' - - '@upstash/redis' - - '@vercel/blob' - - '@vercel/functions' - - '@vercel/kv' - - aws4fetch - - better-sqlite3 - - bufferutil - - db0 - - drizzle-orm - - encoding - - eslint - - idb-keyval - - ioredis - - less - - lightningcss - - magicast - - meow - - mysql2 - - optionator - - rolldown - - rollup - - sass - - sass-embedded - - sqlite3 - - stylelint - - stylus - - sugarss - - supports-color - - terser - - typescript - - uploadthing - - utf-8-validate - - vite - - vls - - vti - - vue-tsc - - xml2js - - nuxt@3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.4)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.9.2)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@3.29.5)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue-tsc@3.2.4(typescript@5.9.3)): + nuxt@3.14.1592(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@25.2.1)(db0@0.3.2)(encoding@0.1.13)(eslint@9.39.2(jiti@2.6.1))(ioredis@5.7.0)(less@4.4.2)(magicast@0.3.5)(optionator@0.9.4)(rolldown@1.0.0-rc.12)(rollup@3.29.5)(sass@1.97.1)(terser@5.44.1)(typescript@5.9.3)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue-tsc@3.2.4(typescript@5.9.3)): dependencies: '@nuxt/devalue': 2.0.2 '@nuxt/devtools': 1.7.0(rollup@3.29.5)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3)) @@ -29202,12 +29031,12 @@ snapshots: unimport: 3.14.6(rollup@3.29.5) unplugin: 1.16.1 unplugin-vue-router: 0.10.9(rollup@3.29.5)(vue-router@4.5.0(vue@3.5.25(typescript@5.9.3)))(vue@3.5.25(typescript@5.9.3)) - unstorage: 1.17.0(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.9.2) + unstorage: 1.17.0(@netlify/blobs@9.1.2)(db0@0.3.2)(ioredis@5.7.0) untyped: 1.5.2 vue: 3.5.25(typescript@5.9.3) vue-bundle-renderer: 2.1.2 vue-devtools-stub: 0.1.0 - vue-router: 4.5.0(vue@3.5.25(typescript@5.9.3)) + vue-router: 4.5.0(vue@3.5.13(typescript@5.9.3)) optionalDependencies: '@parcel/watcher': 2.5.1 '@types/node': 25.2.1 @@ -32618,7 +32447,7 @@ snapshots: unplugin: 2.0.0-beta.1 yaml: 2.8.2 optionalDependencies: - vue-router: 4.5.0(vue@3.5.25(typescript@5.9.3)) + vue-router: 4.5.0(vue@3.5.13(typescript@5.9.3)) transitivePeerDependencies: - rollup - vue @@ -32906,10 +32735,6 @@ snapshots: vite: 7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2) vite-hot-client: 2.1.0(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)) - vite-hot-client@0.2.4(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)): - dependencies: - vite: 5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1) - vite-hot-client@0.2.4(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)): dependencies: vite: 7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2) @@ -33018,24 +32843,6 @@ snapshots: - rollup - supports-color - vite-plugin-inspect@0.8.9(@nuxt/kit@3.21.0(magicast@0.3.5))(rollup@4.56.0)(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)): - dependencies: - '@antfu/utils': 0.7.10 - '@rollup/pluginutils': 5.2.0(rollup@4.56.0) - debug: 4.4.3 - error-stack-parser-es: 0.1.5 - fs-extra: 11.3.1 - open: 10.2.0 - perfect-debounce: 1.0.0 - picocolors: 1.1.1 - sirv: 3.0.2 - vite: 5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1) - optionalDependencies: - '@nuxt/kit': 3.21.0(magicast@0.3.5) - transitivePeerDependencies: - - rollup - - supports-color - vite-plugin-inspect@0.8.9(@nuxt/kit@3.21.0(magicast@0.3.5))(rollup@4.56.0)(vite@7.3.1(@types/node@25.2.1)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)): dependencies: '@antfu/utils': 0.7.10 @@ -33101,21 +32908,6 @@ snapshots: - supports-color - vue - vite-plugin-vue-inspector@5.3.2(vite@5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)): - dependencies: - '@babel/core': 7.28.3 - '@babel/plugin-proposal-decorators': 7.28.0(@babel/core@7.28.3) - '@babel/plugin-syntax-import-attributes': 7.27.1(@babel/core@7.28.3) - '@babel/plugin-syntax-import-meta': 7.10.4(@babel/core@7.28.3) - '@babel/plugin-transform-typescript': 7.28.0(@babel/core@7.28.3) - '@vue/babel-plugin-jsx': 1.5.0(@babel/core@7.28.3) - '@vue/compiler-dom': 3.5.25 - kolorist: 1.8.0 - magic-string: 0.30.21 - vite: 5.4.19(@types/node@25.2.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1) - transitivePeerDependencies: - - supports-color - vite-plugin-vue-inspector@5.3.2(vite@7.3.1(@types/node@24.12.0)(jiti@2.6.1)(less@4.4.2)(sass@1.97.1)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)): dependencies: '@babel/core': 7.28.3 diff --git a/specs/2.0.x/circular.yaml b/specs/2.0.x/circular.yaml new file mode 100644 index 0000000000..7a48a3df49 --- /dev/null +++ b/specs/2.0.x/circular.yaml @@ -0,0 +1,112 @@ +swagger: '2.0' +info: + title: Circular references examples - including self reference and mutual recursive + version: '1' +paths: {} +definitions: + # Self-referencing (A -> A) + TreeNode: + type: object + properties: + id: + type: string + value: + type: string + children: + type: array + items: + $ref: '#/definitions/TreeNode' + required: + - id + - value + + # Mutual reference (A -> B -> A) + Org: + type: object + properties: + id: + type: string + name: + type: string + members: + type: array + items: + $ref: '#/definitions/Member' + required: + - id + - name + + Member: + type: object + properties: + id: + type: string + name: + type: string + org: + $ref: '#/definitions/Org' + required: + - id + - name + + # Three-way circular reference (A -> B -> C -> A) + Department: + type: object + properties: + id: + type: string + name: + type: string + employees: + type: array + items: + $ref: '#/definitions/Employee' + required: + - id + - name + + Employee: + type: object + properties: + id: + type: string + name: + type: string + projects: + type: array + items: + $ref: '#/definitions/Project' + required: + - id + - name + - projects + + Project: + type: object + properties: + id: + type: string + name: + type: string + department: + $ref: '#/definitions/Department' + required: + - id + - name + + # Nullable circular reference (required property, nullable type) + Comment: + type: object + properties: + id: + type: string + text: + type: string + parent: + x-nullable: true + allOf: + - $ref: '#/definitions/Comment' + required: + - id + - text + - parent diff --git a/specs/2.0.x/faker.yaml b/specs/2.0.x/faker.yaml new file mode 100644 index 0000000000..7d2f469e33 --- /dev/null +++ b/specs/2.0.x/faker.yaml @@ -0,0 +1,523 @@ +swagger: '2.0' +info: + title: Faker plugin coverage test + version: '1' +host: localhost +basePath: / +schemes: + - https +produces: + - application/json +consumes: + - application/json +paths: + /pets: + get: + operationId: listPets + parameters: + - name: limit + in: query + required: false + type: integer + minimum: 1 + maximum: 100 + responses: + '200': + description: A list of pets + schema: + type: array + items: + $ref: '#/definitions/Pet' + post: + operationId: createPet + parameters: + - name: body + in: body + required: true + schema: + type: object + properties: + name: + type: string + tag: + type: string + required: + - name + responses: + '201': + description: Pet created + schema: + $ref: '#/definitions/Pet' + '204': + description: No content + /pets/{id}: + get: + operationId: getPet + parameters: + - name: id + in: path + required: true + type: string + responses: + '200': + description: A pet + schema: + $ref: '#/definitions/Pet' + '404': + description: Not found + schema: + $ref: '#/definitions/Error' + put: + operationId: updatePet + parameters: + - name: id + in: path + required: true + type: string + - name: dryRun + in: query + required: false + type: boolean + - name: body + in: body + required: true + schema: + type: object + properties: + name: + type: string + tag: + $ref: '#/definitions/Tag' + required: + - name + responses: + '200': + description: Updated pet + schema: + $ref: '#/definitions/Pet' + delete: + operationId: deletePet + parameters: + - name: id + in: path + required: true + type: string + responses: + '204': + description: Deleted + '404': + description: Not found + schema: + $ref: '#/definitions/Error' + /health: + get: + operationId: healthCheck + responses: + '200': + description: OK + schema: + type: string +definitions: + # --- Primitive types --- + Price: + type: number + Quantity: + type: integer + Active: + type: boolean + + # --- Enums --- + NumericEnum: + type: integer + enum: + - 1 + - 2 + - 3 + + # --- String formats --- + Email: + type: string + format: email + DateTime: + type: string + format: date-time + DateOnly: + type: string + format: date + UniqueId: + type: string + format: uuid + Website: + type: string + format: uri + IPv4Address: + type: string + format: ipv4 + IPv6Address: + type: string + format: ipv6 + + # --- String with pattern --- + ZipCode: + type: string + pattern: '^\d{5}(-\d{4})?$' + + # --- String with length constraints --- + ShortName: + type: string + minLength: 2 + maxLength: 50 + MinOnlyString: + type: string + minLength: 10 + MaxOnlyString: + type: string + maxLength: 5 + + # --- Format takes priority over length constraints --- + EmailWithLength: + type: string + format: email + minLength: 5 + maxLength: 100 + + # --- Numeric constraints --- + BoundedInt: + type: integer + minimum: 1 + maximum: 100 + BoundedFloat: + type: number + minimum: 0.0 + maximum: 1.0 + ExclusiveInt: + type: integer + minimum: 0 + exclusiveMinimum: true + maximum: 10 + exclusiveMaximum: true + MinOnlyNumber: + type: number + minimum: 0 + MaxOnlyInt: + type: integer + maximum: 999 + ExclusiveFloat: + type: number + minimum: 0 + exclusiveMinimum: true + maximum: 1 + exclusiveMaximum: true + ExclusiveFloatNarrow: + type: number + minimum: 10.1 + exclusiveMinimum: true + maximum: 10.2 + exclusiveMaximum: true + + # --- Array types and constraints --- + Tags: + type: array + items: + type: string + TagList: + type: array + items: + type: string + minItems: 1 + maxItems: 10 + MinOnlyArray: + type: array + items: + type: integer + minItems: 3 + MaxOnlyArray: + type: array + items: + type: string + maxItems: 5 + + # --- Default values --- + DefaultString: + type: string + default: 'unknown' + DefaultInt: + type: integer + default: 0 + DefaultBool: + type: boolean + default: true + DefaultOverridesConstraints: + type: integer + minimum: 1 + maximum: 100 + default: 42 + + # --- Nullable types --- + NullableString: + type: string + x-nullable: true + NullableInt: + type: integer + x-nullable: true + + # --- Objects --- + ObjectWithDefaultProp: + type: object + properties: + name: + type: string + status: + type: string + default: 'active' + required: + - name + UserProfile: + type: object + properties: + id: + type: integer + name: + type: string + bio: + type: string + age: + type: integer + required: + - id + - name + Pet: + type: object + properties: + id: + type: string + name: + type: string + age: + type: integer + tag: + $ref: '#/definitions/Tag' + required: + - id + - name + Tag: + type: object + properties: + id: + type: integer + label: + type: string + required: + - id + - label + Error: + type: object + properties: + code: + type: integer + message: + type: string + required: + - code + - message + + # --- Nested $ref --- + Address: + type: object + properties: + street: + type: string + minLength: 1 + maxLength: 200 + zip: + $ref: '#/definitions/ZipCode' + required: + - street + - zip + Person: + type: object + properties: + name: + $ref: '#/definitions/ShortName' + email: + $ref: '#/definitions/Email' + address: + $ref: '#/definitions/Address' + required: + - name + - email + PersonList: + type: array + items: + $ref: '#/definitions/Person' + minItems: 1 + maxItems: 20 + PetList: + type: array + items: + $ref: '#/definitions/Pet' + Team: + type: object + properties: + lead: + $ref: '#/definitions/Person' + config: + $ref: '#/definitions/ObjectWithDefaultProp' + required: + - lead + - config + + # --- allOf intersection --- + PetWithOwner: + allOf: + - $ref: '#/definitions/Pet' + - type: object + properties: + owner: + type: string + required: + - owner + + # --- Property name inference --- + PersonProfile: + type: object + properties: + firstName: + type: string + last_name: + type: string + email: + type: string + phone: + type: string + age: + type: integer + city: + type: string + postalCode: + type: string + bio: + type: string + website: + type: string + format: uri + zipCode: + type: string + pattern: '^\d{5}$' + username: + type: string + minLength: 3 + maxLength: 20 + someRandomField: + type: string + required: + - firstName + - last_name + - email + - phone + - age + - city + - postalCode + - bio + - website + - zipCode + - username + - someRandomField + + # --- Number constraint merging with name defaults --- + PersonWithConstraints: + type: object + properties: + age: + type: integer + minimum: 18 + seniorAge: + type: integer + minimum: 65 + maximum: 100 + required: + - age + + # --- Ancestor-aware inference --- + User: + type: object + properties: + name: + type: string + email: + type: string + required: + - name + - email + Company: + type: object + properties: + name: + type: string + required: + - name + Config: + type: object + properties: + name: + type: string + required: + - name + + # --- Never types (impossible intersections) --- + # Tuple with never elements — should be skipped entirely + NeverTuple: + type: array + items: + allOf: + - type: number + - type: string + minItems: 2 + maxItems: 2 + # Array with never items — should produce empty array [] + NeverArray: + type: array + items: + allOf: + - type: number + - type: string + # Object with a required property that is never — should be skipped + ObjectWithRequiredNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + - impossible + # Object with an optional property that is never — should still be exported + ObjectWithOptionalNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + + # --- String id --- + Document: + type: object + properties: + id: + type: string + _id: + type: string + numericId: + type: integer + required: + - id + - _id + - numericId diff --git a/specs/3.0.x/circular.yaml b/specs/3.0.x/circular.yaml index 211b0f00c6..b2eefdfa0d 100644 --- a/specs/3.0.x/circular.yaml +++ b/specs/3.0.x/circular.yaml @@ -42,3 +42,122 @@ components: type: array items: $ref: '#/components/schemas/Baz' + + # Self-referencing (A → A) + TreeNode: + type: object + properties: + id: + type: string + value: + type: string + children: + type: array + items: + $ref: '#/components/schemas/TreeNode' + required: + - id + - value + + # Mutual reference (A → B → A) + Org: + type: object + properties: + id: + type: string + name: + type: string + members: + type: array + items: + $ref: '#/components/schemas/Member' + required: + - id + - name + + Member: + type: object + properties: + id: + type: string + name: + type: string + org: + $ref: '#/components/schemas/Org' + required: + - id + - name + + # Three-way circular reference (A → B → C → A) + Department: + type: object + properties: + id: + type: string + name: + type: string + employees: + type: array + items: + $ref: '#/components/schemas/Employee' + required: + - id + - name + + Employee: + type: object + properties: + id: + type: string + name: + type: string + projects: + type: array + items: + $ref: '#/components/schemas/Project' + required: + - id + - name + - projects + + Project: + type: object + properties: + id: + type: string + name: + type: string + department: + $ref: '#/components/schemas/Department' + required: + - id + - name + + # Non-circular schema referencing a circular schema (feedback #2) + Wrapper: + type: object + properties: + label: + type: string + tree: + $ref: '#/components/schemas/TreeNode' + required: + - label + - tree + + # Nullable circular reference (required property, nullable type) + Comment: + type: object + properties: + id: + type: string + text: + type: string + parent: + nullable: true + allOf: + - $ref: '#/components/schemas/Comment' + required: + - id + - text + - parent diff --git a/specs/3.0.x/faker.yaml b/specs/3.0.x/faker.yaml new file mode 100644 index 0000000000..541ea1d098 --- /dev/null +++ b/specs/3.0.x/faker.yaml @@ -0,0 +1,635 @@ +openapi: 3.0.4 +info: + title: Faker plugin coverage test + version: '1' +paths: + /pets: + get: + operationId: listPets + parameters: + - name: limit + in: query + required: false + schema: + type: integer + minimum: 1 + maximum: 100 + responses: + '200': + description: A list of pets + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + post: + operationId: createPet + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + tag: + type: string + required: + - name + responses: + '201': + description: Pet created + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '204': + description: No content + /pets/{id}: + get: + operationId: getPet + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '200': + description: A pet + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '404': + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + put: + operationId: updatePet + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: dryRun + in: query + required: false + schema: + type: boolean + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + tag: + $ref: '#/components/schemas/Tag' + required: + - name + responses: + '200': + description: Updated pet + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + delete: + operationId: deletePet + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '204': + description: Deleted + '404': + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /jobs: + post: + operationId: createJob + responses: + '2XX': + description: Job accepted + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '4XX': + description: Client error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /health: + get: + operationId: healthCheck + responses: + '200': + description: OK + content: + application/json: + schema: + type: string +components: + schemas: + # --- Primitive types --- + Price: + type: number + Quantity: + type: integer + Active: + type: boolean + # unknown (empty schema) + Anything: {} + + # --- Enums --- + StatusWithNull: + type: string + nullable: true + enum: + - active + - inactive + - null + NumericEnum: + type: integer + enum: + - 1 + - 2 + - 3 + + # --- String formats --- + Email: + type: string + format: email + DateTime: + type: string + format: date-time + DateOnly: + type: string + format: date + UniqueId: + type: string + format: uuid + Website: + type: string + format: uri + IPv4Address: + type: string + format: ipv4 + IPv6Address: + type: string + format: ipv6 + + # --- String with pattern --- + ZipCode: + type: string + pattern: '^\d{5}(-\d{4})?$' + + # --- String with length constraints --- + ShortName: + type: string + minLength: 2 + maxLength: 50 + MinOnlyString: + type: string + minLength: 10 + MaxOnlyString: + type: string + maxLength: 5 + + # --- Format takes priority over length constraints --- + EmailWithLength: + type: string + format: email + minLength: 5 + maxLength: 100 + + # --- Numeric constraints --- + BoundedInt: + type: integer + minimum: 1 + maximum: 100 + BoundedFloat: + type: number + minimum: 0.0 + maximum: 1.0 + ExclusiveInt: + type: integer + minimum: 0 + exclusiveMinimum: true + maximum: 10 + exclusiveMaximum: true + MinOnlyNumber: + type: number + minimum: 0 + MaxOnlyInt: + type: integer + maximum: 999 + ExclusiveFloat: + type: number + minimum: 0 + exclusiveMinimum: true + maximum: 1 + exclusiveMaximum: true + ExclusiveFloatNarrow: + type: number + minimum: 10.1 + exclusiveMinimum: true + maximum: 10.2 + exclusiveMaximum: true + + # --- Array types and constraints --- + Tags: + type: array + items: + type: string + TagList: + type: array + items: + type: string + minItems: 1 + maxItems: 10 + MinOnlyArray: + type: array + items: + type: integer + minItems: 3 + MaxOnlyArray: + type: array + items: + type: string + maxItems: 5 + + # --- Default values --- + DefaultString: + type: string + default: 'unknown' + DefaultInt: + type: integer + default: 0 + DefaultBool: + type: boolean + default: true + DefaultOverridesConstraints: + type: integer + minimum: 1 + maximum: 100 + default: 42 + + # --- Nullable types --- + NullableString: + type: string + nullable: true + NullableInt: + type: integer + nullable: true + + # --- Objects --- + ObjectWithDefaultProp: + type: object + properties: + name: + type: string + status: + type: string + default: 'active' + required: + - name + UserProfile: + type: object + properties: + id: + type: integer + name: + type: string + bio: + type: string + age: + type: integer + required: + - id + - name + Pet: + type: object + properties: + id: + type: string + name: + type: string + age: + type: integer + tag: + $ref: '#/components/schemas/Tag' + required: + - id + - name + Tag: + type: object + properties: + id: + type: integer + label: + type: string + required: + - id + - label + Error: + type: object + properties: + code: + type: integer + message: + type: string + required: + - code + - message + + # --- Nested $ref --- + Address: + type: object + properties: + street: + type: string + minLength: 1 + maxLength: 200 + zip: + $ref: '#/components/schemas/ZipCode' + required: + - street + - zip + Person: + type: object + properties: + name: + $ref: '#/components/schemas/ShortName' + email: + $ref: '#/components/schemas/Email' + address: + $ref: '#/components/schemas/Address' + required: + - name + - email + PersonList: + type: array + items: + $ref: '#/components/schemas/Person' + minItems: 1 + maxItems: 20 + PetList: + type: array + items: + $ref: '#/components/schemas/Pet' + Team: + type: object + properties: + lead: + $ref: '#/components/schemas/Person' + config: + $ref: '#/components/schemas/ObjectWithDefaultProp' + required: + - lead + - config + + # --- Unions --- + PetOrTag: + oneOf: + - $ref: '#/components/schemas/Pet' + - $ref: '#/components/schemas/Tag' + StringOrNumber: + anyOf: + - type: string + - type: number + NullablePetOrTag: + nullable: true + oneOf: + - $ref: '#/components/schemas/Pet' + - $ref: '#/components/schemas/Tag' + + # --- allOf intersection --- + PetWithOwner: + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + owner: + type: string + required: + - owner + + # --- Discriminated oneOf --- + Circle: + type: object + properties: + kind: + type: string + radius: + type: number + required: + - kind + - radius + Square: + type: object + properties: + kind: + type: string + side: + type: number + required: + - kind + - side + Shape: + oneOf: + - $ref: '#/components/schemas/Circle' + - $ref: '#/components/schemas/Square' + discriminator: + propertyName: kind + + # --- Discriminated oneOf with explicit mapping --- + Dog: + type: object + properties: + type: + type: string + bark: + type: boolean + required: + - type + - bark + Cat: + type: object + properties: + type: + type: string + purr: + type: boolean + required: + - type + - purr + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + discriminator: + propertyName: type + mapping: + dog: '#/components/schemas/Dog' + cat: '#/components/schemas/Cat' + + # --- Property name inference --- + PersonProfile: + type: object + properties: + firstName: + type: string + last_name: + type: string + email: + type: string + phone: + type: string + age: + type: integer + city: + type: string + postalCode: + type: string + bio: + type: string + website: + type: string + format: uri + zipCode: + type: string + pattern: '^\d{5}$' + username: + type: string + minLength: 3 + maxLength: 20 + someRandomField: + type: string + required: + - firstName + - last_name + - email + - phone + - age + - city + - postalCode + - bio + - website + - zipCode + - username + - someRandomField + + # --- Number constraint merging with name defaults --- + PersonWithConstraints: + type: object + properties: + age: + type: integer + minimum: 18 + seniorAge: + type: integer + minimum: 65 + maximum: 100 + required: + - age + + # --- Ancestor-aware inference --- + User: + type: object + properties: + name: + type: string + email: + type: string + required: + - name + - email + Company: + type: object + properties: + name: + type: string + required: + - name + Config: + type: object + properties: + name: + type: string + required: + - name + + # --- Never types (impossible intersections) --- + # Tuple with never elements — should be skipped entirely + NeverTuple: + type: array + items: + allOf: + - type: number + - type: string + minItems: 2 + maxItems: 2 + # Array with never items — should produce empty array [] + NeverArray: + type: array + items: + allOf: + - type: number + - type: string + # Object with a required property that is never — should be skipped + ObjectWithRequiredNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + - impossible + # Object with an optional property that is never — should still be exported + ObjectWithOptionalNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + + # --- String id --- + Document: + type: object + properties: + id: + type: string + _id: + type: string + numericId: + type: integer + required: + - id + - _id + - numericId diff --git a/specs/3.1.x/circular.yaml b/specs/3.1.x/circular.yaml new file mode 100644 index 0000000000..8cc124f1a2 --- /dev/null +++ b/specs/3.1.x/circular.yaml @@ -0,0 +1,138 @@ +openapi: 3.1.0 +info: + title: Circular references examples - including self reference and mutual recursive + version: '1' +components: + schemas: + # Self-referencing (A → A) + TreeNode: + type: object + properties: + id: + type: string + value: + type: string + children: + type: array + items: + $ref: '#/components/schemas/TreeNode' + required: + - id + - value + + # Mutual reference (A → B → A) + Org: + type: object + properties: + id: + type: string + name: + type: string + members: + type: array + items: + $ref: '#/components/schemas/Member' + required: + - id + - name + + Member: + type: object + properties: + id: + type: string + name: + type: string + org: + $ref: '#/components/schemas/Org' + required: + - id + - name + + # Three-way circular reference (A → B → C → A) + Department: + type: object + properties: + id: + type: string + name: + type: string + employees: + type: array + items: + $ref: '#/components/schemas/Employee' + required: + - id + - name + + Employee: + type: object + properties: + id: + type: string + name: + type: string + projects: + type: array + items: + $ref: '#/components/schemas/Project' + required: + - id + - name + - projects + + Project: + type: object + properties: + id: + type: string + name: + type: string + department: + $ref: '#/components/schemas/Department' + required: + - id + - name + + # Non-circular schema referencing a circular schema (feedback #2) + Wrapper: + type: object + properties: + label: + type: string + tree: + $ref: '#/components/schemas/TreeNode' + required: + - label + - tree + + # Tuple containing a $ref to a circular schema (feedback #3) + Pair: + type: object + properties: + nodes: + type: array + prefixItems: + - $ref: '#/components/schemas/TreeNode' + - $ref: '#/components/schemas/TreeNode' + minItems: 2 + maxItems: 2 + required: + - nodes + + # Nullable circular reference (required property, nullable type) + Comment: + type: object + properties: + id: + type: string + text: + type: string + parent: + oneOf: + - $ref: '#/components/schemas/Comment' + - type: 'null' + required: + - id + - text + - parent diff --git a/specs/3.1.x/faker.yaml b/specs/3.1.x/faker.yaml new file mode 100644 index 0000000000..3005a16971 --- /dev/null +++ b/specs/3.1.x/faker.yaml @@ -0,0 +1,656 @@ +openapi: 3.1.0 +info: + title: Faker plugin coverage test + version: '1' +paths: + /pets: + get: + operationId: listPets + summary: Single useful 2XX (array) → no suffix + parameters: + - name: limit + in: query + required: false + schema: + type: integer + minimum: 1 + maximum: 100 + responses: + '200': + description: A list of pets + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + post: + operationId: createPet + summary: Single useful 2XX after void filter → no suffix + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + tag: + type: string + required: + - name + responses: + '201': + description: Pet created + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '204': + description: No content + /pets/{id}: + get: + operationId: getPet + summary: Multiple useful (200 + 404) → suffix + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '200': + description: A pet + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '404': + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + put: + operationId: updatePet + summary: Request with body + path + query combined + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: dryRun + in: query + required: false + schema: + type: boolean + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + tag: + $ref: '#/components/schemas/Tag' + required: + - name + responses: + '200': + description: Updated pet + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + delete: + operationId: deletePet + summary: Single useful non-2XX → suffix + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '204': + description: Deleted + '404': + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /jobs: + post: + operationId: createJob + summary: Wildcard 2XX + wildcard error → suffix with wildcard codes + responses: + '2XX': + description: Job accepted + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '4XX': + description: Client error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /health: + get: + operationId: healthCheck + summary: Single useful 2XX (inline string) → no suffix + responses: + '200': + description: OK + content: + application/json: + schema: + type: string +components: + schemas: + # --- Primitive types --- + Price: + type: number + Quantity: + type: integer + Active: + type: boolean + Nothing: + type: 'null' + # unknown (empty schema) + Anything: {} + + # --- Enums --- + StatusWithNull: + type: + - string + - 'null' + enum: + - active + - inactive + - null + NumericEnum: + type: integer + enum: + - 1 + - 2 + - 3 + + # --- String formats --- + Email: + type: string + format: email + DateTime: + type: string + format: date-time + DateOnly: + type: string + format: date + UniqueId: + type: string + format: uuid + Website: + type: string + format: uri + IPv4Address: + type: string + format: ipv4 + IPv6Address: + type: string + format: ipv6 + + # --- String with pattern --- + ZipCode: + type: string + pattern: '^\d{5}(-\d{4})?$' + + # --- String with length constraints --- + ShortName: + type: string + minLength: 2 + maxLength: 50 + MinOnlyString: + type: string + minLength: 10 + MaxOnlyString: + type: string + maxLength: 5 + + # --- Format takes priority over length constraints --- + EmailWithLength: + type: string + format: email + minLength: 5 + maxLength: 100 + + # --- Numeric constraints --- + BoundedInt: + type: integer + minimum: 1 + maximum: 100 + BoundedFloat: + type: number + minimum: 0.0 + maximum: 1.0 + ExclusiveInt: + type: integer + exclusiveMinimum: 0 + exclusiveMaximum: 10 + MinOnlyNumber: + type: number + minimum: 0 + MaxOnlyInt: + type: integer + maximum: 999 + ExclusiveFloat: + type: number + exclusiveMinimum: 0 + exclusiveMaximum: 1 + ExclusiveFloatNarrow: + type: number + exclusiveMinimum: 10.1 + exclusiveMaximum: 10.2 + + # --- Array types and constraints --- + Tags: + type: array + items: + type: string + TagList: + type: array + items: + type: string + minItems: 1 + maxItems: 10 + MinOnlyArray: + type: array + items: + type: integer + minItems: 3 + MaxOnlyArray: + type: array + items: + type: string + maxItems: 5 + + # --- Default values --- + DefaultString: + type: string + default: 'unknown' + DefaultInt: + type: integer + default: 0 + DefaultBool: + type: boolean + default: true + DefaultOverridesConstraints: + type: integer + minimum: 1 + maximum: 100 + default: 42 + + # --- Nullable types (OpenAPI 3.1 style) --- + NullableString: + type: + - string + - 'null' + NullableInt: + type: + - integer + - 'null' + + # --- Objects --- + ObjectWithDefaultProp: + type: object + properties: + name: + type: string + status: + type: string + default: 'active' + required: + - name + DictionaryObject: + type: object + description: This is a dictionary object + additionalProperties: + type: string + UserProfile: + type: object + properties: + id: + type: integer + name: + type: string + bio: + type: string + age: + type: integer + required: + - id + - name + Pet: + type: object + properties: + id: + type: string + name: + type: string + age: + type: integer + tag: + $ref: '#/components/schemas/Tag' + required: + - id + - name + Tag: + type: object + properties: + id: + type: integer + label: + type: string + required: + - id + - label + Error: + type: object + properties: + code: + type: integer + message: + type: string + required: + - code + - message + + # --- Nested $ref --- + Address: + type: object + properties: + street: + type: string + minLength: 1 + maxLength: 200 + zip: + $ref: '#/components/schemas/ZipCode' + required: + - street + - zip + Person: + type: object + properties: + name: + $ref: '#/components/schemas/ShortName' + email: + $ref: '#/components/schemas/Email' + address: + $ref: '#/components/schemas/Address' + required: + - name + - email + PersonList: + type: array + items: + $ref: '#/components/schemas/Person' + minItems: 1 + maxItems: 20 + PetList: + type: array + items: + $ref: '#/components/schemas/Pet' + Team: + type: object + properties: + lead: + $ref: '#/components/schemas/Person' + config: + $ref: '#/components/schemas/ObjectWithDefaultProp' + required: + - lead + - config + + # --- Unions --- + PetOrTag: + oneOf: + - $ref: '#/components/schemas/Pet' + - $ref: '#/components/schemas/Tag' + StringOrNumber: + anyOf: + - type: string + - type: number + NullablePetOrTag: + oneOf: + - $ref: '#/components/schemas/Pet' + - $ref: '#/components/schemas/Tag' + - type: 'null' + + # --- allOf intersection --- + PetWithOwner: + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + owner: + type: string + required: + - owner + + # --- Discriminated oneOf --- + Circle: + type: object + properties: + kind: + type: string + radius: + type: number + required: + - kind + - radius + Square: + type: object + properties: + kind: + type: string + side: + type: number + required: + - kind + - side + Shape: + oneOf: + - $ref: '#/components/schemas/Circle' + - $ref: '#/components/schemas/Square' + discriminator: + propertyName: kind + + # --- Discriminated oneOf with explicit mapping --- + Dog: + type: object + properties: + type: + type: string + bark: + type: boolean + required: + - type + - bark + Cat: + type: object + properties: + type: + type: string + purr: + type: boolean + required: + - type + - purr + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + discriminator: + propertyName: type + mapping: + dog: '#/components/schemas/Dog' + cat: '#/components/schemas/Cat' + + # --- Property name inference --- + PersonProfile: + type: object + properties: + firstName: + type: string + last_name: + type: string + email: + type: string + phone: + type: string + homePhone: + type: string + age: + type: integer + city: + type: string + postalCode: + type: string + bio: + type: string + # format should take priority over name + website: + type: string + format: uri + # pattern should take priority over name + zipCode: + type: string + pattern: '^\d{5}$' + # name inference takes priority over length constraints + username: + type: string + minLength: 3 + maxLength: 20 + # plain string with no matching name — should use fallback + someRandomField: + type: string + required: + - firstName + - last_name + - email + - phone + - homePhone + - age + - city + - postalCode + - bio + - website + - zipCode + - username + - someRandomField + + # --- Number constraint merging with name defaults --- + PersonWithConstraints: + type: object + properties: + # name rule provides {min:1, max:120}, schema overrides min + age: + type: integer + minimum: 18 + # name rule provides {min:1, max:120}, schema overrides both + seniorAge: + type: integer + minimum: 65 + maximum: 100 + required: + - age + + # --- Ancestor-aware inference --- + User: + type: object + properties: + name: + type: string + email: + type: string + required: + - name + - email + Company: + type: object + properties: + name: + type: string + required: + - name + Config: + type: object + properties: + name: + type: string + required: + - name + + # --- Never types (impossible intersections) --- + # Tuple with never elements — should be skipped entirely + NeverTuple: + type: array + items: + allOf: + - type: number + - type: string + minItems: 2 + maxItems: 2 + # Array with never items — should produce empty array [] + NeverArray: + type: array + items: + allOf: + - type: number + - type: string + # Object with a required property that is never — should be skipped + ObjectWithRequiredNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + - impossible + # Object with an optional property that is never — should still be exported + ObjectWithOptionalNever: + type: object + properties: + id: + type: integer + impossible: + allOf: + - type: number + - type: string + required: + - id + + # --- String id → faker.string.uuid() --- + Document: + type: object + properties: + id: + type: string + _id: + type: string + # integer id should NOT use uuid — stays as faker.number.int() + numericId: + type: integer + required: + - id + - _id + - numericId diff --git a/vitest.config.ts b/vitest.config.ts index 8bd8e3eac1..cf26ea8076 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -84,6 +84,15 @@ export default defineConfig({ setupFiles: ['./vitest.setup.ts'], }, }, + { + extends: true, + test: { + globalSetup: ['./test/globalTeardown.ts'], + name: '@test/openapi-ts-faker-v10', + root: 'packages/openapi-ts-tests/faker/v10', + setupFiles: ['./vitest.setup.ts'], + }, + }, { extends: true, test: {