fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #358 from hey-api/fix/enums-file

feat(parser): generate enums into their own file

authored by

Lubos and committed by
GitHub
7e7f44cc c96c3ec3

+749 -4770
+5
.changeset/modern-dots-study.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + fix: generate enums into their own file
+5
.changeset/young-moles-enjoy.md
··· 1 + --- 2 + "openapi-ts-docs": patch 3 + --- 4 + 5 + docs: add enums migration
+21 -13
docs/openapi-ts/migrating.md
··· 5 5 6 6 # Migrating 7 7 8 - While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. 8 + While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into an issue with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues). 9 9 10 10 ## @next 11 11 ··· 49 49 ### Deprecated `name` 50 50 51 51 This config option is deprecated and will be removed. 52 + 53 + ## v0.39.0 54 + 55 + ### Single `enums.gen.ts` file 56 + 57 + Enums are now exported from a single file. If you used imports from `model.ts`, you can change it to `enums.gen.ts`. 58 + 59 + ```js 60 + import { Enum } from 'client/models' // [!code --] 61 + import { Enum } from 'client/enums.gen.ts' // [!code ++] 62 + ``` 63 + 64 + Enums are no longer exported from `index.ts`. If you used imports from index file, you will need to move enums into their own import statement. 65 + 66 + ```js 67 + import { Enum, DefaultService } from 'client' // [!code --] 68 + import { Enum } from 'client/enums.gen.ts' // [!code ++] 69 + import { DefaultService } from 'client/services' // [!code ++] 70 + ``` 52 71 53 72 ## v0.38.0 54 73 ··· 140 159 141 160 ## OpenAPI TypeScript Codegen 142 161 143 - `openapi-ts` was originally forked from Ferdi Koomen's [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen). Therefore, we want you to be able to migrate your openapi-typescript-codegen projects. Migration should be relatively straightforward if you follow the release notes on this page. If you run into an issue with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues). 144 - 145 - ### Changed 146 - 147 - - `exportSchemas` is `true` by default (see [v0.27.36](#v0-27-36)) 148 - - `useOptions` is `true` by default (see [v0.27.38](#v0-27-38)) 149 - 150 - ### Removed 151 - 152 - - `useUnionTypes` has been removed (see [v0.27.24](#v0-27-24)) 153 - - `indent` has been removed (see [v0.27.26](#v0-27-26)) 154 - - `postfixModels` has been removed (see [v0.35.0](#v0-35-0)) 162 + `openapi-ts` was originally forked from Ferdi Koomen's [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen). Therefore, we want you to be able to migrate your projects. Migration should be relatively straightforward if you follow the release notes on this page. Start here and scroll up to the release you're migrating to.
+11 -4
packages/openapi-ts/src/compiler/index.ts
··· 1 - import { type PathOrFileDescriptor, writeFileSync } from 'node:fs'; 1 + import { writeFileSync } from 'node:fs'; 2 2 3 3 import ts from 'typescript'; 4 4 ··· 15 15 private _headers: Array<string> = []; 16 16 private _imports: Array<ts.Node> = []; 17 17 private _items: Array<ts.Node | string> = []; 18 + private _path: string = ''; 18 19 19 20 public add(...nodes: Array<ts.Node | string>): void { 20 21 this._items = [...this._items, ...nodes]; ··· 29 30 30 31 public addNamedImport(...params: Parameters<typeof module.createNamedImportDeclarations>): void { 31 32 this._imports = [...this._imports, compiler.import.named(...params)]; 33 + } 34 + 35 + public setPath(path: string) { 36 + this._path = path; 37 + return this; 32 38 } 33 39 34 40 public toString(seperator: string = '\n') { ··· 43 49 return output.join(seperator); 44 50 } 45 51 46 - public write(file: PathOrFileDescriptor, seperator: string = '\n') { 47 - if (!this._items.length) { 52 + public write(seperator = '\n') { 53 + // TODO: throw if path is not set. do not throw if items are empty 54 + if (!this._items.length || !this._path) { 48 55 return; 49 56 } 50 - writeFileSync(file, this.toString(seperator)); 57 + writeFileSync(this._path, this.toString(seperator)); 51 58 } 52 59 } 53 60
+52 -45
packages/openapi-ts/src/compiler/types.ts
··· 9 9 */ 10 10 export const toExpression = (value: unknown, unescape = false): ts.Expression | undefined => { 11 11 if (Array.isArray(value)) { 12 - return createArrayType(value); 12 + return createArrayType({ arr: value }); 13 13 } 14 14 15 15 if (typeof value === 'object' && value !== null) { 16 - return createObjectType(value); 16 + return createObjectType({ obj: value }); 17 17 } 18 18 19 19 if (typeof value === 'number') { ··· 39 39 * @param multiLine - if the array should be multiline. 40 40 * @returns ts.ArrayLiteralExpression 41 41 */ 42 - export const createArrayType = <T>(arr: T[], multiLine: boolean = false): ts.ArrayLiteralExpression => 42 + export const createArrayType = <T>({ 43 + arr, 44 + multiLine = false, 45 + }: { 46 + arr: T[]; 47 + multiLine?: boolean; 48 + }): ts.ArrayLiteralExpression => 43 49 ts.factory.createArrayLiteralExpression( 44 50 arr.map(v => toExpression(v)).filter(isType<ts.Expression>), 45 51 // Multiline if the array contains objects, or if specified by the user. ··· 48 54 49 55 /** 50 56 * Create Object type expression. 51 - * @param obj - the object to create. 52 57 * @param options - options to use when creating type. 53 58 * @returns ts.ObjectLiteralExpression 54 59 */ 55 - export const createObjectType = <T extends object>( 56 - obj: T, 57 - options: { 58 - multiLine?: boolean; 59 - unescape?: boolean; 60 - comments?: Record<string | number, Comments>; 61 - } = { 62 - comments: {}, 63 - multiLine: true, 64 - unescape: false, 65 - } 66 - ): ts.ObjectLiteralExpression => { 67 - const expression = ts.factory.createObjectLiteralExpression( 68 - Object.entries(obj) 69 - .map(([key, value]) => { 70 - const initializer = toExpression(value, options.unescape); 71 - if (!initializer) { 72 - return undefined; 73 - } 74 - const c = options.comments?.[key]; 75 - if (key.match(/\W/g) && !key.startsWith("'") && !key.endsWith("'")) { 76 - key = `'${key}'`; 77 - } 78 - const assignment = ts.factory.createPropertyAssignment(key, initializer); 79 - if (c?.length) { 80 - addLeadingComment(assignment, c); 81 - } 82 - return assignment; 83 - }) 84 - .filter(isType<ts.PropertyAssignment>), 85 - options.multiLine 86 - ); 60 + export const createObjectType = <T extends object>({ 61 + comments = {}, 62 + multiLine = true, 63 + obj, 64 + unescape = false, 65 + }: { 66 + obj: T; 67 + multiLine?: boolean; 68 + unescape?: boolean; 69 + comments?: Record<string | number, Comments>; 70 + }): ts.ObjectLiteralExpression => { 71 + const properties = Object.entries(obj) 72 + .map(([key, value]) => { 73 + const initializer = toExpression(value, unescape); 74 + if (!initializer) { 75 + return undefined; 76 + } 77 + if (key.match(/\W/g) && !key.startsWith("'") && !key.endsWith("'")) { 78 + key = `'${key}'`; 79 + } 80 + const assignment = ts.factory.createPropertyAssignment(key, initializer); 81 + const c = comments?.[key]; 82 + if (c?.length) { 83 + addLeadingComment(assignment, c); 84 + } 85 + return assignment; 86 + }) 87 + .filter(isType<ts.PropertyAssignment>); 88 + const expression = ts.factory.createObjectLiteralExpression(properties, multiLine); 87 89 return expression; 88 90 }; 89 91 ··· 91 93 * Create enum declaration. Example `export enum T = { X, Y };` 92 94 * @param name - the name of the enum. 93 95 * @param obj - the object representing the enum. 94 - * @param comment - comment to add to enum. 96 + * @param leadingComment - leading comment to add to enum. 95 97 * @param comments - comments to add to each property of enum. 96 98 * @returns 97 99 */ 98 - export const createEnumDeclaration = <T extends object>( 99 - name: string, 100 - obj: T, 101 - comment: Comments = [], 102 - comments: Record<string | number, Comments> = {} 103 - ): ts.EnumDeclaration => { 100 + export const createEnumDeclaration = <T extends object>({ 101 + name, 102 + obj, 103 + leadingComment = [], 104 + comments = {}, 105 + }: { 106 + name: string; 107 + obj: T; 108 + leadingComment: Comments; 109 + comments: Record<string | number, Comments>; 110 + }): ts.EnumDeclaration => { 104 111 const declaration = ts.factory.createEnumDeclaration( 105 112 [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], 106 113 ts.factory.createIdentifier(name), ··· 114 121 return assignment; 115 122 }) 116 123 ); 117 - if (comment.length) { 118 - addLeadingComment(declaration, comment); 124 + if (leadingComment.length) { 125 + addLeadingComment(declaration, leadingComment); 119 126 } 120 127 return declaration; 121 128 };
+4 -9
packages/openapi-ts/src/utils/enum.ts
··· 43 43 */ 44 44 export const enumName = (client: Client, name?: string) => { 45 45 if (!name) { 46 - return name; 46 + return null; 47 47 } 48 48 const escapedName = unescapeName(name).replace(/[-_]([a-z])/gi, ($0, $1: string) => $1.toLocaleUpperCase()); 49 - let result = `${escapedName.charAt(0).toLocaleUpperCase() + escapedName.slice(1)}Enum`; 50 - let index = 1; 51 - while (client.enumNames.includes(result)) { 52 - if (result.endsWith(index.toString())) { 53 - result = result.slice(0, result.length - index.toString().length); 54 - } 55 - index += 1; 56 - result = result + index.toString(); 49 + const result = `${escapedName.charAt(0).toLocaleUpperCase() + escapedName.slice(1)}Enum`; 50 + if (client.enumNames.includes(result)) { 51 + return null; 57 52 } 58 53 client.enumNames = [...client.enumNames, result]; 59 54 return result;
+9 -9
packages/openapi-ts/src/utils/write/__tests__/core.spec.ts
··· 4 4 import { beforeEach, describe, expect, it, vi } from 'vitest'; 5 5 6 6 import { setConfig } from '../../config'; 7 - import { writeClientCore } from '../core'; 7 + import { writeCore } from '../core'; 8 8 import { mockTemplates } from './mocks'; 9 9 import { openApi } from './models'; 10 10 11 11 vi.mock('node:fs'); 12 12 13 - describe('writeClientCore', () => { 14 - let templates: Parameters<typeof writeClientCore>[3]; 13 + describe('writeCore', () => { 14 + let templates: Parameters<typeof writeCore>[3]; 15 15 beforeEach(() => { 16 16 templates = mockTemplates; 17 17 }); 18 18 19 19 it('writes to filesystem', async () => { 20 - const client: Parameters<typeof writeClientCore>[2] = { 20 + const client: Parameters<typeof writeCore>[2] = { 21 21 enumNames: [], 22 22 models: [], 23 23 server: 'http://localhost:8080', ··· 46 46 useOptions: true, 47 47 }); 48 48 49 - await writeClientCore(openApi, '/', client, templates); 49 + await writeCore(openApi, '/', client, templates); 50 50 51 51 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/', '/OpenAPI.ts'), 'settings'); 52 52 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/', '/ApiError.ts'), 'apiError'); ··· 57 57 }); 58 58 59 59 it('uses client server value for base', async () => { 60 - const client: Parameters<typeof writeClientCore>[2] = { 60 + const client: Parameters<typeof writeCore>[2] = { 61 61 enumNames: [], 62 62 models: [], 63 63 server: 'http://localhost:8080', ··· 86 86 useOptions: true, 87 87 }); 88 88 89 - await writeClientCore(openApi, '/', client, templates); 89 + await writeCore(openApi, '/', client, templates); 90 90 91 91 expect(templates.core.settings).toHaveBeenCalledWith({ 92 92 $config: config, ··· 97 97 }); 98 98 99 99 it('uses custom value for base', async () => { 100 - const client: Parameters<typeof writeClientCore>[2] = { 100 + const client: Parameters<typeof writeCore>[2] = { 101 101 enumNames: [], 102 102 models: [], 103 103 server: 'http://localhost:8080', ··· 127 127 useOptions: true, 128 128 }); 129 129 130 - await writeClientCore(openApi, '/', client, templates); 130 + await writeCore(openApi, '/', client, templates); 131 131 132 132 expect(templates.core.settings).toHaveBeenCalledWith({ 133 133 $config: config,
+4 -4
packages/openapi-ts/src/utils/write/__tests__/models.spec.ts
··· 4 4 import { describe, expect, it, vi } from 'vitest'; 5 5 6 6 import { setConfig } from '../../config'; 7 - import { writeClientModels } from '../models'; 7 + import { writeTypesAndEnums } from '../models'; 8 8 import { openApi } from './models'; 9 9 10 10 vi.mock('node:fs'); 11 11 12 - describe('writeClientModels', () => { 12 + describe('writeTypesAndEnums', () => { 13 13 it('writes to filesystem', async () => { 14 14 setConfig({ 15 15 client: 'fetch', ··· 32 32 useOptions: true, 33 33 }); 34 34 35 - const client: Parameters<typeof writeClientModels>[2] = { 35 + const client: Parameters<typeof writeTypesAndEnums>[2] = { 36 36 enumNames: [], 37 37 models: [ 38 38 { ··· 59 59 version: 'v1', 60 60 }; 61 61 62 - await writeClientModels(openApi, '/', client); 62 + await writeTypesAndEnums(openApi, '/', client); 63 63 64 64 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/', '/models.ts'), expect.anything()); 65 65 });
+25 -3
packages/openapi-ts/src/utils/write/__tests__/schemas.spec.ts
··· 3 3 4 4 import { describe, expect, it, vi } from 'vitest'; 5 5 6 - import { writeClientSchemas } from '../schemas'; 6 + import { setConfig } from '../../config'; 7 + import { writeSchemas } from '../schemas'; 7 8 import { openApi } from './models'; 8 9 9 10 vi.mock('node:fs'); 10 11 11 - describe('writeClientSchemas', () => { 12 + describe('writeSchemas', () => { 12 13 it('writes to filesystem', async () => { 14 + setConfig({ 15 + client: 'fetch', 16 + debug: false, 17 + dryRun: false, 18 + enums: 'javascript', 19 + exportCore: true, 20 + exportModels: true, 21 + exportServices: true, 22 + format: false, 23 + input: '', 24 + lint: false, 25 + name: 'AppClient', 26 + operationId: true, 27 + output: '', 28 + postfixServices: '', 29 + schemas: true, 30 + serviceResponse: 'body', 31 + useDateType: false, 32 + useOptions: true, 33 + }); 34 + 13 35 if ('openapi' in openApi) { 14 36 openApi.components = { 15 37 schemas: { ··· 20 42 }; 21 43 } 22 44 23 - await writeClientSchemas(openApi, '/'); 45 + await writeSchemas(openApi, '/'); 24 46 25 47 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/', '/schemas.ts'), expect.anything()); 26 48 });
+4 -4
packages/openapi-ts/src/utils/write/__tests__/services.spec.ts
··· 3 3 import { describe, expect, it, vi } from 'vitest'; 4 4 5 5 import { setConfig } from '../../config'; 6 - import { writeClientServices } from '../services'; 6 + import { writeServices } from '../services'; 7 7 import { mockTemplates } from './mocks'; 8 8 import { openApi } from './models'; 9 9 10 10 vi.mock('node:fs'); 11 11 12 - describe('writeClientServices', () => { 12 + describe('writeServices', () => { 13 13 it('writes to filesystem', async () => { 14 14 setConfig({ 15 15 client: 'fetch', ··· 31 31 useOptions: false, 32 32 }); 33 33 34 - const client: Parameters<typeof writeClientServices>[2] = { 34 + const client: Parameters<typeof writeServices>[2] = { 35 35 enumNames: [], 36 36 models: [], 37 37 server: 'http://localhost:8080', ··· 46 46 version: 'v1', 47 47 }; 48 48 49 - await writeClientServices(openApi, '/', client, mockTemplates); 49 + await writeServices(openApi, '/', client, mockTemplates); 50 50 51 51 expect(writeFileSync).toHaveBeenCalled(); 52 52 });
+4 -1
packages/openapi-ts/src/utils/write/class.ts
··· 24 24 templates: Templates 25 25 ): Promise<void> => { 26 26 const config = getConfig(); 27 + 27 28 const templateResult = templates.client({ 28 29 $config: config, 29 30 ...client, ··· 32 33 services: sortByName(client.services), 33 34 }); 34 35 35 - await writeFileSync(path.resolve(outputPath, `${config.name}.ts`), templateResult); 36 + if (config.name) { 37 + await writeFileSync(path.resolve(outputPath, `${config.name}.ts`), templateResult); 38 + } 36 39 };
+17 -26
packages/openapi-ts/src/utils/write/client.ts
··· 6 6 import { getConfig } from '../config'; 7 7 import type { Templates } from '../handlebars'; 8 8 import { writeClientClass } from './class'; 9 - import { writeClientCore } from './core'; 9 + import { writeCore } from './core'; 10 10 import { writeClientIndex } from './index'; 11 - import { writeClientModels } from './models'; 12 - import { writeClientSchemas } from './schemas'; 13 - import { writeClientServices } from './services'; 11 + import { writeTypesAndEnums } from './models'; 12 + import { writeSchemas } from './schemas'; 13 + import { writeServices } from './services'; 14 14 15 15 /** 16 16 * Write our OpenAPI client, using the given templates at the given output ··· 38 38 const sections = [ 39 39 { 40 40 dir: 'core', 41 - enabled: config.exportCore, 42 - fn: writeClientCore, 41 + fn: writeCore, 43 42 }, 44 43 { 45 44 dir: '', 46 - enabled: config.schemas, 47 - fn: writeClientSchemas, 45 + fn: writeSchemas, 48 46 }, 49 47 { 50 48 dir: '', 51 - enabled: config.exportModels, 52 - fn: writeClientModels, 49 + fn: writeTypesAndEnums, 53 50 }, 54 51 { 55 52 dir: '', 56 - enabled: config.exportServices, 57 - fn: writeClientServices, 53 + fn: writeServices, 58 54 }, 59 55 { 60 56 dir: '', 61 - enabled: config.name, 62 57 fn: writeClientClass, 63 58 }, 64 59 ] as const; 65 60 66 61 for (const section of sections) { 67 - if (section.enabled) { 68 - const sectionPath = path.resolve(config.output, section.dir); 69 - if (section.dir) { 70 - await rmSync(sectionPath, { 71 - force: true, 72 - recursive: true, 73 - }); 74 - } 75 - await mkdirSync(sectionPath, { 62 + const sectionPath = path.resolve(config.output, section.dir); 63 + if (section.dir) { 64 + await rmSync(sectionPath, { 65 + force: true, 76 66 recursive: true, 77 67 }); 78 - await section.fn(openApi, sectionPath, client, templates); 79 68 } 69 + await mkdirSync(sectionPath, { 70 + recursive: true, 71 + }); 72 + await section.fn(openApi, sectionPath, client, templates); 80 73 } 81 74 82 - if (sections.some(section => section.enabled)) { 83 - await writeClientIndex(client, config.output); 84 - } 75 + await writeClientIndex(client, config.output); 85 76 };
+56 -53
packages/openapi-ts/src/utils/write/core.ts
··· 14 14 * @param client Client containing models, schemas, and services 15 15 * @param templates The loaded handlebar templates 16 16 */ 17 - export const writeClientCore = async ( 17 + export const writeCore = async ( 18 18 openApi: OpenApi, 19 19 outputPath: string, 20 20 client: Client, 21 21 templates: Templates 22 22 ): Promise<void> => { 23 23 const config = getConfig(); 24 + 24 25 const context = { 25 26 httpRequest: getHttpRequestName(config.client), 26 27 server: config.base !== undefined ? config.base : client.server, 27 28 version: client.version, 28 29 }; 29 30 30 - await writeFileSync( 31 - path.resolve(outputPath, 'OpenAPI.ts'), 32 - templates.core.settings({ 33 - $config: config, 34 - ...context, 35 - }) 36 - ); 37 - await writeFileSync( 38 - path.resolve(outputPath, 'ApiError.ts'), 39 - templates.core.apiError({ 40 - $config: config, 41 - ...context, 42 - }) 43 - ); 44 - await writeFileSync( 45 - path.resolve(outputPath, 'ApiRequestOptions.ts'), 46 - templates.core.apiRequestOptions({ 47 - $config: config, 48 - ...context, 49 - }) 50 - ); 51 - await writeFileSync( 52 - path.resolve(outputPath, 'ApiResult.ts'), 53 - templates.core.apiResult({ 54 - $config: config, 55 - ...context, 56 - }) 57 - ); 58 - if (config.client !== 'angular') { 31 + if (config.exportCore) { 32 + await writeFileSync( 33 + path.resolve(outputPath, 'OpenAPI.ts'), 34 + templates.core.settings({ 35 + $config: config, 36 + ...context, 37 + }) 38 + ); 39 + await writeFileSync( 40 + path.resolve(outputPath, 'ApiError.ts'), 41 + templates.core.apiError({ 42 + $config: config, 43 + ...context, 44 + }) 45 + ); 59 46 await writeFileSync( 60 - path.resolve(outputPath, 'CancelablePromise.ts'), 61 - templates.core.cancelablePromise({ 47 + path.resolve(outputPath, 'ApiRequestOptions.ts'), 48 + templates.core.apiRequestOptions({ 62 49 $config: config, 63 50 ...context, 64 51 }) 65 52 ); 66 - } 67 - await writeFileSync( 68 - path.resolve(outputPath, 'request.ts'), 69 - templates.core.request({ 70 - $config: config, 71 - ...context, 72 - }) 73 - ); 74 - 75 - if (config.name) { 76 53 await writeFileSync( 77 - path.resolve(outputPath, 'BaseHttpRequest.ts'), 78 - templates.core.baseHttpRequest({ 54 + path.resolve(outputPath, 'ApiResult.ts'), 55 + templates.core.apiResult({ 79 56 $config: config, 80 57 ...context, 81 58 }) 82 59 ); 60 + if (config.client !== 'angular') { 61 + await writeFileSync( 62 + path.resolve(outputPath, 'CancelablePromise.ts'), 63 + templates.core.cancelablePromise({ 64 + $config: config, 65 + ...context, 66 + }) 67 + ); 68 + } 83 69 await writeFileSync( 84 - path.resolve(outputPath, `${context.httpRequest}.ts`), 85 - templates.core.httpRequest({ 70 + path.resolve(outputPath, 'request.ts'), 71 + templates.core.request({ 86 72 $config: config, 87 73 ...context, 88 74 }) 89 75 ); 90 - } 91 76 92 - if (config.request) { 93 - const requestFile = path.resolve(process.cwd(), config.request); 94 - const requestFileExists = await existsSync(requestFile); 95 - if (!requestFileExists) { 96 - throw new Error(`Custom request file "${requestFile}" does not exists`); 77 + if (config.name) { 78 + await writeFileSync( 79 + path.resolve(outputPath, 'BaseHttpRequest.ts'), 80 + templates.core.baseHttpRequest({ 81 + $config: config, 82 + ...context, 83 + }) 84 + ); 85 + await writeFileSync( 86 + path.resolve(outputPath, `${context.httpRequest}.ts`), 87 + templates.core.httpRequest({ 88 + $config: config, 89 + ...context, 90 + }) 91 + ); 92 + } 93 + 94 + if (config.request) { 95 + const requestFile = path.resolve(process.cwd(), config.request); 96 + const requestFileExists = await existsSync(requestFile); 97 + if (!requestFileExists) { 98 + throw new Error(`Custom request file "${requestFile}" does not exists`); 99 + } 100 + await copyFileSync(requestFile, path.resolve(outputPath, 'request.ts')); 97 101 } 98 - await copyFileSync(requestFile, path.resolve(outputPath, 'request.ts')); 99 102 } 100 103 };
+17 -11
packages/openapi-ts/src/utils/write/index.ts
··· 13 13 export const writeClientIndex = async (client: Client, outputPath: string): Promise<void> => { 14 14 const config = getConfig(); 15 15 16 - const file = new TypeScriptFile().addHeader(); 16 + const fileIndex = new TypeScriptFile().setPath(path.resolve(outputPath, 'index.ts')).addHeader(); 17 17 18 18 if (config.name) { 19 - file.add(compiler.export.named([config.name], `./${config.name}`)); 19 + fileIndex.add(compiler.export.named([config.name], `./${config.name}`)); 20 20 } 21 + 21 22 if (config.exportCore) { 22 - file.add(compiler.export.named('ApiError', './core/ApiError')); 23 + fileIndex.add(compiler.export.named('ApiError', './core/ApiError')); 23 24 if (config.serviceResponse === 'response') { 24 - file.add(compiler.export.named({ isTypeOnly: true, name: 'ApiResult' }, './core/ApiResult')); 25 + fileIndex.add(compiler.export.named({ isTypeOnly: true, name: 'ApiResult' }, './core/ApiResult')); 25 26 } 26 27 if (config.name) { 27 - file.add(compiler.export.named('BaseHttpRequest', './core/BaseHttpRequest')); 28 + fileIndex.add(compiler.export.named('BaseHttpRequest', './core/BaseHttpRequest')); 28 29 } 29 30 if (config.client !== 'angular') { 30 - file.add(compiler.export.named(['CancelablePromise', 'CancelError'], './core/CancelablePromise')); 31 + fileIndex.add(compiler.export.named(['CancelablePromise', 'CancelError'], './core/CancelablePromise')); 31 32 } 32 - file.add(compiler.export.named(['OpenAPI', { isTypeOnly: true, name: 'OpenAPIConfig' }], './core/OpenAPI')); 33 + fileIndex.add( 34 + compiler.export.named(['OpenAPI', { isTypeOnly: true, name: 'OpenAPIConfig' }], './core/OpenAPI') 35 + ); 33 36 } 37 + 34 38 if (client.models.length) { 35 39 if (config.exportModels) { 36 - file.add(compiler.export.all('./models')); 40 + fileIndex.add(compiler.export.all('./models')); 37 41 } 38 42 if (config.schemas) { 39 - file.add(compiler.export.all('./schemas')); 43 + fileIndex.add(compiler.export.all('./schemas')); 40 44 } 41 45 } 46 + 42 47 if (client.services.length && config.exportServices) { 43 - file.add(compiler.export.all('./services')); 48 + fileIndex.add(compiler.export.all('./services')); 44 49 } 45 - file.write(path.resolve(outputPath, 'index.ts')); 50 + 51 + fileIndex.write(); 46 52 };
+68 -39
packages/openapi-ts/src/utils/write/models.ts
··· 1 1 import path from 'node:path'; 2 2 3 3 import { type Comments, compiler, type Node, TypeScriptFile } from '../../compiler'; 4 + import { addLeadingComment } from '../../compiler/utils'; 4 5 import type { Model, OpenApi, OperationParameter, Service } from '../../openApi'; 6 + import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi/common/parser/sanitize'; 5 7 import type { Client } from '../../types/client'; 6 8 import { getConfig } from '../config'; 7 9 import { enumKey, enumName, enumUnionType, enumValue } from '../enum'; ··· 9 11 import { serviceExportedNamespace } from '../handlebars'; 10 12 import { sortByName } from '../sort'; 11 13 import { toType } from './type'; 14 + 15 + type OnNode = (node: Node, type?: 'enum') => void; 12 16 13 17 const emptyModel: Model = { 14 18 $refs: [], ··· 29 33 type: '', 30 34 }; 31 35 32 - const processComposition = (client: Client, model: Model) => [ 33 - processType(client, model), 34 - ...model.enums.flatMap(enumerator => processEnum(client, enumerator, false)), 35 - ]; 36 + const processComposition = (client: Client, model: Model, onNode: OnNode) => { 37 + processType(client, model, onNode); 38 + model.enums.forEach(enumerator => processEnum(client, enumerator, onNode)); 39 + }; 36 40 37 - const processEnum = (client: Client, model: Model, exportType: boolean) => { 41 + const processEnum = (client: Client, model: Model, onNode: OnNode, exportType = false) => { 38 42 const config = getConfig(); 39 - let nodes: Array<Node> = []; 40 43 41 44 const properties: Record<string | number, unknown> = {}; 42 45 const comments: Record<string | number, Comments> = {}; ··· 50 53 } 51 54 }); 52 55 56 + // ignore duplicate enum names 57 + const name = enumName(client, model.name)!; 58 + if (name === null) { 59 + return; 60 + } 61 + 62 + const comment = [model.description && escapeComment(model.description), model.deprecated && '@deprecated']; 63 + 53 64 if (exportType) { 54 - const comment: Comments = [ 55 - model.description && escapeComment(model.description), 56 - model.deprecated && '@deprecated', 57 - ]; 58 - if (config.enums === 'typescript') { 59 - nodes = [...nodes, compiler.types.enum(model.name, properties, comment, comments)]; 60 - } else { 61 - nodes = [...nodes, compiler.typedef.alias(model.name, enumUnionType(model.enum), comment)]; 62 - } 65 + const node = compiler.typedef.alias( 66 + ensureValidTypeScriptJavaScriptIdentifier(model.name), 67 + enumUnionType(model.enum), 68 + comment 69 + ); 70 + onNode(node); 71 + } 72 + 73 + if (config.enums === 'typescript') { 74 + const node = compiler.types.enum({ 75 + comments, 76 + leadingComment: comment, 77 + name, 78 + obj: properties, 79 + }); 80 + onNode(node, 'enum'); 63 81 } 64 82 65 83 if (config.enums === 'javascript') { 66 - const expression = compiler.types.object(properties, { 84 + const expression = compiler.types.object({ 67 85 comments, 68 86 multiLine: true, 87 + obj: properties, 69 88 unescape: true, 70 89 }); 71 - nodes = [...nodes, compiler.export.asConst(enumName(client, model.name)!, expression)]; 90 + const node = compiler.export.asConst(name, expression); 91 + addLeadingComment(node, comment); 92 + onNode(node, 'enum'); 72 93 } 73 - 74 - return nodes; 75 94 }; 76 95 77 - const processType = (client: Client, model: Model) => { 78 - const comment: Comments = [ 79 - model.description && escapeComment(model.description), 80 - model.deprecated && '@deprecated', 81 - ]; 82 - return compiler.typedef.alias(model.name, toType(model), comment); 96 + const processType = (client: Client, model: Model, onNode: OnNode) => { 97 + const comment = [model.description && escapeComment(model.description), model.deprecated && '@deprecated']; 98 + const node = compiler.typedef.alias(model.name, toType(model), comment); 99 + onNode(node); 83 100 }; 84 101 85 - const processModel = (client: Client, model: Model) => { 102 + const processModel = (client: Client, model: Model, onNode: OnNode) => { 86 103 switch (model.export) { 87 104 case 'all-of': 88 105 case 'any-of': 89 106 case 'one-of': 90 107 case 'interface': 91 - return processComposition(client, model); 108 + return processComposition(client, model, onNode); 92 109 case 'enum': 93 - return processEnum(client, model, true); 110 + return processEnum(client, model, onNode, true); 94 111 default: 95 - return processType(client, model); 112 + return processType(client, model, onNode); 96 113 } 97 114 }; 98 115 99 - const processServiceTypes = (services: Service[]) => { 116 + const processServiceTypes = (services: Service[], onNode: OnNode) => { 100 117 type ResMap = Map<number, Model>; 101 118 type MethodMap = Map<'req' | 'res', ResMap | OperationParameter[]>; 102 119 type MethodKey = Service['operations'][number]['method']; ··· 195 212 properties, 196 213 }); 197 214 const namespace = serviceExportedNamespace(); 198 - return compiler.typedef.alias(namespace, type); 215 + const node = compiler.typedef.alias(namespace, type); 216 + onNode(node); 199 217 }; 200 218 201 219 /** ··· 204 222 * @param outputPath Directory to write the generated files to 205 223 * @param client Client containing models, schemas, and services 206 224 */ 207 - export const writeClientModels = async (openApi: OpenApi, outputPath: string, client: Client): Promise<void> => { 208 - const file = new TypeScriptFile().addHeader(); 225 + export const writeTypesAndEnums = async (openApi: OpenApi, outputPath: string, client: Client): Promise<void> => { 226 + const config = getConfig(); 227 + 228 + const fileEnums = new TypeScriptFile().setPath(path.resolve(outputPath, 'enums.gen.ts')).addHeader(); 229 + const fileModels = new TypeScriptFile().setPath(path.resolve(outputPath, 'models.ts')).addHeader(); 209 230 210 231 for (const model of client.models) { 211 - const nodes = processModel(client, model); 212 - const n = Array.isArray(nodes) ? nodes : [nodes]; 213 - file.add(...n); 232 + processModel(client, model, (node, type) => { 233 + if (type === 'enum') { 234 + fileEnums.add(node); 235 + } else { 236 + fileModels.add(node); 237 + } 238 + }); 214 239 } 215 240 216 241 if (client.services.length) { 217 - const serviceTypes = processServiceTypes(client.services); 218 - file.add(serviceTypes); 242 + processServiceTypes(client.services, node => { 243 + fileModels.add(node); 244 + }); 219 245 } 220 246 221 - file.write(path.resolve(outputPath, 'models.ts'), '\n\n'); 247 + if (config.exportModels) { 248 + fileEnums.write('\n\n'); 249 + fileModels.write('\n\n'); 250 + } 222 251 };
+10 -5
packages/openapi-ts/src/utils/write/schemas.ts
··· 3 3 import { compiler, TypeScriptFile } from '../../compiler'; 4 4 import type { OpenApi } from '../../openApi'; 5 5 import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi/common/parser/sanitize'; 6 + import { getConfig } from '../config'; 6 7 7 8 /** 8 9 * Generate Schemas using the Handlebar template and write to disk. 9 10 * @param openApi {@link OpenApi} Dereferenced OpenAPI specification 10 11 * @param outputPath Directory to write the generated files to 11 12 */ 12 - export const writeClientSchemas = async (openApi: OpenApi, outputPath: string): Promise<void> => { 13 - const file = new TypeScriptFile().addHeader(); 13 + export const writeSchemas = async (openApi: OpenApi, outputPath: string): Promise<void> => { 14 + const config = getConfig(); 15 + 16 + const fileSchemas = new TypeScriptFile().setPath(path.resolve(outputPath, 'schemas.ts')).addHeader(); 14 17 15 18 const addSchema = (name: string, obj: any) => { 16 19 const validName = `$${ensureValidTypeScriptJavaScriptIdentifier(name)}`; 17 - const expression = compiler.types.object(obj); 20 + const expression = compiler.types.object({ obj }); 18 21 const statement = compiler.export.asConst(validName, expression); 19 - file.add(statement); 22 + fileSchemas.add(statement); 20 23 }; 21 24 22 25 // OpenAPI 2.0 ··· 47 50 } 48 51 } 49 52 50 - file.write(path.resolve(outputPath, 'schemas.ts'), '\n\n'); 53 + if (config.schemas) { 54 + fileSchemas.write('\n\n'); 55 + } 51 56 };
+16 -14
packages/openapi-ts/src/utils/write/services.ts
··· 1 - import { writeFileSync } from 'node:fs'; 2 1 import path from 'node:path'; 3 2 4 3 import { TypeScriptFile } from '../../compiler'; ··· 15 14 * @param client Client containing models, schemas, and services 16 15 * @param templates The loaded handlebar templates 17 16 */ 18 - export const writeClientServices = async ( 17 + export const writeServices = async ( 19 18 openApi: OpenApi, 20 19 outputPath: string, 21 20 client: Client, 22 21 templates: Templates 23 22 ): Promise<void> => { 24 23 const config = getConfig(); 25 - const file = new TypeScriptFile().addHeader(); 24 + 25 + const fileServices = new TypeScriptFile().setPath(path.resolve(outputPath, 'services.ts')).addHeader(); 26 26 27 27 let imports: string[] = []; 28 28 let results: string[] = []; ··· 39 39 40 40 // Import required packages and core files. 41 41 if (config.client === 'angular') { 42 - file.addNamedImport('Injectable', '@angular/core'); 42 + fileServices.addNamedImport('Injectable', '@angular/core'); 43 43 if (config.name === undefined) { 44 - file.addNamedImport('HttpClient', '@angular/common/http'); 44 + fileServices.addNamedImport('HttpClient', '@angular/common/http'); 45 45 } 46 - file.addNamedImport({ isTypeOnly: true, name: 'Observable' }, 'rxjs'); 46 + fileServices.addNamedImport({ isTypeOnly: true, name: 'Observable' }, 'rxjs'); 47 47 } else { 48 - file.addNamedImport({ isTypeOnly: true, name: 'CancelablePromise' }, './core/CancelablePromise'); 48 + fileServices.addNamedImport({ isTypeOnly: true, name: 'CancelablePromise' }, './core/CancelablePromise'); 49 49 } 50 50 if (config.serviceResponse === 'response') { 51 - file.addNamedImport({ isTypeOnly: true, name: 'ApiResult' }, './core/ApiResult'); 51 + fileServices.addNamedImport({ isTypeOnly: true, name: 'ApiResult' }, './core/ApiResult'); 52 52 } 53 53 if (config.name) { 54 - file.addNamedImport( 54 + fileServices.addNamedImport( 55 55 { isTypeOnly: config.client !== 'angular', name: 'BaseHttpRequest' }, 56 56 './core/BaseHttpRequest' 57 57 ); 58 58 } else { 59 - file.addNamedImport('OpenAPI', './core/OpenAPI'); 60 - file.addNamedImport({ alias: '__request', name: 'request' }, './core/request'); 59 + fileServices.addNamedImport('OpenAPI', './core/OpenAPI'); 60 + fileServices.addNamedImport({ alias: '__request', name: 'request' }, './core/request'); 61 61 } 62 62 63 63 // Import all models required by the services. 64 64 const models = imports.filter(unique).map(imp => ({ isTypeOnly: true, name: imp })); 65 - file.addNamedImport(models, './models'); 65 + fileServices.addNamedImport(models, './models'); 66 66 67 - const data = [file.toString(), ...results].join('\n\n'); 67 + fileServices.add(...results); 68 68 69 - await writeFileSync(path.resolve(outputPath, 'services.ts'), data); 69 + if (config.exportServices) { 70 + fileServices.write('\n\n'); 71 + } 70 72 };
+74
packages/openapi-ts/test/__snapshots__/test/generated/v2/enums.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * This is a simple enum with strings 5 + */ 6 + export const EnumWithStringsEnum = { 7 + SUCCESS: 'Success', 8 + WARNING: 'Warning', 9 + ERROR: 'Error', 10 + _SINGLE_QUOTE_: "'Single Quote'", 11 + _DOUBLE_QUOTES_: '"Double Quotes"', 12 + NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 13 + } as const; 14 + 15 + /** 16 + * This is a simple enum with numbers 17 + */ 18 + export const EnumWithNumbersEnum = { 19 + _1: 1, 20 + _2: 2, 21 + _3: 3, 22 + '_1.1': 1.1, 23 + '_1.2': 1.2, 24 + '_1.3': 1.3, 25 + _100: 100, 26 + _200: 200, 27 + _300: 300, 28 + '_-100': -100, 29 + '_-200': -200, 30 + '_-300': -300, 31 + '_-1.1': -1.1, 32 + '_-1.2': -1.2, 33 + '_-1.3': -1.3, 34 + } as const; 35 + 36 + /** 37 + * This is a simple enum with numbers 38 + */ 39 + export const EnumWithExtensionsEnum = { 40 + /** 41 + * Used when the status of something is successful 42 + */ 43 + CUSTOM_SUCCESS: 200, 44 + /** 45 + * Used when the status of something has a warning 46 + */ 47 + CUSTOM_WARNING: 400, 48 + /** 49 + * Used when the status of something has an error 50 + */ 51 + CUSTOM_ERROR: 500, 52 + } as const; 53 + 54 + /** 55 + * This is a simple enum with strings 56 + */ 57 + export const TestEnum = { 58 + SUCCESS: 'Success', 59 + WARNING: 'Warning', 60 + ERROR: 'Error', 61 + ØÆÅ字符串: 'ØÆÅ字符串', 62 + } as const; 63 + 64 + /** 65 + * These are the HTTP error code enums 66 + */ 67 + export const StatusCodeEnum = { 68 + _100: '100', 69 + _200_FOO: '200 FOO', 70 + _300_FOO_BAR: '300 FOO_BAR', 71 + _400_FOO_BAR: '400 foo-bar', 72 + _500_FOO_BAR: '500 foo.bar', 73 + _600_FOO_BAR: '600 foo&bar', 74 + } as const;
-58
packages/openapi-ts/test/__snapshots__/test/generated/v2/models.ts.snap
··· 84 84 | '"Double Quotes"' 85 85 | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; 86 86 87 - export const EnumWithStringsEnum = { 88 - SUCCESS: 'Success', 89 - WARNING: 'Warning', 90 - ERROR: 'Error', 91 - _SINGLE_QUOTE_: "'Single Quote'", 92 - _DOUBLE_QUOTES_: '"Double Quotes"', 93 - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 94 - } as const; 95 - 96 87 /** 97 88 * This is a simple enum with numbers 98 89 */ 99 90 export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; 100 91 101 - export const EnumWithNumbersEnum = { 102 - _1: 1, 103 - _2: 2, 104 - _3: 3, 105 - '_1.1': 1.1, 106 - '_1.2': 1.2, 107 - '_1.3': 1.3, 108 - _100: 100, 109 - _200: 200, 110 - _300: 300, 111 - '_-100': -100, 112 - '_-200': -200, 113 - '_-300': -300, 114 - '_-1.1': -1.1, 115 - '_-1.2': -1.2, 116 - '_-1.3': -1.3, 117 - } as const; 118 - 119 92 /** 120 93 * Success=1,Warning=2,Error=3 121 94 */ ··· 125 98 * This is a simple enum with numbers 126 99 */ 127 100 export type EnumWithExtensions = 200 | 400 | 500; 128 - 129 - export const EnumWithExtensionsEnum = { 130 - /** 131 - * Used when the status of something is successful 132 - */ 133 - CUSTOM_SUCCESS: 200, 134 - /** 135 - * Used when the status of something has a warning 136 - */ 137 - CUSTOM_WARNING: 400, 138 - /** 139 - * Used when the status of something has an error 140 - */ 141 - CUSTOM_ERROR: 500, 142 - } as const; 143 101 144 102 /** 145 103 * This is a simple array with numbers ··· 271 229 */ 272 230 bool?: boolean; 273 231 }; 274 - 275 - export const TestEnum = { 276 - SUCCESS: 'Success', 277 - WARNING: 'Warning', 278 - ERROR: 'Error', 279 - ØÆÅ字符串: 'ØÆÅ字符串', 280 - } as const; 281 - 282 - export const StatusCodeEnum = { 283 - _100: '100', 284 - _200_FOO: '200 FOO', 285 - _300_FOO_BAR: '300 FOO_BAR', 286 - _400_FOO_BAR: '400 foo-bar', 287 - _500_FOO_BAR: '500 foo.bar', 288 - _600_FOO_BAR: '600 foo&bar', 289 - } as const; 290 232 291 233 /** 292 234 * This is a model with one enum
+111
packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * This is a simple enum with strings 5 + */ 6 + export const EnumWithStringsEnum = { 7 + SUCCESS: 'Success', 8 + WARNING: 'Warning', 9 + ERROR: 'Error', 10 + _SINGLE_QUOTE_: "'Single Quote'", 11 + _DOUBLE_QUOTES_: '"Double Quotes"', 12 + NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 13 + } as const; 14 + 15 + export const EnumWithReplacedCharactersEnum = { 16 + _SINGLE_QUOTE_: "'Single Quote'", 17 + _DOUBLE_QUOTES_: '"Double Quotes"', 18 + ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', 19 + '_3.1': 3.1, 20 + EMPTY_STRING: '', 21 + } as const; 22 + 23 + /** 24 + * This is a simple enum with numbers 25 + */ 26 + export const EnumWithNumbersEnum = { 27 + _1: 1, 28 + _2: 2, 29 + _3: 3, 30 + '_1.1': 1.1, 31 + '_1.2': 1.2, 32 + '_1.3': 1.3, 33 + _100: 100, 34 + _200: 200, 35 + _300: 300, 36 + '_-100': -100, 37 + '_-200': -200, 38 + '_-300': -300, 39 + '_-1.1': -1.1, 40 + '_-1.2': -1.2, 41 + '_-1.3': -1.3, 42 + } as const; 43 + 44 + /** 45 + * This is a simple enum with numbers 46 + */ 47 + export const EnumWithExtensionsEnum = { 48 + /** 49 + * Used when the status of something is successful 50 + */ 51 + CUSTOM_SUCCESS: 200, 52 + /** 53 + * Used when the status of something has a warning 54 + */ 55 + CUSTOM_WARNING: 400, 56 + /** 57 + * Used when the status of something has an error 58 + */ 59 + CUSTOM_ERROR: 500, 60 + } as const; 61 + 62 + export const EnumWithXEnumNamesEnum = { 63 + zero: 0, 64 + one: 1, 65 + two: 2, 66 + } as const; 67 + 68 + /** 69 + * This is a simple enum with strings 70 + */ 71 + export const FooBarEnumEnum = { 72 + SUCCESS: 'Success', 73 + WARNING: 'Warning', 74 + ERROR: 'Error', 75 + ØÆÅ字符串: 'ØÆÅ字符串', 76 + } as const; 77 + 78 + /** 79 + * These are the HTTP error code enums 80 + */ 81 + export const StatusCodeEnum = { 82 + _100: '100', 83 + _200_FOO: '200 FOO', 84 + _300_FOO_BAR: '300 FOO_BAR', 85 + _400_FOO_BAR: '400 foo-bar', 86 + _500_FOO_BAR: '500 foo.bar', 87 + _600_FOO_BAR: '600 foo&bar', 88 + } as const; 89 + 90 + export const FooBarBazQuxEnum = { 91 + _3_0: '3.0', 92 + } as const; 93 + 94 + export const Enum1Enum = { 95 + BIRD: 'Bird', 96 + DOG: 'Dog', 97 + } as const; 98 + 99 + export const FooEnum = { 100 + BAR: 'Bar', 101 + } as const; 102 + 103 + export const ModelWithNestedArrayEnumsDataFooEnum = { 104 + FOO: 'foo', 105 + BAR: 'bar', 106 + } as const; 107 + 108 + export const ModelWithNestedArrayEnumsDataBarEnum = { 109 + BAZ: 'baz', 110 + QUX: 'qux', 111 + } as const;
-109
packages/openapi-ts/test/__snapshots__/test/generated/v3/models.ts.snap
··· 84 84 | '"Double Quotes"' 85 85 | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; 86 86 87 - export const EnumWithStringsEnum = { 88 - SUCCESS: 'Success', 89 - WARNING: 'Warning', 90 - ERROR: 'Error', 91 - _SINGLE_QUOTE_: "'Single Quote'", 92 - _DOUBLE_QUOTES_: '"Double Quotes"', 93 - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 94 - } as const; 95 - 96 87 export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; 97 88 98 - export const EnumWithReplacedCharactersEnum = { 99 - _SINGLE_QUOTE_: "'Single Quote'", 100 - _DOUBLE_QUOTES_: '"Double Quotes"', 101 - ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', 102 - '_3.1': 3.1, 103 - EMPTY_STRING: '', 104 - } as const; 105 - 106 89 /** 107 90 * This is a simple enum with numbers 108 91 */ 109 92 export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; 110 93 111 - export const EnumWithNumbersEnum = { 112 - _1: 1, 113 - _2: 2, 114 - _3: 3, 115 - '_1.1': 1.1, 116 - '_1.2': 1.2, 117 - '_1.3': 1.3, 118 - _100: 100, 119 - _200: 200, 120 - _300: 300, 121 - '_-100': -100, 122 - '_-200': -200, 123 - '_-300': -300, 124 - '_-1.1': -1.1, 125 - '_-1.2': -1.2, 126 - '_-1.3': -1.3, 127 - } as const; 128 - 129 94 /** 130 95 * Success=1,Warning=2,Error=3 131 96 */ ··· 136 101 */ 137 102 export type EnumWithExtensions = 200 | 400 | 500; 138 103 139 - export const EnumWithExtensionsEnum = { 140 - /** 141 - * Used when the status of something is successful 142 - */ 143 - CUSTOM_SUCCESS: 200, 144 - /** 145 - * Used when the status of something has a warning 146 - */ 147 - CUSTOM_WARNING: 400, 148 - /** 149 - * Used when the status of something has an error 150 - */ 151 - CUSTOM_ERROR: 500, 152 - } as const; 153 - 154 104 export type EnumWithXEnumNames = 0 | 1 | 2; 155 105 156 - export const EnumWithXEnumNamesEnum = { 157 - zero: 0, 158 - one: 1, 159 - two: 2, 160 - } as const; 161 - 162 106 /** 163 107 * This is a simple array with numbers 164 108 */ ··· 319 263 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 320 264 }; 321 265 322 - export const FooBarEnumEnum = { 323 - SUCCESS: 'Success', 324 - WARNING: 'Warning', 325 - ERROR: 'Error', 326 - ØÆÅ字符串: 'ØÆÅ字符串', 327 - } as const; 328 - 329 266 /** 330 267 * This is a model with one enum 331 268 */ ··· 344 281 bool?: boolean; 345 282 }; 346 283 347 - export const FooBarEnumEnum2 = { 348 - SUCCESS: 'Success', 349 - WARNING: 'Warning', 350 - ERROR: 'Error', 351 - ØÆÅ字符串: 'ØÆÅ字符串', 352 - } as const; 353 - 354 - export const StatusCodeEnum = { 355 - _100: '100', 356 - _200_FOO: '200 FOO', 357 - _300_FOO_BAR: '300 FOO_BAR', 358 - _400_FOO_BAR: '400 foo-bar', 359 - _500_FOO_BAR: '500 foo.bar', 360 - _600_FOO_BAR: '600 foo&bar', 361 - } as const; 362 - 363 284 /** 364 285 * This is a model with one enum with escaped name 365 286 */ ··· 367 288 'foo-bar-baz-qux'?: '3.0'; 368 289 }; 369 290 370 - export const FooBarBazQuxEnum = { 371 - _3_0: '3.0', 372 - } as const; 373 - 374 291 /** 375 292 * This is a model with one enum 376 293 */ ··· 394 311 */ 395 312 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 396 313 }; 397 - 398 - export const FooBarEnumEnum3 = { 399 - SUCCESS: 'Success', 400 - WARNING: 'Warning', 401 - ERROR: 'Error', 402 - ØÆÅ字符串: 'ØÆÅ字符串', 403 - } as const; 404 314 405 315 /** 406 316 * This is a model with one property containing a reference ··· 520 430 }; 521 431 522 432 export type Enum1 = 'Bird' | 'Dog'; 523 - 524 - export const Enum1Enum = { 525 - BIRD: 'Bird', 526 - DOG: 'Dog', 527 - } as const; 528 433 529 434 export type ConstValue = 'ConstValue'; 530 435 ··· 797 702 foo: 'Corge'; 798 703 }; 799 704 800 - export const FooEnum = { 801 - BAR: 'Bar', 802 - } as const; 803 - 804 705 export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; 805 706 806 - export const ModelWithNestedArrayEnumsDataFooEnum = { 807 - FOO: 'foo', 808 - BAR: 'bar', 809 - } as const; 810 - 811 707 export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; 812 - 813 - export const ModelWithNestedArrayEnumsDataBarEnum = { 814 - BAZ: 'baz', 815 - QUX: 'qux', 816 - } as const; 817 708 818 709 export type ModelWithNestedArrayEnumsData = { 819 710 foo?: Array<ModelWithNestedArrayEnumsDataFoo>;
+111
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * This is a simple enum with strings 5 + */ 6 + export const EnumWithStringsEnum = { 7 + SUCCESS: 'Success', 8 + WARNING: 'Warning', 9 + ERROR: 'Error', 10 + _SINGLE_QUOTE_: "'Single Quote'", 11 + _DOUBLE_QUOTES_: '"Double Quotes"', 12 + NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 13 + } as const; 14 + 15 + export const EnumWithReplacedCharactersEnum = { 16 + _SINGLE_QUOTE_: "'Single Quote'", 17 + _DOUBLE_QUOTES_: '"Double Quotes"', 18 + ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', 19 + '_3.1': 3.1, 20 + EMPTY_STRING: '', 21 + } as const; 22 + 23 + /** 24 + * This is a simple enum with numbers 25 + */ 26 + export const EnumWithNumbersEnum = { 27 + _1: 1, 28 + _2: 2, 29 + _3: 3, 30 + '_1.1': 1.1, 31 + '_1.2': 1.2, 32 + '_1.3': 1.3, 33 + _100: 100, 34 + _200: 200, 35 + _300: 300, 36 + '_-100': -100, 37 + '_-200': -200, 38 + '_-300': -300, 39 + '_-1.1': -1.1, 40 + '_-1.2': -1.2, 41 + '_-1.3': -1.3, 42 + } as const; 43 + 44 + /** 45 + * This is a simple enum with numbers 46 + */ 47 + export const EnumWithExtensionsEnum = { 48 + /** 49 + * Used when the status of something is successful 50 + */ 51 + CUSTOM_SUCCESS: 200, 52 + /** 53 + * Used when the status of something has a warning 54 + */ 55 + CUSTOM_WARNING: 400, 56 + /** 57 + * Used when the status of something has an error 58 + */ 59 + CUSTOM_ERROR: 500, 60 + } as const; 61 + 62 + export const EnumWithXEnumNamesEnum = { 63 + zero: 0, 64 + one: 1, 65 + two: 2, 66 + } as const; 67 + 68 + /** 69 + * This is a simple enum with strings 70 + */ 71 + export const FooBarEnumEnum = { 72 + SUCCESS: 'Success', 73 + WARNING: 'Warning', 74 + ERROR: 'Error', 75 + ØÆÅ字符串: 'ØÆÅ字符串', 76 + } as const; 77 + 78 + /** 79 + * These are the HTTP error code enums 80 + */ 81 + export const StatusCodeEnum = { 82 + _100: '100', 83 + _200_FOO: '200 FOO', 84 + _300_FOO_BAR: '300 FOO_BAR', 85 + _400_FOO_BAR: '400 foo-bar', 86 + _500_FOO_BAR: '500 foo.bar', 87 + _600_FOO_BAR: '600 foo&bar', 88 + } as const; 89 + 90 + export const FooBarBazQuxEnum = { 91 + _3_0: '3.0', 92 + } as const; 93 + 94 + export const Enum1Enum = { 95 + BIRD: 'Bird', 96 + DOG: 'Dog', 97 + } as const; 98 + 99 + export const FooEnum = { 100 + BAR: 'Bar', 101 + } as const; 102 + 103 + export const ModelWithNestedArrayEnumsDataFooEnum = { 104 + FOO: 'foo', 105 + BAR: 'bar', 106 + } as const; 107 + 108 + export const ModelWithNestedArrayEnumsDataBarEnum = { 109 + BAZ: 'baz', 110 + QUX: 'qux', 111 + } as const;
-109
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/models.ts.snap
··· 84 84 | '"Double Quotes"' 85 85 | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; 86 86 87 - export const EnumWithStringsEnum = { 88 - SUCCESS: 'Success', 89 - WARNING: 'Warning', 90 - ERROR: 'Error', 91 - _SINGLE_QUOTE_: "'Single Quote'", 92 - _DOUBLE_QUOTES_: '"Double Quotes"', 93 - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', 94 - } as const; 95 - 96 87 export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; 97 88 98 - export const EnumWithReplacedCharactersEnum = { 99 - _SINGLE_QUOTE_: "'Single Quote'", 100 - _DOUBLE_QUOTES_: '"Double Quotes"', 101 - ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', 102 - '_3.1': 3.1, 103 - EMPTY_STRING: '', 104 - } as const; 105 - 106 89 /** 107 90 * This is a simple enum with numbers 108 91 */ 109 92 export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; 110 93 111 - export const EnumWithNumbersEnum = { 112 - _1: 1, 113 - _2: 2, 114 - _3: 3, 115 - '_1.1': 1.1, 116 - '_1.2': 1.2, 117 - '_1.3': 1.3, 118 - _100: 100, 119 - _200: 200, 120 - _300: 300, 121 - '_-100': -100, 122 - '_-200': -200, 123 - '_-300': -300, 124 - '_-1.1': -1.1, 125 - '_-1.2': -1.2, 126 - '_-1.3': -1.3, 127 - } as const; 128 - 129 94 /** 130 95 * Success=1,Warning=2,Error=3 131 96 */ ··· 136 101 */ 137 102 export type EnumWithExtensions = 200 | 400 | 500; 138 103 139 - export const EnumWithExtensionsEnum = { 140 - /** 141 - * Used when the status of something is successful 142 - */ 143 - CUSTOM_SUCCESS: 200, 144 - /** 145 - * Used when the status of something has a warning 146 - */ 147 - CUSTOM_WARNING: 400, 148 - /** 149 - * Used when the status of something has an error 150 - */ 151 - CUSTOM_ERROR: 500, 152 - } as const; 153 - 154 104 export type EnumWithXEnumNames = 0 | 1 | 2; 155 105 156 - export const EnumWithXEnumNamesEnum = { 157 - zero: 0, 158 - one: 1, 159 - two: 2, 160 - } as const; 161 - 162 106 /** 163 107 * This is a simple array with numbers 164 108 */ ··· 319 263 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 320 264 }; 321 265 322 - export const FooBarEnumEnum = { 323 - SUCCESS: 'Success', 324 - WARNING: 'Warning', 325 - ERROR: 'Error', 326 - ØÆÅ字符串: 'ØÆÅ字符串', 327 - } as const; 328 - 329 266 /** 330 267 * This is a model with one enum 331 268 */ ··· 344 281 bool?: boolean; 345 282 }; 346 283 347 - export const FooBarEnumEnum2 = { 348 - SUCCESS: 'Success', 349 - WARNING: 'Warning', 350 - ERROR: 'Error', 351 - ØÆÅ字符串: 'ØÆÅ字符串', 352 - } as const; 353 - 354 - export const StatusCodeEnum = { 355 - _100: '100', 356 - _200_FOO: '200 FOO', 357 - _300_FOO_BAR: '300 FOO_BAR', 358 - _400_FOO_BAR: '400 foo-bar', 359 - _500_FOO_BAR: '500 foo.bar', 360 - _600_FOO_BAR: '600 foo&bar', 361 - } as const; 362 - 363 284 /** 364 285 * This is a model with one enum with escaped name 365 286 */ ··· 367 288 'foo-bar-baz-qux'?: '3.0'; 368 289 }; 369 290 370 - export const FooBarBazQuxEnum = { 371 - _3_0: '3.0', 372 - } as const; 373 - 374 291 /** 375 292 * This is a model with one enum 376 293 */ ··· 394 311 */ 395 312 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 396 313 }; 397 - 398 - export const FooBarEnumEnum3 = { 399 - SUCCESS: 'Success', 400 - WARNING: 'Warning', 401 - ERROR: 'Error', 402 - ØÆÅ字符串: 'ØÆÅ字符串', 403 - } as const; 404 314 405 315 /** 406 316 * This is a model with one property containing a reference ··· 520 430 }; 521 431 522 432 export type Enum1 = 'Bird' | 'Dog'; 523 - 524 - export const Enum1Enum = { 525 - BIRD: 'Bird', 526 - DOG: 'Dog', 527 - } as const; 528 433 529 434 export type ConstValue = 'ConstValue'; 530 435 ··· 797 702 foo: 'Corge'; 798 703 }; 799 704 800 - export const FooEnum = { 801 - BAR: 'Bar', 802 - } as const; 803 - 804 705 export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; 805 706 806 - export const ModelWithNestedArrayEnumsDataFooEnum = { 807 - FOO: 'foo', 808 - BAR: 'bar', 809 - } as const; 810 - 811 707 export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; 812 - 813 - export const ModelWithNestedArrayEnumsDataBarEnum = { 814 - BAZ: 'baz', 815 - QUX: 'qux', 816 - } as const; 817 708 818 709 export type ModelWithNestedArrayEnumsData = { 819 710 foo?: Array<ModelWithNestedArrayEnumsDataFoo>;
+111
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * This is a simple enum with strings 5 + */ 6 + export enum EnumWithStringsEnum { 7 + SUCCESS = 'Success', 8 + WARNING = 'Warning', 9 + ERROR = 'Error', 10 + _SINGLE_QUOTE_ = "'Single Quote'", 11 + _DOUBLE_QUOTES_ = '"Double Quotes"', 12 + NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'Non-ascii: øæåôöØÆÅÔÖ字符串', 13 + } 14 + 15 + export enum EnumWithReplacedCharactersEnum { 16 + _SINGLE_QUOTE_ = "'Single Quote'", 17 + _DOUBLE_QUOTES_ = '"Double Quotes"', 18 + ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'øæåôöØÆÅÔÖ字符串', 19 + '_3.1' = 3.1, 20 + EMPTY_STRING = '', 21 + } 22 + 23 + /** 24 + * This is a simple enum with numbers 25 + */ 26 + export enum EnumWithNumbersEnum { 27 + '_1' = 1, 28 + '_2' = 2, 29 + '_3' = 3, 30 + '_1.1' = 1.1, 31 + '_1.2' = 1.2, 32 + '_1.3' = 1.3, 33 + '_100' = 100, 34 + '_200' = 200, 35 + '_300' = 300, 36 + '_-100' = -100, 37 + '_-200' = -200, 38 + '_-300' = -300, 39 + '_-1.1' = -1.1, 40 + '_-1.2' = -1.2, 41 + '_-1.3' = -1.3, 42 + } 43 + 44 + /** 45 + * This is a simple enum with numbers 46 + */ 47 + export enum EnumWithExtensionsEnum { 48 + /** 49 + * Used when the status of something is successful 50 + */ 51 + CUSTOM_SUCCESS = 200, 52 + /** 53 + * Used when the status of something has a warning 54 + */ 55 + CUSTOM_WARNING = 400, 56 + /** 57 + * Used when the status of something has an error 58 + */ 59 + CUSTOM_ERROR = 500, 60 + } 61 + 62 + export enum EnumWithXEnumNamesEnum { 63 + zero = 0, 64 + one = 1, 65 + two = 2, 66 + } 67 + 68 + /** 69 + * This is a simple enum with strings 70 + */ 71 + export enum FooBarEnumEnum { 72 + SUCCESS = 'Success', 73 + WARNING = 'Warning', 74 + ERROR = 'Error', 75 + ØÆÅ字符串 = 'ØÆÅ字符串', 76 + } 77 + 78 + /** 79 + * These are the HTTP error code enums 80 + */ 81 + export enum StatusCodeEnum { 82 + _100 = '100', 83 + _200_FOO = '200 FOO', 84 + _300_FOO_BAR = '300 FOO_BAR', 85 + _400_FOO_BAR = '400 foo-bar', 86 + _500_FOO_BAR = '500 foo.bar', 87 + _600_FOO_BAR = '600 foo&bar', 88 + } 89 + 90 + export enum FooBarBazQuxEnum { 91 + _3_0 = '3.0', 92 + } 93 + 94 + export enum Enum1Enum { 95 + BIRD = 'Bird', 96 + DOG = 'Dog', 97 + } 98 + 99 + export enum FooEnum { 100 + BAR = 'Bar', 101 + } 102 + 103 + export enum ModelWithNestedArrayEnumsDataFooEnum { 104 + FOO = 'foo', 105 + BAR = 'bar', 106 + } 107 + 108 + export enum ModelWithNestedArrayEnumsDataBarEnum { 109 + BAZ = 'baz', 110 + QUX = 'qux', 111 + }
+14 -63
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/models.ts.snap
··· 76 76 /** 77 77 * This is a simple enum with strings 78 78 */ 79 - export enum EnumWithStrings { 80 - SUCCESS = 'Success', 81 - WARNING = 'Warning', 82 - ERROR = 'Error', 83 - _SINGLE_QUOTE_ = "'Single Quote'", 84 - _DOUBLE_QUOTES_ = '"Double Quotes"', 85 - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'Non-ascii: øæåôöØÆÅÔÖ字符串', 86 - } 79 + export type EnumWithStrings = 80 + | 'Success' 81 + | 'Warning' 82 + | 'Error' 83 + | "'Single Quote'" 84 + | '"Double Quotes"' 85 + | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; 87 86 88 - export enum EnumWithReplacedCharacters { 89 - _SINGLE_QUOTE_ = "'Single Quote'", 90 - _DOUBLE_QUOTES_ = '"Double Quotes"', 91 - ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'øæåôöØÆÅÔÖ字符串', 92 - '_3.1' = 3.1, 93 - EMPTY_STRING = '', 94 - } 87 + export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; 95 88 96 89 /** 97 90 * This is a simple enum with numbers 98 91 */ 99 - export enum EnumWithNumbers { 100 - '_1' = 1, 101 - '_2' = 2, 102 - '_3' = 3, 103 - '_1.1' = 1.1, 104 - '_1.2' = 1.2, 105 - '_1.3' = 1.3, 106 - '_100' = 100, 107 - '_200' = 200, 108 - '_300' = 300, 109 - '_-100' = -100, 110 - '_-200' = -200, 111 - '_-300' = -300, 112 - '_-1.1' = -1.1, 113 - '_-1.2' = -1.2, 114 - '_-1.3' = -1.3, 115 - } 92 + export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; 116 93 117 94 /** 118 95 * Success=1,Warning=2,Error=3 ··· 122 99 /** 123 100 * This is a simple enum with numbers 124 101 */ 125 - export enum EnumWithExtensions { 126 - /** 127 - * Used when the status of something is successful 128 - */ 129 - CUSTOM_SUCCESS = 200, 130 - /** 131 - * Used when the status of something has a warning 132 - */ 133 - CUSTOM_WARNING = 400, 134 - /** 135 - * Used when the status of something has an error 136 - */ 137 - CUSTOM_ERROR = 500, 138 - } 102 + export type EnumWithExtensions = 200 | 400 | 500; 139 103 140 - export enum EnumWithXEnumNames { 141 - zero = 0, 142 - one = 1, 143 - two = 2, 144 - } 104 + export type EnumWithXEnumNames = 0 | 1 | 2; 145 105 146 106 /** 147 107 * This is a simple array with numbers ··· 469 429 propA?: Array<ModelWithDictionary | null> | Array<ModelWithArray | null>; 470 430 }; 471 431 472 - export enum Enum1 { 473 - BIRD = 'Bird', 474 - DOG = 'Dog', 475 - } 432 + export type Enum1 = 'Bird' | 'Dog'; 476 433 477 434 export type ConstValue = 'ConstValue'; 478 435 ··· 745 702 foo: 'Corge'; 746 703 }; 747 704 748 - export enum ModelWithNestedArrayEnumsDataFoo { 749 - FOO = 'foo', 750 - BAR = 'bar', 751 - } 705 + export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; 752 706 753 - export enum ModelWithNestedArrayEnumsDataBar { 754 - BAZ = 'baz', 755 - QUX = 'qux', 756 - } 707 + export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; 757 708 758 709 export type ModelWithNestedArrayEnumsData = { 759 710 foo?: Array<ModelWithNestedArrayEnumsDataFoo>;
-21
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/ApiError.ts.snap
··· 1 - import type { ApiRequestOptions } from './ApiRequestOptions'; 2 - import type { ApiResult } from './ApiResult'; 3 - 4 - export class ApiError extends Error { 5 - public readonly url: string; 6 - public readonly status: number; 7 - public readonly statusText: string; 8 - public readonly body: unknown; 9 - public readonly request: ApiRequestOptions; 10 - 11 - constructor(request: ApiRequestOptions, response: ApiResult, message: string) { 12 - super(message); 13 - 14 - this.name = 'ApiError'; 15 - this.url = response.url; 16 - this.status = response.status; 17 - this.statusText = response.statusText; 18 - this.body = response.body; 19 - this.request = request; 20 - } 21 - }
-13
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/ApiRequestOptions.ts.snap
··· 1 - export type ApiRequestOptions = { 2 - readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; 3 - readonly url: string; 4 - readonly path?: Record<string, unknown>; 5 - readonly cookies?: Record<string, unknown>; 6 - readonly headers?: Record<string, unknown>; 7 - readonly query?: Record<string, unknown>; 8 - readonly formData?: Record<string, unknown>; 9 - readonly body?: any; 10 - readonly mediaType?: string; 11 - readonly responseHeader?: string; 12 - readonly errors?: Record<number, string>; 13 - };
-7
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/ApiResult.ts.snap
··· 1 - export type ApiResult<TData = any> = { 2 - readonly body: TData; 3 - readonly ok: boolean; 4 - readonly status: number; 5 - readonly statusText: string; 6 - readonly url: string; 7 - };
-126
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/CancelablePromise.ts.snap
··· 1 - export class CancelError extends Error { 2 - constructor(message: string) { 3 - super(message); 4 - this.name = 'CancelError'; 5 - } 6 - 7 - public get isCancelled(): boolean { 8 - return true; 9 - } 10 - } 11 - 12 - export interface OnCancel { 13 - readonly isResolved: boolean; 14 - readonly isRejected: boolean; 15 - readonly isCancelled: boolean; 16 - 17 - (cancelHandler: () => void): void; 18 - } 19 - 20 - export class CancelablePromise<T> implements Promise<T> { 21 - private _isResolved: boolean; 22 - private _isRejected: boolean; 23 - private _isCancelled: boolean; 24 - readonly cancelHandlers: (() => void)[]; 25 - readonly promise: Promise<T>; 26 - private _resolve?: (value: T | PromiseLike<T>) => void; 27 - private _reject?: (reason?: unknown) => void; 28 - 29 - constructor( 30 - executor: ( 31 - resolve: (value: T | PromiseLike<T>) => void, 32 - reject: (reason?: unknown) => void, 33 - onCancel: OnCancel 34 - ) => void 35 - ) { 36 - this._isResolved = false; 37 - this._isRejected = false; 38 - this._isCancelled = false; 39 - this.cancelHandlers = []; 40 - this.promise = new Promise<T>((resolve, reject) => { 41 - this._resolve = resolve; 42 - this._reject = reject; 43 - 44 - const onResolve = (value: T | PromiseLike<T>): void => { 45 - if (this._isResolved || this._isRejected || this._isCancelled) { 46 - return; 47 - } 48 - this._isResolved = true; 49 - if (this._resolve) this._resolve(value); 50 - }; 51 - 52 - const onReject = (reason?: unknown): void => { 53 - if (this._isResolved || this._isRejected || this._isCancelled) { 54 - return; 55 - } 56 - this._isRejected = true; 57 - if (this._reject) this._reject(reason); 58 - }; 59 - 60 - const onCancel = (cancelHandler: () => void): void => { 61 - if (this._isResolved || this._isRejected || this._isCancelled) { 62 - return; 63 - } 64 - this.cancelHandlers.push(cancelHandler); 65 - }; 66 - 67 - Object.defineProperty(onCancel, 'isResolved', { 68 - get: (): boolean => this._isResolved, 69 - }); 70 - 71 - Object.defineProperty(onCancel, 'isRejected', { 72 - get: (): boolean => this._isRejected, 73 - }); 74 - 75 - Object.defineProperty(onCancel, 'isCancelled', { 76 - get: (): boolean => this._isCancelled, 77 - }); 78 - 79 - return executor(onResolve, onReject, onCancel as OnCancel); 80 - }); 81 - } 82 - 83 - get [Symbol.toStringTag]() { 84 - return 'Cancellable Promise'; 85 - } 86 - 87 - public then<TResult1 = T, TResult2 = never>( 88 - onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, 89 - onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null 90 - ): Promise<TResult1 | TResult2> { 91 - return this.promise.then(onFulfilled, onRejected); 92 - } 93 - 94 - public catch<TResult = never>( 95 - onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null 96 - ): Promise<T | TResult> { 97 - return this.promise.catch(onRejected); 98 - } 99 - 100 - public finally(onFinally?: (() => void) | null): Promise<T> { 101 - return this.promise.finally(onFinally); 102 - } 103 - 104 - public cancel(): void { 105 - if (this._isResolved || this._isRejected || this._isCancelled) { 106 - return; 107 - } 108 - this._isCancelled = true; 109 - if (this.cancelHandlers.length) { 110 - try { 111 - for (const cancelHandler of this.cancelHandlers) { 112 - cancelHandler(); 113 - } 114 - } catch (error) { 115 - console.warn('Cancellation threw an error', error); 116 - return; 117 - } 118 - } 119 - this.cancelHandlers.length = 0; 120 - if (this._reject) this._reject(new CancelError('Request aborted')); 121 - } 122 - 123 - public get isCancelled(): boolean { 124 - return this._isCancelled; 125 - } 126 - }
-50
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/OpenAPI.ts.snap
··· 1 - import type { ApiRequestOptions } from './ApiRequestOptions'; 2 - 3 - type Headers = Record<string, string>; 4 - type Middleware<T> = (value: T) => T | Promise<T>; 5 - type Resolver<T> = (options: ApiRequestOptions) => Promise<T>; 6 - 7 - export class Interceptors<T> { 8 - _fns: Middleware<T>[]; 9 - 10 - constructor() { 11 - this._fns = []; 12 - } 13 - 14 - eject(fn: Middleware<T>) { 15 - const index = this._fns.indexOf(fn); 16 - if (index !== -1) { 17 - this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; 18 - } 19 - } 20 - 21 - use(fn: Middleware<T>) { 22 - this._fns = [...this._fns, fn]; 23 - } 24 - } 25 - 26 - export type OpenAPIConfig = { 27 - BASE: string; 28 - CREDENTIALS: 'include' | 'omit' | 'same-origin'; 29 - ENCODE_PATH?: ((path: string) => string) | undefined; 30 - HEADERS?: Headers | Resolver<Headers> | undefined; 31 - PASSWORD?: string | Resolver<string> | undefined; 32 - TOKEN?: string | Resolver<string> | undefined; 33 - USERNAME?: string | Resolver<string> | undefined; 34 - VERSION: string; 35 - WITH_CREDENTIALS: boolean; 36 - interceptors: { request: Interceptors<RequestInit>; response: Interceptors<Response> }; 37 - }; 38 - 39 - export const OpenAPI: OpenAPIConfig = { 40 - BASE: 'http://localhost:3000/base', 41 - CREDENTIALS: 'include', 42 - ENCODE_PATH: undefined, 43 - HEADERS: undefined, 44 - PASSWORD: undefined, 45 - TOKEN: undefined, 46 - USERNAME: undefined, 47 - VERSION: '1.0', 48 - WITH_CREDENTIALS: false, 49 - interceptors: { request: new Interceptors(), response: new Interceptors() }, 50 - };
-351
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/core/request.ts.snap
··· 1 - import { ApiError } from './ApiError'; 2 - import type { ApiRequestOptions } from './ApiRequestOptions'; 3 - import type { ApiResult } from './ApiResult'; 4 - import { CancelablePromise } from './CancelablePromise'; 5 - import type { OnCancel } from './CancelablePromise'; 6 - import type { OpenAPIConfig } from './OpenAPI'; 7 - 8 - export const isString = (value: unknown): value is string => { 9 - return typeof value === 'string'; 10 - }; 11 - 12 - export const isStringWithValue = (value: unknown): value is string => { 13 - return isString(value) && value !== ''; 14 - }; 15 - 16 - export const isBlob = (value: any): value is Blob => { 17 - return value instanceof Blob; 18 - }; 19 - 20 - export const isFormData = (value: unknown): value is FormData => { 21 - return value instanceof FormData; 22 - }; 23 - 24 - export const base64 = (str: string): string => { 25 - try { 26 - return btoa(str); 27 - } catch (err) { 28 - // @ts-ignore 29 - return Buffer.from(str).toString('base64'); 30 - } 31 - }; 32 - 33 - export const getQueryString = (params: Record<string, unknown>): string => { 34 - const qs: string[] = []; 35 - 36 - const append = (key: string, value: unknown) => { 37 - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); 38 - }; 39 - 40 - const encodePair = (key: string, value: unknown) => { 41 - if (value === undefined || value === null) { 42 - return; 43 - } 44 - 45 - if (Array.isArray(value)) { 46 - value.forEach(v => encodePair(key, v)); 47 - } else if (typeof value === 'object') { 48 - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); 49 - } else { 50 - append(key, value); 51 - } 52 - }; 53 - 54 - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 55 - 56 - return qs.length ? `?${qs.join('&')}` : ''; 57 - }; 58 - 59 - const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { 60 - const encoder = config.ENCODE_PATH || encodeURI; 61 - 62 - const path = options.url 63 - .replace('{api-version}', config.VERSION) 64 - .replace(/{(.*?)}/g, (substring: string, group: string) => { 65 - if (options.path?.hasOwnProperty(group)) { 66 - return encoder(String(options.path[group])); 67 - } 68 - return substring; 69 - }); 70 - 71 - const url = config.BASE + path; 72 - return options.query ? url + getQueryString(options.query) : url; 73 - }; 74 - 75 - export const getFormData = (options: ApiRequestOptions): FormData | undefined => { 76 - if (options.formData) { 77 - const formData = new FormData(); 78 - 79 - const process = (key: string, value: unknown) => { 80 - if (isString(value) || isBlob(value)) { 81 - formData.append(key, value); 82 - } else { 83 - formData.append(key, JSON.stringify(value)); 84 - } 85 - }; 86 - 87 - Object.entries(options.formData) 88 - .filter(([, value]) => value !== undefined && value !== null) 89 - .forEach(([key, value]) => { 90 - if (Array.isArray(value)) { 91 - value.forEach(v => process(key, v)); 92 - } else { 93 - process(key, value); 94 - } 95 - }); 96 - 97 - return formData; 98 - } 99 - return undefined; 100 - }; 101 - 102 - type Resolver<T> = (options: ApiRequestOptions) => Promise<T>; 103 - 104 - export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => { 105 - if (typeof resolver === 'function') { 106 - return (resolver as Resolver<T>)(options); 107 - } 108 - return resolver; 109 - }; 110 - 111 - export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => { 112 - const [token, username, password, additionalHeaders] = await Promise.all([ 113 - resolve(options, config.TOKEN), 114 - resolve(options, config.USERNAME), 115 - resolve(options, config.PASSWORD), 116 - resolve(options, config.HEADERS), 117 - ]); 118 - 119 - const headers = Object.entries({ 120 - Accept: 'application/json', 121 - ...additionalHeaders, 122 - ...options.headers, 123 - }) 124 - .filter(([, value]) => value !== undefined && value !== null) 125 - .reduce( 126 - (headers, [key, value]) => ({ 127 - ...headers, 128 - [key]: String(value), 129 - }), 130 - {} as Record<string, string> 131 - ); 132 - 133 - if (isStringWithValue(token)) { 134 - headers['Authorization'] = `Bearer ${token}`; 135 - } 136 - 137 - if (isStringWithValue(username) && isStringWithValue(password)) { 138 - const credentials = base64(`${username}:${password}`); 139 - headers['Authorization'] = `Basic ${credentials}`; 140 - } 141 - 142 - if (options.body !== undefined) { 143 - if (options.mediaType) { 144 - headers['Content-Type'] = options.mediaType; 145 - } else if (isBlob(options.body)) { 146 - headers['Content-Type'] = options.body.type || 'application/octet-stream'; 147 - } else if (isString(options.body)) { 148 - headers['Content-Type'] = 'text/plain'; 149 - } else if (!isFormData(options.body)) { 150 - headers['Content-Type'] = 'application/json'; 151 - } 152 - } 153 - 154 - return new Headers(headers); 155 - }; 156 - 157 - export const getRequestBody = (options: ApiRequestOptions): unknown => { 158 - if (options.body !== undefined) { 159 - if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { 160 - return JSON.stringify(options.body); 161 - } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { 162 - return options.body; 163 - } else { 164 - return JSON.stringify(options.body); 165 - } 166 - } 167 - return undefined; 168 - }; 169 - 170 - export const sendRequest = async ( 171 - config: OpenAPIConfig, 172 - options: ApiRequestOptions, 173 - url: string, 174 - body: any, 175 - formData: FormData | undefined, 176 - headers: Headers, 177 - onCancel: OnCancel 178 - ): Promise<Response> => { 179 - const controller = new AbortController(); 180 - 181 - let request: RequestInit = { 182 - headers, 183 - body: body ?? formData, 184 - method: options.method, 185 - signal: controller.signal, 186 - }; 187 - 188 - if (config.WITH_CREDENTIALS) { 189 - request.credentials = config.CREDENTIALS; 190 - } 191 - 192 - for (const fn of config.interceptors.request._fns) { 193 - request = await fn(request); 194 - } 195 - 196 - onCancel(() => controller.abort()); 197 - 198 - return await fetch(url, request); 199 - }; 200 - 201 - export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { 202 - if (responseHeader) { 203 - const content = response.headers.get(responseHeader); 204 - if (isString(content)) { 205 - return content; 206 - } 207 - } 208 - return undefined; 209 - }; 210 - 211 - export const getResponseBody = async (response: Response): Promise<unknown> => { 212 - if (response.status !== 204) { 213 - try { 214 - const contentType = response.headers.get('Content-Type'); 215 - if (contentType) { 216 - const binaryTypes = [ 217 - 'application/octet-stream', 218 - 'application/pdf', 219 - 'application/zip', 220 - 'audio/', 221 - 'image/', 222 - 'video/', 223 - ]; 224 - if (contentType.includes('application/json') || contentType.includes('+json')) { 225 - return await response.json(); 226 - } else if (binaryTypes.some(type => contentType.includes(type))) { 227 - return await response.blob(); 228 - } else if (contentType.includes('multipart/form-data')) { 229 - return await response.formData(); 230 - } else if (contentType.includes('text/')) { 231 - return await response.text(); 232 - } 233 - } 234 - } catch (error) { 235 - console.error(error); 236 - } 237 - } 238 - return undefined; 239 - }; 240 - 241 - export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { 242 - const errors: Record<number, string> = { 243 - 400: 'Bad Request', 244 - 401: 'Unauthorized', 245 - 402: 'Payment Required', 246 - 403: 'Forbidden', 247 - 404: 'Not Found', 248 - 405: 'Method Not Allowed', 249 - 406: 'Not Acceptable', 250 - 407: 'Proxy Authentication Required', 251 - 408: 'Request Timeout', 252 - 409: 'Conflict', 253 - 410: 'Gone', 254 - 411: 'Length Required', 255 - 412: 'Precondition Failed', 256 - 413: 'Payload Too Large', 257 - 414: 'URI Too Long', 258 - 415: 'Unsupported Media Type', 259 - 416: 'Range Not Satisfiable', 260 - 417: 'Expectation Failed', 261 - 418: 'Im a teapot', 262 - 421: 'Misdirected Request', 263 - 422: 'Unprocessable Content', 264 - 423: 'Locked', 265 - 424: 'Failed Dependency', 266 - 425: 'Too Early', 267 - 426: 'Upgrade Required', 268 - 428: 'Precondition Required', 269 - 429: 'Too Many Requests', 270 - 431: 'Request Header Fields Too Large', 271 - 451: 'Unavailable For Legal Reasons', 272 - 500: 'Internal Server Error', 273 - 501: 'Not Implemented', 274 - 502: 'Bad Gateway', 275 - 503: 'Service Unavailable', 276 - 504: 'Gateway Timeout', 277 - 505: 'HTTP Version Not Supported', 278 - 506: 'Variant Also Negotiates', 279 - 507: 'Insufficient Storage', 280 - 508: 'Loop Detected', 281 - 510: 'Not Extended', 282 - 511: 'Network Authentication Required', 283 - ...options.errors, 284 - }; 285 - 286 - const error = errors[result.status]; 287 - if (error) { 288 - throw new ApiError(options, result, error); 289 - } 290 - 291 - if (!result.ok) { 292 - const errorStatus = result.status ?? 'unknown'; 293 - const errorStatusText = result.statusText ?? 'unknown'; 294 - const errorBody = (() => { 295 - try { 296 - return JSON.stringify(result.body, null, 2); 297 - } catch (e) { 298 - return undefined; 299 - } 300 - })(); 301 - 302 - throw new ApiError( 303 - options, 304 - result, 305 - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` 306 - ); 307 - } 308 - }; 309 - 310 - /** 311 - * Request method 312 - * @param config The OpenAPI configuration object 313 - * @param options The request options from the service 314 - * @returns CancelablePromise<T> 315 - * @throws ApiError 316 - */ 317 - export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => { 318 - return new CancelablePromise(async (resolve, reject, onCancel) => { 319 - try { 320 - const url = getUrl(config, options); 321 - const formData = getFormData(options); 322 - const body = getRequestBody(options); 323 - const headers = await getHeaders(config, options); 324 - 325 - if (!onCancel.isCancelled) { 326 - let response = await sendRequest(config, options, url, body, formData, headers, onCancel); 327 - 328 - for (const fn of config.interceptors.response._fns) { 329 - response = await fn(response); 330 - } 331 - 332 - const responseBody = await getResponseBody(response); 333 - const responseHeader = getResponseHeader(response, options.responseHeader); 334 - 335 - const result: ApiResult = { 336 - url, 337 - ok: response.ok, 338 - status: response.status, 339 - statusText: response.statusText, 340 - body: responseHeader ?? responseBody, 341 - }; 342 - 343 - catchErrorCodes(options, result); 344 - 345 - resolve(result.body); 346 - } 347 - } catch (error) { 348 - reject(error); 349 - } 350 - }); 351 - };
-6
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/index.ts.snap
··· 1 - export { ApiError } from './core/ApiError'; 2 - export { CancelablePromise, CancelError } from './core/CancelablePromise'; 3 - export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; 4 - export * from './models'; 5 - export * from './schemas'; 6 - export * from './services';
-1233
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/models.ts.snap
··· 1 - /** 2 - * Testing multiline comments in string: First line 3 - * Second line 4 - * 5 - * Fourth line 6 - */ 7 - export type CommentWithBreaks = number; 8 - 9 - /** 10 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 11 - */ 12 - export type CommentWithBackticks = number; 13 - 14 - /** 15 - * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work 16 - */ 17 - export type CommentWithBackticksAndQuotes = number; 18 - 19 - /** 20 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 21 - */ 22 - export type CommentWithSlashes = number; 23 - 24 - /** 25 - * Testing expression placeholders in string: ${expression} should work 26 - */ 27 - export type CommentWithExpressionPlaceholders = number; 28 - 29 - /** 30 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 31 - */ 32 - export type CommentWithQuotes = number; 33 - 34 - /** 35 - * Testing reserved characters in string: * inline * and ** inline ** should work 36 - */ 37 - export type CommentWithReservedCharacters = number; 38 - 39 - /** 40 - * This is a simple number 41 - */ 42 - export type SimpleInteger = number; 43 - 44 - /** 45 - * This is a simple boolean 46 - */ 47 - export type SimpleBoolean = boolean; 48 - 49 - /** 50 - * This is a simple string 51 - */ 52 - export type SimpleString = string; 53 - 54 - /** 55 - * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) 56 - */ 57 - export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; 58 - 59 - /** 60 - * This is a simple file 61 - */ 62 - export type SimpleFile = Blob | File; 63 - 64 - /** 65 - * This is a simple reference 66 - */ 67 - export type SimpleReference = ModelWithString; 68 - 69 - /** 70 - * This is a simple string 71 - */ 72 - export type SimpleStringWithPattern = string | null; 73 - 74 - /** 75 - * This is a simple enum with strings 76 - */ 77 - export type EnumWithStrings = 78 - | 'Success' 79 - | 'Warning' 80 - | 'Error' 81 - | "'Single Quote'" 82 - | '"Double Quotes"' 83 - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; 84 - 85 - export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; 86 - 87 - /** 88 - * This is a simple enum with numbers 89 - */ 90 - export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; 91 - 92 - /** 93 - * Success=1,Warning=2,Error=3 94 - */ 95 - export type EnumFromDescription = number; 96 - 97 - /** 98 - * This is a simple enum with numbers 99 - */ 100 - export type EnumWithExtensions = 200 | 400 | 500; 101 - 102 - export type EnumWithXEnumNames = 0 | 1 | 2; 103 - 104 - /** 105 - * This is a simple array with numbers 106 - */ 107 - export type ArrayWithNumbers = Array<number>; 108 - 109 - /** 110 - * This is a simple array with booleans 111 - */ 112 - export type ArrayWithBooleans = Array<boolean>; 113 - 114 - /** 115 - * This is a simple array with strings 116 - */ 117 - export type ArrayWithStrings = Array<string>; 118 - 119 - /** 120 - * This is a simple array with references 121 - */ 122 - export type ArrayWithReferences = Array<ModelWithString>; 123 - 124 - /** 125 - * This is a simple array containing an array 126 - */ 127 - export type ArrayWithArray = Array<Array<ModelWithString>>; 128 - 129 - /** 130 - * This is a simple array with properties 131 - */ 132 - export type ArrayWithProperties = Array<{ 133 - foo?: string; 134 - bar?: string; 135 - }>; 136 - 137 - /** 138 - * This is a simple array with any of properties 139 - */ 140 - export type ArrayWithAnyOfProperties = Array< 141 - | { 142 - foo?: string; 143 - } 144 - | { 145 - bar?: string; 146 - } 147 - >; 148 - 149 - export type AnyOfAnyAndNull = { 150 - data?: unknown | null; 151 - }; 152 - 153 - /** 154 - * This is a simple array with any of properties 155 - */ 156 - export type AnyOfArrays = { 157 - results?: Array< 158 - | { 159 - foo?: string; 160 - } 161 - | { 162 - bar?: string; 163 - } 164 - >; 165 - }; 166 - 167 - /** 168 - * This is a string dictionary 169 - */ 170 - export type DictionaryWithString = Record<string, string>; 171 - 172 - export type DictionaryWithPropertiesAndAdditionalProperties = { 173 - foo?: string; 174 - [key: string]: string | undefined; 175 - }; 176 - 177 - /** 178 - * This is a string reference 179 - */ 180 - export type DictionaryWithReference = Record<string, ModelWithString>; 181 - 182 - /** 183 - * This is a complex dictionary 184 - */ 185 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 186 - 187 - /** 188 - * This is a string dictionary 189 - */ 190 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 191 - 192 - /** 193 - * This is a complex dictionary 194 - */ 195 - export type DictionaryWithProperties = Record< 196 - string, 197 - { 198 - foo?: string; 199 - bar?: string; 200 - } 201 - >; 202 - 203 - /** 204 - * This is a model with one number property 205 - */ 206 - export type ModelWithInteger = { 207 - /** 208 - * This is a simple number property 209 - */ 210 - prop?: number; 211 - }; 212 - 213 - /** 214 - * This is a model with one boolean property 215 - */ 216 - export type ModelWithBoolean = { 217 - /** 218 - * This is a simple boolean property 219 - */ 220 - prop?: boolean; 221 - }; 222 - 223 - /** 224 - * This is a model with one string property 225 - */ 226 - export type ModelWithString = { 227 - /** 228 - * This is a simple string property 229 - */ 230 - prop?: string; 231 - }; 232 - 233 - /** 234 - * `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) 235 - */ 236 - export type Model_From_Zendesk = string; 237 - 238 - /** 239 - * This is a model with one string property 240 - */ 241 - export type ModelWithNullableString = { 242 - /** 243 - * This is a simple string property 244 - */ 245 - nullableProp1?: string | null; 246 - /** 247 - * This is a simple string property 248 - */ 249 - nullableRequiredProp1: string | null; 250 - /** 251 - * This is a simple string property 252 - */ 253 - nullableProp2?: string | null; 254 - /** 255 - * This is a simple string property 256 - */ 257 - nullableRequiredProp2: string | null; 258 - /** 259 - * This is a simple enum with strings 260 - */ 261 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 262 - }; 263 - 264 - /** 265 - * This is a model with one enum 266 - */ 267 - export type ModelWithEnum = { 268 - /** 269 - * This is a simple enum with strings 270 - */ 271 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 272 - /** 273 - * These are the HTTP error code enums 274 - */ 275 - statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 276 - /** 277 - * Simple boolean enum 278 - */ 279 - bool?: boolean; 280 - }; 281 - 282 - /** 283 - * This is a model with one enum with escaped name 284 - */ 285 - export type ModelWithEnumWithHyphen = { 286 - 'foo-bar-baz-qux'?: '3.0'; 287 - }; 288 - 289 - /** 290 - * This is a model with one enum 291 - */ 292 - export type ModelWithEnumFromDescription = { 293 - /** 294 - * Success=1,Warning=2,Error=3 295 - */ 296 - test?: number; 297 - }; 298 - 299 - /** 300 - * This is a model with nested enums 301 - */ 302 - export type ModelWithNestedEnums = { 303 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 304 - dictionaryWithEnumFromDescription?: Record<string, number>; 305 - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 306 - arrayWithDescription?: Array<number>; 307 - /** 308 - * This is a simple enum with strings 309 - */ 310 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 311 - }; 312 - 313 - /** 314 - * This is a model with one property containing a reference 315 - */ 316 - export type ModelWithReference = { 317 - prop?: ModelWithProperties; 318 - }; 319 - 320 - /** 321 - * This is a model with one property containing an array 322 - */ 323 - export type ModelWithArrayReadOnlyAndWriteOnly = { 324 - prop?: Array<ModelWithReadOnlyAndWriteOnly>; 325 - propWithFile?: Array<Blob | File>; 326 - propWithNumber?: Array<number>; 327 - }; 328 - 329 - /** 330 - * This is a model with one property containing an array 331 - */ 332 - export type ModelWithArray = { 333 - prop?: Array<ModelWithString>; 334 - propWithFile?: Array<Blob | File>; 335 - propWithNumber?: Array<number>; 336 - }; 337 - 338 - /** 339 - * This is a model with one property containing a dictionary 340 - */ 341 - export type ModelWithDictionary = { 342 - prop?: Record<string, string>; 343 - }; 344 - 345 - /** 346 - * This is a deprecated model with a deprecated property 347 - * @deprecated 348 - */ 349 - export type DeprecatedModel = { 350 - /** 351 - * This is a deprecated property 352 - * @deprecated 353 - */ 354 - prop?: string; 355 - }; 356 - 357 - /** 358 - * This is a model with one property containing a circular reference 359 - */ 360 - export type ModelWithCircularReference = { 361 - prop?: ModelWithCircularReference; 362 - }; 363 - 364 - /** 365 - * This is a model with one property with a 'one of' relationship 366 - */ 367 - export type CompositionWithOneOf = { 368 - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 369 - }; 370 - 371 - /** 372 - * This is a model with one property with a 'one of' relationship where the options are not $ref 373 - */ 374 - export type CompositionWithOneOfAnonymous = { 375 - propA?: 376 - | { 377 - propA?: string; 378 - } 379 - | string 380 - | number; 381 - }; 382 - 383 - /** 384 - * Circle 385 - */ 386 - export type ModelCircle = { 387 - kind: 'circle'; 388 - radius?: number; 389 - }; 390 - 391 - /** 392 - * Square 393 - */ 394 - export type ModelSquare = { 395 - kind: 'square'; 396 - sideLength?: number; 397 - }; 398 - 399 - /** 400 - * This is a model with one property with a 'one of' relationship where the options are not $ref 401 - */ 402 - export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; 403 - 404 - /** 405 - * This is a model with one property with a 'any of' relationship 406 - */ 407 - export type CompositionWithAnyOf = { 408 - propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 409 - }; 410 - 411 - /** 412 - * This is a model with one property with a 'any of' relationship where the options are not $ref 413 - */ 414 - export type CompositionWithAnyOfAnonymous = { 415 - propA?: 416 - | { 417 - propA?: string; 418 - } 419 - | string 420 - | number; 421 - }; 422 - 423 - /** 424 - * This is a model with nested 'any of' property with a type null 425 - */ 426 - export type CompositionWithNestedAnyAndTypeNull = { 427 - propA?: Array<ModelWithDictionary | null> | Array<ModelWithArray | null>; 428 - }; 429 - 430 - export type Enum1 = 'Bird' | 'Dog'; 431 - 432 - export type ConstValue = 'ConstValue'; 433 - 434 - /** 435 - * This is a model with one property with a 'any of' relationship where the options are not $ref 436 - */ 437 - export type CompositionWithNestedAnyOfAndNull = { 438 - propA?: Array<Enum1 | ConstValue> | null; 439 - }; 440 - 441 - /** 442 - * This is a model with one property with a 'one of' relationship 443 - */ 444 - export type CompositionWithOneOfAndNullable = { 445 - propA?: 446 - | { 447 - boolean?: boolean; 448 - } 449 - | ModelWithEnum 450 - | ModelWithArray 451 - | ModelWithDictionary 452 - | null; 453 - }; 454 - 455 - /** 456 - * This is a model that contains a simple dictionary within composition 457 - */ 458 - export type CompositionWithOneOfAndSimpleDictionary = { 459 - propA?: boolean | Record<string, number>; 460 - }; 461 - 462 - /** 463 - * This is a model that contains a dictionary of simple arrays within composition 464 - */ 465 - export type CompositionWithOneOfAndSimpleArrayDictionary = { 466 - propA?: boolean | Record<string, Array<boolean>>; 467 - }; 468 - 469 - /** 470 - * This is a model that contains a dictionary of complex arrays (composited) within composition 471 - */ 472 - export type CompositionWithOneOfAndComplexArrayDictionary = { 473 - propA?: boolean | Record<string, Array<number | string>>; 474 - }; 475 - 476 - /** 477 - * This is a model with one property with a 'all of' relationship 478 - */ 479 - export type CompositionWithAllOfAndNullable = { 480 - propA?: 481 - | ({ 482 - boolean?: boolean; 483 - } & ModelWithEnum & 484 - ModelWithArray & 485 - ModelWithDictionary) 486 - | null; 487 - }; 488 - 489 - /** 490 - * This is a model with one property with a 'any of' relationship 491 - */ 492 - export type CompositionWithAnyOfAndNullable = { 493 - propA?: 494 - | { 495 - boolean?: boolean; 496 - } 497 - | ModelWithEnum 498 - | ModelWithArray 499 - | ModelWithDictionary 500 - | null; 501 - }; 502 - 503 - /** 504 - * This is a base model with two simple optional properties 505 - */ 506 - export type CompositionBaseModel = { 507 - firstName?: string; 508 - lastname?: string; 509 - }; 510 - 511 - /** 512 - * This is a model that extends the base model 513 - */ 514 - export type CompositionExtendedModel = CompositionBaseModel & { 515 - firstName: string; 516 - lastname: string; 517 - age: number; 518 - }; 519 - 520 - /** 521 - * This is a model with one nested property 522 - */ 523 - export type ModelWithProperties = { 524 - required: string; 525 - readonly requiredAndReadOnly: string; 526 - requiredAndNullable: string | null; 527 - string?: string; 528 - number?: number; 529 - boolean?: boolean; 530 - reference?: ModelWithString; 531 - 'property with space'?: string; 532 - default?: string; 533 - try?: string; 534 - readonly '@namespace.string'?: string; 535 - readonly '@namespace.integer'?: number; 536 - }; 537 - 538 - /** 539 - * This is a model with one nested property 540 - */ 541 - export type ModelWithNestedProperties = { 542 - readonly first: { 543 - readonly second: { 544 - readonly third: string | null; 545 - } | null; 546 - } | null; 547 - }; 548 - 549 - /** 550 - * This is a model with duplicated properties 551 - */ 552 - export type ModelWithDuplicateProperties = { 553 - prop?: ModelWithString; 554 - }; 555 - 556 - /** 557 - * This is a model with ordered properties 558 - */ 559 - export type ModelWithOrderedProperties = { 560 - zebra?: string; 561 - apple?: string; 562 - hawaii?: string; 563 - }; 564 - 565 - /** 566 - * This is a model with duplicated imports 567 - */ 568 - export type ModelWithDuplicateImports = { 569 - propA?: ModelWithString; 570 - propB?: ModelWithString; 571 - propC?: ModelWithString; 572 - }; 573 - 574 - /** 575 - * This is a model that extends another model 576 - */ 577 - export type ModelThatExtends = ModelWithString & { 578 - propExtendsA?: string; 579 - propExtendsB?: ModelWithString; 580 - }; 581 - 582 - /** 583 - * This is a model that extends another model 584 - */ 585 - export type ModelThatExtendsExtends = ModelWithString & 586 - ModelThatExtends & { 587 - propExtendsC?: string; 588 - propExtendsD?: ModelWithString; 589 - }; 590 - 591 - /** 592 - * This is a model that contains a some patterns 593 - */ 594 - export type ModelWithPattern = { 595 - key: string; 596 - name: string; 597 - readonly enabled?: boolean; 598 - readonly modified?: string; 599 - id?: string; 600 - text?: string; 601 - patternWithSingleQuotes?: string; 602 - patternWithNewline?: string; 603 - patternWithBacktick?: string; 604 - }; 605 - 606 - export type File = { 607 - readonly id?: string; 608 - readonly updated_at?: string; 609 - readonly created_at?: string; 610 - mime: string; 611 - readonly file?: string; 612 - }; 613 - 614 - export type _default = { 615 - name?: string; 616 - }; 617 - 618 - export type Pageable = { 619 - page?: number; 620 - size?: number; 621 - sort?: Array<string>; 622 - }; 623 - 624 - /** 625 - * This is a free-form object without additionalProperties. 626 - */ 627 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 628 - 629 - /** 630 - * This is a free-form object with additionalProperties: true. 631 - */ 632 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 633 - 634 - /** 635 - * This is a free-form object with additionalProperties: {}. 636 - */ 637 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 638 - 639 - export type ModelWithConst = { 640 - String?: 'String'; 641 - number?: 0; 642 - null?: null; 643 - withType?: 'Some string'; 644 - }; 645 - 646 - /** 647 - * This is a model with one property and additionalProperties: true 648 - */ 649 - export type ModelWithAdditionalPropertiesEqTrue = { 650 - /** 651 - * This is a simple string property 652 - */ 653 - prop?: string; 654 - [key: string]: unknown; 655 - }; 656 - 657 - export type NestedAnyOfArraysNullable = { 658 - nullableArray?: Array<string | boolean> | null; 659 - }; 660 - 661 - export type CompositionWithOneOfAndProperties = 662 - | { 663 - foo: SimpleParameter; 664 - baz: number | null; 665 - qux: number; 666 - } 667 - | { 668 - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 669 - baz: number | null; 670 - qux: number; 671 - }; 672 - 673 - /** 674 - * An object that can be null 675 - */ 676 - export type NullableObject = { 677 - foo?: string; 678 - } | null; 679 - 680 - export type ModelWithNullableObject = { 681 - data?: NullableObject; 682 - }; 683 - 684 - export type ModelWithOneOfEnum = 685 - | { 686 - foo: 'Bar'; 687 - } 688 - | { 689 - foo: 'Baz'; 690 - } 691 - | { 692 - foo: 'Qux'; 693 - } 694 - | { 695 - content: string; 696 - foo: 'Quux'; 697 - } 698 - | { 699 - content: [string, string]; 700 - foo: 'Corge'; 701 - }; 702 - 703 - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; 704 - 705 - export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; 706 - 707 - export type ModelWithNestedArrayEnumsData = { 708 - foo?: Array<ModelWithNestedArrayEnumsDataFoo>; 709 - bar?: Array<ModelWithNestedArrayEnumsDataBar>; 710 - }; 711 - 712 - export type ModelWithNestedArrayEnums = { 713 - array_strings?: Array<string>; 714 - data?: ModelWithNestedArrayEnumsData; 715 - }; 716 - 717 - export type ModelWithNestedCompositionEnums = { 718 - foo?: ModelWithNestedArrayEnumsDataFoo; 719 - }; 720 - 721 - export type ModelWithReadOnlyAndWriteOnly = { 722 - foo: string; 723 - readonly bar: string; 724 - baz: string; 725 - }; 726 - 727 - export type ModelWithConstantSizeArray = [number, number]; 728 - 729 - export type ModelWithAnyOfConstantSizeArray = [number | string, number | string, number | string]; 730 - 731 - /** 732 - * This is a reusable parameter 733 - */ 734 - export type SimpleParameter = string; 735 - 736 - export type $OpenApiTsDefault = { 737 - '/api/v{api-version}/no-tag': { 738 - post: { 739 - req: { 740 - 200: { 741 - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; 742 - }; 743 - }; 744 - res: ModelWithReadOnlyAndWriteOnly; 745 - }; 746 - get: { 747 - res: void; 748 - }; 749 - }; 750 - }; 751 - 752 - export type $OpenApiTsSimple = { 753 - '/api/v{api-version}/simple/$count': { 754 - get: { 755 - res: Model_From_Zendesk; 756 - }; 757 - }; 758 - '/api/v{api-version}/simple': { 759 - get: { 760 - res: void; 761 - }; 762 - put: { 763 - res: void; 764 - }; 765 - post: { 766 - res: void; 767 - }; 768 - delete: { 769 - res: void; 770 - }; 771 - options: { 772 - res: void; 773 - }; 774 - head: { 775 - res: void; 776 - }; 777 - patch: { 778 - res: void; 779 - }; 780 - }; 781 - }; 782 - 783 - export type $OpenApiTsParameters = { 784 - '/api/v{api-version}/foo/{foo}/bar/{bar}': { 785 - delete: { 786 - res: void; 787 - }; 788 - }; 789 - '/api/v{api-version}/parameters/{parameterPath}': { 790 - post: { 791 - res: void; 792 - }; 793 - }; 794 - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { 795 - post: { 796 - res: void; 797 - }; 798 - }; 799 - '/api/v{api-version}/parameters/': { 800 - get: { 801 - res: void; 802 - }; 803 - post: { 804 - res: void; 805 - }; 806 - }; 807 - }; 808 - 809 - export type $OpenApiTsDescriptions = { 810 - '/api/v{api-version}/descriptions/': { 811 - post: { 812 - res: void; 813 - }; 814 - }; 815 - }; 816 - 817 - export type $OpenApiTsDeprecated = { 818 - '/api/v{api-version}/parameters/deprecated': { 819 - post: { 820 - res: void; 821 - }; 822 - }; 823 - }; 824 - 825 - export type $OpenApiTsRequestBody = { 826 - '/api/v{api-version}/requestBody/': { 827 - post: { 828 - res: void; 829 - }; 830 - }; 831 - }; 832 - 833 - export type $OpenApiTsFormData = { 834 - '/api/v{api-version}/formData/': { 835 - post: { 836 - res: void; 837 - }; 838 - }; 839 - }; 840 - 841 - export type $OpenApiTsDefaults = { 842 - '/api/v{api-version}/defaults': { 843 - get: { 844 - res: void; 845 - }; 846 - post: { 847 - res: void; 848 - }; 849 - put: { 850 - res: void; 851 - }; 852 - }; 853 - }; 854 - 855 - export type $OpenApiTsDuplicate = { 856 - '/api/v{api-version}/duplicate': { 857 - get: { 858 - res: void; 859 - }; 860 - post: { 861 - res: void; 862 - }; 863 - put: { 864 - res: void; 865 - }; 866 - delete: { 867 - res: void; 868 - }; 869 - }; 870 - }; 871 - 872 - export type $OpenApiTsNoContent = { 873 - '/api/v{api-version}/no-content': { 874 - get: { 875 - res: void; 876 - }; 877 - }; 878 - '/api/v{api-version}/multiple-tags/response-and-no-content': { 879 - get: { 880 - res: number | void; 881 - }; 882 - }; 883 - }; 884 - 885 - export type $OpenApiTsResponse = { 886 - '/api/v{api-version}/multiple-tags/response-and-no-content': { 887 - get: { 888 - res: number | void; 889 - }; 890 - }; 891 - '/api/v{api-version}/response': { 892 - get: { 893 - res: ModelWithString; 894 - }; 895 - post: { 896 - res: ModelWithString; 897 - }; 898 - put: { 899 - res: 900 - | { 901 - readonly '@namespace.string'?: string; 902 - readonly '@namespace.integer'?: number; 903 - readonly value?: Array<ModelWithString>; 904 - } 905 - | ModelWithString 906 - | ModelThatExtends 907 - | ModelThatExtendsExtends; 908 - }; 909 - }; 910 - }; 911 - 912 - export type $OpenApiTsMultipleTags1 = { 913 - '/api/v{api-version}/multiple-tags/a': { 914 - get: { 915 - res: void; 916 - }; 917 - }; 918 - '/api/v{api-version}/multiple-tags/b': { 919 - get: { 920 - res: void; 921 - }; 922 - }; 923 - }; 924 - 925 - export type $OpenApiTsMultipleTags2 = { 926 - '/api/v{api-version}/multiple-tags/a': { 927 - get: { 928 - res: void; 929 - }; 930 - }; 931 - '/api/v{api-version}/multiple-tags/b': { 932 - get: { 933 - res: void; 934 - }; 935 - }; 936 - }; 937 - 938 - export type $OpenApiTsMultipleTags3 = { 939 - '/api/v{api-version}/multiple-tags/b': { 940 - get: { 941 - res: void; 942 - }; 943 - }; 944 - }; 945 - 946 - export type $OpenApiTsCollectionFormat = { 947 - '/api/v{api-version}/collectionFormat': { 948 - get: { 949 - res: void; 950 - }; 951 - }; 952 - }; 953 - 954 - export type $OpenApiTsTypes = { 955 - '/api/v{api-version}/types': { 956 - get: { 957 - req: { 958 - 200: { 959 - /** 960 - * This is a number parameter 961 - */ 962 - id?: number; 963 - /** 964 - * This is an array parameter 965 - */ 966 - parameterArray: Array<string> | null; 967 - /** 968 - * This is a boolean parameter 969 - */ 970 - parameterBoolean: boolean | null; 971 - /** 972 - * This is a dictionary parameter 973 - */ 974 - parameterDictionary: Record<string, unknown> | null; 975 - /** 976 - * This is an enum parameter 977 - */ 978 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 979 - /** 980 - * This is a number parameter 981 - */ 982 - parameterNumber: number; 983 - /** 984 - * This is an object parameter 985 - */ 986 - parameterObject: Record<string, unknown> | null; 987 - /** 988 - * This is a string parameter 989 - */ 990 - parameterString: string | null; 991 - }; 992 - 201: { 993 - /** 994 - * This is a number parameter 995 - */ 996 - id?: number; 997 - /** 998 - * This is an array parameter 999 - */ 1000 - parameterArray: Array<string> | null; 1001 - /** 1002 - * This is a boolean parameter 1003 - */ 1004 - parameterBoolean: boolean | null; 1005 - /** 1006 - * This is a dictionary parameter 1007 - */ 1008 - parameterDictionary: Record<string, unknown> | null; 1009 - /** 1010 - * This is an enum parameter 1011 - */ 1012 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 1013 - /** 1014 - * This is a number parameter 1015 - */ 1016 - parameterNumber: number; 1017 - /** 1018 - * This is an object parameter 1019 - */ 1020 - parameterObject: Record<string, unknown> | null; 1021 - /** 1022 - * This is a string parameter 1023 - */ 1024 - parameterString: string | null; 1025 - }; 1026 - 202: { 1027 - /** 1028 - * This is a number parameter 1029 - */ 1030 - id?: number; 1031 - /** 1032 - * This is an array parameter 1033 - */ 1034 - parameterArray: Array<string> | null; 1035 - /** 1036 - * This is a boolean parameter 1037 - */ 1038 - parameterBoolean: boolean | null; 1039 - /** 1040 - * This is a dictionary parameter 1041 - */ 1042 - parameterDictionary: Record<string, unknown> | null; 1043 - /** 1044 - * This is an enum parameter 1045 - */ 1046 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 1047 - /** 1048 - * This is a number parameter 1049 - */ 1050 - parameterNumber: number; 1051 - /** 1052 - * This is an object parameter 1053 - */ 1054 - parameterObject: Record<string, unknown> | null; 1055 - /** 1056 - * This is a string parameter 1057 - */ 1058 - parameterString: string | null; 1059 - }; 1060 - 203: { 1061 - /** 1062 - * This is a number parameter 1063 - */ 1064 - id?: number; 1065 - /** 1066 - * This is an array parameter 1067 - */ 1068 - parameterArray: Array<string> | null; 1069 - /** 1070 - * This is a boolean parameter 1071 - */ 1072 - parameterBoolean: boolean | null; 1073 - /** 1074 - * This is a dictionary parameter 1075 - */ 1076 - parameterDictionary: Record<string, unknown> | null; 1077 - /** 1078 - * This is an enum parameter 1079 - */ 1080 - parameterEnum: 'Success' | 'Warning' | 'Error' | null; 1081 - /** 1082 - * This is a number parameter 1083 - */ 1084 - parameterNumber: number; 1085 - /** 1086 - * This is an object parameter 1087 - */ 1088 - parameterObject: Record<string, unknown> | null; 1089 - /** 1090 - * This is a string parameter 1091 - */ 1092 - parameterString: string | null; 1093 - }; 1094 - }; 1095 - res: number | string | boolean | Record<string, unknown>; 1096 - }; 1097 - }; 1098 - }; 1099 - 1100 - export type $OpenApiTsUpload = { 1101 - '/api/v{api-version}/upload': { 1102 - post: { 1103 - req: { 1104 - 200: { 1105 - /** 1106 - * Supply a file reference for upload 1107 - */ 1108 - file: Blob | File; 1109 - }; 1110 - }; 1111 - res: boolean; 1112 - }; 1113 - }; 1114 - }; 1115 - 1116 - export type $OpenApiTsFileResponse = { 1117 - '/api/v{api-version}/file/{id}': { 1118 - get: { 1119 - req: { 1120 - 200: { 1121 - id: string; 1122 - }; 1123 - }; 1124 - res: Blob | File; 1125 - }; 1126 - }; 1127 - }; 1128 - 1129 - export type $OpenApiTsComplex = { 1130 - '/api/v{api-version}/complex': { 1131 - get: { 1132 - req: { 1133 - 200: { 1134 - /** 1135 - * Parameter containing object 1136 - */ 1137 - parameterObject: { 1138 - first?: { 1139 - second?: { 1140 - third?: string; 1141 - }; 1142 - }; 1143 - }; 1144 - /** 1145 - * Parameter containing reference 1146 - */ 1147 - parameterReference: ModelWithString; 1148 - }; 1149 - }; 1150 - res: Array<ModelWithString>; 1151 - }; 1152 - }; 1153 - '/api/v{api-version}/complex/{id}': { 1154 - put: { 1155 - req: { 1156 - 200: { 1157 - id: number; 1158 - requestBody?: { 1159 - readonly key: string | null; 1160 - name: string | null; 1161 - enabled?: boolean; 1162 - readonly type: 'Monkey' | 'Horse' | 'Bird'; 1163 - listOfModels?: Array<ModelWithString> | null; 1164 - listOfStrings?: Array<string> | null; 1165 - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 1166 - readonly user?: { 1167 - readonly id?: number; 1168 - readonly name?: string | null; 1169 - }; 1170 - }; 1171 - }; 1172 - }; 1173 - res: ModelWithString; 1174 - }; 1175 - }; 1176 - }; 1177 - 1178 - export type $OpenApiTsMultipart = { 1179 - '/api/v{api-version}/multipart': { 1180 - post: { 1181 - res: void; 1182 - }; 1183 - get: { 1184 - res: { 1185 - file?: Blob | File; 1186 - metadata?: { 1187 - foo?: string; 1188 - bar?: string; 1189 - }; 1190 - }; 1191 - }; 1192 - }; 1193 - }; 1194 - 1195 - export type $OpenApiTsHeader = { 1196 - '/api/v{api-version}/header': { 1197 - post: { 1198 - res: string; 1199 - }; 1200 - }; 1201 - }; 1202 - 1203 - export type $OpenApiTsError = { 1204 - '/api/v{api-version}/error': { 1205 - post: { 1206 - req: { 1207 - 200: { 1208 - /** 1209 - * Status code to return 1210 - */ 1211 - status: number; 1212 - }; 1213 - }; 1214 - res: any; 1215 - }; 1216 - }; 1217 - }; 1218 - 1219 - export type $OpenApiTsNonAsciiÆøåÆøÅöôêÊ = { 1220 - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { 1221 - post: { 1222 - req: { 1223 - 200: { 1224 - /** 1225 - * Dummy input param 1226 - */ 1227 - nonAsciiParamæøåÆøÅöôêÊ: number; 1228 - }; 1229 - }; 1230 - res: Array<NonAsciiStringæøåÆØÅöôêÊ字符串>; 1231 - }; 1232 - }; 1233 - };
-1577
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/schemas.ts.snap
··· 1 - export const $CommentWithBreaks = { 2 - description: `Testing multiline comments in string: First line 3 - Second line 4 - 5 - Fourth line`, 6 - type: 'integer', 7 - } as const; 8 - 9 - export const $CommentWithBackticks = { 10 - description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', 11 - type: 'integer', 12 - } as const; 13 - 14 - export const $CommentWithBackticksAndQuotes = { 15 - description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, 16 - type: 'integer', 17 - } as const; 18 - 19 - export const $CommentWithSlashes = { 20 - description: 'Testing slashes in string: \backwards\\ and /forwards/// should work', 21 - type: 'integer', 22 - } as const; 23 - 24 - export const $CommentWithExpressionPlaceholders = { 25 - description: 'Testing expression placeholders in string: ${expression} should work', 26 - type: 'integer', 27 - } as const; 28 - 29 - export const $CommentWithQuotes = { 30 - description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, 31 - type: 'integer', 32 - } as const; 33 - 34 - export const $CommentWithReservedCharacters = { 35 - description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', 36 - type: 'integer', 37 - } as const; 38 - 39 - export const $SimpleInteger = { 40 - description: 'This is a simple number', 41 - type: 'integer', 42 - } as const; 43 - 44 - export const $SimpleBoolean = { 45 - description: 'This is a simple boolean', 46 - type: 'boolean', 47 - } as const; 48 - 49 - export const $SimpleString = { 50 - description: 'This is a simple string', 51 - type: 'string', 52 - } as const; 53 - 54 - export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { 55 - description: 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', 56 - type: 'string', 57 - } as const; 58 - 59 - export const $SimpleFile = { 60 - description: 'This is a simple file', 61 - type: 'file', 62 - } as const; 63 - 64 - export const $SimpleReference = { 65 - description: 'This is a simple reference', 66 - $ref: '#/components/schemas/ModelWithString', 67 - } as const; 68 - 69 - export const $SimpleStringWithPattern = { 70 - description: 'This is a simple string', 71 - type: 'string', 72 - nullable: true, 73 - maxLength: 64, 74 - pattern: '^[a-zA-Z0-9_]*$', 75 - } as const; 76 - 77 - export const $EnumWithStrings = { 78 - description: 'This is a simple enum with strings', 79 - enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 80 - } as const; 81 - 82 - export const $EnumWithReplacedCharacters = { 83 - enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], 84 - type: 'string', 85 - } as const; 86 - 87 - export const $EnumWithNumbers = { 88 - description: 'This is a simple enum with numbers', 89 - enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 90 - default: 200, 91 - } as const; 92 - 93 - export const $EnumFromDescription = { 94 - description: 'Success=1,Warning=2,Error=3', 95 - type: 'number', 96 - } as const; 97 - 98 - export const $EnumWithExtensions = { 99 - description: 'This is a simple enum with numbers', 100 - enum: [200, 400, 500], 101 - 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], 102 - 'x-enum-descriptions': [ 103 - 'Used when the status of something is successful', 104 - 'Used when the status of something has a warning', 105 - 'Used when the status of something has an error', 106 - ], 107 - } as const; 108 - 109 - export const $EnumWithXEnumNames = { 110 - enum: [0, 1, 2], 111 - 'x-enumNames': ['zero', 'one', 'two'], 112 - } as const; 113 - 114 - export const $ArrayWithNumbers = { 115 - description: 'This is a simple array with numbers', 116 - type: 'array', 117 - items: { 118 - type: 'integer', 119 - }, 120 - } as const; 121 - 122 - export const $ArrayWithBooleans = { 123 - description: 'This is a simple array with booleans', 124 - type: 'array', 125 - items: { 126 - type: 'boolean', 127 - }, 128 - } as const; 129 - 130 - export const $ArrayWithStrings = { 131 - description: 'This is a simple array with strings', 132 - type: 'array', 133 - items: { 134 - type: 'string', 135 - }, 136 - default: ['test'], 137 - } as const; 138 - 139 - export const $ArrayWithReferences = { 140 - description: 'This is a simple array with references', 141 - type: 'array', 142 - items: { 143 - $ref: '#/components/schemas/ModelWithString', 144 - }, 145 - } as const; 146 - 147 - export const $ArrayWithArray = { 148 - description: 'This is a simple array containing an array', 149 - type: 'array', 150 - items: { 151 - type: 'array', 152 - items: { 153 - $ref: '#/components/schemas/ModelWithString', 154 - }, 155 - }, 156 - } as const; 157 - 158 - export const $ArrayWithProperties = { 159 - description: 'This is a simple array with properties', 160 - type: 'array', 161 - items: { 162 - type: 'object', 163 - properties: { 164 - foo: { 165 - type: 'string', 166 - }, 167 - bar: { 168 - type: 'string', 169 - }, 170 - }, 171 - }, 172 - } as const; 173 - 174 - export const $ArrayWithAnyOfProperties = { 175 - description: 'This is a simple array with any of properties', 176 - type: 'array', 177 - items: { 178 - anyOf: [ 179 - { 180 - type: 'object', 181 - properties: { 182 - foo: { 183 - type: 'string', 184 - default: 'test', 185 - }, 186 - }, 187 - }, 188 - { 189 - type: 'object', 190 - properties: { 191 - bar: { 192 - type: 'string', 193 - }, 194 - }, 195 - }, 196 - ], 197 - }, 198 - } as const; 199 - 200 - export const $AnyOfAnyAndNull = { 201 - type: 'object', 202 - properties: { 203 - data: { 204 - anyOf: [ 205 - {}, 206 - { 207 - type: 'null', 208 - }, 209 - ], 210 - }, 211 - }, 212 - } as const; 213 - 214 - export const $AnyOfArrays = { 215 - description: 'This is a simple array with any of properties', 216 - type: 'object', 217 - properties: { 218 - results: { 219 - items: { 220 - anyOf: [ 221 - { 222 - type: 'object', 223 - properties: { 224 - foo: { 225 - type: 'string', 226 - }, 227 - }, 228 - }, 229 - { 230 - type: 'object', 231 - properties: { 232 - bar: { 233 - type: 'string', 234 - }, 235 - }, 236 - }, 237 - ], 238 - }, 239 - type: 'array', 240 - }, 241 - }, 242 - } as const; 243 - 244 - export const $DictionaryWithString = { 245 - description: 'This is a string dictionary', 246 - type: 'object', 247 - additionalProperties: { 248 - type: 'string', 249 - }, 250 - } as const; 251 - 252 - export const $DictionaryWithPropertiesAndAdditionalProperties = { 253 - type: 'object', 254 - properties: { 255 - foo: { 256 - type: 'string', 257 - }, 258 - }, 259 - additionalProperties: { 260 - type: 'string', 261 - }, 262 - } as const; 263 - 264 - export const $DictionaryWithReference = { 265 - description: 'This is a string reference', 266 - type: 'object', 267 - additionalProperties: { 268 - $ref: '#/components/schemas/ModelWithString', 269 - }, 270 - } as const; 271 - 272 - export const $DictionaryWithArray = { 273 - description: 'This is a complex dictionary', 274 - type: 'object', 275 - additionalProperties: { 276 - type: 'array', 277 - items: { 278 - $ref: '#/components/schemas/ModelWithString', 279 - }, 280 - }, 281 - } as const; 282 - 283 - export const $DictionaryWithDictionary = { 284 - description: 'This is a string dictionary', 285 - type: 'object', 286 - additionalProperties: { 287 - type: 'object', 288 - additionalProperties: { 289 - type: 'string', 290 - }, 291 - }, 292 - } as const; 293 - 294 - export const $DictionaryWithProperties = { 295 - description: 'This is a complex dictionary', 296 - type: 'object', 297 - additionalProperties: { 298 - type: 'object', 299 - properties: { 300 - foo: { 301 - type: 'string', 302 - }, 303 - bar: { 304 - type: 'string', 305 - }, 306 - }, 307 - }, 308 - } as const; 309 - 310 - export const $ModelWithInteger = { 311 - description: 'This is a model with one number property', 312 - type: 'object', 313 - properties: { 314 - prop: { 315 - description: 'This is a simple number property', 316 - type: 'integer', 317 - }, 318 - }, 319 - } as const; 320 - 321 - export const $ModelWithBoolean = { 322 - description: 'This is a model with one boolean property', 323 - type: 'object', 324 - properties: { 325 - prop: { 326 - description: 'This is a simple boolean property', 327 - type: 'boolean', 328 - }, 329 - }, 330 - } as const; 331 - 332 - export const $ModelWithString = { 333 - description: 'This is a model with one string property', 334 - type: 'object', 335 - properties: { 336 - prop: { 337 - description: 'This is a simple string property', 338 - type: 'string', 339 - }, 340 - }, 341 - } as const; 342 - 343 - export const $Model_From_Zendesk = { 344 - description: `\`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)`, 345 - type: 'string', 346 - } as const; 347 - 348 - export const $ModelWithNullableString = { 349 - description: 'This is a model with one string property', 350 - type: 'object', 351 - required: ['nullableRequiredProp1', 'nullableRequiredProp2'], 352 - properties: { 353 - nullableProp1: { 354 - description: 'This is a simple string property', 355 - type: 'string', 356 - nullable: true, 357 - }, 358 - nullableRequiredProp1: { 359 - description: 'This is a simple string property', 360 - type: 'string', 361 - nullable: true, 362 - }, 363 - nullableProp2: { 364 - description: 'This is a simple string property', 365 - type: ['string', 'null'], 366 - }, 367 - nullableRequiredProp2: { 368 - description: 'This is a simple string property', 369 - type: ['string', 'null'], 370 - }, 371 - 'foo_bar-enum': { 372 - description: 'This is a simple enum with strings', 373 - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 374 - }, 375 - }, 376 - } as const; 377 - 378 - export const $ModelWithEnum = { 379 - description: 'This is a model with one enum', 380 - type: 'object', 381 - properties: { 382 - 'foo_bar-enum': { 383 - description: 'This is a simple enum with strings', 384 - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 385 - }, 386 - statusCode: { 387 - description: 'These are the HTTP error code enums', 388 - enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 389 - }, 390 - bool: { 391 - description: 'Simple boolean enum', 392 - type: 'boolean', 393 - enum: [true], 394 - }, 395 - }, 396 - } as const; 397 - 398 - export const $ModelWithEnumWithHyphen = { 399 - description: 'This is a model with one enum with escaped name', 400 - type: 'object', 401 - properties: { 402 - 'foo-bar-baz-qux': { 403 - type: 'string', 404 - enum: ['3.0'], 405 - title: 'Foo-Bar-Baz-Qux', 406 - default: '3.0', 407 - }, 408 - }, 409 - } as const; 410 - 411 - export const $ModelWithEnumFromDescription = { 412 - description: 'This is a model with one enum', 413 - type: 'object', 414 - properties: { 415 - test: { 416 - type: 'integer', 417 - description: 'Success=1,Warning=2,Error=3', 418 - }, 419 - }, 420 - } as const; 421 - 422 - export const $ModelWithNestedEnums = { 423 - description: 'This is a model with nested enums', 424 - type: 'object', 425 - properties: { 426 - dictionaryWithEnum: { 427 - type: 'object', 428 - additionalProperties: { 429 - enum: ['Success', 'Warning', 'Error'], 430 - }, 431 - }, 432 - dictionaryWithEnumFromDescription: { 433 - type: 'object', 434 - additionalProperties: { 435 - type: 'integer', 436 - description: 'Success=1,Warning=2,Error=3', 437 - }, 438 - }, 439 - arrayWithEnum: { 440 - type: 'array', 441 - items: { 442 - enum: ['Success', 'Warning', 'Error'], 443 - }, 444 - }, 445 - arrayWithDescription: { 446 - type: 'array', 447 - items: { 448 - type: 'integer', 449 - description: 'Success=1,Warning=2,Error=3', 450 - }, 451 - }, 452 - 'foo_bar-enum': { 453 - description: 'This is a simple enum with strings', 454 - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 455 - }, 456 - }, 457 - } as const; 458 - 459 - export const $ModelWithReference = { 460 - description: 'This is a model with one property containing a reference', 461 - type: 'object', 462 - properties: { 463 - prop: { 464 - $ref: '#/components/schemas/ModelWithProperties', 465 - }, 466 - }, 467 - } as const; 468 - 469 - export const $ModelWithArrayReadOnlyAndWriteOnly = { 470 - description: 'This is a model with one property containing an array', 471 - type: 'object', 472 - properties: { 473 - prop: { 474 - type: 'array', 475 - items: { 476 - $ref: '#/components/schemas/ModelWithReadOnlyAndWriteOnly', 477 - }, 478 - }, 479 - propWithFile: { 480 - type: 'array', 481 - items: { 482 - type: 'file', 483 - }, 484 - }, 485 - propWithNumber: { 486 - type: 'array', 487 - items: { 488 - type: 'number', 489 - }, 490 - }, 491 - }, 492 - } as const; 493 - 494 - export const $ModelWithArray = { 495 - description: 'This is a model with one property containing an array', 496 - type: 'object', 497 - properties: { 498 - prop: { 499 - type: 'array', 500 - items: { 501 - $ref: '#/components/schemas/ModelWithString', 502 - }, 503 - }, 504 - propWithFile: { 505 - type: 'array', 506 - items: { 507 - type: 'file', 508 - }, 509 - }, 510 - propWithNumber: { 511 - type: 'array', 512 - items: { 513 - type: 'number', 514 - }, 515 - }, 516 - }, 517 - } as const; 518 - 519 - export const $ModelWithDictionary = { 520 - description: 'This is a model with one property containing a dictionary', 521 - type: 'object', 522 - properties: { 523 - prop: { 524 - type: 'object', 525 - additionalProperties: { 526 - type: 'string', 527 - }, 528 - }, 529 - }, 530 - } as const; 531 - 532 - export const $DeprecatedModel = { 533 - deprecated: true, 534 - description: 'This is a deprecated model with a deprecated property', 535 - type: 'object', 536 - properties: { 537 - prop: { 538 - deprecated: true, 539 - description: 'This is a deprecated property', 540 - type: 'string', 541 - }, 542 - }, 543 - } as const; 544 - 545 - export const $ModelWithCircularReference = { 546 - description: 'This is a model with one property containing a circular reference', 547 - type: 'object', 548 - properties: { 549 - prop: { 550 - $ref: '#/components/schemas/ModelWithCircularReference', 551 - }, 552 - }, 553 - } as const; 554 - 555 - export const $CompositionWithOneOf = { 556 - description: "This is a model with one property with a 'one of' relationship", 557 - type: 'object', 558 - properties: { 559 - propA: { 560 - type: 'object', 561 - oneOf: [ 562 - { 563 - $ref: '#/components/schemas/ModelWithString', 564 - }, 565 - { 566 - $ref: '#/components/schemas/ModelWithEnum', 567 - }, 568 - { 569 - $ref: '#/components/schemas/ModelWithArray', 570 - }, 571 - { 572 - $ref: '#/components/schemas/ModelWithDictionary', 573 - }, 574 - ], 575 - }, 576 - }, 577 - } as const; 578 - 579 - export const $CompositionWithOneOfAnonymous = { 580 - description: "This is a model with one property with a 'one of' relationship where the options are not $ref", 581 - type: 'object', 582 - properties: { 583 - propA: { 584 - type: 'object', 585 - oneOf: [ 586 - { 587 - description: 'Anonymous object type', 588 - type: 'object', 589 - properties: { 590 - propA: { 591 - type: 'string', 592 - }, 593 - }, 594 - }, 595 - { 596 - description: 'Anonymous string type', 597 - type: 'string', 598 - }, 599 - { 600 - description: 'Anonymous integer type', 601 - type: 'integer', 602 - }, 603 - ], 604 - }, 605 - }, 606 - } as const; 607 - 608 - export const $ModelCircle = { 609 - description: 'Circle', 610 - type: 'object', 611 - required: ['kind'], 612 - properties: { 613 - kind: { 614 - type: 'string', 615 - }, 616 - radius: { 617 - type: 'number', 618 - }, 619 - }, 620 - } as const; 621 - 622 - export const $ModelSquare = { 623 - description: 'Square', 624 - type: 'object', 625 - required: ['kind'], 626 - properties: { 627 - kind: { 628 - type: 'string', 629 - }, 630 - sideLength: { 631 - type: 'number', 632 - }, 633 - }, 634 - } as const; 635 - 636 - export const $CompositionWithOneOfDiscriminator = { 637 - description: "This is a model with one property with a 'one of' relationship where the options are not $ref", 638 - type: 'object', 639 - oneOf: [ 640 - { 641 - $ref: '#/components/schemas/ModelCircle', 642 - }, 643 - { 644 - $ref: '#/components/schemas/ModelSquare', 645 - }, 646 - ], 647 - discriminator: { 648 - propertyName: 'kind', 649 - mapping: { 650 - circle: '#/components/schemas/ModelCircle', 651 - square: '#/components/schemas/ModelSquare', 652 - }, 653 - }, 654 - } as const; 655 - 656 - export const $CompositionWithAnyOf = { 657 - description: "This is a model with one property with a 'any of' relationship", 658 - type: 'object', 659 - properties: { 660 - propA: { 661 - type: 'object', 662 - anyOf: [ 663 - { 664 - $ref: '#/components/schemas/ModelWithString', 665 - }, 666 - { 667 - $ref: '#/components/schemas/ModelWithEnum', 668 - }, 669 - { 670 - $ref: '#/components/schemas/ModelWithArray', 671 - }, 672 - { 673 - $ref: '#/components/schemas/ModelWithDictionary', 674 - }, 675 - ], 676 - }, 677 - }, 678 - } as const; 679 - 680 - export const $CompositionWithAnyOfAnonymous = { 681 - description: "This is a model with one property with a 'any of' relationship where the options are not $ref", 682 - type: 'object', 683 - properties: { 684 - propA: { 685 - type: 'object', 686 - anyOf: [ 687 - { 688 - description: 'Anonymous object type', 689 - type: 'object', 690 - properties: { 691 - propA: { 692 - type: 'string', 693 - }, 694 - }, 695 - }, 696 - { 697 - description: 'Anonymous string type', 698 - type: 'string', 699 - }, 700 - { 701 - description: 'Anonymous integer type', 702 - type: 'integer', 703 - }, 704 - ], 705 - }, 706 - }, 707 - } as const; 708 - 709 - export const $CompositionWithNestedAnyAndTypeNull = { 710 - description: "This is a model with nested 'any of' property with a type null", 711 - type: 'object', 712 - properties: { 713 - propA: { 714 - type: 'object', 715 - anyOf: [ 716 - { 717 - items: { 718 - anyOf: [ 719 - { 720 - $ref: '#/components/schemas/ModelWithDictionary', 721 - }, 722 - { 723 - type: 'null', 724 - }, 725 - ], 726 - }, 727 - type: 'array', 728 - }, 729 - { 730 - items: { 731 - anyOf: [ 732 - { 733 - $ref: '#/components/schemas/ModelWithArray', 734 - }, 735 - { 736 - type: 'null', 737 - }, 738 - ], 739 - }, 740 - type: 'array', 741 - }, 742 - ], 743 - }, 744 - }, 745 - } as const; 746 - 747 - export const $Enum1 = { 748 - enum: ['Bird', 'Dog'], 749 - type: 'string', 750 - } as const; 751 - 752 - export const $ConstValue = { 753 - type: 'string', 754 - const: 'ConstValue', 755 - } as const; 756 - 757 - export const $CompositionWithNestedAnyOfAndNull = { 758 - description: "This is a model with one property with a 'any of' relationship where the options are not $ref", 759 - type: 'object', 760 - properties: { 761 - propA: { 762 - anyOf: [ 763 - { 764 - items: { 765 - anyOf: [ 766 - { 767 - $ref: '#/components/schemas/Enum1', 768 - }, 769 - { 770 - $ref: '#/components/schemas/ConstValue', 771 - }, 772 - ], 773 - }, 774 - type: 'array', 775 - }, 776 - { 777 - type: 'null', 778 - }, 779 - ], 780 - title: 'Scopes', 781 - }, 782 - }, 783 - } as const; 784 - 785 - export const $CompositionWithOneOfAndNullable = { 786 - description: "This is a model with one property with a 'one of' relationship", 787 - type: 'object', 788 - properties: { 789 - propA: { 790 - nullable: true, 791 - type: 'object', 792 - oneOf: [ 793 - { 794 - type: 'object', 795 - properties: { 796 - boolean: { 797 - type: 'boolean', 798 - }, 799 - }, 800 - }, 801 - { 802 - $ref: '#/components/schemas/ModelWithEnum', 803 - }, 804 - { 805 - $ref: '#/components/schemas/ModelWithArray', 806 - }, 807 - { 808 - $ref: '#/components/schemas/ModelWithDictionary', 809 - }, 810 - ], 811 - }, 812 - }, 813 - } as const; 814 - 815 - export const $CompositionWithOneOfAndSimpleDictionary = { 816 - description: 'This is a model that contains a simple dictionary within composition', 817 - type: 'object', 818 - properties: { 819 - propA: { 820 - oneOf: [ 821 - { 822 - type: 'boolean', 823 - }, 824 - { 825 - type: 'object', 826 - additionalProperties: { 827 - type: 'number', 828 - }, 829 - }, 830 - ], 831 - }, 832 - }, 833 - } as const; 834 - 835 - export const $CompositionWithOneOfAndSimpleArrayDictionary = { 836 - description: 'This is a model that contains a dictionary of simple arrays within composition', 837 - type: 'object', 838 - properties: { 839 - propA: { 840 - oneOf: [ 841 - { 842 - type: 'boolean', 843 - }, 844 - { 845 - type: 'object', 846 - additionalProperties: { 847 - type: 'array', 848 - items: { 849 - type: 'boolean', 850 - }, 851 - }, 852 - }, 853 - ], 854 - }, 855 - }, 856 - } as const; 857 - 858 - export const $CompositionWithOneOfAndComplexArrayDictionary = { 859 - description: 'This is a model that contains a dictionary of complex arrays (composited) within composition', 860 - type: 'object', 861 - properties: { 862 - propA: { 863 - oneOf: [ 864 - { 865 - type: 'boolean', 866 - }, 867 - { 868 - type: 'object', 869 - additionalProperties: { 870 - type: 'array', 871 - items: { 872 - oneOf: [ 873 - { 874 - type: 'number', 875 - }, 876 - { 877 - type: 'string', 878 - }, 879 - ], 880 - }, 881 - }, 882 - }, 883 - ], 884 - }, 885 - }, 886 - } as const; 887 - 888 - export const $CompositionWithAllOfAndNullable = { 889 - description: "This is a model with one property with a 'all of' relationship", 890 - type: 'object', 891 - properties: { 892 - propA: { 893 - nullable: true, 894 - type: 'object', 895 - allOf: [ 896 - { 897 - type: 'object', 898 - properties: { 899 - boolean: { 900 - type: 'boolean', 901 - }, 902 - }, 903 - }, 904 - { 905 - $ref: '#/components/schemas/ModelWithEnum', 906 - }, 907 - { 908 - $ref: '#/components/schemas/ModelWithArray', 909 - }, 910 - { 911 - $ref: '#/components/schemas/ModelWithDictionary', 912 - }, 913 - ], 914 - }, 915 - }, 916 - } as const; 917 - 918 - export const $CompositionWithAnyOfAndNullable = { 919 - description: "This is a model with one property with a 'any of' relationship", 920 - type: 'object', 921 - properties: { 922 - propA: { 923 - nullable: true, 924 - type: 'object', 925 - anyOf: [ 926 - { 927 - type: 'object', 928 - properties: { 929 - boolean: { 930 - type: 'boolean', 931 - }, 932 - }, 933 - }, 934 - { 935 - $ref: '#/components/schemas/ModelWithEnum', 936 - }, 937 - { 938 - $ref: '#/components/schemas/ModelWithArray', 939 - }, 940 - { 941 - $ref: '#/components/schemas/ModelWithDictionary', 942 - }, 943 - ], 944 - }, 945 - }, 946 - } as const; 947 - 948 - export const $CompositionBaseModel = { 949 - description: 'This is a base model with two simple optional properties', 950 - type: 'object', 951 - properties: { 952 - firstName: { 953 - type: 'string', 954 - }, 955 - lastname: { 956 - type: 'string', 957 - }, 958 - }, 959 - } as const; 960 - 961 - export const $CompositionExtendedModel = { 962 - description: 'This is a model that extends the base model', 963 - type: 'object', 964 - allOf: [ 965 - { 966 - $ref: '#/components/schemas/CompositionBaseModel', 967 - }, 968 - ], 969 - properties: { 970 - age: { 971 - type: 'number', 972 - }, 973 - }, 974 - required: ['firstName', 'lastname', 'age'], 975 - } as const; 976 - 977 - export const $ModelWithProperties = { 978 - description: 'This is a model with one nested property', 979 - type: 'object', 980 - required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], 981 - properties: { 982 - required: { 983 - type: 'string', 984 - }, 985 - requiredAndReadOnly: { 986 - type: 'string', 987 - readOnly: true, 988 - }, 989 - requiredAndNullable: { 990 - type: 'string', 991 - nullable: true, 992 - }, 993 - string: { 994 - type: 'string', 995 - }, 996 - number: { 997 - type: 'number', 998 - }, 999 - boolean: { 1000 - type: 'boolean', 1001 - }, 1002 - reference: { 1003 - $ref: '#/components/schemas/ModelWithString', 1004 - }, 1005 - 'property with space': { 1006 - type: 'string', 1007 - }, 1008 - default: { 1009 - type: 'string', 1010 - }, 1011 - try: { 1012 - type: 'string', 1013 - }, 1014 - '@namespace.string': { 1015 - type: 'string', 1016 - readOnly: true, 1017 - }, 1018 - '@namespace.integer': { 1019 - type: 'integer', 1020 - readOnly: true, 1021 - }, 1022 - }, 1023 - } as const; 1024 - 1025 - export const $ModelWithNestedProperties = { 1026 - description: 'This is a model with one nested property', 1027 - type: 'object', 1028 - required: ['first'], 1029 - properties: { 1030 - first: { 1031 - type: 'object', 1032 - required: ['second'], 1033 - readOnly: true, 1034 - nullable: true, 1035 - properties: { 1036 - second: { 1037 - type: 'object', 1038 - required: ['third'], 1039 - readOnly: true, 1040 - nullable: true, 1041 - properties: { 1042 - third: { 1043 - type: 'string', 1044 - required: true, 1045 - readOnly: true, 1046 - nullable: true, 1047 - }, 1048 - }, 1049 - }, 1050 - }, 1051 - }, 1052 - }, 1053 - } as const; 1054 - 1055 - export const $ModelWithDuplicateProperties = { 1056 - description: 'This is a model with duplicated properties', 1057 - type: 'object', 1058 - properties: { 1059 - prop: { 1060 - $ref: '#/components/schemas/ModelWithString', 1061 - }, 1062 - }, 1063 - } as const; 1064 - 1065 - export const $ModelWithOrderedProperties = { 1066 - description: 'This is a model with ordered properties', 1067 - type: 'object', 1068 - properties: { 1069 - zebra: { 1070 - type: 'string', 1071 - }, 1072 - apple: { 1073 - type: 'string', 1074 - }, 1075 - hawaii: { 1076 - type: 'string', 1077 - }, 1078 - }, 1079 - } as const; 1080 - 1081 - export const $ModelWithDuplicateImports = { 1082 - description: 'This is a model with duplicated imports', 1083 - type: 'object', 1084 - properties: { 1085 - propA: { 1086 - $ref: '#/components/schemas/ModelWithString', 1087 - }, 1088 - propB: { 1089 - $ref: '#/components/schemas/ModelWithString', 1090 - }, 1091 - propC: { 1092 - $ref: '#/components/schemas/ModelWithString', 1093 - }, 1094 - }, 1095 - } as const; 1096 - 1097 - export const $ModelThatExtends = { 1098 - description: 'This is a model that extends another model', 1099 - type: 'object', 1100 - allOf: [ 1101 - { 1102 - $ref: '#/components/schemas/ModelWithString', 1103 - }, 1104 - { 1105 - type: 'object', 1106 - properties: { 1107 - propExtendsA: { 1108 - type: 'string', 1109 - }, 1110 - propExtendsB: { 1111 - $ref: '#/components/schemas/ModelWithString', 1112 - }, 1113 - }, 1114 - }, 1115 - ], 1116 - } as const; 1117 - 1118 - export const $ModelThatExtendsExtends = { 1119 - description: 'This is a model that extends another model', 1120 - type: 'object', 1121 - allOf: [ 1122 - { 1123 - $ref: '#/components/schemas/ModelWithString', 1124 - }, 1125 - { 1126 - $ref: '#/components/schemas/ModelThatExtends', 1127 - }, 1128 - { 1129 - type: 'object', 1130 - properties: { 1131 - propExtendsC: { 1132 - type: 'string', 1133 - }, 1134 - propExtendsD: { 1135 - $ref: '#/components/schemas/ModelWithString', 1136 - }, 1137 - }, 1138 - }, 1139 - ], 1140 - } as const; 1141 - 1142 - export const $ModelWithPattern = { 1143 - description: 'This is a model that contains a some patterns', 1144 - type: 'object', 1145 - required: ['key', 'name'], 1146 - properties: { 1147 - key: { 1148 - maxLength: 64, 1149 - pattern: '^[a-zA-Z0-9_]*$', 1150 - type: 'string', 1151 - }, 1152 - name: { 1153 - maxLength: 255, 1154 - type: 'string', 1155 - }, 1156 - enabled: { 1157 - type: 'boolean', 1158 - readOnly: true, 1159 - }, 1160 - modified: { 1161 - type: 'string', 1162 - format: 'date-time', 1163 - readOnly: true, 1164 - }, 1165 - id: { 1166 - type: 'string', 1167 - pattern: '^d{2}-d{3}-d{4}$', 1168 - }, 1169 - text: { 1170 - type: 'string', 1171 - pattern: '^w+$', 1172 - }, 1173 - patternWithSingleQuotes: { 1174 - type: 'string', 1175 - pattern: "^[a-zA-Z0-9']*$", 1176 - }, 1177 - patternWithNewline: { 1178 - type: 'string', 1179 - pattern: `aaa 1180 - bbb`, 1181 - }, 1182 - patternWithBacktick: { 1183 - type: 'string', 1184 - pattern: 'aaa`bbb', 1185 - }, 1186 - }, 1187 - } as const; 1188 - 1189 - export const $File = { 1190 - required: ['mime'], 1191 - type: 'object', 1192 - properties: { 1193 - id: { 1194 - title: 'Id', 1195 - type: 'string', 1196 - readOnly: true, 1197 - minLength: 1, 1198 - }, 1199 - updated_at: { 1200 - title: 'Updated at', 1201 - type: 'string', 1202 - format: 'date-time', 1203 - readOnly: true, 1204 - }, 1205 - created_at: { 1206 - title: 'Created at', 1207 - type: 'string', 1208 - format: 'date-time', 1209 - readOnly: true, 1210 - }, 1211 - mime: { 1212 - title: 'Mime', 1213 - type: 'string', 1214 - maxLength: 24, 1215 - minLength: 1, 1216 - }, 1217 - file: { 1218 - title: 'File', 1219 - type: 'string', 1220 - readOnly: true, 1221 - format: 'uri', 1222 - }, 1223 - }, 1224 - } as const; 1225 - 1226 - export const $default = { 1227 - type: 'object', 1228 - properties: { 1229 - name: { 1230 - type: 'string', 1231 - }, 1232 - }, 1233 - } as const; 1234 - 1235 - export const $Pageable = { 1236 - type: 'object', 1237 - properties: { 1238 - page: { 1239 - minimum: 0, 1240 - type: 'integer', 1241 - format: 'int32', 1242 - default: 0, 1243 - }, 1244 - size: { 1245 - minimum: 1, 1246 - type: 'integer', 1247 - format: 'int32', 1248 - }, 1249 - sort: { 1250 - type: 'array', 1251 - items: { 1252 - type: 'string', 1253 - }, 1254 - }, 1255 - }, 1256 - } as const; 1257 - 1258 - export const $FreeFormObjectWithoutAdditionalProperties = { 1259 - description: 'This is a free-form object without additionalProperties.', 1260 - type: 'object', 1261 - } as const; 1262 - 1263 - export const $FreeFormObjectWithAdditionalPropertiesEqTrue = { 1264 - description: 'This is a free-form object with additionalProperties: true.', 1265 - type: 'object', 1266 - additionalProperties: true, 1267 - } as const; 1268 - 1269 - export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 1270 - description: 'This is a free-form object with additionalProperties: {}.', 1271 - type: 'object', 1272 - additionalProperties: {}, 1273 - } as const; 1274 - 1275 - export const $ModelWithConst = { 1276 - type: 'object', 1277 - properties: { 1278 - String: { 1279 - const: 'String', 1280 - }, 1281 - number: { 1282 - const: 0, 1283 - }, 1284 - null: { 1285 - const: null, 1286 - }, 1287 - withType: { 1288 - type: 'string', 1289 - const: 'Some string', 1290 - }, 1291 - }, 1292 - } as const; 1293 - 1294 - export const $ModelWithAdditionalPropertiesEqTrue = { 1295 - description: 'This is a model with one property and additionalProperties: true', 1296 - type: 'object', 1297 - properties: { 1298 - prop: { 1299 - description: 'This is a simple string property', 1300 - type: 'string', 1301 - }, 1302 - }, 1303 - additionalProperties: true, 1304 - } as const; 1305 - 1306 - export const $NestedAnyOfArraysNullable = { 1307 - properties: { 1308 - nullableArray: { 1309 - anyOf: [ 1310 - { 1311 - items: { 1312 - anyOf: [ 1313 - { 1314 - type: 'string', 1315 - }, 1316 - { 1317 - type: 'boolean', 1318 - }, 1319 - ], 1320 - }, 1321 - type: 'array', 1322 - }, 1323 - { 1324 - type: 'null', 1325 - }, 1326 - ], 1327 - }, 1328 - }, 1329 - type: 'object', 1330 - } as const; 1331 - 1332 - export const $CompositionWithOneOfAndProperties = { 1333 - type: 'object', 1334 - oneOf: [ 1335 - { 1336 - type: 'object', 1337 - required: ['foo'], 1338 - properties: { 1339 - foo: { 1340 - $ref: '#/components/parameters/SimpleParameter', 1341 - }, 1342 - }, 1343 - additionalProperties: false, 1344 - }, 1345 - { 1346 - type: 'object', 1347 - required: ['bar'], 1348 - properties: { 1349 - bar: { 1350 - $ref: '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2', 1351 - }, 1352 - }, 1353 - additionalProperties: false, 1354 - }, 1355 - ], 1356 - required: ['baz', 'qux'], 1357 - properties: { 1358 - baz: { 1359 - type: 'integer', 1360 - format: 'uint16', 1361 - minimum: 0, 1362 - nullable: true, 1363 - }, 1364 - qux: { 1365 - type: 'integer', 1366 - format: 'uint8', 1367 - minimum: 0, 1368 - }, 1369 - }, 1370 - } as const; 1371 - 1372 - export const $NullableObject = { 1373 - type: 'object', 1374 - nullable: true, 1375 - description: 'An object that can be null', 1376 - properties: { 1377 - foo: { 1378 - type: 'string', 1379 - }, 1380 - }, 1381 - default: null, 1382 - } as const; 1383 - 1384 - export const $ModelWithNullableObject = { 1385 - type: 'object', 1386 - properties: { 1387 - data: { 1388 - $ref: '#/components/schemas/NullableObject', 1389 - }, 1390 - }, 1391 - } as const; 1392 - 1393 - export const $ModelWithOneOfEnum = { 1394 - oneOf: [ 1395 - { 1396 - type: 'object', 1397 - required: ['foo'], 1398 - properties: { 1399 - foo: { 1400 - type: 'string', 1401 - enum: ['Bar'], 1402 - }, 1403 - }, 1404 - }, 1405 - { 1406 - type: 'object', 1407 - required: ['foo'], 1408 - properties: { 1409 - foo: { 1410 - type: 'string', 1411 - enum: ['Baz'], 1412 - }, 1413 - }, 1414 - }, 1415 - { 1416 - type: 'object', 1417 - required: ['foo'], 1418 - properties: { 1419 - foo: { 1420 - type: 'string', 1421 - enum: ['Qux'], 1422 - }, 1423 - }, 1424 - }, 1425 - { 1426 - type: 'object', 1427 - required: ['content', 'foo'], 1428 - properties: { 1429 - content: { 1430 - type: 'string', 1431 - format: 'date-time', 1432 - }, 1433 - foo: { 1434 - type: 'string', 1435 - enum: ['Quux'], 1436 - }, 1437 - }, 1438 - }, 1439 - { 1440 - type: 'object', 1441 - required: ['content', 'foo'], 1442 - properties: { 1443 - content: { 1444 - type: 'array', 1445 - items: [ 1446 - { 1447 - type: 'string', 1448 - format: 'date-time', 1449 - }, 1450 - { 1451 - type: 'string', 1452 - }, 1453 - ], 1454 - maxItems: 2, 1455 - minItems: 2, 1456 - }, 1457 - foo: { 1458 - type: 'string', 1459 - enum: ['Corge'], 1460 - }, 1461 - }, 1462 - }, 1463 - ], 1464 - } as const; 1465 - 1466 - export const $ModelWithNestedArrayEnumsDataFoo = { 1467 - enum: ['foo', 'bar'], 1468 - type: 'string', 1469 - } as const; 1470 - 1471 - export const $ModelWithNestedArrayEnumsDataBar = { 1472 - enum: ['baz', 'qux'], 1473 - type: 'string', 1474 - } as const; 1475 - 1476 - export const $ModelWithNestedArrayEnumsData = { 1477 - type: 'object', 1478 - properties: { 1479 - foo: { 1480 - type: 'array', 1481 - items: { 1482 - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', 1483 - }, 1484 - }, 1485 - bar: { 1486 - type: 'array', 1487 - items: { 1488 - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataBar', 1489 - }, 1490 - }, 1491 - }, 1492 - } as const; 1493 - 1494 - export const $ModelWithNestedArrayEnums = { 1495 - type: 'object', 1496 - properties: { 1497 - array_strings: { 1498 - type: 'array', 1499 - items: { 1500 - type: 'string', 1501 - }, 1502 - }, 1503 - data: { 1504 - allOf: [ 1505 - { 1506 - $ref: '#/components/schemas/ModelWithNestedArrayEnumsData', 1507 - }, 1508 - ], 1509 - }, 1510 - }, 1511 - } as const; 1512 - 1513 - export const $ModelWithNestedCompositionEnums = { 1514 - type: 'object', 1515 - properties: { 1516 - foo: { 1517 - allOf: [ 1518 - { 1519 - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', 1520 - }, 1521 - ], 1522 - }, 1523 - }, 1524 - } as const; 1525 - 1526 - export const $ModelWithReadOnlyAndWriteOnly = { 1527 - type: 'object', 1528 - required: ['foo', 'bar', 'baz'], 1529 - properties: { 1530 - foo: { 1531 - type: 'string', 1532 - }, 1533 - bar: { 1534 - readOnly: true, 1535 - type: 'string', 1536 - }, 1537 - baz: { 1538 - type: 'string', 1539 - writeOnly: true, 1540 - }, 1541 - }, 1542 - } as const; 1543 - 1544 - export const $ModelWithConstantSizeArray = { 1545 - type: 'array', 1546 - items: { 1547 - type: 'number', 1548 - }, 1549 - minItems: 2, 1550 - maxItems: 2, 1551 - } as const; 1552 - 1553 - export const $ModelWithAnyOfConstantSizeArray = { 1554 - type: 'array', 1555 - items: { 1556 - oneOf: [ 1557 - { 1558 - type: 'number', 1559 - }, 1560 - { 1561 - type: 'string', 1562 - }, 1563 - ], 1564 - }, 1565 - minItems: 3, 1566 - maxItems: 3, 1567 - } as const; 1568 - 1569 - export const $SimpleParameter = { 1570 - description: 'This is a reusable parameter', 1571 - name: 'parameter', 1572 - in: 'query', 1573 - required: false, 1574 - schema: { 1575 - type: 'string', 1576 - }, 1577 - } as const;
-807
packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/services.ts.snap
··· 1 - import type { CancelablePromise } from './core/CancelablePromise'; 2 - import { OpenAPI } from './core/OpenAPI'; 3 - import { request as __request } from './core/request'; 4 - import type { 5 - $OpenApiTsDefault, 6 - $OpenApiTsSimple, 7 - $OpenApiTsParameters, 8 - $OpenApiTsDescriptions, 9 - $OpenApiTsDeprecated, 10 - $OpenApiTsRequestBody, 11 - $OpenApiTsFormData, 12 - $OpenApiTsDefaults, 13 - $OpenApiTsDuplicate, 14 - $OpenApiTsNoContent, 15 - $OpenApiTsResponse, 16 - $OpenApiTsMultipleTags1, 17 - $OpenApiTsMultipleTags2, 18 - $OpenApiTsMultipleTags3, 19 - $OpenApiTsCollectionFormat, 20 - $OpenApiTsTypes, 21 - $OpenApiTsUpload, 22 - $OpenApiTsFileResponse, 23 - $OpenApiTsComplex, 24 - $OpenApiTsMultipart, 25 - $OpenApiTsHeader, 26 - $OpenApiTsError, 27 - $OpenApiTsNonAsciiÆøåÆøÅöôêÊ, 28 - } from './models'; 29 - 30 - export class DefaultService { 31 - /** 32 - * @throws ApiError 33 - */ 34 - public static serviceWithEmptyTag(): CancelablePromise<$OpenApiTsDefault['res']['ServiceWithEmptyTag']> { 35 - return __request(OpenAPI, { 36 - method: 'GET', 37 - url: '/api/v{api-version}/no-tag', 38 - }); 39 - } 40 - 41 - /** 42 - * @returns ModelWithReadOnlyAndWriteOnly 43 - * @throws ApiError 44 - */ 45 - public static postServiceWithEmptyTag( 46 - data: $OpenApiTsDefault['req']['PostServiceWithEmptyTag'] 47 - ): CancelablePromise<$OpenApiTsDefault['res']['PostServiceWithEmptyTag']> { 48 - const { query, requestBody } = data; 49 - return __request(OpenAPI, { 50 - method: 'POST', 51 - url: '/api/v{api-version}/no-tag', 52 - body: requestBody, 53 - mediaType: 'application/json', 54 - }); 55 - } 56 - } 57 - 58 - export class SimpleService { 59 - /** 60 - * @returns Model_From_Zendesk Success 61 - * @throws ApiError 62 - */ 63 - public static apiVVersionOdataControllerCount(): CancelablePromise< 64 - $OpenApiTsSimple['res']['ApiVversionOdataControllerCount'] 65 - > { 66 - return __request(OpenAPI, { 67 - method: 'GET', 68 - url: '/api/v{api-version}/simple/$count', 69 - }); 70 - } 71 - 72 - /** 73 - * @throws ApiError 74 - */ 75 - public static getCallWithoutParametersAndResponse(): CancelablePromise< 76 - $OpenApiTsSimple['res']['GetCallWithoutParametersAndResponse'] 77 - > { 78 - return __request(OpenAPI, { 79 - method: 'GET', 80 - url: '/api/v{api-version}/simple', 81 - }); 82 - } 83 - 84 - /** 85 - * @throws ApiError 86 - */ 87 - public static putCallWithoutParametersAndResponse(): CancelablePromise< 88 - $OpenApiTsSimple['res']['PutCallWithoutParametersAndResponse'] 89 - > { 90 - return __request(OpenAPI, { 91 - method: 'PUT', 92 - url: '/api/v{api-version}/simple', 93 - }); 94 - } 95 - 96 - /** 97 - * @throws ApiError 98 - */ 99 - public static postCallWithoutParametersAndResponse(): CancelablePromise< 100 - $OpenApiTsSimple['res']['PostCallWithoutParametersAndResponse'] 101 - > { 102 - return __request(OpenAPI, { 103 - method: 'POST', 104 - url: '/api/v{api-version}/simple', 105 - }); 106 - } 107 - 108 - /** 109 - * @throws ApiError 110 - */ 111 - public static deleteCallWithoutParametersAndResponse(): CancelablePromise< 112 - $OpenApiTsSimple['res']['DeleteCallWithoutParametersAndResponse'] 113 - > { 114 - return __request(OpenAPI, { 115 - method: 'DELETE', 116 - url: '/api/v{api-version}/simple', 117 - }); 118 - } 119 - 120 - /** 121 - * @throws ApiError 122 - */ 123 - public static optionsCallWithoutParametersAndResponse(): CancelablePromise< 124 - $OpenApiTsSimple['res']['OptionsCallWithoutParametersAndResponse'] 125 - > { 126 - return __request(OpenAPI, { 127 - method: 'OPTIONS', 128 - url: '/api/v{api-version}/simple', 129 - }); 130 - } 131 - 132 - /** 133 - * @throws ApiError 134 - */ 135 - public static headCallWithoutParametersAndResponse(): CancelablePromise< 136 - $OpenApiTsSimple['res']['HeadCallWithoutParametersAndResponse'] 137 - > { 138 - return __request(OpenAPI, { 139 - method: 'HEAD', 140 - url: '/api/v{api-version}/simple', 141 - }); 142 - } 143 - 144 - /** 145 - * @throws ApiError 146 - */ 147 - public static patchCallWithoutParametersAndResponse(): CancelablePromise< 148 - $OpenApiTsSimple['res']['PatchCallWithoutParametersAndResponse'] 149 - > { 150 - return __request(OpenAPI, { 151 - method: 'PATCH', 152 - url: '/api/v{api-version}/simple', 153 - }); 154 - } 155 - } 156 - 157 - export class ParametersService { 158 - /** 159 - * @throws ApiError 160 - */ 161 - public static deleteFoo( 162 - data: $OpenApiTsParameters['req']['DeleteFoo'] 163 - ): CancelablePromise<$OpenApiTsParameters['res']['DeleteFoo']> { 164 - const { query, foo, bar } = data; 165 - return __request(OpenAPI, { 166 - method: 'DELETE', 167 - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', 168 - path: {}, 169 - }); 170 - } 171 - 172 - /** 173 - * @throws ApiError 174 - */ 175 - public static callWithParameters( 176 - data: $OpenApiTsParameters['req']['CallWithParameters'] 177 - ): CancelablePromise<$OpenApiTsParameters['res']['CallWithParameters']> { 178 - const { query, parameterHeader, parameterForm, parameterCookie, parameterPath, requestBody } = data; 179 - return __request(OpenAPI, { 180 - method: 'POST', 181 - url: '/api/v{api-version}/parameters/{parameterPath}', 182 - path: {}, 183 - cookies: {}, 184 - headers: {}, 185 - query: { 186 - ...query, 187 - }, 188 - formData: {}, 189 - body: requestBody, 190 - mediaType: 'application/json', 191 - }); 192 - } 193 - 194 - /** 195 - * @throws ApiError 196 - */ 197 - public static callWithWeirdParameterNames( 198 - data: $OpenApiTsParameters['req']['CallWithWeirdParameterNames'] 199 - ): CancelablePromise<$OpenApiTsParameters['res']['CallWithWeirdParameterNames']> { 200 - const { 201 - query, 202 - parameterHeader, 203 - parameterForm, 204 - parameterCookie, 205 - requestBody, 206 - parameterPath1, 207 - parameterPath2, 208 - parameterPath3, 209 - } = data; 210 - return __request(OpenAPI, { 211 - method: 'POST', 212 - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 213 - path: {}, 214 - cookies: {}, 215 - headers: {}, 216 - query: { 217 - ...query, 218 - }, 219 - formData: {}, 220 - body: requestBody, 221 - mediaType: 'application/json', 222 - }); 223 - } 224 - 225 - /** 226 - * @throws ApiError 227 - */ 228 - public static getCallWithOptionalParam( 229 - data: $OpenApiTsParameters['req']['GetCallWithOptionalParam'] 230 - ): CancelablePromise<$OpenApiTsParameters['res']['GetCallWithOptionalParam']> { 231 - const { query, requestBody } = data; 232 - return __request(OpenAPI, { 233 - method: 'GET', 234 - url: '/api/v{api-version}/parameters/', 235 - query: { 236 - ...query, 237 - }, 238 - body: requestBody, 239 - mediaType: 'application/json', 240 - }); 241 - } 242 - 243 - /** 244 - * @throws ApiError 245 - */ 246 - public static postCallWithOptionalParam( 247 - data: $OpenApiTsParameters['req']['PostCallWithOptionalParam'] 248 - ): CancelablePromise<$OpenApiTsParameters['res']['PostCallWithOptionalParam']> { 249 - const { query, requestBody } = data; 250 - return __request(OpenAPI, { 251 - method: 'POST', 252 - url: '/api/v{api-version}/parameters/', 253 - query: { 254 - ...query, 255 - }, 256 - body: requestBody, 257 - mediaType: 'application/json', 258 - }); 259 - } 260 - } 261 - 262 - export class DescriptionsService { 263 - /** 264 - * @throws ApiError 265 - */ 266 - public static callWithDescriptions( 267 - data: $OpenApiTsDescriptions['req']['CallWithDescriptions'] = {} 268 - ): CancelablePromise<$OpenApiTsDescriptions['res']['CallWithDescriptions']> { 269 - const { query } = data; 270 - return __request(OpenAPI, { 271 - method: 'POST', 272 - url: '/api/v{api-version}/descriptions/', 273 - query: { 274 - ...query, 275 - }, 276 - }); 277 - } 278 - } 279 - 280 - export class DeprecatedService { 281 - /** 282 - * @deprecated 283 - * @throws ApiError 284 - */ 285 - public static deprecatedCall( 286 - data: $OpenApiTsDeprecated['req']['DeprecatedCall'] 287 - ): CancelablePromise<$OpenApiTsDeprecated['res']['DeprecatedCall']> { 288 - const { query, parameter } = data; 289 - return __request(OpenAPI, { 290 - method: 'POST', 291 - url: '/api/v{api-version}/parameters/deprecated', 292 - headers: {}, 293 - }); 294 - } 295 - } 296 - 297 - export class RequestBodyService { 298 - /** 299 - * @throws ApiError 300 - */ 301 - public static postApiRequestBody( 302 - data: $OpenApiTsRequestBody['req']['PostApiRequestBody'] = {} 303 - ): CancelablePromise<$OpenApiTsRequestBody['res']['PostApiRequestBody']> { 304 - const { query, foo } = data; 305 - return __request(OpenAPI, { 306 - method: 'POST', 307 - url: '/api/v{api-version}/requestBody/', 308 - query: { 309 - ...query, 310 - }, 311 - body: foo, 312 - mediaType: 'application/json', 313 - }); 314 - } 315 - } 316 - 317 - export class FormDataService { 318 - /** 319 - * @throws ApiError 320 - */ 321 - public static postApiFormData( 322 - data: $OpenApiTsFormData['req']['PostApiFormData'] = {} 323 - ): CancelablePromise<$OpenApiTsFormData['res']['PostApiFormData']> { 324 - const { query, formData } = data; 325 - return __request(OpenAPI, { 326 - method: 'POST', 327 - url: '/api/v{api-version}/formData/', 328 - query: { 329 - ...query, 330 - }, 331 - formData: formData, 332 - mediaType: 'multipart/form-data', 333 - }); 334 - } 335 - } 336 - 337 - export class DefaultsService { 338 - /** 339 - * @throws ApiError 340 - */ 341 - public static callWithDefaultParameters( 342 - data: $OpenApiTsDefaults['req']['CallWithDefaultParameters'] = {} 343 - ): CancelablePromise<$OpenApiTsDefaults['res']['CallWithDefaultParameters']> { 344 - const { query } = data; 345 - return __request(OpenAPI, { 346 - method: 'GET', 347 - url: '/api/v{api-version}/defaults', 348 - query: { 349 - parameterString: 'Hello World!', 350 - parameterNumber: 123, 351 - parameterBoolean: true, 352 - parameterEnum: 'Success', 353 - parameterModel: { 354 - prop: 'Hello World!', 355 - }, 356 - ...query, 357 - }, 358 - }); 359 - } 360 - 361 - /** 362 - * @throws ApiError 363 - */ 364 - public static callWithDefaultOptionalParameters( 365 - data: $OpenApiTsDefaults['req']['CallWithDefaultOptionalParameters'] = {} 366 - ): CancelablePromise<$OpenApiTsDefaults['res']['CallWithDefaultOptionalParameters']> { 367 - const { query } = data; 368 - return __request(OpenAPI, { 369 - method: 'POST', 370 - url: '/api/v{api-version}/defaults', 371 - query: { 372 - parameterString: 'Hello World!', 373 - parameterNumber: 123, 374 - parameterBoolean: true, 375 - parameterEnum: 'Success', 376 - parameterModel: { 377 - prop: 'Hello World!', 378 - }, 379 - ...query, 380 - }, 381 - }); 382 - } 383 - 384 - /** 385 - * @throws ApiError 386 - */ 387 - public static callToTestOrderOfParams( 388 - data: $OpenApiTsDefaults['req']['CallToTestOrderOfParams'] 389 - ): CancelablePromise<$OpenApiTsDefaults['res']['CallToTestOrderOfParams']> { 390 - const { query } = data; 391 - return __request(OpenAPI, { 392 - method: 'PUT', 393 - url: '/api/v{api-version}/defaults', 394 - query: { 395 - parameterOptionalStringWithDefault: 'Hello World!', 396 - parameterOptionalStringWithEmptyDefault: '', 397 - parameterStringWithDefault: 'Hello World!', 398 - parameterStringWithEmptyDefault: '', 399 - parameterStringNullableWithDefault: null, 400 - ...query, 401 - }, 402 - }); 403 - } 404 - } 405 - 406 - export class DuplicateService { 407 - /** 408 - * @throws ApiError 409 - */ 410 - public static duplicateName(): CancelablePromise<$OpenApiTsDuplicate['res']['DuplicateName']> { 411 - return __request(OpenAPI, { 412 - method: 'GET', 413 - url: '/api/v{api-version}/duplicate', 414 - }); 415 - } 416 - 417 - /** 418 - * @throws ApiError 419 - */ 420 - public static duplicateName1(): CancelablePromise<$OpenApiTsDuplicate['res']['DuplicateName1']> { 421 - return __request(OpenAPI, { 422 - method: 'POST', 423 - url: '/api/v{api-version}/duplicate', 424 - }); 425 - } 426 - 427 - /** 428 - * @throws ApiError 429 - */ 430 - public static duplicateName2(): CancelablePromise<$OpenApiTsDuplicate['res']['DuplicateName2']> { 431 - return __request(OpenAPI, { 432 - method: 'PUT', 433 - url: '/api/v{api-version}/duplicate', 434 - }); 435 - } 436 - 437 - /** 438 - * @throws ApiError 439 - */ 440 - public static duplicateName3(): CancelablePromise<$OpenApiTsDuplicate['res']['DuplicateName3']> { 441 - return __request(OpenAPI, { 442 - method: 'DELETE', 443 - url: '/api/v{api-version}/duplicate', 444 - }); 445 - } 446 - } 447 - 448 - export class NoContentService { 449 - /** 450 - * @returns void Success 451 - * @throws ApiError 452 - */ 453 - public static callWithNoContentResponse(): CancelablePromise< 454 - $OpenApiTsNoContent['res']['CallWithNoContentResponse'] 455 - > { 456 - return __request(OpenAPI, { 457 - method: 'GET', 458 - url: '/api/v{api-version}/no-content', 459 - }); 460 - } 461 - 462 - /** 463 - * @returns number Response is a simple number 464 - * @returns void Success 465 - * @throws ApiError 466 - */ 467 - public static callWithResponseAndNoContentResponse(): CancelablePromise< 468 - $OpenApiTsNoContent['res']['CallWithResponseAndNoContentResponse'] 469 - > { 470 - return __request(OpenAPI, { 471 - method: 'GET', 472 - url: '/api/v{api-version}/multiple-tags/response-and-no-content', 473 - }); 474 - } 475 - } 476 - 477 - export class ResponseService { 478 - /** 479 - * @returns number Response is a simple number 480 - * @returns void Success 481 - * @throws ApiError 482 - */ 483 - public static callWithResponseAndNoContentResponse(): CancelablePromise< 484 - $OpenApiTsResponse['res']['CallWithResponseAndNoContentResponse'] 485 - > { 486 - return __request(OpenAPI, { 487 - method: 'GET', 488 - url: '/api/v{api-version}/multiple-tags/response-and-no-content', 489 - }); 490 - } 491 - 492 - /** 493 - * @returns ModelWithString 494 - * @throws ApiError 495 - */ 496 - public static callWithResponse(): CancelablePromise<$OpenApiTsResponse['res']['CallWithResponse']> { 497 - return __request(OpenAPI, { 498 - method: 'GET', 499 - url: '/api/v{api-version}/response', 500 - }); 501 - } 502 - 503 - /** 504 - * @returns ModelWithString Message for default response 505 - * @throws ApiError 506 - */ 507 - public static callWithDuplicateResponses(): CancelablePromise< 508 - $OpenApiTsResponse['res']['CallWithDuplicateResponses'] 509 - > { 510 - return __request(OpenAPI, { 511 - method: 'POST', 512 - url: '/api/v{api-version}/response', 513 - errors: { 514 - 500: `Message for 500 error`, 515 - 501: `Message for 501 error`, 516 - 502: `Message for 502 error`, 517 - }, 518 - }); 519 - } 520 - 521 - /** 522 - * @returns any Message for 200 response 523 - * @returns ModelWithString Message for default response 524 - * @returns ModelThatExtends Message for 201 response 525 - * @returns ModelThatExtendsExtends Message for 202 response 526 - * @throws ApiError 527 - */ 528 - public static callWithResponses(): CancelablePromise<$OpenApiTsResponse['res']['CallWithResponses']> { 529 - return __request(OpenAPI, { 530 - method: 'PUT', 531 - url: '/api/v{api-version}/response', 532 - errors: { 533 - 500: `Message for 500 error`, 534 - 501: `Message for 501 error`, 535 - 502: `Message for 502 error`, 536 - }, 537 - }); 538 - } 539 - } 540 - 541 - export class MultipleTags1Service { 542 - /** 543 - * @returns void Success 544 - * @throws ApiError 545 - */ 546 - public static dummyA(): CancelablePromise<$OpenApiTsMultipleTags1['res']['DummyA']> { 547 - return __request(OpenAPI, { 548 - method: 'GET', 549 - url: '/api/v{api-version}/multiple-tags/a', 550 - }); 551 - } 552 - 553 - /** 554 - * @returns void Success 555 - * @throws ApiError 556 - */ 557 - public static dummyB(): CancelablePromise<$OpenApiTsMultipleTags1['res']['DummyB']> { 558 - return __request(OpenAPI, { 559 - method: 'GET', 560 - url: '/api/v{api-version}/multiple-tags/b', 561 - }); 562 - } 563 - } 564 - 565 - export class MultipleTags2Service { 566 - /** 567 - * @returns void Success 568 - * @throws ApiError 569 - */ 570 - public static dummyA(): CancelablePromise<$OpenApiTsMultipleTags2['res']['DummyA']> { 571 - return __request(OpenAPI, { 572 - method: 'GET', 573 - url: '/api/v{api-version}/multiple-tags/a', 574 - }); 575 - } 576 - 577 - /** 578 - * @returns void Success 579 - * @throws ApiError 580 - */ 581 - public static dummyB(): CancelablePromise<$OpenApiTsMultipleTags2['res']['DummyB']> { 582 - return __request(OpenAPI, { 583 - method: 'GET', 584 - url: '/api/v{api-version}/multiple-tags/b', 585 - }); 586 - } 587 - } 588 - 589 - export class MultipleTags3Service { 590 - /** 591 - * @returns void Success 592 - * @throws ApiError 593 - */ 594 - public static dummyB(): CancelablePromise<$OpenApiTsMultipleTags3['res']['DummyB']> { 595 - return __request(OpenAPI, { 596 - method: 'GET', 597 - url: '/api/v{api-version}/multiple-tags/b', 598 - }); 599 - } 600 - } 601 - 602 - export class CollectionFormatService { 603 - /** 604 - * @throws ApiError 605 - */ 606 - public static collectionFormat( 607 - data: $OpenApiTsCollectionFormat['req']['CollectionFormat'] 608 - ): CancelablePromise<$OpenApiTsCollectionFormat['res']['CollectionFormat']> { 609 - const { query } = data; 610 - return __request(OpenAPI, { 611 - method: 'GET', 612 - url: '/api/v{api-version}/collectionFormat', 613 - query: { 614 - ...query, 615 - }, 616 - }); 617 - } 618 - } 619 - 620 - export class TypesService { 621 - /** 622 - * @returns number Response is a simple number 623 - * @returns string Response is a simple string 624 - * @returns boolean Response is a simple boolean 625 - * @returns unknown Response is a simple object 626 - * @throws ApiError 627 - */ 628 - public static types(data: $OpenApiTsTypes['req']['Types']): CancelablePromise<$OpenApiTsTypes['res']['Types']> { 629 - const { query, id } = data; 630 - return __request(OpenAPI, { 631 - method: 'GET', 632 - url: '/api/v{api-version}/types', 633 - path: {}, 634 - query: { 635 - parameterNumber: 123, 636 - parameterString: 'default', 637 - parameterBoolean: true, 638 - parameterObject: null, 639 - ...query, 640 - }, 641 - }); 642 - } 643 - } 644 - 645 - export class UploadService { 646 - /** 647 - * @returns boolean 648 - * @throws ApiError 649 - */ 650 - public static uploadFile( 651 - data: $OpenApiTsUpload['req']['UploadFile'] 652 - ): CancelablePromise<$OpenApiTsUpload['res']['UploadFile']> { 653 - const { query, file } = data; 654 - return __request(OpenAPI, { 655 - method: 'POST', 656 - url: '/api/v{api-version}/upload', 657 - formData: {}, 658 - }); 659 - } 660 - } 661 - 662 - export class FileResponseService { 663 - /** 664 - * @returns binary Success 665 - * @throws ApiError 666 - */ 667 - public static fileResponse( 668 - data: $OpenApiTsFileResponse['req']['FileResponse'] 669 - ): CancelablePromise<$OpenApiTsFileResponse['res']['FileResponse']> { 670 - const { query, id } = data; 671 - return __request(OpenAPI, { 672 - method: 'GET', 673 - url: '/api/v{api-version}/file/{id}', 674 - path: {}, 675 - }); 676 - } 677 - } 678 - 679 - export class ComplexService { 680 - /** 681 - * @returns ModelWithString Successful response 682 - * @throws ApiError 683 - */ 684 - public static complexTypes( 685 - data: $OpenApiTsComplex['req']['ComplexTypes'] 686 - ): CancelablePromise<$OpenApiTsComplex['res']['ComplexTypes']> { 687 - const { query } = data; 688 - return __request(OpenAPI, { 689 - method: 'GET', 690 - url: '/api/v{api-version}/complex', 691 - query: { 692 - ...query, 693 - }, 694 - errors: { 695 - 400: `400 server error`, 696 - 500: `500 server error`, 697 - }, 698 - }); 699 - } 700 - 701 - /** 702 - * @returns ModelWithString Success 703 - * @throws ApiError 704 - */ 705 - public static complexParams( 706 - data: $OpenApiTsComplex['req']['ComplexParams'] 707 - ): CancelablePromise<$OpenApiTsComplex['res']['ComplexParams']> { 708 - const { query, id, requestBody } = data; 709 - return __request(OpenAPI, { 710 - method: 'PUT', 711 - url: '/api/v{api-version}/complex/{id}', 712 - path: {}, 713 - body: requestBody, 714 - mediaType: 'application/json-patch+json', 715 - }); 716 - } 717 - } 718 - 719 - export class MultipartService { 720 - /** 721 - * @throws ApiError 722 - */ 723 - public static multipartRequest( 724 - data: $OpenApiTsMultipart['req']['MultipartRequest'] = {} 725 - ): CancelablePromise<$OpenApiTsMultipart['res']['MultipartRequest']> { 726 - const { query, formData } = data; 727 - return __request(OpenAPI, { 728 - method: 'POST', 729 - url: '/api/v{api-version}/multipart', 730 - formData: formData, 731 - mediaType: 'multipart/form-data', 732 - }); 733 - } 734 - 735 - /** 736 - * @returns any OK 737 - * @throws ApiError 738 - */ 739 - public static multipartResponse(): CancelablePromise<$OpenApiTsMultipart['res']['MultipartResponse']> { 740 - return __request(OpenAPI, { 741 - method: 'GET', 742 - url: '/api/v{api-version}/multipart', 743 - }); 744 - } 745 - } 746 - 747 - export class HeaderService { 748 - /** 749 - * @returns string Successful response 750 - * @throws ApiError 751 - */ 752 - public static callWithResultFromHeader(): CancelablePromise<$OpenApiTsHeader['res']['CallWithResultFromHeader']> { 753 - return __request(OpenAPI, { 754 - method: 'POST', 755 - url: '/api/v{api-version}/header', 756 - responseHeader: 'operation-location', 757 - errors: { 758 - 400: `400 server error`, 759 - 500: `500 server error`, 760 - }, 761 - }); 762 - } 763 - } 764 - 765 - export class ErrorService { 766 - /** 767 - * @returns any Custom message: Successful response 768 - * @throws ApiError 769 - */ 770 - public static testErrorCode( 771 - data: $OpenApiTsError['req']['TestErrorCode'] 772 - ): CancelablePromise<$OpenApiTsError['res']['TestErrorCode']> { 773 - const { query } = data; 774 - return __request(OpenAPI, { 775 - method: 'POST', 776 - url: '/api/v{api-version}/error', 777 - query: { 778 - ...query, 779 - }, 780 - errors: { 781 - 500: `Custom message: Internal Server Error`, 782 - 501: `Custom message: Not Implemented`, 783 - 502: `Custom message: Bad Gateway`, 784 - 503: `Custom message: Service Unavailable`, 785 - }, 786 - }); 787 - } 788 - } 789 - 790 - export class NonAsciiÆøåÆøÅöôêÊService { 791 - /** 792 - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response 793 - * @throws ApiError 794 - */ 795 - public static nonAsciiæøåÆøÅöôêÊ字符串( 796 - data: $OpenApiTsNonAsciiÆøåÆøÅöôêÊ['req']['NonAsciiæøåÆøÅöôêÊ字符串'] 797 - ): CancelablePromise<$OpenApiTsNonAsciiÆøåÆøÅöôêÊ['res']['NonAsciiæøåÆøÅöôêÊ字符串']> { 798 - const { query } = data; 799 - return __request(OpenAPI, { 800 - method: 'POST', 801 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', 802 - query: { 803 - ...query, 804 - }, 805 - }); 806 - } 807 - }