From a2f521ef943d91dbdfc0396e559620a5b6b18fef Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 30 Mar 2024 16:14:58 +0000 Subject: [PATCH] fix(api): add experimental flag --- .changeset/strange-colts-smell.md | 5 + .github/workflows/ci.yml | 3 + src/index.ts | 2 + src/openApi/__tests__/index.spec.ts | 2 + .../v2/parser/__tests__/getServices.spec.ts | 2 + .../v3/parser/__tests__/getServices.spec.ts | 2 + src/templates/partials/dataDestructure.hbs | 9 + src/types/config.ts | 5 + src/utils/__tests__/handlebars.spec.ts | 4 + src/utils/handlebars.ts | 51 +- src/utils/write/__tests__/class.spec.ts | 2 + src/utils/write/__tests__/client.spec.ts | 2 + src/utils/write/__tests__/core.spec.ts | 6 + src/utils/write/__tests__/index.spec.ts | 2 + src/utils/write/__tests__/models.spec.ts | 2 + src/utils/write/__tests__/schemas.spec.ts | 2 + src/utils/write/__tests__/services.spec.ts | 2 + .../v3_experimental/core/ApiError.ts.snap | 21 + .../core/ApiRequestOptions.ts.snap | 13 + .../v3_experimental/core/ApiResult.ts.snap | 7 + .../core/CancelablePromise.ts.snap | 126 ++ .../v3_experimental/core/OpenAPI.ts.snap | 53 + .../v3_experimental/core/request.ts.snap | 345 ++++ .../v3_experimental/core/types.ts.snap | 10 + .../v3_experimental/index.ts.snap | 8 + .../v3_experimental/models.ts.snap | 705 ++++++++ .../v3_experimental/schemas.ts.snap | 1427 +++++++++++++++++ .../services/CollectionFormatService.ts.snap | 44 + .../services/ComplexService.ts.snap | 77 + .../services/DefaultService.ts.snap | 38 + .../services/DefaultsService.ts.snap | 154 ++ .../services/DeprecatedService.ts.snap | 28 + .../services/DescriptionsService.ts.snap | 51 + .../services/DuplicateService.ts.snap | 45 + .../services/ErrorService.ts.snap | 35 + .../services/FileResponseService.ts.snap | 24 + .../services/FormDataService.ts.snap | 36 + .../services/HeaderService.ts.snap | 21 + .../services/MultipartService.ts.snap | 45 + .../services/MultipleTags1Service.ts.snap | 27 + .../services/MultipleTags2Service.ts.snap | 27 + .../services/MultipleTags3Service.ts.snap | 16 + .../services/NoContentService.ts.snap | 28 + ...66\303\264\303\252\303\212Service.ts.snap" | 32 + .../services/ParametersService.ts.snap | 210 +++ .../services/RequestBodyService.ts.snap | 36 + .../services/ResponseService.ts.snap | 73 + .../services/SimpleService.ts.snap | 75 + .../services/TypesService.ts.snap | 66 + .../services/UploadService.ts.snap | 27 + .../v3_experimental/services/index.ts.snap | 23 + test/__snapshots__/v3_models/index.ts.snap | 1 + test/__snapshots__/v3_models/models.ts.snap | 705 ++++++++ test/index.spec.ts | 19 + 54 files changed, 4779 insertions(+), 2 deletions(-) create mode 100644 .changeset/strange-colts-smell.md create mode 100644 test/__snapshots__/v3_experimental/core/ApiError.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/ApiRequestOptions.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/ApiResult.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/CancelablePromise.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/OpenAPI.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/request.ts.snap create mode 100644 test/__snapshots__/v3_experimental/core/types.ts.snap create mode 100644 test/__snapshots__/v3_experimental/index.ts.snap create mode 100644 test/__snapshots__/v3_experimental/models.ts.snap create mode 100644 test/__snapshots__/v3_experimental/schemas.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/CollectionFormatService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/ComplexService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/DefaultService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/DefaultsService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/DeprecatedService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/DescriptionsService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/DuplicateService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/ErrorService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/FileResponseService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/FormDataService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/HeaderService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/MultipartService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/MultipleTags1Service.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/MultipleTags2Service.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/MultipleTags3Service.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/NoContentService.ts.snap create mode 100644 "test/__snapshots__/v3_experimental/services/NonAscii\303\206\303\270\303\245\303\206\303\270\303\205\303\266\303\264\303\252\303\212Service.ts.snap" create mode 100644 test/__snapshots__/v3_experimental/services/ParametersService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/RequestBodyService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/ResponseService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/SimpleService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/TypesService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/UploadService.ts.snap create mode 100644 test/__snapshots__/v3_experimental/services/index.ts.snap create mode 100644 test/__snapshots__/v3_models/index.ts.snap create mode 100644 test/__snapshots__/v3_models/models.ts.snap diff --git a/.changeset/strange-colts-smell.md b/.changeset/strange-colts-smell.md new file mode 100644 index 000000000..090bb51b8 --- /dev/null +++ b/.changeset/strange-colts-smell.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix(api): add experimental flag diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5713f98e2..0c8172ea4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,9 @@ jobs: - name: Run linter run: npm run lint + - name: Run type check + run: npm run typecheck + - name: Run unit tests run: npm run test diff --git a/src/index.ts b/src/index.ts index 57d83d758..a607824a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -100,6 +100,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => base, debug = false, enums = false, + experimental = false, exportCore = true, exportModels = true, exportSchemas = true, @@ -148,6 +149,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => client, debug, enums, + experimental, exportCore, exportModels, exportSchemas, diff --git a/src/openApi/__tests__/index.spec.ts b/src/openApi/__tests__/index.spec.ts index 464e89ab8..e3c1abceb 100644 --- a/src/openApi/__tests__/index.spec.ts +++ b/src/openApi/__tests__/index.spec.ts @@ -11,7 +11,9 @@ describe('parse', () => { const options: Parameters[1] = { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/openApi/v2/parser/__tests__/getServices.spec.ts b/src/openApi/v2/parser/__tests__/getServices.spec.ts index 842d4b865..9804d7aae 100644 --- a/src/openApi/v2/parser/__tests__/getServices.spec.ts +++ b/src/openApi/v2/parser/__tests__/getServices.spec.ts @@ -6,7 +6,9 @@ describe('getServices', () => { it('should create a unnamed service if tags are empty', () => { const options: Parameters[1] = { client: 'fetch', + debug: false, enums: false, + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/openApi/v3/parser/__tests__/getServices.spec.ts b/src/openApi/v3/parser/__tests__/getServices.spec.ts index 32d02dd7f..79d21cce1 100644 --- a/src/openApi/v3/parser/__tests__/getServices.spec.ts +++ b/src/openApi/v3/parser/__tests__/getServices.spec.ts @@ -6,7 +6,9 @@ describe('getServices', () => { it('should create a unnamed service if tags are empty', () => { const options: Parameters[1] = { client: 'fetch', + debug: false, enums: false, + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/templates/partials/dataDestructure.hbs b/src/templates/partials/dataDestructure.hbs index e99bed7e9..9b88a43b6 100644 --- a/src/templates/partials/dataDestructure.hbs +++ b/src/templates/partials/dataDestructure.hbs @@ -13,8 +13,17 @@ const { {{~#notEquals @root.$config.serviceResponse 'generics'~}} {{~#if parameters~}} const { +{{#if @root.$config.experimental}} +query, +{{/if}} {{#each parameters}} +{{#if @root.$config.experimental}} +{{#notEquals in 'query'}} {{{name}}}{{#if default}} = {{{default}}}{{/if}}, +{{/notEquals}} +{{else}} +{{{name}}}{{#if default}} = {{{default}}}{{/if}}, +{{/if}} {{/each}} } = data; {{/if}} diff --git a/src/types/config.ts b/src/types/config.ts index ac8704409..ea27c5cee 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -18,6 +18,11 @@ export interface UserConfig { * @default false */ enums?: 'javascript' | 'typescript' | false; + /** + * Generate an experimental build? + * @default false + */ + experimental?: boolean; /** * Generate core client classes? * @default true diff --git a/src/utils/__tests__/handlebars.spec.ts b/src/utils/__tests__/handlebars.spec.ts index 55447ee8c..ded814bb2 100644 --- a/src/utils/__tests__/handlebars.spec.ts +++ b/src/utils/__tests__/handlebars.spec.ts @@ -8,7 +8,9 @@ describe('registerHandlebarHelpers', () => { registerHandlebarHelpers( { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, @@ -60,7 +62,9 @@ describe('registerHandlebarTemplates', () => { const templates = registerHandlebarTemplates( { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/handlebars.ts b/src/utils/handlebars.ts index c70a6b237..705de269c 100644 --- a/src/utils/handlebars.ts +++ b/src/utils/handlebars.ts @@ -101,7 +101,24 @@ const modelImports = (model: Service, path: string) => { return `import type { ${model.imports.join(',')} } from '${path}';`; }; -const dataParameters = (parameters: OperationParameter[]) => { +const dataParameters = (config: Config, parameters: OperationParameter[]) => { + if (config.experimental) { + let output = parameters + .filter(parameter => parameter.default !== undefined) + .map(parameter => { + const key = parameter.prop; + const value = parameter.name; + if (key === value || escapeName(key) === key) { + return `${key}: ${parameter.default}`; + } + return `'${key}': ${parameter.default}`; + }); + if (parameters.every(parameter => parameter.in === 'query')) { + output = [...output, '...query']; + } + return output.join(', '); + } + const output = parameters.map(parameter => { const key = parameter.prop; const value = parameter.name; @@ -132,6 +149,12 @@ const operationDataType = (config: Config, service: Service) => { const name = nameOperationDataType(operation.name); return `export type ${name} = { ${sortByName(operation.parameters) + .filter(parameter => { + if (!config.experimental) { + return true; + } + return parameter.in !== 'query'; + }) .map(parameter => { let comment: string[] = []; if (parameter.description) { @@ -143,6 +166,26 @@ const operationDataType = (config: Config, service: Service) => { ].join('\n'); }) .join('\n')} + ${ + config.experimental + ? ` + query${operation.parametersQuery.every(parameter => !parameter.isRequired) ? '?' : ''}: { + ${sortByName(operation.parametersQuery) + .map(parameter => { + let comment: string[] = []; + if (parameter.description) { + comment = ['/**', ` * ${escapeComment(parameter.description)}`, ' */']; + } + return [ + ...comment, + `${parameter.name + isRequired(parameter)}: ${partialType({ $config: config, ...parameter })}`, + ].join('\n'); + }) + .join('\n')} + } + ` + : '' + } }`; }); return output.join('\n'); @@ -151,7 +194,11 @@ const operationDataType = (config: Config, service: Service) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars export const registerHandlebarHelpers = (config: Config, client: Client): void => { Handlebars.registerHelper('camelCase', camelCase); - Handlebars.registerHelper('dataParameters', dataParameters); + + Handlebars.registerHelper('dataParameters', function (parameters: OperationParameter[]) { + return dataParameters(config, parameters); + }); + Handlebars.registerHelper('enumKey', enumKey); Handlebars.registerHelper('enumName', enumName); Handlebars.registerHelper('enumUnionType', enumUnionType); diff --git a/src/utils/write/__tests__/class.spec.ts b/src/utils/write/__tests__/class.spec.ts index 10b8ab45c..ded911509 100644 --- a/src/utils/write/__tests__/class.spec.ts +++ b/src/utils/write/__tests__/class.spec.ts @@ -18,7 +18,9 @@ describe('writeClientClass', () => { await writeClientClass(client, mockTemplates, './dist', { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/client.spec.ts b/src/utils/write/__tests__/client.spec.ts index cc6cce263..3855450dd 100644 --- a/src/utils/write/__tests__/client.spec.ts +++ b/src/utils/write/__tests__/client.spec.ts @@ -18,7 +18,9 @@ describe('writeClient', () => { await writeClient(client, mockTemplates, { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/core.spec.ts b/src/utils/write/__tests__/core.spec.ts index 42c463c8e..5bf4bdc90 100644 --- a/src/utils/write/__tests__/core.spec.ts +++ b/src/utils/write/__tests__/core.spec.ts @@ -24,7 +24,9 @@ describe('writeClientCore', () => { const config: Parameters[3] = { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, @@ -64,7 +66,9 @@ describe('writeClientCore', () => { const config: Parameters[3] = { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, @@ -104,7 +108,9 @@ describe('writeClientCore', () => { const config: Parameters[3] = { base: 'foo', client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/index.spec.ts b/src/utils/write/__tests__/index.spec.ts index aa100281d..73095ddd9 100644 --- a/src/utils/write/__tests__/index.spec.ts +++ b/src/utils/write/__tests__/index.spec.ts @@ -19,7 +19,9 @@ describe('writeClientIndex', () => { await writeClientIndex(client, mockTemplates, '/', { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/models.spec.ts b/src/utils/write/__tests__/models.spec.ts index 0981507e3..c8178b70f 100644 --- a/src/utils/write/__tests__/models.spec.ts +++ b/src/utils/write/__tests__/models.spec.ts @@ -38,7 +38,9 @@ describe('writeClientModels', () => { await writeClientModels(client, mockTemplates, '/', { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/schemas.spec.ts b/src/utils/write/__tests__/schemas.spec.ts index 9d07bdda0..10af99f79 100644 --- a/src/utils/write/__tests__/schemas.spec.ts +++ b/src/utils/write/__tests__/schemas.spec.ts @@ -38,7 +38,9 @@ describe('writeClientSchemas', () => { await writeClientSchemas(client, mockTemplates, '/', { client: 'fetch', + debug: false, enums: 'javascript', + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/src/utils/write/__tests__/services.spec.ts b/src/utils/write/__tests__/services.spec.ts index cc3aae1a0..e5e9a4fc9 100644 --- a/src/utils/write/__tests__/services.spec.ts +++ b/src/utils/write/__tests__/services.spec.ts @@ -26,7 +26,9 @@ describe('writeClientServices', () => { await writeClientServices(client, mockTemplates, '/', { client: 'fetch', + debug: false, enums: false, + experimental: false, exportCore: true, exportModels: true, exportSchemas: true, diff --git a/test/__snapshots__/v3_experimental/core/ApiError.ts.snap b/test/__snapshots__/v3_experimental/core/ApiError.ts.snap new file mode 100644 index 000000000..2c11b4136 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/ApiError.ts.snap @@ -0,0 +1,21 @@ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; + +export class ApiError extends Error { + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; + + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); + + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} diff --git a/test/__snapshots__/v3_experimental/core/ApiRequestOptions.ts.snap b/test/__snapshots__/v3_experimental/core/ApiRequestOptions.ts.snap new file mode 100644 index 000000000..e93003ee7 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/ApiRequestOptions.ts.snap @@ -0,0 +1,13 @@ +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; diff --git a/test/__snapshots__/v3_experimental/core/ApiResult.ts.snap b/test/__snapshots__/v3_experimental/core/ApiResult.ts.snap new file mode 100644 index 000000000..caa79c2ea --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/ApiResult.ts.snap @@ -0,0 +1,7 @@ +export type ApiResult = { + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; diff --git a/test/__snapshots__/v3_experimental/core/CancelablePromise.ts.snap b/test/__snapshots__/v3_experimental/core/CancelablePromise.ts.snap new file mode 100644 index 000000000..e6b03b6a2 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/CancelablePromise.ts.snap @@ -0,0 +1,126 @@ +export class CancelError extends Error { + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } +} + +export interface OnCancel { + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; + + (cancelHandler: () => void): void; +} + +export class CancelablePromise implements Promise { + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return 'Cancellable Promise'; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} diff --git a/test/__snapshots__/v3_experimental/core/OpenAPI.ts.snap b/test/__snapshots__/v3_experimental/core/OpenAPI.ts.snap new file mode 100644 index 000000000..dcee84803 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/OpenAPI.ts.snap @@ -0,0 +1,53 @@ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { TResult } from './types'; + +type Headers = Record; +type Middleware = (value: T) => T | Promise; +type Resolver = (options: ApiRequestOptions) => Promise; + +export class Interceptors { + _fns: Middleware[]; + + constructor() { + this._fns = []; + } + + eject(fn: Middleware) { + const index = this._fns.indexOf(fn); + if (index !== -1) { + this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; + } + } + + use(fn: Middleware) { + this._fns = [...this._fns, fn]; + } +} + +export type OpenAPIConfig = { + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + RESULT?: TResult; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { request: Interceptors; response: Interceptors }; +}; + +export const OpenAPI: OpenAPIConfig = { + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + RESULT: 'body', + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { request: new Interceptors(), response: new Interceptors() }, +}; diff --git a/test/__snapshots__/v3_experimental/core/request.ts.snap b/test/__snapshots__/v3_experimental/core/request.ts.snap new file mode 100644 index 000000000..b7e9802f1 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/request.ts.snap @@ -0,0 +1,345 @@ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import { CancelablePromise } from './CancelablePromise'; +import type { OnCancel } from './CancelablePromise'; +import type { OpenAPIConfig } from './OpenAPI'; + +export const isString = (value: unknown): value is string => { + return typeof value === 'string'; +}; + +export const isStringWithValue = (value: unknown): value is string => { + return isString(value) && value !== ''; +}; + +export const isBlob = (value: any): value is Blob => { + return value instanceof Blob; +}; + +export const isFormData = (value: unknown): value is FormData => { + return value instanceof FormData; +}; + +export const base64 = (str: string): string => { + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } +}; + +export const getQueryString = (params: Record): string => { + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; +}; + +const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; +}; + +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; +}; + +type Resolver = (options: ApiRequestOptions) => Promise; + +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; +}; + +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce( + (headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), + {} as Record + ); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); +}; + +export const getRequestBody = (options: ApiRequestOptions): unknown => { + if (options.body !== undefined) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; +}; + +export const sendRequest = async ( + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel +): Promise => { + const controller = new AbortController(); + + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; + + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } + + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } + + onCancel(() => controller.abort()); + + return await fetch(url, request); +}; + +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; +}; + +export const getResponseBody = async (response: Response): Promise => { + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const jsonTypes = ['application/json', 'application/problem+json']; + const binaryTypes = ['audio/', 'image/', 'video/']; + const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type)); + if (isJSON) { + return await response.json(); + } else if (isBinary) { + return await response.blob(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; +}; + +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + }; + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError( + options, + result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } +}; + +/** + * Request method + * @param config The OpenAPI configuration object + * @param options The request options from the service + * @returns CancelablePromise + * @throws ApiError + */ +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; diff --git a/test/__snapshots__/v3_experimental/core/types.ts.snap b/test/__snapshots__/v3_experimental/core/types.ts.snap new file mode 100644 index 000000000..e33a5d996 --- /dev/null +++ b/test/__snapshots__/v3_experimental/core/types.ts.snap @@ -0,0 +1,10 @@ +import type { ApiResult } from './ApiResult'; + +export type TResult = 'body' | 'raw'; + +export type TApiResponse = + Exclude extends never ? ApiResult : ApiResult['body']; + +export type TConfig = { + _result?: T; +}; diff --git a/test/__snapshots__/v3_experimental/index.ts.snap b/test/__snapshots__/v3_experimental/index.ts.snap new file mode 100644 index 000000000..2c5a14f44 --- /dev/null +++ b/test/__snapshots__/v3_experimental/index.ts.snap @@ -0,0 +1,8 @@ +export { ApiError } from './core/ApiError'; +export { CancelablePromise, CancelError } from './core/CancelablePromise'; +export { OpenAPI } from './core/OpenAPI'; +export type { OpenAPIConfig } from './core/OpenAPI'; + +export * from './models'; +export * from './schemas'; +export * from './services'; diff --git a/test/__snapshots__/v3_experimental/models.ts.snap b/test/__snapshots__/v3_experimental/models.ts.snap new file mode 100644 index 000000000..ad411322f --- /dev/null +++ b/test/__snapshots__/v3_experimental/models.ts.snap @@ -0,0 +1,705 @@ +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = + | 'Success' + | 'Warning' + | 'Error' + | "'Single Quote'" + | '"Double Quotes"' + | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array< + | { + foo?: string; + } + | { + bar?: string; + } +>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array< + | { + foo?: string; + } + | { + bar?: string; + } + >; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = Record; + +/** + * This is a string reference + */ +export type DictionaryWithReference = Record; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = Record>; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = Record>; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = Record< + string, + { + foo?: string; + bar?: string; + } +>; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: Record; + dictionaryWithEnumFromDescription?: Record; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: Record; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: + | { + propA?: string; + } + | string + | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: 'circle'; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: 'square'; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: + | { + propA?: string; + } + | string + | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type Enum1 = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: + | { + boolean?: boolean; + } + | ModelWithEnum + | ModelWithArray + | ModelWithDictionary + | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | Record; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | Record>; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | Record>; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: + | ({ + boolean?: boolean; + } & ModelWithEnum & + ModelWithArray & + ModelWithDictionary) + | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: + | { + boolean?: boolean; + } + | ModelWithEnum + | ModelWithArray + | ModelWithDictionary + | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + firstName: string; + lastname: string; + age: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & + ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; + }; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = Record; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = + | { + foo: SimpleParameter; + baz: number | null; + qux: number; + } + | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; + }; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = + | { + foo: 'Bar'; + } + | { + foo: 'Baz'; + } + | { + foo: 'Qux'; + } + | { + content: string; + foo: 'Quux'; + } + | { + content: [string, string]; + foo: 'Corge'; + }; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; diff --git a/test/__snapshots__/v3_experimental/schemas.ts.snap b/test/__snapshots__/v3_experimental/schemas.ts.snap new file mode 100644 index 000000000..9876643a6 --- /dev/null +++ b/test/__snapshots__/v3_experimental/schemas.ts.snap @@ -0,0 +1,1427 @@ +export const $CommentWithBreaks = { + type: 'number', + description: `Testing multiline comments in string: First line +Second line + +Fourth line`, +} as const; + +export const $CommentWithBackticks = { + type: 'number', + description: `Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work`, +} as const; + +export const $CommentWithSlashes = { + type: 'number', + description: `Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work`, +} as const; + +export const $CommentWithExpressionPlaceholders = { + type: 'number', + description: `Testing expression placeholders in string: \${expression} should work`, +} as const; + +export const $CommentWithQuotes = { + type: 'number', + description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, +} as const; + +export const $CommentWithReservedCharacters = { + type: 'number', + description: `Testing reserved characters in string: /* inline */ and /** inline **/ should work`, +} as const; + +export const $SimpleInteger = { + type: 'number', + description: `This is a simple number`, +} as const; + +export const $SimpleBoolean = { + type: 'boolean', + description: `This is a simple boolean`, +} as const; + +export const $SimpleString = { + type: 'string', + description: `This is a simple string`, +} as const; + +export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { + type: 'string', + description: `A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)`, +} as const; + +export const $SimpleFile = { + type: 'binary', + description: `This is a simple file`, +} as const; + +export const $SimpleReference = { + type: 'ModelWithString', + description: `This is a simple reference`, +} as const; + +export const $SimpleStringWithPattern = { + type: 'string', + description: `This is a simple string`, + isNullable: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', +} as const; + +export const $EnumWithStrings = { + type: 'Enum', +} as const; + +export const $EnumWithReplacedCharacters = { + type: 'Enum', +} as const; + +export const $EnumWithNumbers = { + type: 'Enum', +} as const; + +export const $EnumFromDescription = { + type: 'number', + description: `Success=1,Warning=2,Error=3`, +} as const; + +export const $EnumWithExtensions = { + type: 'Enum', +} as const; + +export const $ArrayWithNumbers = { + type: 'array', + contains: { + type: 'number', + }, +} as const; + +export const $ArrayWithBooleans = { + type: 'array', + contains: { + type: 'boolean', + }, +} as const; + +export const $ArrayWithStrings = { + type: 'array', + contains: { + type: 'string', + }, +} as const; + +export const $ArrayWithReferences = { + type: 'array', + contains: { + type: 'ModelWithString', + }, +} as const; + +export const $ArrayWithArray = { + type: 'array', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, +} as const; + +export const $ArrayWithProperties = { + type: 'array', + contains: { + properties: { + foo: { + type: 'string', + }, + bar: { + type: 'string', + }, + }, + }, +} as const; + +export const $ArrayWithAnyOfProperties = { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + properties: { + foo: { + type: 'string', + }, + }, + }, + { + properties: { + bar: { + type: 'string', + }, + }, + }, + ], + }, +} as const; + +export const $AnyOfAnyAndNull = { + properties: { + data: { + type: 'any-of', + contains: [ + { + properties: {}, + }, + { + type: 'null', + }, + ], + }, + }, +} as const; + +export const $AnyOfArrays = { + description: `This is a simple array with any of properties`, + properties: { + results: { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + properties: { + foo: { + type: 'string', + }, + }, + }, + { + properties: { + bar: { + type: 'string', + }, + }, + }, + ], + }, + }, + }, +} as const; + +export const $DictionaryWithString = { + type: 'dictionary', + contains: { + type: 'string', + }, +} as const; + +export const $DictionaryWithReference = { + type: 'dictionary', + contains: { + type: 'ModelWithString', + }, +} as const; + +export const $DictionaryWithArray = { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, +} as const; + +export const $DictionaryWithDictionary = { + type: 'dictionary', + contains: { + type: 'dictionary', + contains: { + type: 'string', + }, + }, +} as const; + +export const $DictionaryWithProperties = { + type: 'dictionary', + contains: { + properties: { + foo: { + type: 'string', + }, + bar: { + type: 'string', + }, + }, + }, +} as const; + +export const $ModelWithInteger = { + description: `This is a model with one number property`, + properties: { + prop: { + type: 'number', + description: `This is a simple number property`, + }, + }, +} as const; + +export const $ModelWithBoolean = { + description: `This is a model with one boolean property`, + properties: { + prop: { + type: 'boolean', + description: `This is a simple boolean property`, + }, + }, +} as const; + +export const $ModelWithString = { + description: `This is a model with one string property`, + properties: { + prop: { + type: 'string', + description: `This is a simple string property`, + }, + }, +} as const; + +export const $ModelWithNullableString = { + description: `This is a model with one string property`, + properties: { + nullableProp1: { + type: 'string', + description: `This is a simple string property`, + isNullable: true, + }, + nullableRequiredProp1: { + type: 'string', + description: `This is a simple string property`, + isRequired: true, + isNullable: true, + }, + nullableProp2: { + type: 'string', + description: `This is a simple string property`, + isNullable: true, + }, + nullableRequiredProp2: { + type: 'string', + description: `This is a simple string property`, + isRequired: true, + isNullable: true, + }, + }, +} as const; + +export const $ModelWithEnum = { + description: `This is a model with one enum`, + properties: { + test: { + type: 'Enum', + }, + statusCode: { + type: 'Enum', + }, + bool: { + type: 'boolean', + description: `Simple boolean enum`, + }, + }, +} as const; + +export const $ModelWithEnumWithHyphen = { + description: `This is a model with one enum with escaped name`, + properties: { + 'foo-bar-baz-qux': { + type: 'Enum', + }, + }, +} as const; + +export const $ModelWithEnumFromDescription = { + description: `This is a model with one enum`, + properties: { + test: { + type: 'number', + description: `Success=1,Warning=2,Error=3`, + }, + }, +} as const; + +export const $ModelWithNestedEnums = { + description: `This is a model with nested enums`, + properties: { + dictionaryWithEnum: { + type: 'dictionary', + contains: { + type: 'Enum', + }, + }, + dictionaryWithEnumFromDescription: { + type: 'dictionary', + contains: { + type: 'number', + description: `Success=1,Warning=2,Error=3`, + }, + }, + arrayWithEnum: { + type: 'array', + contains: { + type: 'Enum', + }, + }, + arrayWithDescription: { + type: 'array', + contains: { + type: 'number', + description: `Success=1,Warning=2,Error=3`, + }, + }, + }, +} as const; + +export const $ModelWithReference = { + description: `This is a model with one property containing a reference`, + properties: { + prop: { + type: 'ModelWithProperties', + }, + }, +} as const; + +export const $ModelWithArrayReadOnlyAndWriteOnly = { + description: `This is a model with one property containing an array`, + properties: { + prop: { + type: 'array', + contains: { + type: 'ModelWithReadOnlyAndWriteOnly', + }, + }, + propWithFile: { + type: 'array', + contains: { + type: 'binary', + }, + }, + propWithNumber: { + type: 'array', + contains: { + type: 'number', + }, + }, + }, +} as const; + +export const $ModelWithArray = { + description: `This is a model with one property containing an array`, + properties: { + prop: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, + propWithFile: { + type: 'array', + contains: { + type: 'binary', + }, + }, + propWithNumber: { + type: 'array', + contains: { + type: 'number', + }, + }, + }, +} as const; + +export const $ModelWithDictionary = { + description: `This is a model with one property containing a dictionary`, + properties: { + prop: { + type: 'dictionary', + contains: { + type: 'string', + }, + }, + }, +} as const; + +export const $DeprecatedModel = { + description: `This is a deprecated model with a deprecated property`, + properties: { + prop: { + type: 'string', + description: `This is a deprecated property`, + }, + }, +} as const; + +export const $ModelWithCircularReference = { + description: `This is a model with one property containing a circular reference`, + properties: { + prop: { + type: 'ModelWithCircularReference', + }, + }, +} as const; + +export const $CompositionWithOneOf = { + description: `This is a model with one property with a 'one of' relationship`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + type: 'ModelWithString', + }, + { + type: 'ModelWithEnum', + }, + { + type: 'ModelWithArray', + }, + { + type: 'ModelWithDictionary', + }, + ], + }, + }, +} as const; + +export const $CompositionWithOneOfAnonymous = { + description: `This is a model with one property with a 'one of' relationship where the options are not $ref`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + description: `Anonymous object type`, + properties: { + propA: { + type: 'string', + }, + }, + }, + { + type: 'string', + description: `Anonymous string type`, + }, + { + type: 'number', + description: `Anonymous integer type`, + }, + ], + }, + }, +} as const; + +export const $ModelCircle = { + description: `Circle`, + properties: { + kind: { + type: 'string', + isRequired: true, + }, + radius: { + type: 'number', + }, + }, +} as const; + +export const $ModelSquare = { + description: `Square`, + properties: { + kind: { + type: 'string', + isRequired: true, + }, + sideLength: { + type: 'number', + }, + }, +} as const; + +export const $CompositionWithOneOfDiscriminator = { + type: 'one-of', + description: `This is a model with one property with a 'one of' relationship where the options are not $ref`, + contains: [ + { + type: 'ModelCircle', + }, + { + type: 'ModelSquare', + }, + ], +} as const; + +export const $CompositionWithAnyOf = { + description: `This is a model with one property with a 'any of' relationship`, + properties: { + propA: { + type: 'any-of', + contains: [ + { + type: 'ModelWithString', + }, + { + type: 'ModelWithEnum', + }, + { + type: 'ModelWithArray', + }, + { + type: 'ModelWithDictionary', + }, + ], + }, + }, +} as const; + +export const $CompositionWithAnyOfAnonymous = { + description: `This is a model with one property with a 'any of' relationship where the options are not $ref`, + properties: { + propA: { + type: 'any-of', + contains: [ + { + description: `Anonymous object type`, + properties: { + propA: { + type: 'string', + }, + }, + }, + { + type: 'string', + description: `Anonymous string type`, + }, + { + type: 'number', + description: `Anonymous integer type`, + }, + ], + }, + }, +} as const; + +export const $CompositionWithNestedAnyAndTypeNull = { + description: `This is a model with nested 'any of' property with a type null`, + properties: { + propA: { + type: 'any-of', + contains: [ + { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + type: 'ModelWithDictionary', + }, + { + type: 'null', + }, + ], + }, + }, + { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + type: 'ModelWithArray', + }, + { + type: 'null', + }, + ], + }, + }, + ], + }, + }, +} as const; + +export const $Enum1 = { + type: 'Enum', +} as const; + +export const $ConstValue = { + type: '"ConstValue"', +} as const; + +export const $CompositionWithNestedAnyOfAndNull = { + description: `This is a model with one property with a 'any of' relationship where the options are not $ref`, + properties: { + propA: { + type: 'any-of', + contains: [ + { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + type: 'Enum1', + }, + { + type: 'ConstValue', + }, + ], + }, + }, + { + type: 'null', + }, + ], + }, + }, +} as const; + +export const $CompositionWithOneOfAndNullable = { + description: `This is a model with one property with a 'one of' relationship`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + properties: { + boolean: { + type: 'boolean', + }, + }, + }, + { + type: 'ModelWithEnum', + }, + { + type: 'ModelWithArray', + }, + { + type: 'ModelWithDictionary', + }, + ], + isNullable: true, + }, + }, +} as const; + +export const $CompositionWithOneOfAndSimpleDictionary = { + description: `This is a model that contains a simple dictionary within composition`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + type: 'boolean', + }, + { + type: 'dictionary', + contains: { + type: 'number', + }, + }, + ], + }, + }, +} as const; + +export const $CompositionWithOneOfAndSimpleArrayDictionary = { + description: `This is a model that contains a dictionary of simple arrays within composition`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + type: 'boolean', + }, + { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'boolean', + }, + }, + }, + ], + }, + }, +} as const; + +export const $CompositionWithOneOfAndComplexArrayDictionary = { + description: `This is a model that contains a dictionary of complex arrays (composited) within composition`, + properties: { + propA: { + type: 'one-of', + contains: [ + { + type: 'boolean', + }, + { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'one-of', + contains: [ + { + type: 'number', + }, + { + type: 'string', + }, + ], + }, + }, + }, + ], + }, + }, +} as const; + +export const $CompositionWithAllOfAndNullable = { + description: `This is a model with one property with a 'all of' relationship`, + properties: { + propA: { + type: 'all-of', + contains: [ + { + properties: { + boolean: { + type: 'boolean', + }, + }, + }, + { + type: 'ModelWithEnum', + }, + { + type: 'ModelWithArray', + }, + { + type: 'ModelWithDictionary', + }, + ], + isNullable: true, + }, + }, +} as const; + +export const $CompositionWithAnyOfAndNullable = { + description: `This is a model with one property with a 'any of' relationship`, + properties: { + propA: { + type: 'any-of', + contains: [ + { + properties: { + boolean: { + type: 'boolean', + }, + }, + }, + { + type: 'ModelWithEnum', + }, + { + type: 'ModelWithArray', + }, + { + type: 'ModelWithDictionary', + }, + ], + isNullable: true, + }, + }, +} as const; + +export const $CompositionBaseModel = { + description: `This is a base model with two simple optional properties`, + properties: { + firstName: { + type: 'string', + }, + lastname: { + type: 'string', + }, + }, +} as const; + +export const $CompositionExtendedModel = { + type: 'all-of', + description: `This is a model that extends the base model`, + contains: [ + { + type: 'CompositionBaseModel', + }, + { + properties: { + firstName: { + type: 'string', + isRequired: true, + }, + lastname: { + type: 'string', + isRequired: true, + }, + age: { + type: 'number', + isRequired: true, + }, + }, + }, + ], +} as const; + +export const $ModelWithProperties = { + description: `This is a model with one nested property`, + properties: { + required: { + type: 'string', + isRequired: true, + }, + requiredAndReadOnly: { + type: 'string', + isReadOnly: true, + isRequired: true, + }, + requiredAndNullable: { + type: 'string', + isRequired: true, + isNullable: true, + }, + string: { + type: 'string', + }, + number: { + type: 'number', + }, + boolean: { + type: 'boolean', + }, + reference: { + type: 'ModelWithString', + }, + 'property with space': { + type: 'string', + }, + default: { + type: 'string', + }, + try: { + type: 'string', + }, + '@namespace.string': { + type: 'string', + isReadOnly: true, + }, + '@namespace.integer': { + type: 'number', + isReadOnly: true, + }, + }, +} as const; + +export const $ModelWithNestedProperties = { + description: `This is a model with one nested property`, + properties: { + first: { + properties: { + second: { + properties: { + third: { + type: 'string', + isReadOnly: true, + isRequired: true, + isNullable: true, + }, + }, + isReadOnly: true, + isRequired: true, + isNullable: true, + }, + }, + isReadOnly: true, + isRequired: true, + isNullable: true, + }, + }, +} as const; + +export const $ModelWithDuplicateProperties = { + description: `This is a model with duplicated properties`, + properties: { + prop: { + type: 'ModelWithString', + }, + }, +} as const; + +export const $ModelWithOrderedProperties = { + description: `This is a model with ordered properties`, + properties: { + zebra: { + type: 'string', + }, + apple: { + type: 'string', + }, + hawaii: { + type: 'string', + }, + }, +} as const; + +export const $ModelWithDuplicateImports = { + description: `This is a model with duplicated imports`, + properties: { + propA: { + type: 'ModelWithString', + }, + propB: { + type: 'ModelWithString', + }, + propC: { + type: 'ModelWithString', + }, + }, +} as const; + +export const $ModelThatExtends = { + type: 'all-of', + description: `This is a model that extends another model`, + contains: [ + { + type: 'ModelWithString', + }, + { + properties: { + propExtendsA: { + type: 'string', + }, + propExtendsB: { + type: 'ModelWithString', + }, + }, + }, + ], +} as const; + +export const $ModelThatExtendsExtends = { + type: 'all-of', + description: `This is a model that extends another model`, + contains: [ + { + type: 'ModelWithString', + }, + { + type: 'ModelThatExtends', + }, + { + properties: { + propExtendsC: { + type: 'string', + }, + propExtendsD: { + type: 'ModelWithString', + }, + }, + }, + ], +} as const; + +export const $ModelWithPattern = { + description: `This is a model that contains a some patterns`, + properties: { + key: { + type: 'string', + isRequired: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', + }, + name: { + type: 'string', + isRequired: true, + maxLength: 255, + }, + enabled: { + type: 'boolean', + isReadOnly: true, + }, + modified: { + type: 'string', + isReadOnly: true, + format: 'date-time', + }, + id: { + type: 'string', + pattern: '^\\d{2}-\\d{3}-\\d{4}$', + }, + text: { + type: 'string', + pattern: '^\\w+$', + }, + patternWithSingleQuotes: { + type: 'string', + pattern: "^[a-zA-Z0-9']*$", + }, + patternWithNewline: { + type: 'string', + pattern: 'aaa\nbbb', + }, + patternWithBacktick: { + type: 'string', + pattern: 'aaa`bbb', + }, + }, +} as const; + +export const $File = { + properties: { + id: { + type: 'string', + isReadOnly: true, + minLength: 1, + }, + updated_at: { + type: 'string', + isReadOnly: true, + format: 'date-time', + }, + created_at: { + type: 'string', + isReadOnly: true, + format: 'date-time', + }, + mime: { + type: 'string', + isRequired: true, + maxLength: 24, + minLength: 1, + }, + file: { + type: 'string', + isReadOnly: true, + format: 'uri', + }, + }, +} as const; + +export const $_default = { + properties: { + name: { + type: 'string', + }, + }, +} as const; + +export const $Pageable = { + properties: { + page: { + type: 'number', + format: 'int32', + }, + size: { + type: 'number', + format: 'int32', + minimum: 1, + }, + sort: { + type: 'array', + contains: { + type: 'string', + }, + }, + }, +} as const; + +export const $FreeFormObjectWithoutAdditionalProperties = { + type: 'dictionary', + contains: { + properties: {}, + }, +} as const; + +export const $FreeFormObjectWithAdditionalPropertiesEqTrue = { + type: 'dictionary', + contains: { + properties: {}, + }, +} as const; + +export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + type: 'dictionary', + contains: { + properties: {}, + }, +} as const; + +export const $ModelWithConst = { + properties: { + String: { + type: '"String"', + }, + number: { + type: '0', + }, + null: { + type: 'null', + }, + withType: { + type: '"Some string"', + }, + }, +} as const; + +export const $ModelWithAdditionalPropertiesEqTrue = { + description: `This is a model with one property and additionalProperties: true`, + properties: { + prop: { + type: 'string', + description: `This is a simple string property`, + }, + }, +} as const; + +export const $NestedAnyOfArraysNullable = { + properties: { + nullableArray: { + type: 'any-of', + contains: [ + { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + type: 'string', + }, + { + type: 'boolean', + }, + ], + }, + }, + { + type: 'null', + }, + ], + }, + }, +} as const; + +export const $CompositionWithOneOfAndProperties = { + type: 'one-of', + contains: [ + { + properties: { + foo: { + type: 'SimpleParameter', + isRequired: true, + }, + baz: { + type: 'number', + isRequired: true, + isNullable: true, + format: 'uint16', + }, + qux: { + type: 'number', + isRequired: true, + format: 'uint8', + }, + }, + }, + { + properties: { + bar: { + type: 'NonAsciiStringæøåÆØÅöôêÊ字符串', + isRequired: true, + }, + baz: { + type: 'number', + isRequired: true, + isNullable: true, + format: 'uint16', + }, + qux: { + type: 'number', + isRequired: true, + format: 'uint8', + }, + }, + }, + ], +} as const; + +export const $NullableObject = { + description: `An object that can be null`, + properties: { + foo: { + type: 'string', + }, + }, + isNullable: true, +} as const; + +export const $ModelWithNullableObject = { + properties: { + data: { + type: 'NullableObject', + }, + }, +} as const; + +export const $ModelWithOneOfEnum = { + type: 'one-of', + contains: [ + { + properties: { + foo: { + type: 'Enum', + isRequired: true, + }, + }, + }, + { + properties: { + foo: { + type: 'Enum', + isRequired: true, + }, + }, + }, + { + properties: { + foo: { + type: 'Enum', + isRequired: true, + }, + }, + }, + { + properties: { + content: { + type: 'string', + isRequired: true, + format: 'date-time', + }, + foo: { + type: 'Enum', + isRequired: true, + }, + }, + }, + { + properties: { + content: { + type: 'array', + contains: { + type: 'any-of', + contains: [ + { + type: 'string', + format: 'date-time', + }, + { + type: 'string', + }, + ], + }, + isRequired: true, + }, + foo: { + type: 'Enum', + isRequired: true, + }, + }, + }, + ], +} as const; + +export const $ModelWithNestedArrayEnumsDataFoo = { + type: 'Enum', +} as const; + +export const $ModelWithNestedArrayEnumsDataBar = { + type: 'Enum', +} as const; + +export const $ModelWithNestedArrayEnumsData = { + properties: { + foo: { + type: 'array', + contains: { + type: 'ModelWithNestedArrayEnumsDataFoo', + }, + }, + bar: { + type: 'array', + contains: { + type: 'ModelWithNestedArrayEnumsDataBar', + }, + }, + }, +} as const; + +export const $ModelWithNestedArrayEnums = { + properties: { + array_strings: { + type: 'array', + contains: { + type: 'string', + }, + }, + data: { + type: 'all-of', + contains: [ + { + type: 'ModelWithNestedArrayEnumsData', + }, + ], + }, + }, +} as const; + +export const $ModelWithNestedCompositionEnums = { + properties: { + foo: { + type: 'all-of', + contains: [ + { + type: 'ModelWithNestedArrayEnumsDataFoo', + }, + ], + }, + }, +} as const; + +export const $ModelWithReadOnlyAndWriteOnly = { + properties: { + foo: { + type: 'string', + isRequired: true, + }, + bar: { + type: 'string', + isReadOnly: true, + isRequired: true, + }, + baz: { + type: 'string', + isRequired: true, + }, + }, +} as const; + +export const $SimpleParameter = { + type: 'string', + description: `This is a reusable parameter`, +} as const; diff --git a/test/__snapshots__/v3_experimental/services/CollectionFormatService.ts.snap b/test/__snapshots__/v3_experimental/services/CollectionFormatService.ts.snap new file mode 100644 index 000000000..7acbb053e --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/CollectionFormatService.ts.snap @@ -0,0 +1,44 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataCollectionFormat = { + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array | null; + }; +}; + +export class CollectionFormatService { + /** + * @throws ApiError + */ + public static collectionFormat(data: TDataCollectionFormat): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + ...query, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/ComplexService.ts.snap b/test/__snapshots__/v3_experimental/services/ComplexService.ts.snap new file mode 100644 index 000000000..1a7a11d44 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/ComplexService.ts.snap @@ -0,0 +1,77 @@ +import type { ModelWithArray, ModelWithDictionary, ModelWithEnum, ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataComplexTypes = { + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; +}; +export type TDataComplexParams = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + + query?: {}; +}; + +export class ComplexService { + /** + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static complexTypes(data: TDataComplexTypes): CancelablePromise> { + const { query } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + ...query, + }, + errors: { + 400: `400 server error`, + 500: `500 server error`, + }, + }); + } + + /** + * @returns ModelWithString Success + * @throws ApiError + */ + public static complexParams(data: TDataComplexParams): CancelablePromise { + const { query, id, requestBody } = data; + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: {}, + body: requestBody, + mediaType: 'application/json-patch+json', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/DefaultService.ts.snap b/test/__snapshots__/v3_experimental/services/DefaultService.ts.snap new file mode 100644 index 000000000..0986ff543 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/DefaultService.ts.snap @@ -0,0 +1,38 @@ +import type { ModelWithArrayReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnly } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataPostServiceWithEmptyTag = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + + query?: {}; +}; + +export class DefaultService { + /** + * @throws ApiError + */ + public static serviceWithEmptyTag(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag', + }); + } + + /** + * @returns ModelWithReadOnlyAndWriteOnly + * @throws ApiError + */ + public static postServiceWithEmptyTag( + data: TDataPostServiceWithEmptyTag + ): CancelablePromise { + const { query, requestBody } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/no-tag', + body: requestBody, + mediaType: 'application/json', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/DefaultsService.ts.snap b/test/__snapshots__/v3_experimental/services/DefaultsService.ts.snap new file mode 100644 index 000000000..591e36376 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/DefaultsService.ts.snap @@ -0,0 +1,154 @@ +import type { ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataCallWithDefaultParameters = { + query?: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; +}; +export type TDataCallWithDefaultOptionalParameters = { + query?: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; +}; +export type TDataCallToTestOrderOfParams = { + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault?: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault?: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; +}; + +export class DefaultsService { + /** + * @throws ApiError + */ + public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterBoolean: true, + parameterEnum: 'Success', + parameterModel: { + prop: 'Hello World!', + }, + parameterNumber: 123, + parameterString: 'Hello World!', + ...query, + }, + }); + } + + /** + * @throws ApiError + */ + public static callWithDefaultOptionalParameters( + data: TDataCallWithDefaultOptionalParameters = {} + ): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterBoolean: true, + parameterEnum: 'Success', + parameterModel: { + prop: 'Hello World!', + }, + parameterNumber: 123, + parameterString: 'Hello World!', + ...query, + }, + }); + } + + /** + * @throws ApiError + */ + public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: 'Hello World!', + parameterOptionalStringWithEmptyDefault: '', + parameterStringNullableWithDefault: null, + parameterStringWithDefault: 'Hello World!', + parameterStringWithEmptyDefault: '', + ...query, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/DeprecatedService.ts.snap b/test/__snapshots__/v3_experimental/services/DeprecatedService.ts.snap new file mode 100644 index 000000000..fd0712507 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/DeprecatedService.ts.snap @@ -0,0 +1,28 @@ +import type { DeprecatedModel } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataDeprecatedCall = { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + + query?: {}; +}; + +export class DeprecatedService { + /** + * @deprecated + * @throws ApiError + */ + public static deprecatedCall(data: TDataDeprecatedCall): CancelablePromise { + const { query, parameter } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: {}, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/DescriptionsService.ts.snap b/test/__snapshots__/v3_experimental/services/DescriptionsService.ts.snap new file mode 100644 index 000000000..b86fedf1f --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/DescriptionsService.ts.snap @@ -0,0 +1,51 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataCallWithDescriptions = { + query?: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; + }; +}; + +export class DescriptionsService { + /** + * @throws ApiError + */ + public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + ...query, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/DuplicateService.ts.snap b/test/__snapshots__/v3_experimental/services/DuplicateService.ts.snap new file mode 100644 index 000000000..7381aac77 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/DuplicateService.ts.snap @@ -0,0 +1,45 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class DuplicateService { + /** + * @throws ApiError + */ + public static duplicateName(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate', + }); + } + + /** + * @throws ApiError + */ + public static duplicateName1(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate', + }); + } + + /** + * @throws ApiError + */ + public static duplicateName2(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate', + }); + } + + /** + * @throws ApiError + */ + public static duplicateName3(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/ErrorService.ts.snap b/test/__snapshots__/v3_experimental/services/ErrorService.ts.snap new file mode 100644 index 000000000..3f944b6a1 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/ErrorService.ts.snap @@ -0,0 +1,35 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataTestErrorCode = { + query: { + /** + * Status code to return + */ + status: number; + }; +}; + +export class ErrorService { + /** + * @returns any Custom message: Successful response + * @throws ApiError + */ + public static testErrorCode(data: TDataTestErrorCode): CancelablePromise { + const { query } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + ...query, + }, + errors: { + 500: `Custom message: Internal Server Error`, + 501: `Custom message: Not Implemented`, + 502: `Custom message: Bad Gateway`, + 503: `Custom message: Service Unavailable`, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/FileResponseService.ts.snap b/test/__snapshots__/v3_experimental/services/FileResponseService.ts.snap new file mode 100644 index 000000000..bbec566d3 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/FileResponseService.ts.snap @@ -0,0 +1,24 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataFileResponse = { + id: string; + + query?: {}; +}; + +export class FileResponseService { + /** + * @returns binary Success + * @throws ApiError + */ + public static fileResponse(data: TDataFileResponse): CancelablePromise { + const { query, id } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/file/{id}', + path: {}, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/FormDataService.ts.snap b/test/__snapshots__/v3_experimental/services/FormDataService.ts.snap new file mode 100644 index 000000000..2e0cdde8d --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/FormDataService.ts.snap @@ -0,0 +1,36 @@ +import type { ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataPostApiFormData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export class FormDataService { + /** + * @throws ApiError + */ + public static postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise { + const { query, formData } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + ...query, + }, + formData: formData, + mediaType: 'multipart/form-data', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/HeaderService.ts.snap b/test/__snapshots__/v3_experimental/services/HeaderService.ts.snap new file mode 100644 index 000000000..e451c3035 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/HeaderService.ts.snap @@ -0,0 +1,21 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class HeaderService { + /** + * @returns string Successful response + * @throws ApiError + */ + public static callWithResultFromHeader(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: `400 server error`, + 500: `500 server error`, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/MultipartService.ts.snap b/test/__snapshots__/v3_experimental/services/MultipartService.ts.snap new file mode 100644 index 000000000..014c73e6d --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/MultipartService.ts.snap @@ -0,0 +1,45 @@ +import type { ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataMultipartRequest = { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + + query?: {}; +}; + +export class MultipartService { + /** + * @throws ApiError + */ + public static multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise { + const { query, formData } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/multipart', + formData: formData, + mediaType: 'multipart/form-data', + }); + } + + /** + * @returns any OK + * @throws ApiError + */ + public static multipartResponse(): CancelablePromise<{ + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multipart', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/MultipleTags1Service.ts.snap b/test/__snapshots__/v3_experimental/services/MultipleTags1Service.ts.snap new file mode 100644 index 000000000..21cac6e19 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/MultipleTags1Service.ts.snap @@ -0,0 +1,27 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class MultipleTags1Service { + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/MultipleTags2Service.ts.snap b/test/__snapshots__/v3_experimental/services/MultipleTags2Service.ts.snap new file mode 100644 index 000000000..1c86961ad --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/MultipleTags2Service.ts.snap @@ -0,0 +1,27 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class MultipleTags2Service { + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/MultipleTags3Service.ts.snap b/test/__snapshots__/v3_experimental/services/MultipleTags3Service.ts.snap new file mode 100644 index 000000000..15fc09d44 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/MultipleTags3Service.ts.snap @@ -0,0 +1,16 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class MultipleTags3Service { + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/NoContentService.ts.snap b/test/__snapshots__/v3_experimental/services/NoContentService.ts.snap new file mode 100644 index 000000000..4af0ece57 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/NoContentService.ts.snap @@ -0,0 +1,28 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class NoContentService { + /** + * @returns void Success + * @throws ApiError + */ + public static callWithNoContentResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content', + }); + } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + }); + } +} diff --git "a/test/__snapshots__/v3_experimental/services/NonAscii\303\206\303\270\303\245\303\206\303\270\303\205\303\266\303\264\303\252\303\212Service.ts.snap" "b/test/__snapshots__/v3_experimental/services/NonAscii\303\206\303\270\303\245\303\206\303\270\303\205\303\266\303\264\303\252\303\212Service.ts.snap" new file mode 100644 index 000000000..c3ab023b0 --- /dev/null +++ "b/test/__snapshots__/v3_experimental/services/NonAscii\303\206\303\270\303\245\303\206\303\270\303\205\303\266\303\264\303\252\303\212Service.ts.snap" @@ -0,0 +1,32 @@ +import type { NonAsciiStringæøåÆØÅöôêÊ字符串 } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; +}; + +export class NonAsciiÆøåÆøÅöôêÊService { + /** + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public static nonAsciiæøåÆøÅöôêÊ字符串( + data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + ): CancelablePromise> { + const { query } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + ...query, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/ParametersService.ts.snap b/test/__snapshots__/v3_experimental/services/ParametersService.ts.snap new file mode 100644 index 000000000..bda2eab89 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/ParametersService.ts.snap @@ -0,0 +1,210 @@ +import type { ModelWithNestedArrayEnumsDataFoo, ModelWithOneOfEnum, ModelWithString, Pageable } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataDeleteFoo = { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + + query?: {}; +}; +export type TDataCallWithParameters = { + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + + query: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + }; +}; +export type TDataCallWithWeirdParameterNames = { + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + + query: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + }; +}; +export type TDataGetCallWithOptionalParam = { + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + + query?: { + /** + * This is an optional parameter + */ + parameter?: string; + }; +}; +export type TDataPostCallWithOptionalParam = { + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; +}; + +export class ParametersService { + /** + * @throws ApiError + */ + public static deleteFoo(data: TDataDeleteFoo): CancelablePromise { + const { query, bar, foo } = data; + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: {}, + }); + } + + /** + * @throws ApiError + */ + public static callWithParameters(data: TDataCallWithParameters): CancelablePromise { + const { query, parameterCookie, parameterForm, parameterHeader, parameterPath, requestBody } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: {}, + cookies: {}, + headers: {}, + query: { + ...query, + }, + formData: {}, + body: requestBody, + mediaType: 'application/json', + }); + } + + /** + * @throws ApiError + */ + public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + const { + query, + parameterCookie, + parameterForm, + parameterHeader, + parameterPath1, + parameterPath2, + parameterPath3, + requestBody, + } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: {}, + cookies: {}, + headers: {}, + query: { + ...query, + }, + formData: {}, + body: requestBody, + mediaType: 'application/json', + }); + } + + /** + * @throws ApiError + */ + public static getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise { + const { query, requestBody } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + ...query, + }, + body: requestBody, + mediaType: 'application/json', + }); + } + + /** + * @throws ApiError + */ + public static postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise { + const { query, requestBody } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + ...query, + }, + body: requestBody, + mediaType: 'application/json', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/RequestBodyService.ts.snap b/test/__snapshots__/v3_experimental/services/RequestBodyService.ts.snap new file mode 100644 index 000000000..15583a5fd --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/RequestBodyService.ts.snap @@ -0,0 +1,36 @@ +import type { ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataPostApiRequestBody = { + /** + * A reusable request body + */ + foo?: ModelWithString; + + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export class RequestBodyService { + /** + * @throws ApiError + */ + public static postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise { + const { query, foo } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + ...query, + }, + body: foo, + mediaType: 'application/json', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/ResponseService.ts.snap b/test/__snapshots__/v3_experimental/services/ResponseService.ts.snap new file mode 100644 index 000000000..d25e4d887 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/ResponseService.ts.snap @@ -0,0 +1,73 @@ +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class ResponseService { + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + }); + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public static callWithResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response', + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static callWithDuplicateResponses(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/response', + errors: { + 500: `Message for 500 error`, + 501: `Message for 501 error`, + 502: `Message for 502 error`, + }, + }); + } + + /** + * @returns any Message for 200 response + * @returns ModelWithString Message for default response + * @returns ModelThatExtends Message for 201 response + * @returns ModelThatExtendsExtends Message for 202 response + * @throws ApiError + */ + public static callWithResponses(): CancelablePromise< + | { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } + | ModelWithString + | ModelThatExtends + | ModelThatExtendsExtends + > { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/response', + errors: { + 500: `Message for 500 error`, + 501: `Message for 501 error`, + 502: `Message for 502 error`, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/SimpleService.ts.snap b/test/__snapshots__/v3_experimental/services/SimpleService.ts.snap new file mode 100644 index 000000000..733ff7439 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/SimpleService.ts.snap @@ -0,0 +1,75 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class SimpleService { + /** + * @throws ApiError + */ + public static getCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static postCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static deleteCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static optionsCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static headCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple', + }); + } + + /** + * @throws ApiError + */ + public static patchCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple', + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/TypesService.ts.snap b/test/__snapshots__/v3_experimental/services/TypesService.ts.snap new file mode 100644 index 000000000..3fb7c69df --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/TypesService.ts.snap @@ -0,0 +1,66 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataTypes = { + /** + * This is a number parameter + */ + id?: number; + + query: { + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a boolean parameter + */ + parameterBoolean?: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; +}; + +export class TypesService { + /** + * @returns number Response is a simple number + * @returns string Response is a simple string + * @returns boolean Response is a simple boolean + * @returns unknown Response is a simple object + * @throws ApiError + */ + public static types(data: TDataTypes): CancelablePromise> { + const { query, id } = data; + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: {}, + query: { + parameterBoolean: true, + parameterNumber: 123, + parameterObject: null, + parameterString: 'default', + ...query, + }, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/UploadService.ts.snap b/test/__snapshots__/v3_experimental/services/UploadService.ts.snap new file mode 100644 index 000000000..66e14a79a --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/UploadService.ts.snap @@ -0,0 +1,27 @@ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export type TDataUploadFile = { + /** + * Supply a file reference for upload + */ + file: Blob | File; + + query?: {}; +}; + +export class UploadService { + /** + * @returns boolean + * @throws ApiError + */ + public static uploadFile(data: TDataUploadFile): CancelablePromise { + const { query, file } = data; + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/upload', + formData: {}, + }); + } +} diff --git a/test/__snapshots__/v3_experimental/services/index.ts.snap b/test/__snapshots__/v3_experimental/services/index.ts.snap new file mode 100644 index 000000000..3243a2fb1 --- /dev/null +++ b/test/__snapshots__/v3_experimental/services/index.ts.snap @@ -0,0 +1,23 @@ +export { CollectionFormatService } from './CollectionFormatService'; +export { ComplexService } from './ComplexService'; +export { DefaultService } from './DefaultService'; +export { DefaultsService } from './DefaultsService'; +export { DeprecatedService } from './DeprecatedService'; +export { DescriptionsService } from './DescriptionsService'; +export { DuplicateService } from './DuplicateService'; +export { ErrorService } from './ErrorService'; +export { FileResponseService } from './FileResponseService'; +export { FormDataService } from './FormDataService'; +export { HeaderService } from './HeaderService'; +export { MultipartService } from './MultipartService'; +export { MultipleTags1Service } from './MultipleTags1Service'; +export { MultipleTags2Service } from './MultipleTags2Service'; +export { MultipleTags3Service } from './MultipleTags3Service'; +export { NoContentService } from './NoContentService'; +export { NonAsciiÆøåÆøÅöôêÊService } from './NonAsciiÆøåÆøÅöôêÊService'; +export { ParametersService } from './ParametersService'; +export { RequestBodyService } from './RequestBodyService'; +export { ResponseService } from './ResponseService'; +export { SimpleService } from './SimpleService'; +export { TypesService } from './TypesService'; +export { UploadService } from './UploadService'; diff --git a/test/__snapshots__/v3_models/index.ts.snap b/test/__snapshots__/v3_models/index.ts.snap new file mode 100644 index 000000000..e9644dae4 --- /dev/null +++ b/test/__snapshots__/v3_models/index.ts.snap @@ -0,0 +1 @@ +export * from './models'; diff --git a/test/__snapshots__/v3_models/models.ts.snap b/test/__snapshots__/v3_models/models.ts.snap new file mode 100644 index 000000000..ad411322f --- /dev/null +++ b/test/__snapshots__/v3_models/models.ts.snap @@ -0,0 +1,705 @@ +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = + | 'Success' + | 'Warning' + | 'Error' + | "'Single Quote'" + | '"Double Quotes"' + | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array< + | { + foo?: string; + } + | { + bar?: string; + } +>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array< + | { + foo?: string; + } + | { + bar?: string; + } + >; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = Record; + +/** + * This is a string reference + */ +export type DictionaryWithReference = Record; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = Record>; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = Record>; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = Record< + string, + { + foo?: string; + bar?: string; + } +>; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: Record; + dictionaryWithEnumFromDescription?: Record; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: Record; +}; + +/** + * This is a deprecated model with a deprecated property + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: + | { + propA?: string; + } + | string + | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: 'circle'; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: 'square'; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: + | { + propA?: string; + } + | string + | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type Enum1 = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: + | { + boolean?: boolean; + } + | ModelWithEnum + | ModelWithArray + | ModelWithDictionary + | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | Record; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | Record>; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | Record>; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: + | ({ + boolean?: boolean; + } & ModelWithEnum & + ModelWithArray & + ModelWithDictionary) + | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: + | { + boolean?: boolean; + } + | ModelWithEnum + | ModelWithArray + | ModelWithDictionary + | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + firstName: string; + lastname: string; + age: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & + ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; + }; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; + +export type File = { + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; +}; + +export type _default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = Record; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = + | { + foo: SimpleParameter; + baz: number | null; + qux: number; + } + | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; + }; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = + | { + foo: 'Bar'; + } + | { + foo: 'Baz'; + } + | { + foo: 'Qux'; + } + | { + content: string; + foo: 'Quux'; + } + | { + content: [string, string]; + foo: 'Corge'; + }; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; + baz: string; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; diff --git a/test/index.spec.ts b/test/index.spec.ts index b26627478..0e4668e59 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -165,6 +165,25 @@ describe('OpenAPI v3', () => { useOptions: true, } as UserConfig, }, + { + description: 'generate models', + name: 'v3_models', + config: { + client: 'fetch', + exportCore: false, + exportModels: true, + exportSchemas: false, + exportServices: false, + } as UserConfig, + }, + { + description: 'generate experimental build', + name: 'v3_experimental', + config: { + client: 'fetch', + experimental: true, + } as UserConfig, + }, ])('$description', async ({ name, config }) => { const output = toOutputPath(name); await createClient({