From d9069e2214c3c9bd7825347e8e5d0cbd2ff4ee3c Mon Sep 17 00:00:00 2001 From: lub0v-parsable Date: Thu, 2 Sep 2021 19:52:36 -0700 Subject: [PATCH] support paths without tags --- src/templates/exportAppClient.hbs | 11 +- src/utils/writeAppClient.ts | 11 +- test/__snapshots__/index.client.spec.js.snap | 8554 +++++++++++------- test/index.client.spec.js | 69 +- test/spec/v2_no_tags.json | 23 + test/spec/v2_tags_combined.json | 29 + test/spec/v3_no_tags.json | 25 + test/spec/v3_tags_combined.json | 31 + 8 files changed, 5284 insertions(+), 3469 deletions(-) create mode 100644 test/spec/v2_no_tags.json create mode 100644 test/spec/v2_tags_combined.json create mode 100644 test/spec/v3_no_tags.json create mode 100644 test/spec/v3_tags_combined.json diff --git a/src/templates/exportAppClient.hbs b/src/templates/exportAppClient.hbs index 3cb7417bc..1e417a5f9 100644 --- a/src/templates/exportAppClient.hbs +++ b/src/templates/exportAppClient.hbs @@ -8,15 +8,18 @@ import { {{{httpClientRequest}}} } from './core/{{{httpClientRequest}}}'; import { {{{name}}} } from './services/{{{name}}}'; {{/each}} {{/if}} +{{#if service}} +import { {{{service.name}}} } from './services/{{{service.name}}}'; +{{/if}} -export class {{{clientName}}} { +export class {{{clientName}}} {{#if service}}extends {{{service.name}}} {{/if}}{ {{#each services}} readonly {{{shortName}}}: {{{name}}}; {{/each}} readonly request: BaseHttpRequest; constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = {{{httpClientRequest}}}) { - this.request = new HttpRequest({ + {{#if service}}const request{{else}}this.request{{/if}} = new HttpRequest({ BASE: openApiConfig?.BASE ?? '{{{server}}}', VERSION: openApiConfig?.VERSION ?? '{{{version}}}', WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, @@ -25,6 +28,10 @@ export class {{{clientName}}} { PASSWORD: openApiConfig?.PASSWORD, HEADERS: openApiConfig?.HEADERS, }); + {{#if service}} + super(request); + this.request = request; + {{/if}} {{#each services}} this.{{{shortName}}} = new {{{name}}}(this.request); {{/each}} diff --git a/src/utils/writeAppClient.ts b/src/utils/writeAppClient.ts index fc2a86b6e..bf06b5a03 100644 --- a/src/utils/writeAppClient.ts +++ b/src/utils/writeAppClient.ts @@ -19,10 +19,13 @@ export async function writeAppClient(client: Client, templates: Templates, outpu await writeFile( resolve(outputPath, 'client.ts'), templates.client({ - services: sortServicesByName(client.services).map(s => ({ - name: s.name, - shortName: s.name.replace('Service', '').toLowerCase(), - })), + services: sortServicesByName(client.services) + .filter(s => s.name !== 'Service') + .map(s => ({ + name: s.name, + shortName: s.name.replace('Service', '').toLowerCase(), + })), + service: client.services.find(s => s.name === 'Service'), clientName, httpClientRequest: getHttpRequestName(httpClient), server: client.server, diff --git a/test/__snapshots__/index.client.spec.js.snap b/test/__snapshots__/index.client.spec.js.snap index b92bed6d9..c23be3a99 100644 --- a/test/__snapshots__/index.client.spec.js.snap +++ b/test/__snapshots__/index.client.spec.js.snap @@ -1,38 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`v2 should generate with exportClient: ./test/generated/v2_client/client.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/client.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from './core/BaseHttpRequest'; import type { OpenAPIConfig } from './core/OpenAPI'; import { FetchHttpRequest } from './core/FetchHttpRequest'; -import { CollectionFormatService } from './services/CollectionFormatService'; -import { ComplexService } from './services/ComplexService'; -import { DefaultsService } from './services/DefaultsService'; -import { DuplicateService } from './services/DuplicateService'; -import { HeaderService } from './services/HeaderService'; -import { NoContentService } from './services/NoContentService'; -import { ParametersService } from './services/ParametersService'; -import { ResponseService } from './services/ResponseService'; import { SimpleService } from './services/SimpleService'; -import { TypesService } from './services/TypesService'; +import { Service } from './services/Service'; -export class TestClient { - readonly collectionformat: CollectionFormatService; - readonly complex: ComplexService; - readonly defaults: DefaultsService; - readonly duplicate: DuplicateService; - readonly header: HeaderService; - readonly nocontent: NoContentService; - readonly parameters: ParametersService; - readonly response: ResponseService; +export class TestClient extends Service { readonly simple: SimpleService; - readonly types: TypesService; readonly request: BaseHttpRequest; constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { - this.request = new HttpRequest({ + const request = new HttpRequest({ BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', VERSION: openApiConfig?.VERSION ?? '1.0', WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, @@ -41,21 +24,14 @@ export class TestClient { PASSWORD: openApiConfig?.PASSWORD, HEADERS: openApiConfig?.HEADERS, }); - this.collectionformat = new CollectionFormatService(this.request); - this.complex = new ComplexService(this.request); - this.defaults = new DefaultsService(this.request); - this.duplicate = new DuplicateService(this.request); - this.header = new HeaderService(this.request); - this.nocontent = new NoContentService(this.request); - this.parameters = new ParametersService(this.request); - this.response = new ResponseService(this.request); + super(request); + this.request = request; this.simple = new SimpleService(this.request); - this.types = new TypesService(this.request); } }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiError.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/ApiError.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -78,7 +54,7 @@ export class ApiError extends Error { }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiRequestOptions.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/ApiRequestOptions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -96,7 +72,7 @@ export type ApiRequestOptions = { }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiResult.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -109,7 +85,7 @@ export type ApiResult = { }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/BaseHttpRequest.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/BaseHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -130,7 +106,7 @@ export class BaseHttpRequest { }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/FetchHttpRequest.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/FetchHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -350,7 +326,7 @@ export class FetchHttpRequest extends BaseHttpRequest { " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/OpenAPI.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -371,7 +347,7 @@ export type OpenAPIConfig = { " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/index.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -382,657 +358,646 @@ export type { OpenAPIConfig } from './core/OpenAPI'; export { BaseHttpRequest } from './core/BaseHttpRequest'; export { FetchHttpRequest } from './core/FetchHttpRequest'; -export type { ArrayWithArray } from './models/ArrayWithArray'; -export type { ArrayWithBooleans } from './models/ArrayWithBooleans'; -export type { ArrayWithNumbers } from './models/ArrayWithNumbers'; -export type { ArrayWithProperties } from './models/ArrayWithProperties'; -export type { ArrayWithReferences } from './models/ArrayWithReferences'; -export type { ArrayWithStrings } from './models/ArrayWithStrings'; -export type { Date } from './models/Date'; -export type { DictionaryWithArray } from './models/DictionaryWithArray'; -export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary'; -export type { DictionaryWithProperties } from './models/DictionaryWithProperties'; -export type { DictionaryWithReference } from './models/DictionaryWithReference'; -export type { DictionaryWithString } from './models/DictionaryWithString'; -export { EnumFromDescription } from './models/EnumFromDescription'; -export { EnumWithExtensions } from './models/EnumWithExtensions'; -export { EnumWithNumbers } from './models/EnumWithNumbers'; -export { EnumWithStrings } from './models/EnumWithStrings'; -export type { ModelThatExtends } from './models/ModelThatExtends'; -export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; -export type { ModelWithArray } from './models/ModelWithArray'; -export type { ModelWithBoolean } from './models/ModelWithBoolean'; -export type { ModelWithCircularReference } from './models/ModelWithCircularReference'; -export type { ModelWithDictionary } from './models/ModelWithDictionary'; -export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports'; -export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties'; -export { ModelWithEnum } from './models/ModelWithEnum'; -export { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription'; -export type { ModelWithInteger } from './models/ModelWithInteger'; -export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums'; -export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties'; -export type { ModelWithNullableString } from './models/ModelWithNullableString'; -export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties'; -export type { ModelWithPattern } from './models/ModelWithPattern'; -export type { ModelWithProperties } from './models/ModelWithProperties'; -export type { ModelWithReference } from './models/ModelWithReference'; -export type { ModelWithString } from './models/ModelWithString'; -export type { MultilineComment } from './models/MultilineComment'; -export type { SimpleBoolean } from './models/SimpleBoolean'; -export type { SimpleFile } from './models/SimpleFile'; -export type { SimpleInteger } from './models/SimpleInteger'; -export type { SimpleReference } from './models/SimpleReference'; -export type { SimpleString } from './models/SimpleString'; -export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern'; - -export { $ArrayWithArray } from './schemas/$ArrayWithArray'; -export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans'; -export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers'; -export { $ArrayWithProperties } from './schemas/$ArrayWithProperties'; -export { $ArrayWithReferences } from './schemas/$ArrayWithReferences'; -export { $ArrayWithStrings } from './schemas/$ArrayWithStrings'; -export { $Date } from './schemas/$Date'; -export { $DictionaryWithArray } from './schemas/$DictionaryWithArray'; -export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary'; -export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties'; -export { $DictionaryWithReference } from './schemas/$DictionaryWithReference'; -export { $DictionaryWithString } from './schemas/$DictionaryWithString'; -export { $EnumFromDescription } from './schemas/$EnumFromDescription'; -export { $EnumWithExtensions } from './schemas/$EnumWithExtensions'; -export { $EnumWithNumbers } from './schemas/$EnumWithNumbers'; -export { $EnumWithStrings } from './schemas/$EnumWithStrings'; -export { $ModelThatExtends } from './schemas/$ModelThatExtends'; -export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; -export { $ModelWithArray } from './schemas/$ModelWithArray'; -export { $ModelWithBoolean } from './schemas/$ModelWithBoolean'; -export { $ModelWithCircularReference } from './schemas/$ModelWithCircularReference'; -export { $ModelWithDictionary } from './schemas/$ModelWithDictionary'; -export { $ModelWithDuplicateImports } from './schemas/$ModelWithDuplicateImports'; -export { $ModelWithDuplicateProperties } from './schemas/$ModelWithDuplicateProperties'; -export { $ModelWithEnum } from './schemas/$ModelWithEnum'; -export { $ModelWithEnumFromDescription } from './schemas/$ModelWithEnumFromDescription'; -export { $ModelWithInteger } from './schemas/$ModelWithInteger'; -export { $ModelWithNestedEnums } from './schemas/$ModelWithNestedEnums'; -export { $ModelWithNestedProperties } from './schemas/$ModelWithNestedProperties'; -export { $ModelWithNullableString } from './schemas/$ModelWithNullableString'; -export { $ModelWithOrderedProperties } from './schemas/$ModelWithOrderedProperties'; -export { $ModelWithPattern } from './schemas/$ModelWithPattern'; -export { $ModelWithProperties } from './schemas/$ModelWithProperties'; -export { $ModelWithReference } from './schemas/$ModelWithReference'; -export { $ModelWithString } from './schemas/$ModelWithString'; -export { $MultilineComment } from './schemas/$MultilineComment'; -export { $SimpleBoolean } from './schemas/$SimpleBoolean'; -export { $SimpleFile } from './schemas/$SimpleFile'; -export { $SimpleInteger } from './schemas/$SimpleInteger'; -export { $SimpleReference } from './schemas/$SimpleReference'; -export { $SimpleString } from './schemas/$SimpleString'; -export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern'; - -export { CollectionFormatService } from './services/CollectionFormatService'; -export { ComplexService } from './services/ComplexService'; -export { DefaultsService } from './services/DefaultsService'; -export { DuplicateService } from './services/DuplicateService'; -export { HeaderService } from './services/HeaderService'; -export { NoContentService } from './services/NoContentService'; -export { ParametersService } from './services/ParametersService'; -export { ResponseService } from './services/ResponseService'; +export { Service } from './services/Service'; export { SimpleService } from './services/SimpleService'; -export { TypesService } from './services/TypesService'; export { TestClient } from './client'; " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithArray.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/services/Service.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -import type { ModelWithString } from './ModelWithString'; +export class Service { + private httpRequest: BaseHttpRequest; -/** - * This is a simple array containing an array - */ -export type ArrayWithArray = Array>;" -`; + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithBooleans.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + /** + * @throws ApiError + */ + public async postCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } -/** - * This is a simple array with booleans - */ -export type ArrayWithBooleans = Array;" +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithNumbers.ts 1`] = ` +exports[`v2 should generate with combined tags: ./test/generated/v2_client_tags_combined/services/SimpleService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -/** - * This is a simple array with numbers - */ -export type ArrayWithNumbers = Array;" -`; - -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +export class SimpleService { + private httpRequest: BaseHttpRequest; -/** - * This is a simple array with properties - */ -export type ArrayWithProperties = Array<{ - foo?: string, - bar?: string, -}>;" -`; + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithReferences.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + /** + * @throws ApiError + */ + public async getCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } -import type { ModelWithString } from './ModelWithString'; + /** + * @throws ApiError + */ + public async putCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } -/** - * This is a simple array with references - */ -export type ArrayWithReferences = Array;" +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithStrings.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/client.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; +import { CollectionFormatService } from './services/CollectionFormatService'; +import { ComplexService } from './services/ComplexService'; +import { DefaultsService } from './services/DefaultsService'; +import { DuplicateService } from './services/DuplicateService'; +import { HeaderService } from './services/HeaderService'; +import { NoContentService } from './services/NoContentService'; +import { ParametersService } from './services/ParametersService'; +import { ResponseService } from './services/ResponseService'; +import { SimpleService } from './services/SimpleService'; +import { TypesService } from './services/TypesService'; -/** - * This is a simple array with strings - */ -export type ArrayWithStrings = Array;" -`; - -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/Date.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +export class TestClient { + readonly collectionformat: CollectionFormatService; + readonly complex: ComplexService; + readonly defaults: DefaultsService; + readonly duplicate: DuplicateService; + readonly header: HeaderService; + readonly nocontent: NoContentService; + readonly parameters: ParametersService; + readonly response: ResponseService; + readonly simple: SimpleService; + readonly types: TypesService; + readonly request: BaseHttpRequest; -/** - * This is a type-only model that defines Date as a string - */ -export type Date = string;" + constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { + this.request = new HttpRequest({ + BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', + VERSION: openApiConfig?.VERSION ?? '1.0', + WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, + TOKEN: openApiConfig?.TOKEN, + USERNAME: openApiConfig?.USERNAME, + PASSWORD: openApiConfig?.PASSWORD, + HEADERS: openApiConfig?.HEADERS, + }); + this.collectionformat = new CollectionFormatService(this.request); + this.complex = new ComplexService(this.request); + this.defaults = new DefaultsService(this.request); + this.duplicate = new DuplicateService(this.request); + this.header = new HeaderService(this.request); + this.nocontent = new NoContentService(this.request); + this.parameters = new ParametersService(this.request); + this.response = new ResponseService(this.request); + this.simple = new SimpleService(this.request); + this.types = new TypesService(this.request); + } +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithArray.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiError.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiResult } from './ApiResult'; -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a complex dictionary - */ -export type DictionaryWithArray = Record>;" -`; +export class ApiError extends Error { + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithDictionary.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + constructor(response: ApiResult, message: string) { + super(message); -/** - * This is a string dictionary - */ -export type DictionaryWithDictionary = Record>;" + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + } +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiRequestOptions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -/** - * This is a complex dictionary - */ -export type DictionaryWithProperties = Record;" +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly path: string; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a string reference - */ -export type DictionaryWithReference = Record;" +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/BaseHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; -/** - * This is a string dictionary - */ -export type DictionaryWithString = Record;" -`; +export class BaseHttpRequest { + readonly openApiConfig: OpenAPIConfig; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumFromDescription.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + constructor(openApiConfig: OpenAPIConfig) { + this.openApiConfig = openApiConfig; + } -/** - * Success=1,Warning=2,Error=3 - */ -export enum EnumFromDescription { - SUCCESS = 1, - WARNING = 2, - ERROR = 3, + async request(options: ApiRequestOptions): Promise { + throw new Error('Not Implemented'); + } }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithExtensions.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/FetchHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; +import { BaseHttpRequest } from './BaseHttpRequest'; -/** - * This is a simple enum with numbers - */ -export enum EnumWithExtensions { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS = 200, - /** - * Used when the status of something has a warning - */ - CUSTOM_WARNING = 400, - /** - * Used when the status of something has an error - */ - CUSTOM_ERROR = 500, -}" -`; +function isDefined(value: T | null | undefined): value is Exclude { + return value !== undefined && value !== null; +} -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithNumbers.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function isString(value: any): value is string { + return typeof value === 'string'; +} -/** - * This is a simple enum with numbers - */ -export enum EnumWithNumbers { - '_1' = 1, - '_2' = 2, - '_3' = 3, - '_1.1' = 1.1, - '_1.2' = 1.2, - '_1.3' = 1.3, - '_100' = 100, - '_200' = 200, - '_300' = 300, - '_-100' = -100, - '_-200' = -200, - '_-300' = -300, - '_-1.1' = -1.1, - '_-1.2' = -1.2, - '_-1.3' = -1.3, -}" -`; +function isStringWithValue(value: any): value is string { + return isString(value) && value !== ''; +} -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithStrings.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function isBlob(value: any): value is Blob { + return value instanceof Blob; +} -/** - * This is a simple enum with strings - */ -export enum EnumWithStrings { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', -}" -`; +function getQueryString(params: Record): string { + const qs: string[] = []; + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + if (Array.isArray(value)) { + value.forEach(value => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }); + } else { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + } + } + }); + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; + } + return ''; +} -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelThatExtends.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getUrl(options: ApiRequestOptions, config: OpenAPIConfig): string { + const path = options.path.replace(/[:]/g, '_'); + const url = \`\${config.BASE}\${path}\`; -import type { ModelWithString } from './ModelWithString'; + if (options.query) { + return \`\${url}\${getQueryString(options.query)}\`; + } + return url; +} -/** - * This is a model that extends another model - */ -export type ModelThatExtends = (ModelWithString & { - propExtendsA?: string, - propExtendsB?: ModelWithString, -}); -" -`; +function getFormData(params: Record): FormData { + const formData = new FormData(); + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + formData.append(key, value); + } + }); + return formData; +} -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelThatExtendsExtends.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +type Resolver = (options: ApiRequestOptions) => Promise; -import type { ModelThatExtends } from './ModelThatExtends'; -import type { ModelWithString } from './ModelWithString'; +async function resolve(options: ApiRequestOptions, resolver?: T | Resolver): Promise { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; +} -/** - * This is a model that extends another model - */ -export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & { - propExtendsC?: string, - propExtendsD?: ModelWithString, -}); -" -`; +async function getHeaders(options: ApiRequestOptions, config: OpenAPIConfig): Promise { + const token = await resolve(options, config.TOKEN); + const username = await resolve(options, config.USERNAME); + const password = await resolve(options, config.PASSWORD); + const defaultHeaders = await resolve(options, config.HEADERS); -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithArray.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + const headers = new Headers({ + Accept: 'application/json', + ...defaultHeaders, + ...options.headers, + }); -import type { ModelWithString } from './ModelWithString'; + if (isStringWithValue(token)) { + headers.append('Authorization', \`Bearer \${token}\`); + } -/** - * This is a model with one property containing an array - */ -export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = btoa(\`\${username}:\${password}\`); + headers.append('Authorization', \`Basic \${credentials}\`); + } + + if (options.body) { + if (options.mediaType) { + headers.append('Content-Type', options.mediaType); + } else if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } + } + return headers; } -" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithBoolean.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { + if (options.formData) { + return getFormData(options.formData); + } + if (options.body) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; +} -/** - * This is a model with one boolean property - */ -export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; +async function sendRequest(options: ApiRequestOptions, config: OpenAPIConfig, url: string): Promise { + const request: RequestInit = { + method: options.method, + headers: await getHeaders(options, config), + body: getRequestBody(options), + }; + if (config.WITH_CREDENTIALS) { + request.credentials = 'include'; + } + return await fetch(url, request); } -" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithCircularReference.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getResponseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return null; +} -/** - * This is a model with one property containing a circular reference - */ -export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; +async function getResponseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const isJSON = contentType.toLowerCase().startsWith('application/json'); + if (isJSON) { + return await response.json(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + return null; } -" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDictionary.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function catchErrors(options: ApiRequestOptions, result: ApiResult): void { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 500: 'Internal Server Error', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + ...options.errors, + } -/** - * This is a model with one property containing a dictionary - */ -export type ModelWithDictionary = { - prop?: Record; + const error = errors[result.status]; + if (error) { + throw new ApiError(result, error); + } + + if (!result.ok) { + throw new ApiError(result, 'Generic Error'); + } } -" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDuplicateImports.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +export class FetchHttpRequest extends BaseHttpRequest { + constructor(openApiConfig: OpenAPIConfig) { + super(openApiConfig); + } -import type { ModelWithString } from './ModelWithString'; + /** + * Request using fetch client + * @param options The request options from the the service + * @returns ApiResult + * @throws ApiError + */ + async request(options: ApiRequestOptions): Promise { + const url = getUrl(options, this.openApiConfig); + const response = await sendRequest(options, this.openApiConfig, url); + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); -/** - * This is a model with duplicated imports - */ -export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader || responseBody, + }; + + catchErrors(options, result); + return result; + } } " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDuplicateProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; -import type { ModelWithString } from './ModelWithString'; +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; -/** - * This is a model with duplicated properties - */ -export type ModelWithDuplicateProperties = { - prop?: ModelWithString; +export type OpenAPIConfig = { + BASE?: string; + VERSION?: string; + WITH_CREDENTIALS?: boolean; + TOKEN?: string | Resolver; + USERNAME?: string | Resolver; + PASSWORD?: string | Resolver; + HEADERS?: Headers | Resolver; } " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithEnum.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +export { ApiError } from './core/ApiError'; +export type { ApiRequestOptions } from './core/ApiRequestOptions'; +export type { ApiResult } from './core/ApiResult'; +export type { OpenAPIConfig } from './core/OpenAPI'; +export { BaseHttpRequest } from './core/BaseHttpRequest'; +export { FetchHttpRequest } from './core/FetchHttpRequest'; -/** - * This is a model with one enum - */ -export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - test?: ModelWithEnum.test; - /** - * These are the HTTP error code enums - */ - statusCode?: ModelWithEnum.statusCode; - /** - * Simple boolean enum - */ - bool?: boolean; -} - -export namespace ModelWithEnum { - - /** - * This is a simple enum with strings - */ - export enum test { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', - } +export type { ArrayWithArray } from './models/ArrayWithArray'; +export type { ArrayWithBooleans } from './models/ArrayWithBooleans'; +export type { ArrayWithNumbers } from './models/ArrayWithNumbers'; +export type { ArrayWithProperties } from './models/ArrayWithProperties'; +export type { ArrayWithReferences } from './models/ArrayWithReferences'; +export type { ArrayWithStrings } from './models/ArrayWithStrings'; +export type { Date } from './models/Date'; +export type { DictionaryWithArray } from './models/DictionaryWithArray'; +export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary'; +export type { DictionaryWithProperties } from './models/DictionaryWithProperties'; +export type { DictionaryWithReference } from './models/DictionaryWithReference'; +export type { DictionaryWithString } from './models/DictionaryWithString'; +export { EnumFromDescription } from './models/EnumFromDescription'; +export { EnumWithExtensions } from './models/EnumWithExtensions'; +export { EnumWithNumbers } from './models/EnumWithNumbers'; +export { EnumWithStrings } from './models/EnumWithStrings'; +export type { ModelThatExtends } from './models/ModelThatExtends'; +export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; +export type { ModelWithArray } from './models/ModelWithArray'; +export type { ModelWithBoolean } from './models/ModelWithBoolean'; +export type { ModelWithCircularReference } from './models/ModelWithCircularReference'; +export type { ModelWithDictionary } from './models/ModelWithDictionary'; +export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports'; +export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties'; +export { ModelWithEnum } from './models/ModelWithEnum'; +export { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription'; +export type { ModelWithInteger } from './models/ModelWithInteger'; +export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums'; +export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties'; +export type { ModelWithNullableString } from './models/ModelWithNullableString'; +export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties'; +export type { ModelWithPattern } from './models/ModelWithPattern'; +export type { ModelWithProperties } from './models/ModelWithProperties'; +export type { ModelWithReference } from './models/ModelWithReference'; +export type { ModelWithString } from './models/ModelWithString'; +export type { MultilineComment } from './models/MultilineComment'; +export type { SimpleBoolean } from './models/SimpleBoolean'; +export type { SimpleFile } from './models/SimpleFile'; +export type { SimpleInteger } from './models/SimpleInteger'; +export type { SimpleReference } from './models/SimpleReference'; +export type { SimpleString } from './models/SimpleString'; +export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern'; - /** - * These are the HTTP error code enums - */ - export enum statusCode { - _100 = '100', - _200_FOO = '200 FOO', - _300_FOO_BAR = '300 FOO_BAR', - _400_FOO_BAR = '400 foo-bar', - _500_FOO_BAR = '500 foo.bar', - _600_FOO_BAR = '600 foo&bar', - } +export { $ArrayWithArray } from './schemas/$ArrayWithArray'; +export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans'; +export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers'; +export { $ArrayWithProperties } from './schemas/$ArrayWithProperties'; +export { $ArrayWithReferences } from './schemas/$ArrayWithReferences'; +export { $ArrayWithStrings } from './schemas/$ArrayWithStrings'; +export { $Date } from './schemas/$Date'; +export { $DictionaryWithArray } from './schemas/$DictionaryWithArray'; +export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary'; +export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties'; +export { $DictionaryWithReference } from './schemas/$DictionaryWithReference'; +export { $DictionaryWithString } from './schemas/$DictionaryWithString'; +export { $EnumFromDescription } from './schemas/$EnumFromDescription'; +export { $EnumWithExtensions } from './schemas/$EnumWithExtensions'; +export { $EnumWithNumbers } from './schemas/$EnumWithNumbers'; +export { $EnumWithStrings } from './schemas/$EnumWithStrings'; +export { $ModelThatExtends } from './schemas/$ModelThatExtends'; +export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; +export { $ModelWithArray } from './schemas/$ModelWithArray'; +export { $ModelWithBoolean } from './schemas/$ModelWithBoolean'; +export { $ModelWithCircularReference } from './schemas/$ModelWithCircularReference'; +export { $ModelWithDictionary } from './schemas/$ModelWithDictionary'; +export { $ModelWithDuplicateImports } from './schemas/$ModelWithDuplicateImports'; +export { $ModelWithDuplicateProperties } from './schemas/$ModelWithDuplicateProperties'; +export { $ModelWithEnum } from './schemas/$ModelWithEnum'; +export { $ModelWithEnumFromDescription } from './schemas/$ModelWithEnumFromDescription'; +export { $ModelWithInteger } from './schemas/$ModelWithInteger'; +export { $ModelWithNestedEnums } from './schemas/$ModelWithNestedEnums'; +export { $ModelWithNestedProperties } from './schemas/$ModelWithNestedProperties'; +export { $ModelWithNullableString } from './schemas/$ModelWithNullableString'; +export { $ModelWithOrderedProperties } from './schemas/$ModelWithOrderedProperties'; +export { $ModelWithPattern } from './schemas/$ModelWithPattern'; +export { $ModelWithProperties } from './schemas/$ModelWithProperties'; +export { $ModelWithReference } from './schemas/$ModelWithReference'; +export { $ModelWithString } from './schemas/$ModelWithString'; +export { $MultilineComment } from './schemas/$MultilineComment'; +export { $SimpleBoolean } from './schemas/$SimpleBoolean'; +export { $SimpleFile } from './schemas/$SimpleFile'; +export { $SimpleInteger } from './schemas/$SimpleInteger'; +export { $SimpleReference } from './schemas/$SimpleReference'; +export { $SimpleString } from './schemas/$SimpleString'; +export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern'; +export { CollectionFormatService } from './services/CollectionFormatService'; +export { ComplexService } from './services/ComplexService'; +export { DefaultsService } from './services/DefaultsService'; +export { DuplicateService } from './services/DuplicateService'; +export { HeaderService } from './services/HeaderService'; +export { NoContentService } from './services/NoContentService'; +export { ParametersService } from './services/ParametersService'; +export { ResponseService } from './services/ResponseService'; +export { SimpleService } from './services/SimpleService'; +export { TypesService } from './services/TypesService'; -} +export { TestClient } from './client'; " `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithEnumFromDescription.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * This is a model with one enum + * This is a simple array containing an array */ -export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: ModelWithEnumFromDescription.test; -} - -export namespace ModelWithEnumFromDescription { - - /** - * Success=1,Warning=2,Error=3 - */ - export enum test { - SUCCESS = 1, - WARNING = 2, - ERROR = 3, - } - - -} -" +export type ArrayWithArray = Array>;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithInteger.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithBooleans.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model with one number property + * This is a simple array with booleans */ -export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; -} -" +export type ArrayWithBooleans = Array;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNestedEnums.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model with nested enums + * This is a simple array with numbers */ -export type ModelWithNestedEnums = { - dictionaryWithEnum?: Record; - dictionaryWithEnumFromDescription?: Record; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array<1 | 2 | 3>; -} -" +export type ArrayWithNumbers = Array;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNestedProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model with one nested property + * This is a simple array with properties */ -export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string, - }, - }; -} -" +export type ArrayWithProperties = Array<{ + foo?: string, + bar?: string, +}>;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNullableString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithReferences.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * This is a model with one string property + * This is a simple array with references */ -export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp: string | null; -} -" +export type ArrayWithReferences = Array;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithOrderedProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ArrayWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model with ordered properties + * This is a simple array with strings */ -export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; -} -" +export type ArrayWithStrings = Array;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithPattern.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/Date.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model that contains a some patterns + * This is a type-only model that defines Date as a string */ -export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; -} -" +export type Date = string;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -1040,1297 +1005,1278 @@ exports[`v2 should generate with exportClient: ./test/generated/v2_client/models import type { ModelWithString } from './ModelWithString'; /** - * This is a model with one nested property + * This is a complex dictionary */ -export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; -} -" +export type DictionaryWithArray = Record>;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithProperties } from './ModelWithProperties'; - /** - * This is a model with one property containing a reference + * This is a string dictionary */ -export type ModelWithReference = { - prop?: ModelWithProperties; -} -" +export type DictionaryWithDictionary = Record>;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a model with one string property + * This is a complex dictionary */ -export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; -} -" +export type DictionaryWithProperties = Record;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/MultilineComment.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * Testing multiline comments. - * This must go to the next line. - * - * This will contain a break. + * This is a string reference */ -export type MultilineComment = number;" +export type DictionaryWithReference = Record;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleBoolean.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/DictionaryWithString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple boolean + * This is a string dictionary */ -export type SimpleBoolean = boolean;" +export type DictionaryWithString = Record;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleFile.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumFromDescription.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple file + * Success=1,Warning=2,Error=3 */ -export type SimpleFile = Blob;" +export enum EnumFromDescription { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleInteger.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithExtensions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple number + * This is a simple enum with numbers */ -export type SimpleInteger = number;" +export enum EnumWithExtensions { + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS = 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING = 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR = 500, +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from './ModelWithString'; - /** - * This is a simple reference + * This is a simple enum with numbers */ -export type SimpleReference = ModelWithString;" +export enum EnumWithNumbers { + '_1' = 1, + '_2' = 2, + '_3' = 3, + '_1.1' = 1.1, + '_1.2' = 1.2, + '_1.3' = 1.3, + '_100' = 100, + '_200' = 200, + '_300' = 300, + '_-100' = -100, + '_-200' = -200, + '_-300' = -300, + '_-1.1' = -1.1, + '_-1.2' = -1.2, + '_-1.3' = -1.3, +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/EnumWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple string + * This is a simple enum with strings */ -export type SimpleString = string;" +export enum EnumWithStrings { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', +}" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleStringWithPattern.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelThatExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * This is a simple string + * This is a model that extends another model */ -export type SimpleStringWithPattern = string;" +export type ModelThatExtends = (ModelWithString & { + propExtendsA?: string, + propExtendsB?: ModelWithString, +}); +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithArray.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelThatExtendsExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithArray = { - type: 'array', - contains: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, -};" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithBooleans.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export const $ArrayWithBooleans = { - type: 'array', - contains: { - type: 'boolean', - }, -};" +import type { ModelThatExtends } from './ModelThatExtends'; +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & { + propExtendsC?: string, + propExtendsD?: ModelWithString, +}); +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithNumbers.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithNumbers = { - type: 'array', - contains: { - type: 'number', - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithProperties = { - type: 'array', - contains: { - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, -};" + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithReferences.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithCircularReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithReferences = { - type: 'array', - contains: { - type: 'ModelWithString', - }, -};" + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithStrings.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithStrings = { - type: 'array', - contains: { - type: 'string', - }, -};" + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: Record; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$Date.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDuplicateImports.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $Date = { - type: 'string', -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithArray.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithDuplicateProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithArray = { - type: 'dictionary', - contains: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithDictionary.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithEnum.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithDictionary = { - type: 'dictionary', - contains: { - type: 'dictionary', - contains: { - type: 'string', - }, - }, -};" -`; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export const $DictionaryWithProperties = { - type: 'dictionary', - contains: { - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, -};" +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: ModelWithEnum.test; + /** + * These are the HTTP error code enums + */ + statusCode?: ModelWithEnum.statusCode; + /** + * Simple boolean enum + */ + bool?: boolean; +} + +export namespace ModelWithEnum { + + /** + * This is a simple enum with strings + */ + export enum test { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', + } + + /** + * These are the HTTP error code enums + */ + export enum statusCode { + _100 = '100', + _200_FOO = '200 FOO', + _300_FOO_BAR = '300 FOO_BAR', + _400_FOO_BAR = '400 foo-bar', + _500_FOO_BAR = '500 foo.bar', + _600_FOO_BAR = '600 foo&bar', + } + + +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithEnumFromDescription.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithReference = { - type: 'dictionary', - contains: { - type: 'ModelWithString', - }, -};" + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: ModelWithEnumFromDescription.test; +} + +export namespace ModelWithEnumFromDescription { + + /** + * Success=1,Warning=2,Error=3 + */ + export enum test { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, + } + + +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithInteger.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithString = { - type: 'dictionary', - contains: { - type: 'string', - }, -};" + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumFromDescription.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNestedEnums.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumFromDescription = { - type: 'Enum', -};" + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: Record; + dictionaryWithEnumFromDescription?: Record; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array<1 | 2 | 3>; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithExtensions.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNestedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithExtensions = { - type: 'Enum', -};" + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string, + }, + }; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithNumbers.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithNullableString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithNumbers = { - type: 'Enum', -};" + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp: string | null; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithStrings.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithOrderedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithStrings = { - type: 'Enum', -};" + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelThatExtends.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithPattern.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelThatExtends = { - type: 'all-of', - contains: [{ - type: 'ModelWithString', - }, { - properties: { - propExtendsA: { - type: 'string', - }, - propExtendsB: { - type: '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; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelThatExtendsExtends.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelThatExtendsExtends = { - type: 'all-of', - contains: [{ - type: 'ModelWithString', - }, { - type: 'ModelThatExtends', - }, { - properties: { - propExtendsC: { - type: 'string', - }, - propExtendsD: { - type: 'ModelWithString', - }, - }, - }], -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithArray.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithArray = { - properties: { - prop: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, - propWithFile: { - type: 'array', - contains: { - type: 'File', - }, - }, - propWithNumber: { - type: 'array', - contains: { - type: 'number', - }, - }, - }, -};" + +import type { ModelWithProperties } from './ModelWithProperties'; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithBoolean.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/ModelWithString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithBoolean = { - properties: { - prop: { - type: 'boolean', - }, - }, -};" + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +} +" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithCircularReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/MultilineComment.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithCircularReference = { - properties: { - prop: { - type: 'ModelWithCircularReference', - }, - }, -};" + +/** + * Testing multiline comments. + * This must go to the next line. + * + * This will contain a break. + */ +export type MultilineComment = number;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDictionary.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDictionary = { - properties: { - prop: { - type: 'dictionary', - contains: { - type: 'string', - }, - }, - }, -};" + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDuplicateImports.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleFile.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDuplicateImports = { - properties: { - propA: { - type: 'ModelWithString', - }, - propB: { - type: 'ModelWithString', - }, - propC: { - type: 'ModelWithString', - }, - }, -};" + +/** + * This is a simple file + */ +export type SimpleFile = Blob;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDuplicateProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleInteger.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDuplicateProperties = { - properties: { - prop: { - type: 'ModelWithString', - }, - }, -};" + +/** + * This is a simple number + */ +export type SimpleInteger = number;" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithEnum.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithEnum = { - properties: { - test: { - type: 'Enum', - }, - statusCode: { - type: 'Enum', - }, - bool: { - type: 'boolean', + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString;" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * This is a simple string + */ +export type SimpleString = string;" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/models/SimpleStringWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string;" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ArrayWithArray = { + type: 'array', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', }, }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithBooleans.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithEnumFromDescription = { - properties: { - test: { - type: 'Enum', - }, +export const $ArrayWithBooleans = { + type: 'array', + contains: { + type: 'boolean', }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithInteger.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithInteger = { - properties: { - prop: { - type: 'number', - }, +export const $ArrayWithNumbers = { + type: 'array', + contains: { + type: 'number', }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNestedEnums.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithNestedEnums = { - properties: { - dictionaryWithEnum: { - type: 'dictionary', - contains: { - type: 'Enum', - }, - }, - dictionaryWithEnumFromDescription: { - type: 'dictionary', - contains: { - type: 'Enum', - }, - }, - arrayWithEnum: { - type: 'array', - contains: { - type: 'Enum', +export const $ArrayWithProperties = { + type: 'array', + contains: { + properties: { + foo: { + type: 'string', }, - }, - arrayWithDescription: { - type: 'array', - contains: { - type: 'Enum', + bar: { + type: 'string', }, }, }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNestedProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithReferences.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithNestedProperties = { - properties: { - first: { - properties: { - second: { - properties: { - third: { - type: 'string', - isReadOnly: true, - isRequired: true, - }, - }, - isReadOnly: true, - isRequired: true, - }, - }, - isReadOnly: true, - isRequired: true, - }, +export const $ArrayWithReferences = { + type: 'array', + contains: { + type: 'ModelWithString', }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNullableString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ArrayWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithNullableString = { - properties: { - nullableProp: { - type: 'string', - isNullable: true, - }, - nullableRequiredProp: { - type: 'string', - isRequired: true, - isNullable: true, - }, +export const $ArrayWithStrings = { + type: 'array', + contains: { + type: 'string', }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithOrderedProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$Date.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithOrderedProperties = { - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, +export const $Date = { + type: 'string', };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithPattern.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithPattern = { - 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+$', +export const $DictionaryWithArray = { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', }, }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithProperties.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithProperties = { - properties: { - required: { - type: 'string', - isRequired: true, - }, - requiredAndReadOnly: { - type: 'string', - isReadOnly: true, - isRequired: 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': { +export const $DictionaryWithDictionary = { + type: 'dictionary', + contains: { + type: 'dictionary', + contains: { type: 'string', - isReadOnly: true, - }, - '@namespace.integer': { - type: 'number', - isReadOnly: true, }, }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithReference = { - properties: { - prop: { - type: 'ModelWithProperties', +export const $DictionaryWithProperties = { + type: 'dictionary', + contains: { + properties: { + foo: { + type: 'string', + }, + bar: { + type: 'string', + }, }, }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithString = { - properties: { - prop: { - type: 'string', - }, +export const $DictionaryWithReference = { + type: 'dictionary', + contains: { + type: 'ModelWithString', }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$MultilineComment.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$DictionaryWithString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $MultilineComment = { - type: 'number', +export const $DictionaryWithString = { + type: 'dictionary', + contains: { + type: 'string', + }, };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleBoolean.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumFromDescription.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleBoolean = { - type: 'boolean', +export const $EnumFromDescription = { + type: 'Enum', };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleFile.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithExtensions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleFile = { - type: 'File', +export const $EnumWithExtensions = { + type: 'Enum', };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleInteger.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleInteger = { - type: 'number', +export const $EnumWithNumbers = { + type: 'Enum', };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleReference.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$EnumWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleReference = { - type: 'ModelWithString', +export const $EnumWithStrings = { + type: 'Enum', };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleString.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelThatExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleString = { - type: 'string', +export const $ModelThatExtends = { + type: 'all-of', + contains: [{ + type: 'ModelWithString', + }, { + properties: { + propExtendsA: { + type: 'string', + }, + propExtendsB: { + type: 'ModelWithString', + }, + }, + }], };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleStringWithPattern.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelThatExtendsExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleStringWithPattern = { - type: 'string', - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', +export const $ModelThatExtendsExtends = { + type: 'all-of', + contains: [{ + type: 'ModelWithString', + }, { + type: 'ModelThatExtends', + }, { + properties: { + propExtendsC: { + type: 'string', + }, + propExtendsD: { + type: 'ModelWithString', + }, + }, + }], };" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/CollectionFormatService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class CollectionFormatService { - private httpRequest: BaseHttpRequest; +export const $ModelWithArray = { + properties: { + prop: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, + propWithFile: { + type: 'array', + contains: { + type: 'File', + }, + }, + propWithNumber: { + type: 'array', + contains: { + type: 'number', + }, + }, + }, +};" +`; - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithBoolean = { + properties: { + prop: { + type: 'boolean', + }, + }, +};" +`; - /** - * @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values) - * @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values) - * @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values) - * @param parameterArrayPipes This is an array parameter that is send as pipes format (pipe-separated values) - * @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances) - * @throws ApiError - */ - public async collectionFormat( - parameterArrayCsv: Array, - parameterArraySsv: Array, - parameterArrayTsv: Array, - parameterArrayPipes: Array, - parameterArrayMulti: Array, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/collectionFormat\`, - query: { - 'parameterArrayCSV': parameterArrayCsv, - 'parameterArraySSV': parameterArraySsv, - 'parameterArrayTSV': parameterArrayTsv, - 'parameterArrayPipes': parameterArrayPipes, - 'parameterArrayMulti': parameterArrayMulti, - }, - }); - return result.body; - } - -}" +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithCircularReference = { + properties: { + prop: { + type: 'ModelWithCircularReference', + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ComplexService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class ComplexService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param parameterObject Parameter containing object - * @param parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public async complexTypes( - parameterObject: { - first?: { - second?: { - third?: string, - }, +export const $ModelWithDictionary = { + properties: { + prop: { + type: 'dictionary', + contains: { + type: 'string', }, }, - parameterReference: ModelWithString, - ): Promise> { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex\`, - query: { - 'parameterObject': parameterObject, - 'parameterReference': parameterReference, - }, - errors: { - 400: \`400 server error\`, - 500: \`500 server error\`, - }, - }); - return result.body; - } - -}" + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/DefaultsService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDuplicateImports.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class DefaultsService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param parameterString This is a simple string with default value - * @param parameterNumber This is a simple number with default value - * @param parameterBoolean This is a simple boolean with default value - * @param parameterEnum This is a simple enum with default value - * @param parameterModel This is a simple model with default value - * @throws ApiError - */ - public async callWithDefaultParameters( - parameterString: string = 'Hello World!', - parameterNumber: number = 123, - parameterBoolean: boolean = true, - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', - parameterModel: ModelWithString = { - \\"prop\\": \\"Hello World!\\" +export const $ModelWithDuplicateImports = { + properties: { + propA: { + type: 'ModelWithString', }, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, - query: { - 'parameterString': parameterString, - 'parameterNumber': parameterNumber, - 'parameterBoolean': parameterBoolean, - 'parameterEnum': parameterEnum, - 'parameterModel': parameterModel, - }, - }); - return result.body; - } - - /** - * @param parameterString This is a simple string that is optional with default value - * @param parameterNumber This is a simple number that is optional with default value - * @param parameterBoolean This is a simple boolean that is optional with default value - * @param parameterEnum This is a simple enum that is optional with default value - * @param parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public async callWithDefaultOptionalParameters( - parameterString: string = 'Hello World!', - parameterNumber: number = 123, - parameterBoolean: boolean = true, - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', - parameterModel: ModelWithString = { - \\"prop\\": \\"Hello World!\\" + propB: { + type: 'ModelWithString', }, - ): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, - query: { - 'parameterString': parameterString, - 'parameterNumber': parameterNumber, - 'parameterBoolean': parameterBoolean, - 'parameterEnum': parameterEnum, - 'parameterModel': parameterModel, - }, - }); - return result.body; - } - - /** - * @param parameterStringWithNoDefault This is a string with no default - * @param parameterOptionalStringWithDefault This is a optional string with default - * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param parameterOptionalStringWithNoDefault This is a optional string with no default - * @param parameterStringWithDefault This is a string with default - * @param parameterStringWithEmptyDefault This is a string with empty default - * @throws ApiError - */ - public async callToTestOrderOfParams( - parameterStringWithNoDefault: string, - parameterOptionalStringWithDefault: string = 'Hello World!', - parameterOptionalStringWithEmptyDefault: string = '', - parameterOptionalStringWithNoDefault?: string, - parameterStringWithDefault: string = 'Hello World!', - parameterStringWithEmptyDefault: string = '', - ): Promise { - const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, - query: { - 'parameterStringWithNoDefault': parameterStringWithNoDefault, - 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, - 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, - 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, - 'parameterStringWithDefault': parameterStringWithDefault, - 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, - }, - }); - return result.body; - } - -}" + propC: { + type: 'ModelWithString', + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/DuplicateService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithDuplicateProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; +export const $ModelWithDuplicateProperties = { + properties: { + prop: { + type: 'ModelWithString', + }, + }, +};" +`; -export class DuplicateService { - private httpRequest: BaseHttpRequest; +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithEnum = { + properties: { + test: { + type: 'Enum', + }, + statusCode: { + type: 'Enum', + }, + bool: { + type: 'boolean', + }, + }, +};" +`; - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithEnumFromDescription = { + properties: { + test: { + type: 'Enum', + }, + }, +};" +`; - /** - * @throws ApiError - */ - public async duplicateName(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async duplicateName1(): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async duplicateName2(): Promise { - const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async duplicateName3(): Promise { - const result = await this.httpRequest.request({ - method: 'DELETE', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, - }); - return result.body; - } - -}" +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithInteger = { + properties: { + prop: { + type: 'number', + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/HeaderService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNestedEnums.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class HeaderService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @returns string Successful response - * @throws ApiError - */ - public async callWithResultFromHeader(): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/header\`, - responseHeader: 'operation-location', - errors: { - 400: \`400 server error\`, - 500: \`500 server error\`, +export const $ModelWithNestedEnums = { + properties: { + dictionaryWithEnum: { + type: 'dictionary', + contains: { + type: 'Enum', }, - }); - return result.body; - } - -}" + }, + dictionaryWithEnumFromDescription: { + type: 'dictionary', + contains: { + type: 'Enum', + }, + }, + arrayWithEnum: { + type: 'array', + contains: { + type: 'Enum', + }, + }, + arrayWithDescription: { + type: 'array', + contains: { + type: 'Enum', + }, + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/NoContentService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNestedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class NoContentService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @returns void - * @throws ApiError - */ - public async callWithNoContentResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/no-content\`, - }); - return result.body; - } - -}" +export const $ModelWithNestedProperties = { + properties: { + first: { + properties: { + second: { + properties: { + third: { + type: 'string', + isReadOnly: true, + isRequired: true, + }, + }, + isReadOnly: true, + isRequired: true, + }, + }, + isReadOnly: true, + isRequired: true, + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ParametersService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithNullableString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class ParametersService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param parameterHeader This is the parameter that goes into the header - * @param parameterQuery This is the parameter that goes into the query params - * @param parameterForm This is the parameter that goes into the form data - * @param parameterBody This is the parameter that is send as request body - * @param parameterPath This is the parameter that goes into the path - * @throws ApiError - */ - public async callWithParameters( - parameterHeader: string, - parameterQuery: string, - parameterForm: string, - parameterBody: string, - parameterPath: string, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath}\`, - headers: { - 'parameterHeader': parameterHeader, - }, - query: { - 'parameterQuery': parameterQuery, - }, - formData: { - 'parameterForm': parameterForm, - }, - body: parameterBody, - }); - return result.body; - } - - /** - * @param parameterHeader This is the parameter that goes into the request header - * @param parameterQuery This is the parameter that goes into the request query params - * @param parameterForm This is the parameter that goes into the request form data - * @param parameterBody This is the parameter that is send as request body - * @param parameterPath1 This is the parameter that goes into the path - * @param parameterPath2 This is the parameter that goes into the path - * @param parameterPath3 This is the parameter that goes into the path - * @param _default This is the parameter with a reserved keyword - * @throws ApiError - */ - public async callWithWeirdParameterNames( - parameterHeader: string, - parameterQuery: string, - parameterForm: string, - parameterBody: string, - parameterPath1?: string, - parameterPath2?: string, - parameterPath3?: string, - _default?: string, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, - headers: { - 'parameter.header': parameterHeader, - }, - query: { - 'parameter-query': parameterQuery, - 'default': _default, - }, - formData: { - 'parameter_form': parameterForm, - }, - body: parameterBody, - }); - return result.body; - } - -}" +export const $ModelWithNullableString = { + properties: { + nullableProp: { + type: 'string', + isNullable: true, + }, + nullableRequiredProp: { + type: 'string', + isRequired: true, + isNullable: true, + }, + }, +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ResponseService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithOrderedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelThatExtends } from '../models/ModelThatExtends'; -import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class ResponseService { - private httpRequest: BaseHttpRequest; +export const $ModelWithOrderedProperties = { + properties: { + zebra: { + type: 'string', + }, + apple: { + type: 'string', + }, + hawaii: { + type: 'string', + }, + }, +};" +`; - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithPattern = { + 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+$', + }, + }, +};" +`; - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public async callWithResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - }); - return result.body; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithProperties = { + properties: { + required: { + type: 'string', + isRequired: true, + }, + requiredAndReadOnly: { + type: 'string', + isReadOnly: true, + isRequired: 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, + }, + }, +};" +`; - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public async callWithDuplicateResponses(): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - errors: { - 500: \`Message for 500 error\`, - 501: \`Message for 501 error\`, - 502: \`Message for 502 error\`, - }, - }); - return result.body; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithReference = { + properties: { + prop: { + type: 'ModelWithProperties', + }, + }, +};" +`; - /** - * @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 async callWithResponses(): Promise<{ - readonly '@namespace.string'?: string, - readonly '@namespace.integer'?: number, - readonly value?: Array, - } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { - const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - errors: { - 500: \`Message for 500 error\`, - 501: \`Message for 501 error\`, - 502: \`Message for 502 error\`, - }, - }); - return result.body; - } +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithString = { + properties: { + prop: { + type: 'string', + }, + }, +};" +`; -}" +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $MultilineComment = { + type: 'number', +};" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/SimpleService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleBoolean = { + type: 'boolean', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleFile = { + type: 'File', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleInteger = { + type: 'number', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleReference = { + type: 'ModelWithString', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleString = { + type: 'string', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/schemas/$SimpleStringWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleStringWithPattern = { + type: 'string', + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', +};" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/CollectionFormatService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class SimpleService { +export class CollectionFormatService { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -2338,56 +2284,216 @@ export class SimpleService { } /** + * @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values) + * @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values) + * @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values) + * @param parameterArrayPipes This is an array parameter that is send as pipes format (pipe-separated values) + * @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances) * @throws ApiError */ - public async getCallWithoutParametersAndResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, - }); - return result.body; + public async collectionFormat( + parameterArrayCsv: Array, + parameterArraySsv: Array, + parameterArrayTsv: Array, + parameterArrayPipes: Array, + parameterArrayMulti: Array, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/collectionFormat\`, + query: { + 'parameterArrayCSV': parameterArrayCsv, + 'parameterArraySSV': parameterArraySsv, + 'parameterArrayTSV': parameterArrayTsv, + 'parameterArrayPipes': parameterArrayPipes, + 'parameterArrayMulti': parameterArrayMulti, + }, + }); + return result.body; + } + +}" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ComplexService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class ComplexService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; } /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @returns ModelWithString Successful response * @throws ApiError */ - public async putCallWithoutParametersAndResponse(): Promise { + public async complexTypes( + parameterObject: { + first?: { + second?: { + third?: string, + }, + }, + }, + parameterReference: ModelWithString, + ): Promise> { const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex\`, + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + return result.body; + } + +}" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/DefaultsService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class DefaultsService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @param parameterString This is a simple string with default value + * @param parameterNumber This is a simple number with default value + * @param parameterBoolean This is a simple boolean with default value + * @param parameterEnum This is a simple enum with default value + * @param parameterModel This is a simple model with default value + * @throws ApiError + */ + public async callWithDefaultParameters( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, }); return result.body; } /** + * @param parameterString This is a simple string that is optional with default value + * @param parameterNumber This is a simple number that is optional with default value + * @param parameterBoolean This is a simple boolean that is optional with default value + * @param parameterEnum This is a simple enum that is optional with default value + * @param parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public async postCallWithoutParametersAndResponse(): Promise { + public async callWithDefaultOptionalParameters( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise { const result = await this.httpRequest.request({ method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, }); return result.body; } /** + * @param parameterStringWithNoDefault This is a string with no default + * @param parameterOptionalStringWithDefault This is a optional string with default + * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param parameterOptionalStringWithNoDefault This is a optional string with no default + * @param parameterStringWithDefault This is a string with default + * @param parameterStringWithEmptyDefault This is a string with empty default * @throws ApiError */ - public async deleteCallWithoutParametersAndResponse(): Promise { + public async callToTestOrderOfParams( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'Hello World!', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'Hello World!', + parameterStringWithEmptyDefault: string = '', + ): Promise { const result = await this.httpRequest.request({ - method: 'DELETE', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + }, }); return result.body; } +}" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/DuplicateService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class DuplicateService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + /** * @throws ApiError */ - public async optionsCallWithoutParametersAndResponse(): Promise { + public async duplicateName(): Promise { const result = await this.httpRequest.request({ - method: 'OPTIONS', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, }); return result.body; } @@ -2395,10 +2501,10 @@ export class SimpleService { /** * @throws ApiError */ - public async headCallWithoutParametersAndResponse(): Promise { + public async duplicateName1(): Promise { const result = await this.httpRequest.request({ - method: 'HEAD', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, }); return result.body; } @@ -2406,10 +2512,21 @@ export class SimpleService { /** * @throws ApiError */ - public async patchCallWithoutParametersAndResponse(): Promise { + public async duplicateName2(): Promise { const result = await this.httpRequest.request({ - method: 'PATCH', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async duplicateName3(): Promise { + const result = await this.httpRequest.request({ + method: 'DELETE', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, }); return result.body; } @@ -2417,13 +2534,13 @@ export class SimpleService { }" `; -exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/TypesService.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/HeaderService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class TypesService { +export class HeaderService { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -2431,41 +2548,17 @@ export class TypesService { } /** - * @param parameterArray This is an array parameter - * @param parameterDictionary This is a dictionary parameter - * @param parameterEnum This is an enum parameter - * @param parameterNumber This is a number parameter - * @param parameterString This is a string parameter - * @param parameterBoolean This is a boolean parameter - * @param parameterObject This is an object parameter - * @param id This is a number parameter - * @returns number Response is a simple number - * @returns string Response is a simple string - * @returns boolean Response is a simple boolean - * @returns any Response is a simple object + * @returns string Successful response * @throws ApiError */ - public async types( - parameterArray: Array, - parameterDictionary: Record, - parameterEnum: 'Success' | 'Warning' | 'Error', - parameterNumber: number = 123, - parameterString: string = 'default', - parameterBoolean: boolean = true, - parameterObject: any = null, - id?: number, - ): Promise { + public async callWithResultFromHeader(): Promise { const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/types\`, - query: { - 'parameterArray': parameterArray, - 'parameterDictionary': parameterDictionary, - 'parameterEnum': parameterEnum, - 'parameterNumber': parameterNumber, - 'parameterString': parameterString, - 'parameterBoolean': parameterBoolean, - 'parameterObject': parameterObject, + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/header\`, + responseHeader: 'operation-location', + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, }, }); return result.body; @@ -2474,146 +2567,447 @@ export class TypesService { }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/client.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/NoContentService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from './core/BaseHttpRequest'; -import type { OpenAPIConfig } from './core/OpenAPI'; -import { FetchHttpRequest } from './core/FetchHttpRequest'; -import { CollectionFormatService } from './services/CollectionFormatService'; -import { ComplexService } from './services/ComplexService'; -import { DefaultsService } from './services/DefaultsService'; -import { DuplicateService } from './services/DuplicateService'; -import { HeaderService } from './services/HeaderService'; -import { MultipartService } from './services/MultipartService'; -import { NoContentService } from './services/NoContentService'; -import { ParametersService } from './services/ParametersService'; -import { RequestBodyService } from './services/RequestBodyService'; -import { ResponseService } from './services/ResponseService'; -import { SimpleService } from './services/SimpleService'; -import { TypesService } from './services/TypesService'; -import { UploadService } from './services/UploadService'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class TestClient { - readonly collectionformat: CollectionFormatService; - readonly complex: ComplexService; - readonly defaults: DefaultsService; - readonly duplicate: DuplicateService; - readonly header: HeaderService; - readonly multipart: MultipartService; - readonly nocontent: NoContentService; - readonly parameters: ParametersService; - readonly requestbody: RequestBodyService; - readonly response: ResponseService; - readonly simple: SimpleService; - readonly types: TypesService; - readonly upload: UploadService; - readonly request: BaseHttpRequest; +export class NoContentService { + private httpRequest: BaseHttpRequest; - constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { - this.request = new HttpRequest({ - BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', - VERSION: openApiConfig?.VERSION ?? '1.0', - WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, - TOKEN: openApiConfig?.TOKEN, - USERNAME: openApiConfig?.USERNAME, - PASSWORD: openApiConfig?.PASSWORD, - HEADERS: openApiConfig?.HEADERS, + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @returns void + * @throws ApiError + */ + public async callWithNoContentResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/no-content\`, }); - this.collectionformat = new CollectionFormatService(this.request); - this.complex = new ComplexService(this.request); - this.defaults = new DefaultsService(this.request); - this.duplicate = new DuplicateService(this.request); - this.header = new HeaderService(this.request); - this.multipart = new MultipartService(this.request); - this.nocontent = new NoContentService(this.request); - this.parameters = new ParametersService(this.request); - this.requestbody = new RequestBodyService(this.request); - this.response = new ResponseService(this.request); - this.simple = new SimpleService(this.request); - this.types = new TypesService(this.request); - this.upload = new UploadService(this.request); + return result.body; } + }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiError.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ParametersService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ApiResult } from './ApiResult'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: any; +export class ParametersService { + private httpRequest: BaseHttpRequest; - constructor(response: ApiResult, message: string) { - super(message); + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; + /** + * @param parameterHeader This is the parameter that goes into the header + * @param parameterQuery This is the parameter that goes into the query params + * @param parameterForm This is the parameter that goes into the form data + * @param parameterBody This is the parameter that is send as request body + * @param parameterPath This is the parameter that goes into the path + * @throws ApiError + */ + public async callWithParameters( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath: string, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath}\`, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: parameterBody, + }); + return result.body; } -}" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiRequestOptions.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export type ApiRequestOptions = { - readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; - readonly path: string; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}" -`; + /** + * @param parameterHeader This is the parameter that goes into the request header + * @param parameterQuery This is the parameter that goes into the request query params + * @param parameterForm This is the parameter that goes into the request form data + * @param parameterBody This is the parameter that is send as request body + * @param parameterPath1 This is the parameter that goes into the path + * @param parameterPath2 This is the parameter that goes into the path + * @param parameterPath3 This is the parameter that goes into the path + * @param _default This is the parameter with a reserved keyword + * @throws ApiError + */ + public async callWithWeirdParameterNames( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + _default?: string, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'parameter-query': parameterQuery, + 'default': _default, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: parameterBody, + }); + return result.body; + } -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiResult.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export type ApiResult = { - readonly url: string; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly body: any; }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/BaseHttpRequest.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/ResponseService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ApiRequestOptions } from './ApiRequestOptions'; -import type { ApiResult } from './ApiResult'; -import type { OpenAPIConfig } from './OpenAPI'; +import type { ModelThatExtends } from '../models/ModelThatExtends'; +import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class BaseHttpRequest { - readonly openApiConfig: OpenAPIConfig; +export class ResponseService { + private httpRequest: BaseHttpRequest; - constructor(openApiConfig: OpenAPIConfig) { - this.openApiConfig = openApiConfig; + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; } - async request(options: ApiRequestOptions): Promise { - throw new Error('Not Implemented'); + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public async callWithResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + }); + return result.body; + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public async callWithDuplicateResponses(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + return result.body; + } + + /** + * @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 async callWithResponses(): Promise<{ + readonly '@namespace.string'?: string, + readonly '@namespace.integer'?: number, + readonly value?: Array, + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + return result.body; } + }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/FetchHttpRequest.ts 1`] = ` +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/SimpleService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class SimpleService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @throws ApiError + */ + public async getCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async putCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async postCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async deleteCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'DELETE', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async optionsCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'OPTIONS', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async headCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'HEAD', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async patchCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PATCH', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + +}" +`; + +exports[`v2 should generate with exportClient: ./test/generated/v2_client/services/TypesService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class TypesService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @param parameterArray This is an array parameter + * @param parameterDictionary This is a dictionary parameter + * @param parameterEnum This is an enum parameter + * @param parameterNumber This is a number parameter + * @param parameterString This is a string parameter + * @param parameterBoolean This is a boolean parameter + * @param parameterObject This is an object parameter + * @param id This is a number parameter + * @returns number Response is a simple number + * @returns string Response is a simple string + * @returns boolean Response is a simple boolean + * @returns any Response is a simple object + * @throws ApiError + */ + public async types( + parameterArray: Array, + parameterDictionary: Record, + parameterEnum: 'Success' | 'Warning' | 'Error', + parameterNumber: number = 123, + parameterString: string = 'default', + parameterBoolean: boolean = true, + parameterObject: any = null, + id?: number, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/types\`, + query: { + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, + }, + }); + return result.body; + } + +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/client.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; +import { Service } from './services/Service'; + +export class TestClient extends Service { + readonly request: BaseHttpRequest; + + constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { + const request = new HttpRequest({ + BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', + VERSION: openApiConfig?.VERSION ?? '1.0', + WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, + TOKEN: openApiConfig?.TOKEN, + USERNAME: openApiConfig?.USERNAME, + PASSWORD: openApiConfig?.PASSWORD, + HEADERS: openApiConfig?.HEADERS, + }); + super(request); + this.request = request; + } +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/ApiError.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +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: any; + + constructor(response: ApiResult, message: string) { + super(message); + + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + } +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/ApiRequestOptions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly path: string; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/ApiResult.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/BaseHttpRequest.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; + +export class BaseHttpRequest { + readonly openApiConfig: OpenAPIConfig; + + constructor(openApiConfig: OpenAPIConfig) { + this.openApiConfig = openApiConfig; + } + + async request(options: ApiRequestOptions): Promise { + throw new Error('Not Implemented'); + } +}" +`; + +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/FetchHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -2833,7 +3227,7 @@ export class FetchHttpRequest extends BaseHttpRequest { " `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/OpenAPI.ts 1`] = ` +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -2854,7 +3248,7 @@ export type OpenAPIConfig = { " `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/index.ts 1`] = ` +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ @@ -2865,1962 +3259,3240 @@ export type { OpenAPIConfig } from './core/OpenAPI'; export { BaseHttpRequest } from './core/BaseHttpRequest'; export { FetchHttpRequest } from './core/FetchHttpRequest'; -export type { ArrayWithArray } from './models/ArrayWithArray'; -export type { ArrayWithBooleans } from './models/ArrayWithBooleans'; -export type { ArrayWithNumbers } from './models/ArrayWithNumbers'; -export type { ArrayWithProperties } from './models/ArrayWithProperties'; -export type { ArrayWithReferences } from './models/ArrayWithReferences'; -export type { ArrayWithStrings } from './models/ArrayWithStrings'; -export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAllOfAndNullable'; -export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf'; -export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable'; -export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous'; -export type { CompositionWithOneOf } from './models/CompositionWithOneOf'; -export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable'; -export type { CompositionWithOneOfAnonymous } from './models/CompositionWithOneOfAnonymous'; -export type { DictionaryWithArray } from './models/DictionaryWithArray'; -export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary'; -export type { DictionaryWithProperties } from './models/DictionaryWithProperties'; -export type { DictionaryWithReference } from './models/DictionaryWithReference'; -export type { DictionaryWithString } from './models/DictionaryWithString'; -export { EnumFromDescription } from './models/EnumFromDescription'; -export { EnumWithExtensions } from './models/EnumWithExtensions'; -export { EnumWithNumbers } from './models/EnumWithNumbers'; -export { EnumWithStrings } from './models/EnumWithStrings'; -export type { ModelThatExtends } from './models/ModelThatExtends'; -export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; -export type { ModelWithArray } from './models/ModelWithArray'; -export type { ModelWithBoolean } from './models/ModelWithBoolean'; -export type { ModelWithCircularReference } from './models/ModelWithCircularReference'; -export type { ModelWithDictionary } from './models/ModelWithDictionary'; -export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports'; -export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties'; -export { ModelWithEnum } from './models/ModelWithEnum'; -export { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription'; -export type { ModelWithInteger } from './models/ModelWithInteger'; -export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums'; -export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties'; -export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties'; -export type { ModelWithPattern } from './models/ModelWithPattern'; -export type { ModelWithProperties } from './models/ModelWithProperties'; -export type { ModelWithReference } from './models/ModelWithReference'; -export type { ModelWithString } from './models/ModelWithString'; -export type { MultilineComment } from './models/MultilineComment'; -export type { SimpleBoolean } from './models/SimpleBoolean'; -export type { SimpleFile } from './models/SimpleFile'; -export type { SimpleInteger } from './models/SimpleInteger'; -export type { SimpleReference } from './models/SimpleReference'; -export type { SimpleString } from './models/SimpleString'; -export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern'; - -export { $ArrayWithArray } from './schemas/$ArrayWithArray'; -export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans'; -export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers'; -export { $ArrayWithProperties } from './schemas/$ArrayWithProperties'; -export { $ArrayWithReferences } from './schemas/$ArrayWithReferences'; -export { $ArrayWithStrings } from './schemas/$ArrayWithStrings'; -export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllOfAndNullable'; -export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf'; -export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable'; -export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous'; -export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf'; -export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable'; -export { $CompositionWithOneOfAnonymous } from './schemas/$CompositionWithOneOfAnonymous'; -export { $DictionaryWithArray } from './schemas/$DictionaryWithArray'; -export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary'; -export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties'; -export { $DictionaryWithReference } from './schemas/$DictionaryWithReference'; -export { $DictionaryWithString } from './schemas/$DictionaryWithString'; -export { $EnumFromDescription } from './schemas/$EnumFromDescription'; -export { $EnumWithExtensions } from './schemas/$EnumWithExtensions'; -export { $EnumWithNumbers } from './schemas/$EnumWithNumbers'; -export { $EnumWithStrings } from './schemas/$EnumWithStrings'; -export { $ModelThatExtends } from './schemas/$ModelThatExtends'; -export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; -export { $ModelWithArray } from './schemas/$ModelWithArray'; -export { $ModelWithBoolean } from './schemas/$ModelWithBoolean'; -export { $ModelWithCircularReference } from './schemas/$ModelWithCircularReference'; -export { $ModelWithDictionary } from './schemas/$ModelWithDictionary'; -export { $ModelWithDuplicateImports } from './schemas/$ModelWithDuplicateImports'; -export { $ModelWithDuplicateProperties } from './schemas/$ModelWithDuplicateProperties'; -export { $ModelWithEnum } from './schemas/$ModelWithEnum'; -export { $ModelWithEnumFromDescription } from './schemas/$ModelWithEnumFromDescription'; -export { $ModelWithInteger } from './schemas/$ModelWithInteger'; -export { $ModelWithNestedEnums } from './schemas/$ModelWithNestedEnums'; -export { $ModelWithNestedProperties } from './schemas/$ModelWithNestedProperties'; -export { $ModelWithOrderedProperties } from './schemas/$ModelWithOrderedProperties'; -export { $ModelWithPattern } from './schemas/$ModelWithPattern'; -export { $ModelWithProperties } from './schemas/$ModelWithProperties'; -export { $ModelWithReference } from './schemas/$ModelWithReference'; -export { $ModelWithString } from './schemas/$ModelWithString'; -export { $MultilineComment } from './schemas/$MultilineComment'; -export { $SimpleBoolean } from './schemas/$SimpleBoolean'; -export { $SimpleFile } from './schemas/$SimpleFile'; -export { $SimpleInteger } from './schemas/$SimpleInteger'; -export { $SimpleReference } from './schemas/$SimpleReference'; -export { $SimpleString } from './schemas/$SimpleString'; -export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern'; - -export { CollectionFormatService } from './services/CollectionFormatService'; -export { ComplexService } from './services/ComplexService'; -export { DefaultsService } from './services/DefaultsService'; -export { DuplicateService } from './services/DuplicateService'; -export { HeaderService } from './services/HeaderService'; -export { MultipartService } from './services/MultipartService'; -export { NoContentService } from './services/NoContentService'; -export { ParametersService } from './services/ParametersService'; -export { RequestBodyService } from './services/RequestBodyService'; -export { ResponseService } from './services/ResponseService'; -export { SimpleService } from './services/SimpleService'; -export { TypesService } from './services/TypesService'; -export { UploadService } from './services/UploadService'; +export { Service } from './services/Service'; export { TestClient } from './client'; " `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithArray.ts 1`] = ` +exports[`v2 should generate with no tags: ./test/generated/v2_client_no_tags/services/Service.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; -import type { ModelWithString } from './ModelWithString'; +export class Service { + private httpRequest: BaseHttpRequest; -/** - * This is a simple array containing an array - */ -export type ArrayWithArray = Array>;" + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @throws ApiError + */ + public async getCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async putCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async postCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithBooleans.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/client.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; +import { SimpleService } from './services/SimpleService'; +import { Service } from './services/Service'; -/** - * This is a simple array with booleans - */ -export type ArrayWithBooleans = Array;" +export class TestClient extends Service { + readonly simple: SimpleService; + readonly request: BaseHttpRequest; + + constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { + const request = new HttpRequest({ + BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', + VERSION: openApiConfig?.VERSION ?? '1.0', + WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, + TOKEN: openApiConfig?.TOKEN, + USERNAME: openApiConfig?.USERNAME, + PASSWORD: openApiConfig?.PASSWORD, + HEADERS: openApiConfig?.HEADERS, + }); + super(request); + this.request = request; + this.simple = new SimpleService(this.request); + } +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithNumbers.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/ApiError.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiResult } from './ApiResult'; -/** - * This is a simple array with numbers - */ -export type ArrayWithNumbers = Array;" +export class ApiError extends Error { + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; + + constructor(response: ApiResult, message: string) { + super(message); + + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + } +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithProperties.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/ApiRequestOptions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -/** - * This is a simple array with properties - */ -export type ArrayWithProperties = Array<{ - foo?: string, - bar?: string, -}>;" +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly path: string; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithReferences.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a simple array with references - */ -export type ArrayWithReferences = Array;" +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithStrings.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/BaseHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; -/** - * This is a simple array with strings - */ -export type ArrayWithStrings = Array;" +export class BaseHttpRequest { + readonly openApiConfig: OpenAPIConfig; + + constructor(openApiConfig: OpenAPIConfig) { + this.openApiConfig = openApiConfig; + } + + async request(options: ApiRequestOptions): Promise { + throw new Error('Not Implemented'); + } +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAllOfAndNullable.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/FetchHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; +import { BaseHttpRequest } from './BaseHttpRequest'; -import type { ModelWithArray } from './ModelWithArray'; -import type { ModelWithDictionary } from './ModelWithDictionary'; -import type { ModelWithEnum } from './ModelWithEnum'; +function isDefined(value: T | null | undefined): value is Exclude { + return value !== undefined && value !== null; +} -/** - * This is a model with one property with a 'all of' relationship - */ -export type CompositionWithAllOfAndNullable = { - propA?: ({ - boolean?: boolean, - } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +function isString(value: any): value is string { + return typeof value === 'string'; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOf.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function isStringWithValue(value: any): value is string { + return isString(value) && value !== ''; +} -import type { ModelWithArray } from './ModelWithArray'; -import type { ModelWithDictionary } from './ModelWithDictionary'; -import type { ModelWithEnum } from './ModelWithEnum'; -import type { ModelWithString } from './ModelWithString'; +function isBlob(value: any): value is Blob { + return value instanceof Blob; +} -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOf = { - propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); +function getQueryString(params: Record): string { + const qs: string[] = []; + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + if (Array.isArray(value)) { + value.forEach(value => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }); + } else { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + } + } + }); + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; + } + return ''; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOfAndNullable.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getUrl(options: ApiRequestOptions, config: OpenAPIConfig): string { + const path = options.path.replace(/[:]/g, '_'); + const url = \`\${config.BASE}\${path}\`; -import type { ModelWithArray } from './ModelWithArray'; -import type { ModelWithDictionary } from './ModelWithDictionary'; -import type { ModelWithEnum } from './ModelWithEnum'; + if (options.query) { + return \`\${url}\${getQueryString(options.query)}\`; + } + return url; +} -/** - * This is a model with one property with a 'any of' relationship - */ -export type CompositionWithAnyOfAndNullable = { - propA?: ({ - boolean?: boolean, - } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null; +function getFormData(params: Record): FormData { + const formData = new FormData(); + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + formData.append(key, value); + } + }); + return formData; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOfAnonymous.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +type Resolver = (options: ApiRequestOptions) => Promise; -/** - * This is a model with one property with a 'any of' relationship where the options are not $ref - */ -export type CompositionWithAnyOfAnonymous = { - propA?: ({ - propA?: any, - } | string | number); +async function resolve(options: ApiRequestOptions, resolver?: T | Resolver): Promise { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; } -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOf.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { ModelWithArray } from './ModelWithArray'; -import type { ModelWithDictionary } from './ModelWithDictionary'; -import type { ModelWithEnum } from './ModelWithEnum'; -import type { ModelWithString } from './ModelWithString'; +async function getHeaders(options: ApiRequestOptions, config: OpenAPIConfig): Promise { + const token = await resolve(options, config.TOKEN); + const username = await resolve(options, config.USERNAME); + const password = await resolve(options, config.PASSWORD); + const defaultHeaders = await resolve(options, config.HEADERS); -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOf = { - propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); -} -" -`; + const headers = new Headers({ + Accept: 'application/json', + ...defaultHeaders, + ...options.headers, + }); -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOfAndNullable.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + if (isStringWithValue(token)) { + headers.append('Authorization', \`Bearer \${token}\`); + } -import type { ModelWithArray } from './ModelWithArray'; -import type { ModelWithDictionary } from './ModelWithDictionary'; -import type { ModelWithEnum } from './ModelWithEnum'; + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = btoa(\`\${username}:\${password}\`); + headers.append('Authorization', \`Basic \${credentials}\`); + } -/** - * This is a model with one property with a 'one of' relationship - */ -export type CompositionWithOneOfAndNullable = { - propA?: ({ - boolean?: boolean, - } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null; + if (options.body) { + if (options.mediaType) { + headers.append('Content-Type', options.mediaType); + } else if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } + } + return headers; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOfAnonymous.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { + if (options.formData) { + return getFormData(options.formData); + } + if (options.body) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; +} -/** - * This is a model with one property with a 'one of' relationship where the options are not $ref - */ -export type CompositionWithOneOfAnonymous = { - propA?: ({ - propA?: any, - } | string | number); +async function sendRequest(options: ApiRequestOptions, config: OpenAPIConfig, url: string): Promise { + const request: RequestInit = { + method: options.method, + headers: await getHeaders(options, config), + body: getRequestBody(options), + }; + if (config.WITH_CREDENTIALS) { + request.credentials = 'include'; + } + return await fetch(url, request); } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithArray.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getResponseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return null; +} -import type { ModelWithString } from './ModelWithString'; +async function getResponseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const isJSON = contentType.toLowerCase().startsWith('application/json'); + if (isJSON) { + return await response.json(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + return null; +} -/** - * This is a complex dictionary - */ -export type DictionaryWithArray = Record>;" -`; +function catchErrors(options: ApiRequestOptions, result: ApiResult): void { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 500: 'Internal Server Error', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + ...options.errors, + } -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithDictionary.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + const error = errors[result.status]; + if (error) { + throw new ApiError(result, error); + } -/** - * This is a string dictionary - */ -export type DictionaryWithDictionary = Record>;" -`; + if (!result.ok) { + throw new ApiError(result, 'Generic Error'); + } +} -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +export class FetchHttpRequest extends BaseHttpRequest { + constructor(openApiConfig: OpenAPIConfig) { + super(openApiConfig); + } -/** - * This is a complex dictionary - */ -export type DictionaryWithProperties = Record;" + /** + * Request using fetch client + * @param options The request options from the the service + * @returns ApiResult + * @throws ApiError + */ + async request(options: ApiRequestOptions): Promise { + const url = getUrl(options, this.openApiConfig); + const response = await sendRequest(options, this.openApiConfig, url); + 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, + }; + + catchErrors(options, result); + return result; + } +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithReference.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; -import type { ModelWithString } from './ModelWithString'; +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; -/** - * This is a string reference - */ -export type DictionaryWithReference = Record;" +export type OpenAPIConfig = { + BASE?: string; + VERSION?: string; + WITH_CREDENTIALS?: boolean; + TOKEN?: string | Resolver; + USERNAME?: string | Resolver; + PASSWORD?: string | Resolver; + HEADERS?: Headers | Resolver; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithString.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +export { ApiError } from './core/ApiError'; +export type { ApiRequestOptions } from './core/ApiRequestOptions'; +export type { ApiResult } from './core/ApiResult'; +export type { OpenAPIConfig } from './core/OpenAPI'; +export { BaseHttpRequest } from './core/BaseHttpRequest'; +export { FetchHttpRequest } from './core/FetchHttpRequest'; -/** - * This is a string dictionary - */ -export type DictionaryWithString = Record;" +export { Service } from './services/Service'; +export { SimpleService } from './services/SimpleService'; + +export { TestClient } from './client'; +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumFromDescription.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/services/Service.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class Service { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @throws ApiError + */ + public async postCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } -/** - * Success=1,Warning=2,Error=3 - */ -export enum EnumFromDescription { - SUCCESS = 1, - WARNING = 2, - ERROR = 3, }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithExtensions.ts 1`] = ` +exports[`v3 should generate with combined tags: ./test/generated/v3_client_tags_combined/services/SimpleService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class SimpleService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } -/** - * This is a simple enum with numbers - */ -export enum EnumWithExtensions { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS = 200, /** - * Used when the status of something has a warning + * @throws ApiError */ - CUSTOM_WARNING = 400, + public async getCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + /** - * Used when the status of something has an error + * @throws ApiError */ - CUSTOM_ERROR = 500, + public async putCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithNumbers.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/client.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; +import { CollectionFormatService } from './services/CollectionFormatService'; +import { ComplexService } from './services/ComplexService'; +import { DefaultsService } from './services/DefaultsService'; +import { DuplicateService } from './services/DuplicateService'; +import { HeaderService } from './services/HeaderService'; +import { MultipartService } from './services/MultipartService'; +import { NoContentService } from './services/NoContentService'; +import { ParametersService } from './services/ParametersService'; +import { RequestBodyService } from './services/RequestBodyService'; +import { ResponseService } from './services/ResponseService'; +import { SimpleService } from './services/SimpleService'; +import { TypesService } from './services/TypesService'; +import { UploadService } from './services/UploadService'; -/** - * This is a simple enum with numbers - */ -export enum EnumWithNumbers { - '_1' = 1, - '_2' = 2, - '_3' = 3, - '_1.1' = 1.1, - '_1.2' = 1.2, - '_1.3' = 1.3, - '_100' = 100, - '_200' = 200, - '_300' = 300, - '_-100' = -100, - '_-200' = -200, - '_-300' = -300, - '_-1.1' = -1.1, - '_-1.2' = -1.2, - '_-1.3' = -1.3, +export class TestClient { + readonly collectionformat: CollectionFormatService; + readonly complex: ComplexService; + readonly defaults: DefaultsService; + readonly duplicate: DuplicateService; + readonly header: HeaderService; + readonly multipart: MultipartService; + readonly nocontent: NoContentService; + readonly parameters: ParametersService; + readonly requestbody: RequestBodyService; + readonly response: ResponseService; + readonly simple: SimpleService; + readonly types: TypesService; + readonly upload: UploadService; + readonly request: BaseHttpRequest; + + constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { + this.request = new HttpRequest({ + BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', + VERSION: openApiConfig?.VERSION ?? '1.0', + WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, + TOKEN: openApiConfig?.TOKEN, + USERNAME: openApiConfig?.USERNAME, + PASSWORD: openApiConfig?.PASSWORD, + HEADERS: openApiConfig?.HEADERS, + }); + this.collectionformat = new CollectionFormatService(this.request); + this.complex = new ComplexService(this.request); + this.defaults = new DefaultsService(this.request); + this.duplicate = new DuplicateService(this.request); + this.header = new HeaderService(this.request); + this.multipart = new MultipartService(this.request); + this.nocontent = new NoContentService(this.request); + this.parameters = new ParametersService(this.request); + this.requestbody = new RequestBodyService(this.request); + this.response = new ResponseService(this.request); + this.simple = new SimpleService(this.request); + this.types = new TypesService(this.request); + this.upload = new UploadService(this.request); + } }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithStrings.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiError.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiResult } from './ApiResult'; -/** - * This is a simple enum with strings - */ -export enum EnumWithStrings { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', +export class ApiError extends Error { + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; + + constructor(response: ApiResult, message: string) { + super(message); + + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + } }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelThatExtends.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiRequestOptions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a model that extends another model - */ -export type ModelThatExtends = (ModelWithString & { - propExtendsA?: string, - propExtendsB?: ModelWithString, -}); -" +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly path: string; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelThatExtendsExtends.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ - -import type { ModelThatExtends } from './ModelThatExtends'; -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a model that extends another model - */ -export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & { - propExtendsC?: string, - propExtendsD?: ModelWithString, -}); -" +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithArray.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/BaseHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; -import type { ModelWithString } from './ModelWithString'; - -/** - * This is a model with one property containing an array - */ -export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; -} -" -`; +export class BaseHttpRequest { + readonly openApiConfig: OpenAPIConfig; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithBoolean.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + constructor(openApiConfig: OpenAPIConfig) { + this.openApiConfig = openApiConfig; + } -/** - * This is a model with one boolean property - */ -export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; -} -" + async request(options: ApiRequestOptions): Promise { + throw new Error('Not Implemented'); + } +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithCircularReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/FetchHttpRequest.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; +import { BaseHttpRequest } from './BaseHttpRequest'; -/** - * This is a model with one property containing a circular reference - */ -export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; +function isDefined(value: T | null | undefined): value is Exclude { + return value !== undefined && value !== null; } -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDictionary.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -/** - * This is a model with one property containing a dictionary - */ -export type ModelWithDictionary = { - prop?: Record; +function isString(value: any): value is string { + return typeof value === 'string'; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDuplicateImports.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function isStringWithValue(value: any): value is string { + return isString(value) && value !== ''; +} -import type { ModelWithString } from './ModelWithString'; +function isBlob(value: any): value is Blob { + return value instanceof Blob; +} -/** - * This is a model with duplicated imports - */ -export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; +function getQueryString(params: Record): string { + const qs: string[] = []; + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + if (Array.isArray(value)) { + value.forEach(value => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }); + } else { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + } + } + }); + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; + } + return ''; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDuplicateProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +function getUrl(options: ApiRequestOptions, config: OpenAPIConfig): string { + const path = options.path.replace(/[:]/g, '_'); + const url = \`\${config.BASE}\${path}\`; -import type { ModelWithString } from './ModelWithString'; + if (options.query) { + return \`\${url}\${getQueryString(options.query)}\`; + } + return url; +} -/** - * This is a model with duplicated properties - */ -export type ModelWithDuplicateProperties = { - prop?: ModelWithString; +function getFormData(params: Record): FormData { + const formData = new FormData(); + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + formData.append(key, value); + } + }); + return formData; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithEnum.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +type Resolver = (options: ApiRequestOptions) => Promise; -/** - * This is a model with one enum - */ -export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - test?: ModelWithEnum.test; - /** - * These are the HTTP error code enums - */ - statusCode?: ModelWithEnum.statusCode; - /** - * Simple boolean enum - */ - bool?: boolean; +async function resolve(options: ApiRequestOptions, resolver?: T | Resolver): Promise { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; } -export namespace ModelWithEnum { +async function getHeaders(options: ApiRequestOptions, config: OpenAPIConfig): Promise { + const token = await resolve(options, config.TOKEN); + const username = await resolve(options, config.USERNAME); + const password = await resolve(options, config.PASSWORD); + const defaultHeaders = await resolve(options, config.HEADERS); - /** - * This is a simple enum with strings - */ - export enum test { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', - } + const headers = new Headers({ + Accept: 'application/json', + ...defaultHeaders, + ...options.headers, + }); - /** - * These are the HTTP error code enums - */ - export enum statusCode { - _100 = '100', - _200_FOO = '200 FOO', - _300_FOO_BAR = '300 FOO_BAR', - _400_FOO_BAR = '400 foo-bar', - _500_FOO_BAR = '500 foo.bar', - _600_FOO_BAR = '600 foo&bar', + if (isStringWithValue(token)) { + headers.append('Authorization', \`Bearer \${token}\`); } + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = btoa(\`\${username}:\${password}\`); + headers.append('Authorization', \`Basic \${credentials}\`); + } + if (options.body) { + if (options.mediaType) { + headers.append('Content-Type', options.mediaType); + } else if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } + } + return headers; } -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithEnumFromDescription.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -/** - * This is a model with one enum - */ -export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: ModelWithEnumFromDescription.test; +function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { + if (options.formData) { + return getFormData(options.formData); + } + if (options.body) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; } -export namespace ModelWithEnumFromDescription { - - /** - * Success=1,Warning=2,Error=3 - */ - export enum test { - SUCCESS = 1, - WARNING = 2, - ERROR = 3, +async function sendRequest(options: ApiRequestOptions, config: OpenAPIConfig, url: string): Promise { + const request: RequestInit = { + method: options.method, + headers: await getHeaders(options, config), + body: getRequestBody(options), + }; + if (config.WITH_CREDENTIALS) { + request.credentials = 'include'; } - - + return await fetch(url, request); } -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithInteger.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -/** - * This is a model with one number property - */ -export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; +function getResponseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return null; } -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithNestedEnums.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -/** - * This is a model with nested enums - */ -export type ModelWithNestedEnums = { - dictionaryWithEnum?: Record; - dictionaryWithEnumFromDescription?: Record; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array<1 | 2 | 3>; +async function getResponseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const isJSON = contentType.toLowerCase().startsWith('application/json'); + if (isJSON) { + return await response.json(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + return null; } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithNestedProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ - -/** - * This is a model with one nested property - */ -export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null, - } | null, - } | null; -} -" -`; +function catchErrors(options: ApiRequestOptions, result: ApiResult): void { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 500: 'Internal Server Error', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + ...options.errors, + } -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithOrderedProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + const error = errors[result.status]; + if (error) { + throw new ApiError(result, error); + } -/** - * This is a model with ordered properties - */ -export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + if (!result.ok) { + throw new ApiError(result, 'Generic Error'); + } } -" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithPattern.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ - -/** - * 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; -} -" -`; +export class FetchHttpRequest extends BaseHttpRequest { + constructor(openApiConfig: OpenAPIConfig) { + super(openApiConfig); + } -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ + /** + * Request using fetch client + * @param options The request options from the the service + * @returns ApiResult + * @throws ApiError + */ + async request(options: ApiRequestOptions): Promise { + const url = getUrl(options, this.openApiConfig); + const response = await sendRequest(options, this.openApiConfig, url); + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); -import type { ModelWithString } from './ModelWithString'; + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader || responseBody, + }; -/** - * 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; + catchErrors(options, result); + return result; + } } " `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; -import type { ModelWithProperties } from './ModelWithProperties'; - -/** - * This is a model with one property containing a reference - */ -export type ModelWithReference = { - prop?: ModelWithProperties; -} -" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithString.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; -/** - * This is a model with one string property - */ -export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; +export type OpenAPIConfig = { + BASE?: string; + VERSION?: string; + WITH_CREDENTIALS?: boolean; + TOKEN?: string | Resolver; + USERNAME?: string | Resolver; + PASSWORD?: string | Resolver; + HEADERS?: Headers | Resolver; } " `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/MultilineComment.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +export { ApiError } from './core/ApiError'; +export type { ApiRequestOptions } from './core/ApiRequestOptions'; +export type { ApiResult } from './core/ApiResult'; +export type { OpenAPIConfig } from './core/OpenAPI'; +export { BaseHttpRequest } from './core/BaseHttpRequest'; +export { FetchHttpRequest } from './core/FetchHttpRequest'; -/** - * Testing multiline comments. - * This must go to the next line. - * - * This will contain a break. - */ -export type MultilineComment = number;" +export type { ArrayWithArray } from './models/ArrayWithArray'; +export type { ArrayWithBooleans } from './models/ArrayWithBooleans'; +export type { ArrayWithNumbers } from './models/ArrayWithNumbers'; +export type { ArrayWithProperties } from './models/ArrayWithProperties'; +export type { ArrayWithReferences } from './models/ArrayWithReferences'; +export type { ArrayWithStrings } from './models/ArrayWithStrings'; +export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAllOfAndNullable'; +export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf'; +export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable'; +export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous'; +export type { CompositionWithOneOf } from './models/CompositionWithOneOf'; +export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable'; +export type { CompositionWithOneOfAnonymous } from './models/CompositionWithOneOfAnonymous'; +export type { DictionaryWithArray } from './models/DictionaryWithArray'; +export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary'; +export type { DictionaryWithProperties } from './models/DictionaryWithProperties'; +export type { DictionaryWithReference } from './models/DictionaryWithReference'; +export type { DictionaryWithString } from './models/DictionaryWithString'; +export { EnumFromDescription } from './models/EnumFromDescription'; +export { EnumWithExtensions } from './models/EnumWithExtensions'; +export { EnumWithNumbers } from './models/EnumWithNumbers'; +export { EnumWithStrings } from './models/EnumWithStrings'; +export type { ModelThatExtends } from './models/ModelThatExtends'; +export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; +export type { ModelWithArray } from './models/ModelWithArray'; +export type { ModelWithBoolean } from './models/ModelWithBoolean'; +export type { ModelWithCircularReference } from './models/ModelWithCircularReference'; +export type { ModelWithDictionary } from './models/ModelWithDictionary'; +export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports'; +export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties'; +export { ModelWithEnum } from './models/ModelWithEnum'; +export { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription'; +export type { ModelWithInteger } from './models/ModelWithInteger'; +export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums'; +export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties'; +export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties'; +export type { ModelWithPattern } from './models/ModelWithPattern'; +export type { ModelWithProperties } from './models/ModelWithProperties'; +export type { ModelWithReference } from './models/ModelWithReference'; +export type { ModelWithString } from './models/ModelWithString'; +export type { MultilineComment } from './models/MultilineComment'; +export type { SimpleBoolean } from './models/SimpleBoolean'; +export type { SimpleFile } from './models/SimpleFile'; +export type { SimpleInteger } from './models/SimpleInteger'; +export type { SimpleReference } from './models/SimpleReference'; +export type { SimpleString } from './models/SimpleString'; +export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern'; + +export { $ArrayWithArray } from './schemas/$ArrayWithArray'; +export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans'; +export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers'; +export { $ArrayWithProperties } from './schemas/$ArrayWithProperties'; +export { $ArrayWithReferences } from './schemas/$ArrayWithReferences'; +export { $ArrayWithStrings } from './schemas/$ArrayWithStrings'; +export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllOfAndNullable'; +export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf'; +export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable'; +export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous'; +export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf'; +export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable'; +export { $CompositionWithOneOfAnonymous } from './schemas/$CompositionWithOneOfAnonymous'; +export { $DictionaryWithArray } from './schemas/$DictionaryWithArray'; +export { $DictionaryWithDictionary } from './schemas/$DictionaryWithDictionary'; +export { $DictionaryWithProperties } from './schemas/$DictionaryWithProperties'; +export { $DictionaryWithReference } from './schemas/$DictionaryWithReference'; +export { $DictionaryWithString } from './schemas/$DictionaryWithString'; +export { $EnumFromDescription } from './schemas/$EnumFromDescription'; +export { $EnumWithExtensions } from './schemas/$EnumWithExtensions'; +export { $EnumWithNumbers } from './schemas/$EnumWithNumbers'; +export { $EnumWithStrings } from './schemas/$EnumWithStrings'; +export { $ModelThatExtends } from './schemas/$ModelThatExtends'; +export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; +export { $ModelWithArray } from './schemas/$ModelWithArray'; +export { $ModelWithBoolean } from './schemas/$ModelWithBoolean'; +export { $ModelWithCircularReference } from './schemas/$ModelWithCircularReference'; +export { $ModelWithDictionary } from './schemas/$ModelWithDictionary'; +export { $ModelWithDuplicateImports } from './schemas/$ModelWithDuplicateImports'; +export { $ModelWithDuplicateProperties } from './schemas/$ModelWithDuplicateProperties'; +export { $ModelWithEnum } from './schemas/$ModelWithEnum'; +export { $ModelWithEnumFromDescription } from './schemas/$ModelWithEnumFromDescription'; +export { $ModelWithInteger } from './schemas/$ModelWithInteger'; +export { $ModelWithNestedEnums } from './schemas/$ModelWithNestedEnums'; +export { $ModelWithNestedProperties } from './schemas/$ModelWithNestedProperties'; +export { $ModelWithOrderedProperties } from './schemas/$ModelWithOrderedProperties'; +export { $ModelWithPattern } from './schemas/$ModelWithPattern'; +export { $ModelWithProperties } from './schemas/$ModelWithProperties'; +export { $ModelWithReference } from './schemas/$ModelWithReference'; +export { $ModelWithString } from './schemas/$ModelWithString'; +export { $MultilineComment } from './schemas/$MultilineComment'; +export { $SimpleBoolean } from './schemas/$SimpleBoolean'; +export { $SimpleFile } from './schemas/$SimpleFile'; +export { $SimpleInteger } from './schemas/$SimpleInteger'; +export { $SimpleReference } from './schemas/$SimpleReference'; +export { $SimpleString } from './schemas/$SimpleString'; +export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern'; + +export { CollectionFormatService } from './services/CollectionFormatService'; +export { ComplexService } from './services/ComplexService'; +export { DefaultsService } from './services/DefaultsService'; +export { DuplicateService } from './services/DuplicateService'; +export { HeaderService } from './services/HeaderService'; +export { MultipartService } from './services/MultipartService'; +export { NoContentService } from './services/NoContentService'; +export { ParametersService } from './services/ParametersService'; +export { RequestBodyService } from './services/RequestBodyService'; +export { ResponseService } from './services/ResponseService'; +export { SimpleService } from './services/SimpleService'; +export { TypesService } from './services/TypesService'; +export { UploadService } from './services/UploadService'; + +export { TestClient } from './client'; +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleBoolean.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * This is a simple boolean + * This is a simple array containing an array */ -export type SimpleBoolean = boolean;" +export type ArrayWithArray = Array>;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleFile.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithBooleans.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple file + * This is a simple array with booleans */ -export type SimpleFile = Blob;" +export type ArrayWithBooleans = Array;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleInteger.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple number + * This is a simple array with numbers */ -export type SimpleInteger = number;" +export type ArrayWithNumbers = Array;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from './ModelWithString'; - /** - * This is a simple reference + * This is a simple array with properties */ -export type SimpleReference = ModelWithString;" +export type ArrayWithProperties = Array<{ + foo?: string, + bar?: string, +}>;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleString.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithReferences.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ModelWithString } from './ModelWithString'; + /** - * This is a simple string + * This is a simple array with references */ -export type SimpleString = string;" +export type ArrayWithReferences = Array;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleStringWithPattern.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ArrayWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ /** - * This is a simple string + * This is a simple array with strings */ -export type SimpleStringWithPattern = string | null;" +export type ArrayWithStrings = Array;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithArray.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAllOfAndNullable.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithArray = { - type: 'array', - contains: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, -};" + +import type { ModelWithArray } from './ModelWithArray'; +import type { ModelWithDictionary } from './ModelWithDictionary'; +import type { ModelWithEnum } from './ModelWithEnum'; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean, + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithBooleans.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOf.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithBooleans = { - type: 'array', - contains: { - type: 'boolean', - }, -};" + +import type { ModelWithArray } from './ModelWithArray'; +import type { ModelWithDictionary } from './ModelWithDictionary'; +import type { ModelWithEnum } from './ModelWithEnum'; +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithNumbers.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOfAndNullable.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithNumbers = { - type: 'array', - contains: { - type: 'number', - }, -};" + +import type { ModelWithArray } from './ModelWithArray'; +import type { ModelWithDictionary } from './ModelWithDictionary'; +import type { ModelWithEnum } from './ModelWithEnum'; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: ({ + boolean?: boolean, + } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithProperties.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithAnyOfAnonymous.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithProperties = { - type: 'array', - contains: { - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, -};" + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: ({ + propA?: any, + } | string | number); +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithReferences.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOf.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ArrayWithReferences = { - type: 'array', - contains: { - type: 'ModelWithString', - }, -};" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithStrings.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export const $ArrayWithStrings = { - type: 'array', - contains: { - type: 'string', - }, -};" +import type { ModelWithArray } from './ModelWithArray'; +import type { ModelWithDictionary } from './ModelWithDictionary'; +import type { ModelWithEnum } from './ModelWithEnum'; +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAllOfAndNullable.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOfAndNullable.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithAllOfAndNullable = { - properties: { - propA: { - type: 'all-of', - contains: [{ - properties: { - boolean: { - type: 'boolean', - }, - }, - }, { - type: 'ModelWithEnum', - }, { - type: 'ModelWithArray', - }, { - type: 'ModelWithDictionary', - }], - isNullable: true, - }, - }, -};" + +import type { ModelWithArray } from './ModelWithArray'; +import type { ModelWithDictionary } from './ModelWithDictionary'; +import type { ModelWithEnum } from './ModelWithEnum'; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: ({ + boolean?: boolean, + } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOf.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/CompositionWithOneOfAnonymous.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithAnyOf = { - properties: { - propA: { - type: 'any-of', - contains: [{ - type: 'ModelWithString', - }, { - type: 'ModelWithEnum', - }, { - type: 'ModelWithArray', - }, { - type: 'ModelWithDictionary', - }], - }, - }, -};" + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: ({ + propA?: any, + } | string | number); +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOfAndNullable.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithAnyOfAndNullable = { - properties: { - propA: { - type: 'any-of', - contains: [{ - properties: { - boolean: { - type: 'boolean', - }, - }, - }, { - type: 'ModelWithEnum', - }, { - type: 'ModelWithArray', - }, { - type: 'ModelWithDictionary', - }], - isNullable: true, - }, - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = Record>;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOfAnonymous.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithAnyOfAnonymous = { - properties: { - propA: { - type: 'any-of', - contains: [{ - properties: { - propA: { - properties: { - }, - }, - }, - }, { - type: 'string', - }, { - type: 'number', - }], - }, - }, -};" + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = Record>;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOf.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithOneOf = { - properties: { - propA: { - type: 'one-of', - contains: [{ - type: 'ModelWithString', - }, { - type: 'ModelWithEnum', - }, { - type: 'ModelWithArray', - }, { - type: 'ModelWithDictionary', - }], - }, - }, -};" + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = Record;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOfAndNullable.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithOneOfAndNullable = { - properties: { - propA: { - type: 'one-of', - contains: [{ - properties: { - boolean: { - type: 'boolean', - }, - }, - }, { - type: 'ModelWithEnum', - }, { - type: 'ModelWithArray', - }, { - type: 'ModelWithDictionary', - }], - isNullable: true, - }, - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a string reference + */ +export type DictionaryWithReference = Record;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOfAnonymous.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/DictionaryWithString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $CompositionWithOneOfAnonymous = { - properties: { - propA: { - type: 'one-of', - contains: [{ - properties: { - propA: { - properties: { - }, - }, - }, - }, { - type: 'string', - }, { - type: 'number', - }], - }, - }, -};" + +/** + * This is a string dictionary + */ +export type DictionaryWithString = Record;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithArray.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumFromDescription.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithArray = { - type: 'dictionary', - contains: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, -};" + +/** + * Success=1,Warning=2,Error=3 + */ +export enum EnumFromDescription { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithDictionary.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithExtensions.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithDictionary = { - type: 'dictionary', - contains: { - type: 'dictionary', - contains: { - type: 'string', - }, - }, -};" + +/** + * This is a simple enum with numbers + */ +export enum EnumWithExtensions { + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS = 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING = 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR = 500, +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithProperties.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithProperties = { - type: 'dictionary', - contains: { - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, -};" + +/** + * This is a simple enum with numbers + */ +export enum EnumWithNumbers { + '_1' = 1, + '_2' = 2, + '_3' = 3, + '_1.1' = 1.1, + '_1.2' = 1.2, + '_1.3' = 1.3, + '_100' = 100, + '_200' = 200, + '_300' = 300, + '_-100' = -100, + '_-200' = -200, + '_-300' = -300, + '_-1.1' = -1.1, + '_-1.2' = -1.2, + '_-1.3' = -1.3, +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/EnumWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithReference = { - type: 'dictionary', - contains: { - type: 'ModelWithString', - }, -};" + +/** + * This is a simple enum with strings + */ +export enum EnumWithStrings { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', +}" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithString.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelThatExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $DictionaryWithString = { - type: 'dictionary', - contains: { - type: 'string', - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = (ModelWithString & { + propExtendsA?: string, + propExtendsB?: ModelWithString, +}); +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumFromDescription.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelThatExtendsExtends.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumFromDescription = { - type: 'Enum', -};" + +import type { ModelThatExtends } from './ModelThatExtends'; +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = (ModelWithString & ModelThatExtends & { + propExtendsC?: string, + propExtendsD?: ModelWithString, +}); +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithExtensions.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithExtensions = { - type: 'Enum', -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithNumbers.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithNumbers = { - type: 'Enum', -};" + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithStrings.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithCircularReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $EnumWithStrings = { - type: 'Enum', -};" + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelThatExtends.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDictionary.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelThatExtends = { - type: 'all-of', - contains: [{ - type: 'ModelWithString', - }, { - properties: { - propExtendsA: { - type: 'string', - }, - propExtendsB: { - type: 'ModelWithString', - }, - }, - }], -};" + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: Record; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelThatExtendsExtends.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDuplicateImports.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelThatExtendsExtends = { - type: 'all-of', - contains: [{ - type: 'ModelWithString', - }, { - type: 'ModelThatExtends', - }, { - properties: { - propExtendsC: { - type: 'string', - }, - propExtendsD: { - type: 'ModelWithString', - }, - }, - }], -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithArray.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithDuplicateProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithArray = { - properties: { - prop: { - type: 'array', - contains: { - type: 'ModelWithString', - }, - }, - propWithFile: { - type: 'array', - contains: { - type: 'File', - }, - }, - propWithNumber: { - type: 'array', - contains: { - type: 'number', - }, - }, - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithBoolean.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithEnum.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithBoolean = { - properties: { - prop: { - type: 'boolean', - }, - }, -};" + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: ModelWithEnum.test; + /** + * These are the HTTP error code enums + */ + statusCode?: ModelWithEnum.statusCode; + /** + * Simple boolean enum + */ + bool?: boolean; +} + +export namespace ModelWithEnum { + + /** + * This is a simple enum with strings + */ + export enum test { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', + } + + /** + * These are the HTTP error code enums + */ + export enum statusCode { + _100 = '100', + _200_FOO = '200 FOO', + _300_FOO_BAR = '300 FOO_BAR', + _400_FOO_BAR = '400 foo-bar', + _500_FOO_BAR = '500 foo.bar', + _600_FOO_BAR = '600 foo&bar', + } + + +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithCircularReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithEnumFromDescription.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithCircularReference = { - properties: { - prop: { - type: 'ModelWithCircularReference', - }, - }, -};" + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: ModelWithEnumFromDescription.test; +} + +export namespace ModelWithEnumFromDescription { + + /** + * Success=1,Warning=2,Error=3 + */ + export enum test { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, + } + + +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDictionary.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithInteger.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDictionary = { - properties: { - prop: { - type: 'dictionary', - contains: { - type: 'string', - }, - }, - }, -};" + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDuplicateImports.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithNestedEnums.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDuplicateImports = { - properties: { - propA: { - type: 'ModelWithString', - }, - propB: { - type: 'ModelWithString', - }, - propC: { - type: 'ModelWithString', - }, - }, -};" + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: Record; + dictionaryWithEnumFromDescription?: Record; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array<1 | 2 | 3>; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDuplicateProperties.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithNestedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithDuplicateProperties = { - properties: { - prop: { - type: 'ModelWithString', - }, - }, -};" + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null, + } | null, + } | null; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithEnum.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithOrderedProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithEnum = { - properties: { - test: { - type: 'Enum', - }, - statusCode: { - type: 'Enum', - }, - bool: { - type: 'boolean', - }, - }, -};" + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithPattern.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithEnumFromDescription = { - properties: { - test: { - type: 'Enum', - }, - }, -};" + +/** + * 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; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithInteger.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithInteger = { - properties: { - prop: { - type: 'number', - }, - }, -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * 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; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithNestedEnums.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithNestedEnums = { - properties: { - dictionaryWithEnum: { - type: 'dictionary', - contains: { - type: 'Enum', - }, - }, - dictionaryWithEnumFromDescription: { - type: 'dictionary', - contains: { - type: 'Enum', - }, - }, - arrayWithEnum: { - type: 'array', - contains: { - type: 'Enum', - }, - }, - arrayWithDescription: { - type: 'array', - contains: { - type: 'Enum', - }, - }, - }, -};" -`; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithNestedProperties.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export const $ModelWithNestedProperties = { - 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, - }, - }, -};" +import type { ModelWithProperties } from './ModelWithProperties'; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithOrderedProperties.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/ModelWithString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithOrderedProperties = { - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, -};" + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithPattern.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/MultilineComment.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithPattern = { - 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+$', - }, - }, -};" + +/** + * Testing multiline comments. + * This must go to the next line. + * + * This will contain a break. + */ +export type MultilineComment = number;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithProperties.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithProperties = { - 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, - }, - }, -};" + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleFile.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithReference = { - properties: { - prop: { - type: 'ModelWithProperties', - }, - }, -};" + +/** + * This is a simple file + */ +export type SimpleFile = Blob;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithString.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleInteger.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $ModelWithString = { - properties: { - prop: { - type: 'string', - }, - }, -};" + +/** + * This is a simple number + */ +export type SimpleInteger = number;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$MultilineComment.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleReference.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $MultilineComment = { - type: 'number', -};" + +import type { ModelWithString } from './ModelWithString'; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleBoolean.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleString.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleBoolean = { - type: 'boolean', -};" + +/** + * This is a simple string + */ +export type SimpleString = string;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleFile.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/models/SimpleStringWithPattern.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleFile = { - type: 'File', -};" + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null;" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleInteger.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithArray.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleInteger = { - type: 'number', +export const $ArrayWithArray = { + type: 'array', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, };" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleReference.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithBooleans.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleReference = { - type: 'ModelWithString', +export const $ArrayWithBooleans = { + type: 'array', + contains: { + type: 'boolean', + }, };" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleString.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithNumbers.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleString = { - type: 'string', +export const $ArrayWithNumbers = { + type: 'array', + contains: { + type: 'number', + }, };" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleStringWithPattern.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithProperties.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export const $SimpleStringWithPattern = { - type: 'string', - isNullable: true, - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', +export const $ArrayWithProperties = { + type: 'array', + contains: { + properties: { + foo: { + type: 'string', + }, + bar: { + type: 'string', + }, + }, + }, };" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/CollectionFormatService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithReferences.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class CollectionFormatService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values) - * @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values) - * @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values) - * @param parameterArrayPipes This is an array parameter that is send as pipes format (pipe-separated values) - * @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances) - * @throws ApiError - */ - public async collectionFormat( - parameterArrayCsv: Array | null, - parameterArraySsv: Array | null, - parameterArrayTsv: Array | null, - parameterArrayPipes: Array | null, - parameterArrayMulti: Array | null, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/collectionFormat\`, - query: { - 'parameterArrayCSV': parameterArrayCsv, - 'parameterArraySSV': parameterArraySsv, - 'parameterArrayTSV': parameterArrayTsv, - 'parameterArrayPipes': parameterArrayPipes, - 'parameterArrayMulti': parameterArrayMulti, - }, - }); - return result.body; - } - -}" +export const $ArrayWithReferences = { + type: 'array', + contains: { + type: 'ModelWithString', + }, +};" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ComplexService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ArrayWithStrings.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithArray } from '../models/ModelWithArray'; -import type { ModelWithDictionary } from '../models/ModelWithDictionary'; -import type { ModelWithEnum } from '../models/ModelWithEnum'; -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; +export const $ArrayWithStrings = { + type: 'array', + contains: { + type: 'string', + }, +};" +`; -export class ComplexService { - private httpRequest: BaseHttpRequest; +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAllOfAndNullable.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithAllOfAndNullable = { + properties: { + propA: { + type: 'all-of', + contains: [{ + properties: { + boolean: { + type: 'boolean', + }, + }, + }, { + type: 'ModelWithEnum', + }, { + type: 'ModelWithArray', + }, { + type: 'ModelWithDictionary', + }], + isNullable: true, + }, + }, +};" +`; - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOf.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithAnyOf = { + properties: { + propA: { + type: 'any-of', + contains: [{ + type: 'ModelWithString', + }, { + type: 'ModelWithEnum', + }, { + type: 'ModelWithArray', + }, { + type: 'ModelWithDictionary', + }], + }, + }, +};" +`; - /** - * @param parameterObject Parameter containing object - * @param parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public async complexTypes( - parameterObject: { - first?: { - second?: { - third?: string, +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOfAndNullable.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithAnyOfAndNullable = { + properties: { + propA: { + type: 'any-of', + contains: [{ + properties: { + boolean: { + type: 'boolean', + }, }, - }, + }, { + type: 'ModelWithEnum', + }, { + type: 'ModelWithArray', + }, { + type: 'ModelWithDictionary', + }], + isNullable: true, }, - parameterReference: ModelWithString, - ): Promise> { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex\`, - query: { - 'parameterObject': parameterObject, - 'parameterReference': parameterReference, - }, - errors: { - 400: \`400 server error\`, - 500: \`500 server error\`, - }, - }); - return result.body; - } + }, +};" +`; - /** - * @param id - * @param requestBody - * @returns ModelWithString Success - * @throws ApiError - */ - public async complexParams( - 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, - }, +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithAnyOfAnonymous.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithAnyOfAnonymous = { + properties: { + propA: { + type: 'any-of', + contains: [{ + properties: { + propA: { + properties: { + }, + }, + }, + }, { + type: 'string', + }, { + type: 'number', + }], }, - ): Promise { - const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex/\${id}\`, - body: requestBody, - mediaType: 'application/json-patch+json', - }); - return result.body; - } - -}" + }, +};" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/DefaultsService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOf.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; +export const $CompositionWithOneOf = { + properties: { + propA: { + type: 'one-of', + contains: [{ + type: 'ModelWithString', + }, { + type: 'ModelWithEnum', + }, { + type: 'ModelWithArray', + }, { + type: 'ModelWithDictionary', + }], + }, + }, +};" +`; -export class DefaultsService { - private httpRequest: BaseHttpRequest; +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOfAndNullable.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithOneOfAndNullable = { + properties: { + propA: { + type: 'one-of', + contains: [{ + properties: { + boolean: { + type: 'boolean', + }, + }, + }, { + type: 'ModelWithEnum', + }, { + type: 'ModelWithArray', + }, { + type: 'ModelWithDictionary', + }], + isNullable: true, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$CompositionWithOneOfAnonymous.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithOneOfAnonymous = { + properties: { + propA: { + type: 'one-of', + contains: [{ + properties: { + propA: { + properties: { + }, + }, + }, + }, { + type: 'string', + }, { + type: 'number', + }], + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $DictionaryWithArray = { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $DictionaryWithDictionary = { + type: 'dictionary', + contains: { + type: 'dictionary', + contains: { + type: 'string', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $DictionaryWithProperties = { + type: 'dictionary', + contains: { + properties: { + foo: { + type: 'string', + }, + bar: { + type: 'string', + }, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $DictionaryWithReference = { + type: 'dictionary', + contains: { + type: 'ModelWithString', + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$DictionaryWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $DictionaryWithString = { + type: 'dictionary', + contains: { + type: 'string', + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $EnumFromDescription = { + type: 'Enum', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithExtensions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $EnumWithExtensions = { + type: 'Enum', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $EnumWithNumbers = { + type: 'Enum', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$EnumWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $EnumWithStrings = { + type: 'Enum', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelThatExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelThatExtends = { + type: 'all-of', + contains: [{ + type: 'ModelWithString', + }, { + properties: { + propExtendsA: { + type: 'string', + }, + propExtendsB: { + type: 'ModelWithString', + }, + }, + }], +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelThatExtendsExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelThatExtendsExtends = { + type: 'all-of', + contains: [{ + type: 'ModelWithString', + }, { + type: 'ModelThatExtends', + }, { + properties: { + propExtendsC: { + type: 'string', + }, + propExtendsD: { + type: 'ModelWithString', + }, + }, + }], +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithArray = { + properties: { + prop: { + type: 'array', + contains: { + type: 'ModelWithString', + }, + }, + propWithFile: { + type: 'array', + contains: { + type: 'File', + }, + }, + propWithNumber: { + type: 'array', + contains: { + type: 'number', + }, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithBoolean = { + properties: { + prop: { + type: 'boolean', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithCircularReference = { + properties: { + prop: { + type: 'ModelWithCircularReference', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithDictionary = { + properties: { + prop: { + type: 'dictionary', + contains: { + type: 'string', + }, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDuplicateImports.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithDuplicateImports = { + properties: { + propA: { + type: 'ModelWithString', + }, + propB: { + type: 'ModelWithString', + }, + propC: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithDuplicateProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithDuplicateProperties = { + properties: { + prop: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithEnum = { + properties: { + test: { + type: 'Enum', + }, + statusCode: { + type: 'Enum', + }, + bool: { + type: 'boolean', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithEnumFromDescription = { + properties: { + test: { + type: 'Enum', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithInteger = { + properties: { + prop: { + type: 'number', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithNestedEnums.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithNestedEnums = { + properties: { + dictionaryWithEnum: { + type: 'dictionary', + contains: { + type: 'Enum', + }, + }, + dictionaryWithEnumFromDescription: { + type: 'dictionary', + contains: { + type: 'Enum', + }, + }, + arrayWithEnum: { + type: 'array', + contains: { + type: 'Enum', + }, + }, + arrayWithDescription: { + type: 'array', + contains: { + type: 'Enum', + }, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithNestedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithNestedProperties = { + 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, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithOrderedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithOrderedProperties = { + properties: { + zebra: { + type: 'string', + }, + apple: { + type: 'string', + }, + hawaii: { + type: 'string', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithPattern = { + 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+$', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithProperties = { + 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, + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithReference = { + properties: { + prop: { + type: 'ModelWithProperties', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ModelWithString = { + properties: { + prop: { + type: 'string', + }, + }, +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $MultilineComment = { + type: 'number', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleBoolean = { + type: 'boolean', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleFile = { + type: 'File', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleInteger = { + type: 'number', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleReference = { + type: 'ModelWithString', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleString = { + type: 'string', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/schemas/$SimpleStringWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $SimpleStringWithPattern = { + type: 'string', + isNullable: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', +};" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/CollectionFormatService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class CollectionFormatService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values) + * @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values) + * @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values) + * @param parameterArrayPipes This is an array parameter that is send as pipes format (pipe-separated values) + * @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances) + * @throws ApiError + */ + public async collectionFormat( + parameterArrayCsv: Array | null, + parameterArraySsv: Array | null, + parameterArrayTsv: Array | null, + parameterArrayPipes: Array | null, + parameterArrayMulti: Array | null, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/collectionFormat\`, + query: { + 'parameterArrayCSV': parameterArrayCsv, + 'parameterArraySSV': parameterArraySsv, + 'parameterArrayTSV': parameterArrayTsv, + 'parameterArrayPipes': parameterArrayPipes, + 'parameterArrayMulti': parameterArrayMulti, + }, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ComplexService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithArray } from '../models/ModelWithArray'; +import type { ModelWithDictionary } from '../models/ModelWithDictionary'; +import type { ModelWithEnum } from '../models/ModelWithEnum'; +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class ComplexService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public async complexTypes( + parameterObject: { + first?: { + second?: { + third?: string, + }, + }, + }, + parameterReference: ModelWithString, + ): Promise> { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex\`, + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + return result.body; + } + + /** + * @param id + * @param requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public async complexParams( + 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, + }, + }, + ): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/complex/\${id}\`, + body: requestBody, + mediaType: 'application/json-patch+json', + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/DefaultsService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class DefaultsService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @param parameterString This is a simple string with default value + * @param parameterNumber This is a simple number with default value + * @param parameterBoolean This is a simple boolean with default value + * @param parameterEnum This is a simple enum with default value + * @param parameterModel This is a simple model with default value + * @throws ApiError + */ + public async callWithDefaultParameters( + parameterString: string | null = 'Hello World!', + parameterNumber: number | null = 123, + parameterBoolean: boolean | null = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString | null = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + return result.body; + } + + /** + * @param parameterString This is a simple string that is optional with default value + * @param parameterNumber This is a simple number that is optional with default value + * @param parameterBoolean This is a simple boolean that is optional with default value + * @param parameterEnum This is a simple enum that is optional with default value + * @param parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public async callWithDefaultOptionalParameters( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + return result.body; + } + + /** + * @param parameterStringWithNoDefault This is a string with no default + * @param parameterOptionalStringWithDefault This is a optional string with default + * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param parameterOptionalStringWithNoDefault This is a optional string with no default + * @param parameterStringWithDefault This is a string with default + * @param parameterStringWithEmptyDefault This is a string with empty default + * @throws ApiError + */ + public async callToTestOrderOfParams( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'Hello World!', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'Hello World!', + parameterStringWithEmptyDefault: string = '', + ): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + query: { + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + }, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/DuplicateService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class DuplicateService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @throws ApiError + */ + public async duplicateName(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async duplicateName1(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async duplicateName2(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async duplicateName3(): Promise { + const result = await this.httpRequest.request({ + method: 'DELETE', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/HeaderService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class HeaderService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @returns string Successful response + * @throws ApiError + */ + public async callWithResultFromHeader(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/header\`, + responseHeader: 'operation-location', + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/MultipartService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class MultipartService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @returns any OK + * @throws ApiError + */ + public async multipartResponse(): Promise<{ + file?: string, + metadata?: { + foo?: string, + bar?: string, + }, + }> { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/multipart\`, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/NoContentService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class NoContentService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @returns void + * @throws ApiError + */ + public async callWithNoContentResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/no-content\`, + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ParametersService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class ParametersService { + private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { this.httpRequest = httpRequest; } /** - * @param parameterString This is a simple string with default value - * @param parameterNumber This is a simple number with default value - * @param parameterBoolean This is a simple boolean with default value - * @param parameterEnum This is a simple enum with default value - * @param parameterModel This is a simple model with default value + * @param parameterHeader This is the parameter that goes into the header + * @param parameterQuery This is the parameter that goes into the query params + * @param parameterForm This is the parameter that goes into the form data + * @param parameterCookie This is the parameter that goes into the cookie + * @param parameterPath This is the parameter that goes into the path + * @param requestBody This is the parameter that goes into the body + * @throws ApiError + */ + public async callWithParameters( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + parameterPath: string | null, + requestBody: ModelWithString | null, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath}\`, + cookies: { + 'parameterCookie': parameterCookie, + }, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: requestBody, + mediaType: 'application/json', + }); + return result.body; + } + + /** + * @param parameterHeader This is the parameter that goes into the request header + * @param parameterQuery This is the parameter that goes into the request query params + * @param parameterForm This is the parameter that goes into the request form data + * @param parameterCookie This is the parameter that goes into the cookie + * @param requestBody This is the parameter that goes into the body + * @param parameterPath1 This is the parameter that goes into the path + * @param parameterPath2 This is the parameter that goes into the path + * @param parameterPath3 This is the parameter that goes into the path + * @param _default This is the parameter with a reserved keyword + * @throws ApiError + */ + public async callWithWeirdParameterNames( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + requestBody: ModelWithString | null, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + _default?: string, + ): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, + cookies: { + 'PARAMETER-COOKIE': parameterCookie, + }, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'parameter-query': parameterQuery, + 'default': _default, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: requestBody, + mediaType: 'application/json', + }); + return result.body; + } + + /** + * @param requestBody This is a required parameter + * @param parameter This is an optional parameter * @throws ApiError */ - public async callWithDefaultParameters( - parameterString: string | null = 'Hello World!', - parameterNumber: number | null = 123, - parameterBoolean: boolean | null = true, - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', - parameterModel: ModelWithString | null = { - \\"prop\\": \\"Hello World!\\" - }, + public async getCallWithOptionalParam( + requestBody: ModelWithString, + parameter?: string, ): Promise { const result = await this.httpRequest.request({ method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\`, query: { - 'parameterString': parameterString, - 'parameterNumber': parameterNumber, - 'parameterBoolean': parameterBoolean, - 'parameterEnum': parameterEnum, - 'parameterModel': parameterModel, + 'parameter': parameter, }, + body: requestBody, + mediaType: 'application/json', }); return result.body; } /** - * @param parameterString This is a simple string that is optional with default value - * @param parameterNumber This is a simple number that is optional with default value - * @param parameterBoolean This is a simple boolean that is optional with default value - * @param parameterEnum This is a simple enum that is optional with default value - * @param parameterModel This is a simple model that is optional with default value + * @param parameter This is a required parameter + * @param requestBody This is an optional parameter * @throws ApiError */ - public async callWithDefaultOptionalParameters( - parameterString: string = 'Hello World!', - parameterNumber: number = 123, - parameterBoolean: boolean = true, - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', - parameterModel: ModelWithString = { - \\"prop\\": \\"Hello World!\\" - }, + public async postCallWithOptionalParam( + parameter: string, + requestBody?: ModelWithString, ): Promise { const result = await this.httpRequest.request({ method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\`, query: { - 'parameterString': parameterString, - 'parameterNumber': parameterNumber, - 'parameterBoolean': parameterBoolean, - 'parameterEnum': parameterEnum, - 'parameterModel': parameterModel, + 'parameter': parameter, }, + body: requestBody, + mediaType: 'application/json', }); return result.body; } +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/RequestBodyService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class RequestBodyService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + /** - * @param parameterStringWithNoDefault This is a string with no default - * @param parameterOptionalStringWithDefault This is a optional string with default - * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param parameterOptionalStringWithNoDefault This is a optional string with no default - * @param parameterStringWithDefault This is a string with default - * @param parameterStringWithEmptyDefault This is a string with empty default + * @param requestBody A reusable request body * @throws ApiError */ - public async callToTestOrderOfParams( - parameterStringWithNoDefault: string, - parameterOptionalStringWithDefault: string = 'Hello World!', - parameterOptionalStringWithEmptyDefault: string = '', - parameterOptionalStringWithNoDefault?: string, - parameterStringWithDefault: string = 'Hello World!', - parameterStringWithEmptyDefault: string = '', + public async postRequestBodyService( + requestBody?: ModelWithString, ): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/requestBody/\`, + body: requestBody, + mediaType: 'application/json', + }); + return result.body; + } + +}" +`; + +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ResponseService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelThatExtends } from '../models/ModelThatExtends'; +import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; +import type { ModelWithString } from '../models/ModelWithString'; +import { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class ResponseService { + private httpRequest: BaseHttpRequest; + + constructor(httpRequest: BaseHttpRequest) { + this.httpRequest = httpRequest; + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public async callWithResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + }); + return result.body; + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public async callWithDuplicateResponses(): Promise { + const result = await this.httpRequest.request({ + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + return result.body; + } + + /** + * @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 async callWithResponses(): Promise<{ + readonly '@namespace.string'?: string, + readonly '@namespace.integer'?: number, + readonly value?: Array, + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { const result = await this.httpRequest.request({ method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/defaults\`, - query: { - 'parameterStringWithNoDefault': parameterStringWithNoDefault, - 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, - 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, - 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, - 'parameterStringWithDefault': parameterStringWithDefault, - 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, }, }); return result.body; @@ -4829,13 +6501,13 @@ export class DefaultsService { }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/DuplicateService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/SimpleService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class DuplicateService { +export class SimpleService { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -4845,10 +6517,10 @@ export class DuplicateService { /** * @throws ApiError */ - public async duplicateName(): Promise { + public async getCallWithoutParametersAndResponse(): Promise { const result = await this.httpRequest.request({ method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, }); return result.body; } @@ -4856,10 +6528,21 @@ export class DuplicateService { /** * @throws ApiError */ - public async duplicateName1(): Promise { + public async putCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'PUT', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async postCallWithoutParametersAndResponse(): Promise { const result = await this.httpRequest.request({ method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, }); return result.body; } @@ -4867,10 +6550,32 @@ export class DuplicateService { /** * @throws ApiError */ - public async duplicateName2(): Promise { + public async deleteCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'DELETE', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async optionsCallWithoutParametersAndResponse(): Promise { + const result = await this.httpRequest.request({ + method: 'OPTIONS', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, + }); + return result.body; + } + + /** + * @throws ApiError + */ + public async headCallWithoutParametersAndResponse(): Promise { const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + method: 'HEAD', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, }); return result.body; } @@ -4878,10 +6583,10 @@ export class DuplicateService { /** * @throws ApiError */ - public async duplicateName3(): Promise { + public async patchCallWithoutParametersAndResponse(): Promise { const result = await this.httpRequest.request({ - method: 'DELETE', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/duplicate\`, + method: 'PATCH', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, }); return result.body; } @@ -4889,13 +6594,13 @@ export class DuplicateService { }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/HeaderService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/TypesService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class HeaderService { +export class TypesService { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -4903,17 +6608,41 @@ export class HeaderService { } /** - * @returns string Successful response + * @param parameterArray This is an array parameter + * @param parameterDictionary This is a dictionary parameter + * @param parameterEnum This is an enum parameter + * @param parameterNumber This is a number parameter + * @param parameterString This is a string parameter + * @param parameterBoolean This is a boolean parameter + * @param parameterObject This is an object parameter + * @param id This is a number parameter + * @returns number Response is a simple number + * @returns string Response is a simple string + * @returns boolean Response is a simple boolean + * @returns any Response is a simple object * @throws ApiError */ - public async callWithResultFromHeader(): Promise { + public async types( + parameterArray: Array | null, + parameterDictionary: any, + parameterEnum: 'Success' | 'Warning' | 'Error' | null, + parameterNumber: number = 123, + parameterString: string | null = 'default', + parameterBoolean: boolean | null = true, + parameterObject: any = null, + id?: number, + ): Promise { const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/header\`, - responseHeader: 'operation-location', - errors: { - 400: \`400 server error\`, - 500: \`500 server error\`, + method: 'GET', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/types\`, + query: { + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, }, }); return result.body; @@ -4922,13 +6651,13 @@ export class HeaderService { }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/MultipartService.ts 1`] = ` +exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/UploadService.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class MultipartService { +export class UploadService { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -4936,19 +6665,19 @@ export class MultipartService { } /** - * @returns any OK + * @param file Supply a file reference for upload + * @returns boolean * @throws ApiError */ - public async multipartResponse(): Promise<{ - file?: string, - metadata?: { - foo?: string, - bar?: string, - }, - }> { + public async uploadFile( + file: Blob, + ): Promise { const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/multipart\`, + method: 'POST', + path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/upload\`, + formData: { + 'file': file, + }, }); return result.body; } @@ -4956,288 +6685,374 @@ export class MultipartService { }" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/NoContentService.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/client.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; +import { Service } from './services/Service'; + +export class TestClient extends Service { + readonly request: BaseHttpRequest; + + constructor(openApiConfig?: OpenAPIConfig, HttpRequest: new (config: OpenAPIConfig) => BaseHttpRequest = FetchHttpRequest) { + const request = new HttpRequest({ + BASE: openApiConfig?.BASE ?? 'http://localhost:3000/base', + VERSION: openApiConfig?.VERSION ?? '1.0', + WITH_CREDENTIALS: openApiConfig?.WITH_CREDENTIALS ?? false, + TOKEN: openApiConfig?.TOKEN, + USERNAME: openApiConfig?.USERNAME, + PASSWORD: openApiConfig?.PASSWORD, + HEADERS: openApiConfig?.HEADERS, + }); + super(request); + this.request = request; + } +}" +`; + +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/ApiError.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +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: any; + + constructor(response: ApiResult, message: string) { + super(message); + + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + } +}" +`; + +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/ApiRequestOptions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly path: string; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}" +`; + +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/ApiResult.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}" +`; + +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/BaseHttpRequest.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; + +export class BaseHttpRequest { + readonly openApiConfig: OpenAPIConfig; + + constructor(openApiConfig: OpenAPIConfig) { + this.openApiConfig = openApiConfig; + } + + async request(options: ApiRequestOptions): Promise { + throw new Error('Not Implemented'); + } +}" +`; + +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/FetchHttpRequest.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import type { OpenAPIConfig } from './OpenAPI'; +import { BaseHttpRequest } from './BaseHttpRequest'; + +function isDefined(value: T | null | undefined): value is Exclude { + return value !== undefined && value !== null; +} + +function isString(value: any): value is string { + return typeof value === 'string'; +} + +function isStringWithValue(value: any): value is string { + return isString(value) && value !== ''; +} + +function isBlob(value: any): value is Blob { + return value instanceof Blob; +} + +function getQueryString(params: Record): string { + const qs: string[] = []; + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + if (Array.isArray(value)) { + value.forEach(value => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }); + } else { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + } + } + }); + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; + } + return ''; +} + +function getUrl(options: ApiRequestOptions, config: OpenAPIConfig): string { + const path = options.path.replace(/[:]/g, '_'); + const url = \`\${config.BASE}\${path}\`; + + if (options.query) { + return \`\${url}\${getQueryString(options.query)}\`; + } + return url; +} + +function getFormData(params: Record): FormData { + const formData = new FormData(); + Object.keys(params).forEach(key => { + const value = params[key]; + if (isDefined(value)) { + formData.append(key, value); + } + }); + return formData; +} + +type Resolver = (options: ApiRequestOptions) => Promise; + +async function resolve(options: ApiRequestOptions, resolver?: T | Resolver): Promise { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; +} + +async function getHeaders(options: ApiRequestOptions, config: OpenAPIConfig): Promise { + const token = await resolve(options, config.TOKEN); + const username = await resolve(options, config.USERNAME); + const password = await resolve(options, config.PASSWORD); + const defaultHeaders = await resolve(options, config.HEADERS); + + const headers = new Headers({ + Accept: 'application/json', + ...defaultHeaders, + ...options.headers, + }); + + if (isStringWithValue(token)) { + headers.append('Authorization', \`Bearer \${token}\`); + } -export class NoContentService { - private httpRequest: BaseHttpRequest; + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = btoa(\`\${username}:\${password}\`); + headers.append('Authorization', \`Basic \${credentials}\`); + } - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; + if (options.body) { + if (options.mediaType) { + headers.append('Content-Type', options.mediaType); + } else if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } } + return headers; +} - /** - * @returns void - * @throws ApiError - */ - public async callWithNoContentResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/no-content\`, - }); - return result.body; +function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { + if (options.formData) { + return getFormData(options.formData); + } + if (options.body) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } } + return undefined; +} -}" -`; +async function sendRequest(options: ApiRequestOptions, config: OpenAPIConfig, url: string): Promise { + const request: RequestInit = { + method: options.method, + headers: await getHeaders(options, config), + body: getRequestBody(options), + }; + if (config.WITH_CREDENTIALS) { + request.credentials = 'include'; + } + return await fetch(url, request); +} -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ParametersService.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; +function getResponseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return null; +} -export class ParametersService { - private httpRequest: BaseHttpRequest; +async function getResponseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const isJSON = contentType.toLowerCase().startsWith('application/json'); + if (isJSON) { + return await response.json(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + return null; +} - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; +function catchErrors(options: ApiRequestOptions, result: ApiResult): void { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 500: 'Internal Server Error', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + ...options.errors, } - /** - * @param parameterHeader This is the parameter that goes into the header - * @param parameterQuery This is the parameter that goes into the query params - * @param parameterForm This is the parameter that goes into the form data - * @param parameterCookie This is the parameter that goes into the cookie - * @param parameterPath This is the parameter that goes into the path - * @param requestBody This is the parameter that goes into the body - * @throws ApiError - */ - public async callWithParameters( - parameterHeader: string | null, - parameterQuery: string | null, - parameterForm: string | null, - parameterCookie: string | null, - parameterPath: string | null, - requestBody: ModelWithString | null, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath}\`, - cookies: { - 'parameterCookie': parameterCookie, - }, - headers: { - 'parameterHeader': parameterHeader, - }, - query: { - 'parameterQuery': parameterQuery, - }, - formData: { - 'parameterForm': parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - return result.body; + const error = errors[result.status]; + if (error) { + throw new ApiError(result, error); } - /** - * @param parameterHeader This is the parameter that goes into the request header - * @param parameterQuery This is the parameter that goes into the request query params - * @param parameterForm This is the parameter that goes into the request form data - * @param parameterCookie This is the parameter that goes into the cookie - * @param requestBody This is the parameter that goes into the body - * @param parameterPath1 This is the parameter that goes into the path - * @param parameterPath2 This is the parameter that goes into the path - * @param parameterPath3 This is the parameter that goes into the path - * @param _default This is the parameter with a reserved keyword - * @throws ApiError - */ - public async callWithWeirdParameterNames( - parameterHeader: string | null, - parameterQuery: string | null, - parameterForm: string | null, - parameterCookie: string | null, - requestBody: ModelWithString | null, - parameterPath1?: string, - parameterPath2?: string, - parameterPath3?: string, - _default?: string, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, - cookies: { - 'PARAMETER-COOKIE': parameterCookie, - }, - headers: { - 'parameter.header': parameterHeader, - }, - query: { - 'parameter-query': parameterQuery, - 'default': _default, - }, - formData: { - 'parameter_form': parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - return result.body; + if (!result.ok) { + throw new ApiError(result, 'Generic Error'); } +} - /** - * @param requestBody This is a required parameter - * @param parameter This is an optional parameter - * @throws ApiError - */ - public async getCallWithOptionalParam( - requestBody: ModelWithString, - parameter?: string, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\`, - query: { - 'parameter': parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - return result.body; +export class FetchHttpRequest extends BaseHttpRequest { + constructor(openApiConfig: OpenAPIConfig) { + super(openApiConfig); } /** - * @param parameter This is a required parameter - * @param requestBody This is an optional parameter - * @throws ApiError - */ - public async postCallWithOptionalParam( - parameter: string, - requestBody?: ModelWithString, - ): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/parameters/\`, - query: { - 'parameter': parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - return result.body; - } + * Request using fetch client + * @param options The request options from the the service + * @returns ApiResult + * @throws ApiError + */ + async request(options: ApiRequestOptions): Promise { + const url = getUrl(options, this.openApiConfig); + const response = await sendRequest(options, this.openApiConfig, url); + 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, + }; -}" + catchErrors(options, result); + return result; + } +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/RequestBodyService.ts 1`] = ` +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/core/OpenAPI.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class RequestBodyService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } +import type { ApiRequestOptions } from './ApiRequestOptions'; - /** - * @param requestBody A reusable request body - * @throws ApiError - */ - public async postRequestBodyService( - requestBody?: ModelWithString, - ): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/requestBody/\`, - body: requestBody, - mediaType: 'application/json', - }); - return result.body; - } +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; -}" +export type OpenAPIConfig = { + BASE?: string; + VERSION?: string; + WITH_CREDENTIALS?: boolean; + TOKEN?: string | Resolver; + USERNAME?: string | Resolver; + PASSWORD?: string | Resolver; + HEADERS?: Headers | Resolver; +} +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/ResponseService.ts 1`] = ` +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/index.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { ModelThatExtends } from '../models/ModelThatExtends'; -import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; -import type { ModelWithString } from '../models/ModelWithString'; -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class ResponseService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @returns ModelWithString - * @throws ApiError - */ - public async callWithResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - }); - return result.body; - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public async callWithDuplicateResponses(): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - errors: { - 500: \`Message for 500 error\`, - 501: \`Message for 501 error\`, - 502: \`Message for 502 error\`, - }, - }); - return result.body; - } +export { ApiError } from './core/ApiError'; +export type { ApiRequestOptions } from './core/ApiRequestOptions'; +export type { ApiResult } from './core/ApiResult'; +export type { OpenAPIConfig } from './core/OpenAPI'; +export { BaseHttpRequest } from './core/BaseHttpRequest'; +export { FetchHttpRequest } from './core/FetchHttpRequest'; - /** - * @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 async callWithResponses(): Promise<{ - readonly '@namespace.string'?: string, - readonly '@namespace.integer'?: number, - readonly value?: Array, - } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { - const result = await this.httpRequest.request({ - method: 'PUT', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/response\`, - errors: { - 500: \`Message for 500 error\`, - 501: \`Message for 501 error\`, - 502: \`Message for 502 error\`, - }, - }); - return result.body; - } +export { Service } from './services/Service'; -}" +export { TestClient } from './client'; +" `; -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/SimpleService.ts 1`] = ` +exports[`v3 should generate with no tags: ./test/generated/v3_client_no_tags/services/Service.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ import { BaseHttpRequest } from '../core/BaseHttpRequest'; -export class SimpleService { +export class Service { private httpRequest: BaseHttpRequest; constructor(httpRequest: BaseHttpRequest) { @@ -5277,140 +7092,5 @@ export class SimpleService { return result.body; } - /** - * @throws ApiError - */ - public async deleteCallWithoutParametersAndResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'DELETE', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async optionsCallWithoutParametersAndResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'OPTIONS', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async headCallWithoutParametersAndResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'HEAD', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, - }); - return result.body; - } - - /** - * @throws ApiError - */ - public async patchCallWithoutParametersAndResponse(): Promise { - const result = await this.httpRequest.request({ - method: 'PATCH', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/simple\`, - }); - return result.body; - } - -}" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/TypesService.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class TypesService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param parameterArray This is an array parameter - * @param parameterDictionary This is a dictionary parameter - * @param parameterEnum This is an enum parameter - * @param parameterNumber This is a number parameter - * @param parameterString This is a string parameter - * @param parameterBoolean This is a boolean parameter - * @param parameterObject This is an object parameter - * @param id This is a number parameter - * @returns number Response is a simple number - * @returns string Response is a simple string - * @returns boolean Response is a simple boolean - * @returns any Response is a simple object - * @throws ApiError - */ - public async types( - parameterArray: Array | null, - parameterDictionary: any, - parameterEnum: 'Success' | 'Warning' | 'Error' | null, - parameterNumber: number = 123, - parameterString: string | null = 'default', - parameterBoolean: boolean | null = true, - parameterObject: any = null, - id?: number, - ): Promise { - const result = await this.httpRequest.request({ - method: 'GET', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/types\`, - query: { - 'parameterArray': parameterArray, - 'parameterDictionary': parameterDictionary, - 'parameterEnum': parameterEnum, - 'parameterNumber': parameterNumber, - 'parameterString': parameterString, - 'parameterBoolean': parameterBoolean, - 'parameterObject': parameterObject, - }, - }); - return result.body; - } - -}" -`; - -exports[`v3 should generate with exportClient: ./test/generated/v3_client/services/UploadService.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import { BaseHttpRequest } from '../core/BaseHttpRequest'; - -export class UploadService { - private httpRequest: BaseHttpRequest; - - constructor(httpRequest: BaseHttpRequest) { - this.httpRequest = httpRequest; - } - - /** - * @param file Supply a file reference for upload - * @returns boolean - * @throws ApiError - */ - public async uploadFile( - file: Blob, - ): Promise { - const result = await this.httpRequest.request({ - method: 'POST', - path: \`/api/v\${this.httpRequest.openApiConfig.VERSION}/upload\`, - formData: { - 'file': file, - }, - }); - return result.body; - } - }" `; diff --git a/test/index.client.spec.js b/test/index.client.spec.js index fdce7fff1..4edda3ebb 100644 --- a/test/index.client.spec.js +++ b/test/index.client.spec.js @@ -4,23 +4,40 @@ const OpenAPI = require('../dist'); const glob = require('glob'); const fs = require('fs'); +async function gen(version, postfix) { + await OpenAPI.generate({ + input: `./test/spec/v${version}${postfix}.json`, + output: `./test/generated/v${version}_client${postfix}`, + httpClient: OpenAPI.HttpClient.FETCH, + useOptions: false, + useUnionTypes: false, + exportCore: true, + exportSchemas: true, + exportModels: true, + exportServices: true, + exportClient: true, + clientName: 'TestClient', + }); + return glob.sync(`./test/generated/v${version}_client${postfix}/**/*.ts`); +} + describe('v2', () => { it('should generate with exportClient', async () => { - await OpenAPI.generate({ - input: './test/spec/v2.json', - output: './test/generated/v2_client', - httpClient: OpenAPI.HttpClient.FETCH, - useOptions: false, - useUnionTypes: false, - exportCore: true, - exportSchemas: true, - exportModels: true, - exportServices: true, - exportClient: true, - clientName: 'TestClient', + (await gen(2, '')).forEach(file => { + const content = fs.readFileSync(file, 'utf8').toString(); + expect(content).toMatchSnapshot(file); + }); + }); + + it('should generate with no tags', async () => { + (await gen(2, '_no_tags')).forEach(file => { + const content = fs.readFileSync(file, 'utf8').toString(); + expect(content).toMatchSnapshot(file); }); + }); - glob.sync('./test/generated/v2_client/**/*.ts').forEach(file => { + it('should generate with combined tags', async () => { + (await gen(2, '_tags_combined')).forEach(file => { const content = fs.readFileSync(file, 'utf8').toString(); expect(content).toMatchSnapshot(file); }); @@ -29,21 +46,21 @@ describe('v2', () => { describe('v3', () => { it('should generate with exportClient', async () => { - await OpenAPI.generate({ - input: './test/spec/v3.json', - output: './test/generated/v3_client', - httpClient: OpenAPI.HttpClient.FETCH, - useOptions: false, - useUnionTypes: false, - exportCore: true, - exportSchemas: true, - exportModels: true, - exportServices: true, - exportClient: true, - clientName: 'TestClient', + (await gen(3, '')).forEach(file => { + const content = fs.readFileSync(file, 'utf8').toString(); + expect(content).toMatchSnapshot(file); }); + }); + + it('should generate with no tags', async () => { + (await gen(3, '_no_tags')).forEach(file => { + const content = fs.readFileSync(file, 'utf8').toString(); + expect(content).toMatchSnapshot(file); + }); + }); - glob.sync('./test/generated/v3_client/**/*.ts').forEach(file => { + it('should generate with combined tags', async () => { + (await gen(3, '_tags_combined')).forEach(file => { const content = fs.readFileSync(file, 'utf8').toString(); expect(content).toMatchSnapshot(file); }); diff --git a/test/spec/v2_no_tags.json b/test/spec/v2_no_tags.json new file mode 100644 index 000000000..4e9659b37 --- /dev/null +++ b/test/spec/v2_no_tags.json @@ -0,0 +1,23 @@ +{ + "swagger": "2.0", + "info": { + "title": "swagger", + "version": "v1.0" + }, + "host": "localhost:3000", + "basePath": "/base", + "schemes": ["http"], + "paths": { + "/api/v{api-version}/simple": { + "get": { + "operationId": "GetCallWithoutParametersAndResponse" + }, + "put": { + "operationId": "PutCallWithoutParametersAndResponse" + }, + "post": { + "operationId": "PostCallWithoutParametersAndResponse" + } + } + } +} diff --git a/test/spec/v2_tags_combined.json b/test/spec/v2_tags_combined.json new file mode 100644 index 000000000..c5e80d533 --- /dev/null +++ b/test/spec/v2_tags_combined.json @@ -0,0 +1,29 @@ +{ + "swagger": "2.0", + "info": { + "title": "swagger", + "version": "v1.0" + }, + "host": "localhost:3000", + "basePath": "/base", + "schemes": ["http"], + "paths": { + "/api/v{api-version}/simple": { + "get": { + "tags": [ + "Simple" + ], + "operationId": "GetCallWithoutParametersAndResponse" + }, + "put": { + "tags": [ + "Simple" + ], + "operationId": "PutCallWithoutParametersAndResponse" + }, + "post": { + "operationId": "PostCallWithoutParametersAndResponse" + } + } + } +} diff --git a/test/spec/v3_no_tags.json b/test/spec/v3_no_tags.json new file mode 100644 index 000000000..dc9b92853 --- /dev/null +++ b/test/spec/v3_no_tags.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "swagger", + "version": "v1.0" + }, + "servers": [ + { + "url": "http://localhost:3000/base" + } + ], + "paths": { + "/api/v{api-version}/simple": { + "get": { + "operationId": "GetCallWithoutParametersAndResponse" + }, + "put": { + "operationId": "PutCallWithoutParametersAndResponse" + }, + "post": { + "operationId": "PostCallWithoutParametersAndResponse" + } + } + } +} diff --git a/test/spec/v3_tags_combined.json b/test/spec/v3_tags_combined.json new file mode 100644 index 000000000..37b42b0f8 --- /dev/null +++ b/test/spec/v3_tags_combined.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "swagger", + "version": "v1.0" + }, + "servers": [ + { + "url": "http://localhost:3000/base" + } + ], + "paths": { + "/api/v{api-version}/simple": { + "get": { + "tags": [ + "Simple" + ], + "operationId": "GetCallWithoutParametersAndResponse" + }, + "put": { + "tags": [ + "Simple" + ], + "operationId": "PutCallWithoutParametersAndResponse" + }, + "post": { + "operationId": "PostCallWithoutParametersAndResponse" + } + } + } +}