From 3715ce2631414c912eb92f8cf42c4e751c76c010 Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Fri, 28 Aug 2020 21:20:11 +0200 Subject: [PATCH] - Fixed snapshot --- rollup.config.js | 10 +- test/__snapshots__/index.spec.js.snap | 5223 +++++++++++++++++++++++++ 2 files changed, 5228 insertions(+), 5 deletions(-) create mode 100644 test/__snapshots__/index.spec.js.snap diff --git a/rollup.config.js b/rollup.config.js index a8743a13..d6050c46 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -66,10 +66,10 @@ export default { }), nodeResolve(), commonjs(), - // terser({ - // output: { - // comments: false, - // }, - // }), + terser({ + output: { + comments: false, + }, + }), ], }; diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap new file mode 100644 index 00000000..4c212bd1 --- /dev/null +++ b/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,5223 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`v2 should generate: ./test/result/v2/core/ApiError.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { isSuccess } from './isSuccess'; +import { Result } from './Result'; + +export class ApiError extends Error { + + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; + + constructor(result: Readonly, message: string) { + super(message); + + this.url = result.url; + this.status = result.status; + this.statusText = result.statusText; + this.body = result.body; + } +} + +export namespace ApiError { + export enum Message { + BAD_REQUEST = 'Bad Request', + UNAUTHORIZED = 'Unauthorized', + FORBIDDEN = 'Forbidden', + NOT_FOUND = 'Not Found', + INTERNAL_SERVER_ERROR = 'Internal Server Error', + BAD_GATEWAY = 'Bad Gateway', + SERVICE_UNAVAILABLE = 'Service Unavailable', + GENERIC_ERROR = 'Generic Error', + } +} + +/** + * Catch common errors (based on status code). + * @param result + */ +export function catchGenericError(result: Result): void { + switch (result.status) { + case 400: throw new ApiError(result, ApiError.Message.BAD_REQUEST); + case 401: throw new ApiError(result, ApiError.Message.UNAUTHORIZED); + case 403: throw new ApiError(result, ApiError.Message.FORBIDDEN); + case 404: throw new ApiError(result, ApiError.Message.NOT_FOUND); + case 500: throw new ApiError(result, ApiError.Message.INTERNAL_SERVER_ERROR); + case 502: throw new ApiError(result, ApiError.Message.BAD_GATEWAY); + case 503: throw new ApiError(result, ApiError.Message.SERVICE_UNAVAILABLE); + } + + if (!isSuccess(result.status)) { + throw new ApiError(result, ApiError.Message.GENERIC_ERROR); + } +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/OpenAPI.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +interface Config { + BASE: string; + VERSION: string; + CLIENT: 'fetch' | 'xhr'; + WITH_CREDENTIALS: boolean; + TOKEN: string; +} + +export const OpenAPI: Config = { + BASE: 'http://localhost:8080/api', + VERSION: '9.0', + CLIENT: 'fetch', + WITH_CREDENTIALS: false, + TOKEN: '', +};" +`; + +exports[`v2 should generate: ./test/result/v2/core/RequestOptions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export interface RequestOptions { + method: 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch'; + path: string; + cookies?: { [key: string]: any }; + headers?: { [key: string]: any }; + query?: { [key: string]: any }; + formData?: { [key: string]: any }; + body?: any; + responseHeader?: string; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/Result.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export interface Result { + url: string; + ok: boolean; + status: number; + statusText: string; + body: any; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/getFormData.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Get FormData from object. This method is needed to upload + * multipart form data to the REST API. + * @param params Key value based object. + */ +export function getFormData(params: { [key: string]: any }): FormData { + const formData = new FormData(); + for (const key in params) { + if (typeof params[key] !== 'undefined') { + const value: any = params[key]; + if (value !== undefined && value !== null) { + formData.append(key, value); + } + } + } + return formData; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/getQueryString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Get query string from query parameters object. This method also + * supports multi-value items by creating a key for each item. + * @param params Key value based object. + */ +export function getQueryString(params: { [key: string]: any }): string { + const qs: string[] = []; + for (const key in params) { + if (typeof params[key] !== 'undefined') { + const value: any = params[key]; + if (value !== undefined && value !== null) { + 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: ./test/result/v2/core/isSuccess.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Check success response code. + * @param status Status code + */ +export function isSuccess(status: number): boolean { + return status >= 200 && status < 300; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/request.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { getFormData } from './getFormData'; +import { getQueryString } from './getQueryString'; +import { OpenAPI } from './OpenAPI'; +import { RequestOptions } from './RequestOptions'; +import { requestUsingFetch } from './requestUsingFetch'; +import { requestUsingXHR } from './requestUsingXHR'; +import { Result } from './Result'; + +/** + * Create the request. + * @param options Request method options. + * @returns Result object (see above) + */ +export async function request(options: Readonly): Promise { + + // Escape path (RFC3986) and create the request URL + let path = options.path.replace(/[:]/g, '_'); + let url = \`\${OpenAPI.BASE}\${path}\`; + + // Create request headers + const headers = new Headers({ + ...options.headers, + Accept: 'application/json', + }); + + // Create request settings + const request: RequestInit = { + headers, + method: options.method, + }; + + // If we specified to send requests with credentials, then we + // set the request credentials options to include. This is only + // needed if you make cross-origin calls. + if (OpenAPI.WITH_CREDENTIALS) { + request.credentials = 'include'; + } + + // If we have a bearer token then we set the authentication header. + if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') { + headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`); + } + + // Add the query parameters (if defined). + if (options.query) { + url += getQueryString(options.query); + } + + // Append formData as body + if (options.formData) { + request.body = getFormData(options.formData); + } else if (options.body) { + + // If this is blob data, then pass it directly to the body and set content type. + // Otherwise we just convert request data to JSON string (needed for fetch api) + if (options.body instanceof Blob) { + request.body = options.body; + if (options.body.type) { + headers.append('Content-Type', options.body.type); + } + } else { + request.body = JSON.stringify(options.body); + headers.append('Content-Type', 'application/json'); + } + } + + try { + switch (OpenAPI.CLIENT) { + case 'xhr': + return await requestUsingXHR(url, request, options.responseHeader); + default: + return await requestUsingFetch(url, request, options.responseHeader); + } + } catch (error) { + return { + url, + ok: false, + status: 0, + statusText: '', + body: error, + }; + } +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/requestUsingFetch.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Result } from './Result'; + +/** + * Try to parse the content for any response status code. + * We check the \\"Content-Type\\" header to see if we need to parse the + * content as json or as plain text. + * @param response Response object from fetch + */ +async function parseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + switch (contentType.toLowerCase()) { + case 'application/json': + case 'application/json; charset=utf-8': + return await response.json(); + + default: + return await response.text(); + } + } + } catch (e) { + console.error(e); + } + return null; +} + +/** + * Fetch the response header (if specified) + * @param response Response object from fetch + * @param responseHeader The name of the header to fetch + */ +function parseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (typeof content === 'string') { + return content; + } + } + return null; +} + +/** + * Request content using the new Fetch API. This is the default API that is used and + * is create for all JSON, XML and text objects. However it is limited to UTF-8. + * This is a problem for some of the Docs content, since that requires UTF-16! + * @param url The url to request. + * @param request The request object, containing method, headers, body, etc. + * @param responseHeader The header we want to parse. + */ +export async function requestUsingFetch(url: string, request: Readonly, responseHeader?: string): Promise { + + // Fetch response using fetch API. + const response = await fetch(url, request); + + // Get content of response header or response body + const contentHeader = parseHeader(response, responseHeader); + const contentBody = await parseBody(response); + + // Create result object. + return { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: contentHeader || contentBody, + }; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/core/requestUsingXHR.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { isSuccess } from './isSuccess'; +import { Result } from './Result'; + +/** + * Try to parse the content for any response status code. + * We check the \\"Content-Type\\" header to see if we need to parse the + * content as json or as plain text. + * @param xhr XHR request object + */ +function parseBody(xhr: XMLHttpRequest): any { + try { + const contentType = xhr.getResponseHeader('Content-Type'); + if (contentType) { + switch (contentType.toLowerCase()) { + case 'application/json': + case 'application/json; charset=utf-8': + return JSON.parse(xhr.responseText); + + default: + return xhr.responseText; + } + } + } catch (e) { + console.error(e); + } + return null; +} + +/** + * Fetch the response header (if specified) + * @param xhr XHR request object + * @param responseHeader The name of the header to fetch + */ +function parseHeader(xhr: XMLHttpRequest, responseHeader?: string): string | null { + if (responseHeader) { + const content = xhr.getResponseHeader(responseHeader); + if (typeof content === 'string') { + return content; + } + } + return null; +} + +/** + * Request content using the new legacy XMLHttpRequest API. This method is useful + * when we want to request UTF-16 content, since it natively supports loading UTF-16. + * We could do the same with the Fetch API, but then we will need to convert the + * content using JavaScript... And that is very very slow. + * @param url The url to request. + * @param request The request object, containing method, headers, body, etc. + * @param responseHeader The header we want to parse. + */ +export async function requestUsingXHR(url: string, request: Readonly, responseHeader?: string): Promise { + return new Promise(resolve => { + const xhr = new XMLHttpRequest(); + + // Open the request, remember to do this before adding any headers, + // because the request needs to be initialized! + xhr.open(request.method!, url, true); + + // When request credentials are set to include then this is + // the same behaviour as withCredentials = true in XHR: + // https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials + xhr.withCredentials = request.credentials === 'include'; + + // Add the headers (required when dealing with JSON) + const headers = request.headers as Headers; + headers.forEach((value: string, key: string): void => { + xhr.setRequestHeader(key, value); + }); + + // Register the readystate handler, this will fire when the request is done. + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + + // Get content of response header or response body + const contentHeader = parseHeader(xhr, responseHeader); + const contentBody = parseBody(xhr); + + // Create result object. + const result: Result = { + url, + ok: isSuccess(xhr.status), + status: xhr.status, + statusText: xhr.statusText, + body: contentHeader || contentBody, + }; + + // Done! + resolve(result); + } + }; + + // Start the request! + xhr.send(request.body); + }); +} +" +`; + +exports[`v2 should generate: ./test/result/v2/index.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export { ApiError } from './core/ApiError'; +export { isSuccess } from './core/isSuccess'; +export { OpenAPI } from './core/OpenAPI'; + +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 { 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 { ModelLink } from './models/ModelLink'; +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 { ModelWithLink } from './models/ModelWithLink'; +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 { $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 { $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 { $ModelLink } from './schemas/$ModelLink'; +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 { $ModelWithLink } from './schemas/$ModelWithLink'; +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 { ComplexService } from './services/ComplexService'; +export { DefaultsService } from './services/DefaultsService'; +export { DuplicateService } from './services/DuplicateService'; +export { HeaderService } from './services/HeaderService'; +export { ParametersService } from './services/ParametersService'; +export { ResponseService } from './services/ResponseService'; +export { SimpleService } from './services/SimpleService'; +export { TypesService } from './services/TypesService'; +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>;" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithBooleans.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array;" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array;" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string, + bar?: string, +}>;" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithReferences.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array;" +`; + +exports[`v2 should generate: ./test/result/v2/models/ArrayWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array;" +`; + +exports[`v2 should generate: ./test/result/v2/models/Dictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Dictionary = { + [key: string]: T; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/DictionaryWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = Dictionary>;" +`; + +exports[`v2 should generate: ./test/result/v2/models/DictionaryWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = Dictionary>;" +`; + +exports[`v2 should generate: ./test/result/v2/models/DictionaryWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = Dictionary<{ + foo?: string, + bar?: string, +}>;" +`; + +exports[`v2 should generate: ./test/result/v2/models/DictionaryWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a string reference + */ +export type DictionaryWithReference = Dictionary;" +`; + +exports[`v2 should generate: ./test/result/v2/models/DictionaryWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = Dictionary;" +`; + +exports[`v2 should generate: ./test/result/v2/models/EnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * Success=1,Warning=2,Error=3 + */ +export enum EnumFromDescription { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, +}" +`; + +exports[`v2 should generate: ./test/result/v2/models/EnumWithExtensions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * 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[`v2 should generate: ./test/result/v2/models/EnumWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple enum with numbers + */ +export enum EnumWithNumbers { + _1 = 1, + _2 = 2, + _3 = 3, +}" +`; + +exports[`v2 should generate: ./test/result/v2/models/EnumWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple enum with strings + */ +export enum EnumWithStrings { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', +}" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model that can have a template?? + */ +export interface ModelLink { + id?: string; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelThatExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export interface ModelThatExtends extends ModelWithString { + propExtendsA?: string; + propExtendsB?: ModelWithString; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelThatExtendsExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelThatExtends } from './ModelThatExtends'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export interface ModelThatExtendsExtends extends ModelWithString, ModelThatExtends { + propExtendsC?: string; + propExtendsD?: ModelWithString; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property containing an array + */ +export interface ModelWithArray { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one boolean property + */ +export interface ModelWithBoolean { + /** + * This is a simple boolean property + */ + prop?: boolean; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one property containing a circular reference + */ +export interface ModelWithCircularReference { + prop?: ModelWithCircularReference; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a model with one property containing a dictionary + */ +export interface ModelWithDictionary { + prop?: Dictionary; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithDuplicateImports.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated imports + */ +export interface ModelWithDuplicateImports { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithDuplicateProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated properties + */ +export interface ModelWithDuplicateProperties { + prop?: ModelWithString; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one enum + */ +export interface ModelWithEnum { + /** + * This is a simple enum with strings + */ + test?: ModelWithEnum.test; + /** + * These are the HTTP error code enums + */ + statusCode?: ModelWithEnum.statusCode; +} + +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: ./test/result/v2/models/ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one enum + */ +export interface 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: ./test/result/v2/models/ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one number property + */ +export interface ModelWithInteger { + /** + * This is a simple number property + */ + prop?: number; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelLink } from './ModelLink'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that can have a template?? + */ +export interface ModelWithLink { + prop?: ModelLink; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithNestedEnums.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a model with nested enums + */ +export interface ModelWithNestedEnums { + dictionaryWithEnum?: Dictionary<('Success' | 'Warning' | 'Error')>; + dictionaryWithEnumFromDescription?: Dictionary<(1 | 2 | 3)>; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(1 | 2 | 3)>; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithNestedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one nested property + */ +export interface ModelWithNestedProperties { + readonly first: { + readonly second: { + readonly third: string, + }, + }; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithOrderedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with ordered properties + */ +export interface ModelWithOrderedProperties { + zebra?: string; + apple?: string; + hawaii?: string; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model that contains a some patterns + */ +export interface ModelWithPattern { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one nested property + */ +export interface ModelWithProperties { + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithProperties } from './ModelWithProperties'; + +/** + * This is a model with one property containing a reference + */ +export interface ModelWithReference { + prop?: ModelWithProperties; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one string property + */ +export interface ModelWithString { + /** + * This is a simple string property + */ + prop?: string; +} +" +`; + +exports[`v2 should generate: ./test/result/v2/models/MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * Testing multiline comments. + * This must go to the next line. + * + * This will contain a break. + */ +export type MultilineComment = number;" +`; + +exports[`v2 should generate: ./test/result/v2/models/SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean;" +`; + +exports[`v2 should generate: ./test/result/v2/models/SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple file + */ +export type SimpleFile = File;" +`; + +exports[`v2 should generate: ./test/result/v2/models/SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple number + */ +export type SimpleInteger = number;" +`; + +exports[`v2 should generate: ./test/result/v2/models/SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString;" +`; + +exports[`v2 should generate: ./test/result/v2/models/SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple string + */ +export type SimpleString = string;" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithArray = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithBooleans.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithBooleans = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithNumbers = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithProperties = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithReferences.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithReferences = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ArrayWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithStrings = { + type: 'Array', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$DictionaryWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithArray = { + type: 'Dictionary', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$DictionaryWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithDictionary = { + type: 'Dictionary', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$DictionaryWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithProperties = { + type: 'Dictionary', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$DictionaryWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithReference = { + type: 'Dictionary', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$DictionaryWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithString = { + type: 'Dictionary', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$EnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumFromDescription = { + type: 'Enum', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$EnumWithExtensions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithExtensions = { + type: 'Enum', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$EnumWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithNumbers = { + type: 'Enum', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$EnumWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithStrings = { + type: 'Enum', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelLink = { + properties: { + id: { + type: 'string', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelThatExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { $ModelWithString } from './$ModelWithString'; + +export const $ModelThatExtends = { + properties: { + ...$ModelWithString.properties, + propExtendsA: { + type: 'string', + }, + propExtendsB: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelThatExtendsExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { $ModelWithString } from './$ModelWithString'; +import { $ModelThatExtends } from './$ModelThatExtends'; + +export const $ModelThatExtendsExtends = { + properties: { + ...$ModelWithString.properties, + ...$ModelThatExtends.properties, + propExtendsC: { + type: 'string', + }, + propExtendsD: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithArray = { + properties: { + prop: { + type: 'Array', + }, + propWithFile: { + type: 'Array', + }, + propWithNumber: { + type: 'Array', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithBoolean = { + properties: { + prop: { + type: 'boolean', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithCircularReference = { + properties: { + prop: { + type: 'ModelWithCircularReference', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithDictionary = { + properties: { + prop: { + type: 'Dictionary', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/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[`v2 should generate: ./test/result/v2/schemas/$ModelWithDuplicateProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithDuplicateProperties = { + properties: { + prop: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithEnum = { + properties: { + test: { + type: 'Enum', + }, + statusCode: { + type: 'Enum', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithEnumFromDescription = { + properties: { + test: { + type: 'Enum', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithInteger = { + properties: { + prop: { + type: 'number', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithLink = { + properties: { + prop: { + type: 'ModelLink', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithNestedEnums.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithNestedEnums = { + properties: { + dictionaryWithEnum: { + type: 'Dictionary', + }, + dictionaryWithEnumFromDescription: { + type: 'Dictionary', + }, + arrayWithEnum: { + type: 'Array', + }, + arrayWithDescription: { + type: 'Array', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/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, + }, + }, + isReadOnly: true, + isRequired: true, + }, + }, + isReadOnly: true, + isRequired: true, + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/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[`v2 should generate: ./test/result/v2/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', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/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', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithReference = { + properties: { + prop: { + type: 'ModelWithProperties', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithString = { + properties: { + prop: { + type: 'string', + }, + }, +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $MultilineComment = { + type: 'number', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleBoolean = { + type: 'boolean', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleFile = { + type: 'File', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleInteger = { + type: 'number', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleReference = { + type: 'ModelWithString', +};" +`; + +exports[`v2 should generate: ./test/result/v2/schemas/$SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleString = { + type: 'string', +};" +`; + +exports[`v2 should generate: ./test/result/v2/services/ComplexService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from '../models/ModelWithString'; +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ComplexService { + + /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @result ModelWithString Successful response + * @throws ApiError + */ + public static async complexTypes( + parameterObject: { + first?: { + second?: { + third?: string, + }, + }, + }, + parameterReference: ModelWithString, + ): Promise> { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/complex\`, + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + }); + + if (!result.ok) { + switch (result.status) { + case 400: throw new ApiError(result, \`400 server error\`); + case 500: throw new ApiError(result, \`500 server error\`); + } + } + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/DefaultsService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from '../models/ModelWithString'; +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class DefaultsService { + + /** + * @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 static 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 __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + catchGenericError(result); + + 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 static 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 __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + catchGenericError(result); + + 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 static async callToTestOrderOfParams( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'Hello World!', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'hello', + parameterStringWithEmptyDefault: string = '', + ): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + }, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/DuplicateService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class DuplicateService { + + /** + * @throws ApiError + */ + public static async duplicateName(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName1(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName2(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName3(): Promise { + + const result = await __request({ + method: 'delete', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/HeaderService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class HeaderService { + + /** + * @result string Successful response + * @throws ApiError + */ + public static async callWithResultFromHeader(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/header\`, + responseHeader: 'operation-location', + }); + + if (!result.ok) { + switch (result.status) { + case 400: throw new ApiError(result, \`400 server error\`); + case 500: throw new ApiError(result, \`500 server error\`); + } + } + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/ParametersService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ParametersService { + + /** + * @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 static async callWithParameters( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath: string, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath}\`, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: parameterBody, + }); + + catchGenericError(result); + + 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 + * @throws ApiError + */ + public static async callWithWeirdParameterNames( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'parameter-query': parameterQuery, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: parameterBody, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/ResponseService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelThatExtends } from '../models/ModelThatExtends'; +import { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; +import { ModelWithString } from '../models/ModelWithString'; +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ResponseService { + + /** + * @result ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithResponse(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @result ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithDuplicateResponses(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + if (!result.ok) { + switch (result.status) { + case 500: throw new ApiError(result, \`Message for 500 error\`); + case 501: throw new ApiError(result, \`Message for 501 error\`); + case 502: throw new ApiError(result, \`Message for 502 error\`); + } + } + + catchGenericError(result); + + return result.body; + } + + /** + * @result ModelWithString Message for default response + * @result ModelThatExtends Message for 201 response + * @result ModelThatExtendsExtends Message for 202 response + * @throws ApiError + */ + public static async callWithResponses(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + if (!result.ok) { + switch (result.status) { + case 500: throw new ApiError(result, \`Message for 500 error\`); + case 501: throw new ApiError(result, \`Message for 501 error\`); + case 502: throw new ApiError(result, \`Message for 502 error\`); + } + } + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/SimpleService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class SimpleService { + + /** + * @throws ApiError + */ + public static async getCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async putCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async postCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async deleteCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'delete', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async optionsCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'options', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async headCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'head', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async patchCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'patch', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v2 should generate: ./test/result/v2/services/TypesService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from '../models/Dictionary'; +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +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 + * @result number Response is a simple number + * @result string Response is a simple string + * @result boolean Response is a simple boolean + * @result any Response is a simple object + * @throws ApiError + */ + public static async types( + parameterArray: Array, + parameterDictionary: Dictionary, + parameterEnum: ('Success' | 'Warning' | 'Error'), + parameterNumber: number = 123, + parameterString: string = 'default', + parameterBoolean: boolean = true, + parameterObject: any = null, + id?: number, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/types\`, + query: { + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, + }, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/core/ApiError.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { isSuccess } from './isSuccess'; +import { Result } from './Result'; + +export class ApiError extends Error { + + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; + + constructor(result: Readonly, message: string) { + super(message); + + this.url = result.url; + this.status = result.status; + this.statusText = result.statusText; + this.body = result.body; + } +} + +export namespace ApiError { + export enum Message { + BAD_REQUEST = 'Bad Request', + UNAUTHORIZED = 'Unauthorized', + FORBIDDEN = 'Forbidden', + NOT_FOUND = 'Not Found', + INTERNAL_SERVER_ERROR = 'Internal Server Error', + BAD_GATEWAY = 'Bad Gateway', + SERVICE_UNAVAILABLE = 'Service Unavailable', + GENERIC_ERROR = 'Generic Error', + } +} + +/** + * Catch common errors (based on status code). + * @param result + */ +export function catchGenericError(result: Result): void { + switch (result.status) { + case 400: throw new ApiError(result, ApiError.Message.BAD_REQUEST); + case 401: throw new ApiError(result, ApiError.Message.UNAUTHORIZED); + case 403: throw new ApiError(result, ApiError.Message.FORBIDDEN); + case 404: throw new ApiError(result, ApiError.Message.NOT_FOUND); + case 500: throw new ApiError(result, ApiError.Message.INTERNAL_SERVER_ERROR); + case 502: throw new ApiError(result, ApiError.Message.BAD_GATEWAY); + case 503: throw new ApiError(result, ApiError.Message.SERVICE_UNAVAILABLE); + } + + if (!isSuccess(result.status)) { + throw new ApiError(result, ApiError.Message.GENERIC_ERROR); + } +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/OpenAPI.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +interface Config { + BASE: string; + VERSION: string; + CLIENT: 'fetch' | 'xhr'; + WITH_CREDENTIALS: boolean; + TOKEN: string; +} + +export const OpenAPI: Config = { + BASE: '/api', + VERSION: '1', + CLIENT: 'fetch', + WITH_CREDENTIALS: false, + TOKEN: '', +};" +`; + +exports[`v3 should generate: ./test/result/v3/core/RequestOptions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export interface RequestOptions { + method: 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch'; + path: string; + cookies?: { [key: string]: any }; + headers?: { [key: string]: any }; + query?: { [key: string]: any }; + formData?: { [key: string]: any }; + body?: any; + responseHeader?: string; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/Result.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export interface Result { + url: string; + ok: boolean; + status: number; + statusText: string; + body: any; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/getFormData.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Get FormData from object. This method is needed to upload + * multipart form data to the REST API. + * @param params Key value based object. + */ +export function getFormData(params: { [key: string]: any }): FormData { + const formData = new FormData(); + for (const key in params) { + if (typeof params[key] !== 'undefined') { + const value: any = params[key]; + if (value !== undefined && value !== null) { + formData.append(key, value); + } + } + } + return formData; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/getQueryString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Get query string from query parameters object. This method also + * supports multi-value items by creating a key for each item. + * @param params Key value based object. + */ +export function getQueryString(params: { [key: string]: any }): string { + const qs: string[] = []; + for (const key in params) { + if (typeof params[key] !== 'undefined') { + const value: any = params[key]; + if (value !== undefined && value !== null) { + 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: ./test/result/v3/core/isSuccess.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * Check success response code. + * @param status Status code + */ +export function isSuccess(status: number): boolean { + return status >= 200 && status < 300; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/request.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { getFormData } from './getFormData'; +import { getQueryString } from './getQueryString'; +import { OpenAPI } from './OpenAPI'; +import { RequestOptions } from './RequestOptions'; +import { requestUsingFetch } from './requestUsingFetch'; +import { requestUsingXHR } from './requestUsingXHR'; +import { Result } from './Result'; + +/** + * Create the request. + * @param options Request method options. + * @returns Result object (see above) + */ +export async function request(options: Readonly): Promise { + + // Escape path (RFC3986) and create the request URL + let path = options.path.replace(/[:]/g, '_'); + let url = \`\${OpenAPI.BASE}\${path}\`; + + // Create request headers + const headers = new Headers({ + ...options.headers, + Accept: 'application/json', + }); + + // Create request settings + const request: RequestInit = { + headers, + method: options.method, + }; + + // If we specified to send requests with credentials, then we + // set the request credentials options to include. This is only + // needed if you make cross-origin calls. + if (OpenAPI.WITH_CREDENTIALS) { + request.credentials = 'include'; + } + + // If we have a bearer token then we set the authentication header. + if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') { + headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`); + } + + // Add the query parameters (if defined). + if (options.query) { + url += getQueryString(options.query); + } + + // Append formData as body + if (options.formData) { + request.body = getFormData(options.formData); + } else if (options.body) { + + // If this is blob data, then pass it directly to the body and set content type. + // Otherwise we just convert request data to JSON string (needed for fetch api) + if (options.body instanceof Blob) { + request.body = options.body; + if (options.body.type) { + headers.append('Content-Type', options.body.type); + } + } else { + request.body = JSON.stringify(options.body); + headers.append('Content-Type', 'application/json'); + } + } + + try { + switch (OpenAPI.CLIENT) { + case 'xhr': + return await requestUsingXHR(url, request, options.responseHeader); + default: + return await requestUsingFetch(url, request, options.responseHeader); + } + } catch (error) { + return { + url, + ok: false, + status: 0, + statusText: '', + body: error, + }; + } +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/requestUsingFetch.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Result } from './Result'; + +/** + * Try to parse the content for any response status code. + * We check the \\"Content-Type\\" header to see if we need to parse the + * content as json or as plain text. + * @param response Response object from fetch + */ +async function parseBody(response: Response): Promise { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + switch (contentType.toLowerCase()) { + case 'application/json': + case 'application/json; charset=utf-8': + return await response.json(); + + default: + return await response.text(); + } + } + } catch (e) { + console.error(e); + } + return null; +} + +/** + * Fetch the response header (if specified) + * @param response Response object from fetch + * @param responseHeader The name of the header to fetch + */ +function parseHeader(response: Response, responseHeader?: string): string | null { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (typeof content === 'string') { + return content; + } + } + return null; +} + +/** + * Request content using the new Fetch API. This is the default API that is used and + * is create for all JSON, XML and text objects. However it is limited to UTF-8. + * This is a problem for some of the Docs content, since that requires UTF-16! + * @param url The url to request. + * @param request The request object, containing method, headers, body, etc. + * @param responseHeader The header we want to parse. + */ +export async function requestUsingFetch(url: string, request: Readonly, responseHeader?: string): Promise { + + // Fetch response using fetch API. + const response = await fetch(url, request); + + // Get content of response header or response body + const contentHeader = parseHeader(response, responseHeader); + const contentBody = await parseBody(response); + + // Create result object. + return { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: contentHeader || contentBody, + }; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/core/requestUsingXHR.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { isSuccess } from './isSuccess'; +import { Result } from './Result'; + +/** + * Try to parse the content for any response status code. + * We check the \\"Content-Type\\" header to see if we need to parse the + * content as json or as plain text. + * @param xhr XHR request object + */ +function parseBody(xhr: XMLHttpRequest): any { + try { + const contentType = xhr.getResponseHeader('Content-Type'); + if (contentType) { + switch (contentType.toLowerCase()) { + case 'application/json': + case 'application/json; charset=utf-8': + return JSON.parse(xhr.responseText); + + default: + return xhr.responseText; + } + } + } catch (e) { + console.error(e); + } + return null; +} + +/** + * Fetch the response header (if specified) + * @param xhr XHR request object + * @param responseHeader The name of the header to fetch + */ +function parseHeader(xhr: XMLHttpRequest, responseHeader?: string): string | null { + if (responseHeader) { + const content = xhr.getResponseHeader(responseHeader); + if (typeof content === 'string') { + return content; + } + } + return null; +} + +/** + * Request content using the new legacy XMLHttpRequest API. This method is useful + * when we want to request UTF-16 content, since it natively supports loading UTF-16. + * We could do the same with the Fetch API, but then we will need to convert the + * content using JavaScript... And that is very very slow. + * @param url The url to request. + * @param request The request object, containing method, headers, body, etc. + * @param responseHeader The header we want to parse. + */ +export async function requestUsingXHR(url: string, request: Readonly, responseHeader?: string): Promise { + return new Promise(resolve => { + const xhr = new XMLHttpRequest(); + + // Open the request, remember to do this before adding any headers, + // because the request needs to be initialized! + xhr.open(request.method!, url, true); + + // When request credentials are set to include then this is + // the same behaviour as withCredentials = true in XHR: + // https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials + xhr.withCredentials = request.credentials === 'include'; + + // Add the headers (required when dealing with JSON) + const headers = request.headers as Headers; + headers.forEach((value: string, key: string): void => { + xhr.setRequestHeader(key, value); + }); + + // Register the readystate handler, this will fire when the request is done. + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + + // Get content of response header or response body + const contentHeader = parseHeader(xhr, responseHeader); + const contentBody = parseBody(xhr); + + // Create result object. + const result: Result = { + url, + ok: isSuccess(xhr.status), + status: xhr.status, + statusText: xhr.statusText, + body: contentHeader || contentBody, + }; + + // Done! + resolve(result); + } + }; + + // Start the request! + xhr.send(request.body); + }); +} +" +`; + +exports[`v3 should generate: ./test/result/v3/index.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export { ApiError } from './core/ApiError'; +export { isSuccess } from './core/isSuccess'; +export { OpenAPI } from './core/OpenAPI'; + +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 { 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 { ModelLink } from './models/ModelLink'; +export type { ModelThatExtends } from './models/ModelThatExtends'; +export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; +export type { ModelWithAnyOf } from './models/ModelWithAnyOf'; +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 { ModelWithLink } from './models/ModelWithLink'; +export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums'; +export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties'; +export type { ModelWithOneOf } from './models/ModelWithOneOf'; +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 { $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 { $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 { $ModelLink } from './schemas/$ModelLink'; +export { $ModelThatExtends } from './schemas/$ModelThatExtends'; +export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; +export { $ModelWithAnyOf } from './schemas/$ModelWithAnyOf'; +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 { $ModelWithLink } from './schemas/$ModelWithLink'; +export { $ModelWithNestedEnums } from './schemas/$ModelWithNestedEnums'; +export { $ModelWithNestedProperties } from './schemas/$ModelWithNestedProperties'; +export { $ModelWithOneOf } from './schemas/$ModelWithOneOf'; +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 { 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 { ParametersService } from './services/ParametersService'; +export { ResponseService } from './services/ResponseService'; +export { SimpleService } from './services/SimpleService'; +export { TypesService } from './services/TypesService'; +export { UploadService } from './services/UploadService'; +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>;" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithBooleans.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array;" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array;" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string, + bar?: string, +}>;" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithReferences.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array;" +`; + +exports[`v3 should generate: ./test/result/v3/models/ArrayWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array;" +`; + +exports[`v3 should generate: ./test/result/v3/models/Dictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Dictionary = { + [key: string]: T; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/DictionaryWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = Dictionary>;" +`; + +exports[`v3 should generate: ./test/result/v3/models/DictionaryWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = Dictionary>;" +`; + +exports[`v3 should generate: ./test/result/v3/models/DictionaryWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = Dictionary<{ + foo?: string, + bar?: string, +}>;" +`; + +exports[`v3 should generate: ./test/result/v3/models/DictionaryWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a string reference + */ +export type DictionaryWithReference = Dictionary;" +`; + +exports[`v3 should generate: ./test/result/v3/models/DictionaryWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = Dictionary;" +`; + +exports[`v3 should generate: ./test/result/v3/models/EnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * Success=1,Warning=2,Error=3 + */ +export enum EnumFromDescription { + SUCCESS = 1, + WARNING = 2, + ERROR = 3, +}" +`; + +exports[`v3 should generate: ./test/result/v3/models/EnumWithExtensions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * 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: ./test/result/v3/models/EnumWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple enum with numbers + */ +export enum EnumWithNumbers { + _1 = 1, + _2 = 2, + _3 = 3, +}" +`; + +exports[`v3 should generate: ./test/result/v3/models/EnumWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple enum with strings + */ +export enum EnumWithStrings { + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', +}" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model that can have a template?? + */ +export interface ModelLink { + id?: string; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelThatExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export interface ModelThatExtends extends ModelWithString { + propExtendsA?: string; + propExtendsB?: ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelThatExtendsExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelThatExtends } from './ModelThatExtends'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that extends another model + */ +export interface ModelThatExtendsExtends extends ModelWithString, ModelThatExtends { + propExtendsC?: string; + propExtendsD?: ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithAnyOf.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithArray } from './ModelWithArray'; +import { ModelWithDictionary } from './ModelWithDictionary'; +import { ModelWithEnum } from './ModelWithEnum'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property with a 'any of' relationship + */ +export interface ModelWithAnyOf { + propA?: ModelWithArray | ModelWithDictionary | ModelWithEnum | ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property containing an array + */ +export interface ModelWithArray { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one boolean property + */ +export interface ModelWithBoolean { + /** + * This is a simple boolean property + */ + prop?: boolean; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one property containing a circular reference + */ +export interface ModelWithCircularReference { + prop?: ModelWithCircularReference; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a model with one property containing a dictionary + */ +export interface ModelWithDictionary { + prop?: Dictionary; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithDuplicateImports.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated imports + */ +export interface ModelWithDuplicateImports { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithDuplicateProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with duplicated properties + */ +export interface ModelWithDuplicateProperties { + prop?: ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one enum + */ +export interface ModelWithEnum { + /** + * This is a simple enum with strings + */ + test?: ModelWithEnum.test; + /** + * These are the HTTP error code enums + */ + statusCode?: ModelWithEnum.statusCode; +} + +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: ./test/result/v3/models/ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one enum + */ +export interface 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: ./test/result/v3/models/ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one number property + */ +export interface ModelWithInteger { + /** + * This is a simple number property + */ + prop?: number; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelLink } from './ModelLink'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model that can have a template?? + */ +export interface ModelWithLink { + prop?: ModelLink; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithNestedEnums.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { Dictionary } from './Dictionary'; + +/** + * This is a model with nested enums + */ +export interface ModelWithNestedEnums { + dictionaryWithEnum?: Dictionary<('Success' | 'Warning' | 'Error')>; + dictionaryWithEnumFromDescription?: Dictionary<(1 | 2 | 3)>; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(1 | 2 | 3)>; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithNestedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one nested property + */ +export interface ModelWithNestedProperties { + readonly first: { + readonly second: { + readonly third: string | null, + } | null, + } | null; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithOneOf.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithArray } from './ModelWithArray'; +import { ModelWithDictionary } from './ModelWithDictionary'; +import { ModelWithEnum } from './ModelWithEnum'; +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one property with a 'one of' relationship + */ +export interface ModelWithOneOf { + propA?: ModelWithArray | ModelWithDictionary | ModelWithEnum | ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithOrderedProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with ordered properties + */ +export interface ModelWithOrderedProperties { + zebra?: string; + apple?: string; + hawaii?: string; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithPattern.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model that contains a some patterns + */ +export interface ModelWithPattern { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a model with one nested property + */ +export interface ModelWithProperties { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithProperties } from './ModelWithProperties'; + +/** + * This is a model with one property containing a reference + */ +export interface ModelWithReference { + prop?: ModelWithProperties; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a model with one string property + */ +export interface ModelWithString { + /** + * This is a simple string property + */ + prop?: string; +} +" +`; + +exports[`v3 should generate: ./test/result/v3/models/MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * Testing multiline comments. + * This must go to the next line. + * + * This will contain a break. + */ +export type MultilineComment = number;" +`; + +exports[`v3 should generate: ./test/result/v3/models/SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean;" +`; + +exports[`v3 should generate: ./test/result/v3/models/SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple file + */ +export type SimpleFile = File;" +`; + +exports[`v3 should generate: ./test/result/v3/models/SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple number + */ +export type SimpleInteger = number;" +`; + +exports[`v3 should generate: ./test/result/v3/models/SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from './ModelWithString'; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString;" +`; + +exports[`v3 should generate: ./test/result/v3/models/SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + + +/** + * This is a simple string + */ +export type SimpleString = string;" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithArray = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithBooleans.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithBooleans = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithNumbers = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithProperties = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithReferences.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithReferences = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ArrayWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ArrayWithStrings = { + type: 'Array', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$DictionaryWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithArray = { + type: 'Dictionary', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$DictionaryWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithDictionary = { + type: 'Dictionary', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$DictionaryWithProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithProperties = { + type: 'Dictionary', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$DictionaryWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithReference = { + type: 'Dictionary', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$DictionaryWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $DictionaryWithString = { + type: 'Dictionary', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$EnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumFromDescription = { + type: 'Enum', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$EnumWithExtensions.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithExtensions = { + type: 'Enum', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$EnumWithNumbers.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithNumbers = { + type: 'Enum', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$EnumWithStrings.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $EnumWithStrings = { + type: 'Enum', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelLink = { + properties: { + id: { + type: 'string', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelThatExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { $ModelWithString } from './$ModelWithString'; + +export const $ModelThatExtends = { + properties: { + ...$ModelWithString.properties, + propExtendsA: { + type: 'string', + }, + propExtendsB: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelThatExtendsExtends.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { $ModelWithString } from './$ModelWithString'; +import { $ModelThatExtends } from './$ModelThatExtends'; + +export const $ModelThatExtendsExtends = { + properties: { + ...$ModelWithString.properties, + ...$ModelThatExtends.properties, + propExtendsC: { + type: 'string', + }, + propExtendsD: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithAnyOf.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithAnyOf = { + properties: { + propA: { + type: 'ModelWithArray | ModelWithDictionary | ModelWithEnum | ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithArray.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithArray = { + properties: { + prop: { + type: 'Array', + }, + propWithFile: { + type: 'Array', + }, + propWithNumber: { + type: 'Array', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithBoolean = { + properties: { + prop: { + type: 'boolean', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithCircularReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithCircularReference = { + properties: { + prop: { + type: 'ModelWithCircularReference', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithDictionary = { + properties: { + prop: { + type: 'Dictionary', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/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: ./test/result/v3/schemas/$ModelWithDuplicateProperties.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithDuplicateProperties = { + properties: { + prop: { + type: 'ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithEnum.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithEnum = { + properties: { + test: { + type: 'Enum', + }, + statusCode: { + type: 'Enum', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithEnumFromDescription.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithEnumFromDescription = { + properties: { + test: { + type: 'Enum', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithInteger = { + properties: { + prop: { + type: 'number', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithLink.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithLink = { + properties: { + prop: { + type: 'ModelLink', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithNestedEnums.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithNestedEnums = { + properties: { + dictionaryWithEnum: { + type: 'Dictionary', + }, + dictionaryWithEnumFromDescription: { + type: 'Dictionary', + }, + arrayWithEnum: { + type: 'Array', + }, + arrayWithDescription: { + type: 'Array', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/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: ./test/result/v3/schemas/$ModelWithOneOf.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithOneOf = { + properties: { + propA: { + type: 'ModelWithArray | ModelWithDictionary | ModelWithEnum | ModelWithString', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/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: ./test/result/v3/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', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/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', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithReference = { + properties: { + prop: { + type: 'ModelWithProperties', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$ModelWithString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $ModelWithString = { + properties: { + prop: { + type: 'string', + }, + }, +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$MultilineComment.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $MultilineComment = { + type: 'number', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$SimpleBoolean.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleBoolean = { + type: 'boolean', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$SimpleFile.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleFile = { + type: 'File', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$SimpleInteger.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleInteger = { + type: 'number', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$SimpleReference.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleReference = { + type: 'ModelWithString', +};" +`; + +exports[`v3 should generate: ./test/result/v3/schemas/$SimpleString.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export const $SimpleString = { + type: 'string', +};" +`; + +exports[`v3 should generate: ./test/result/v3/services/ComplexService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithArray } from '../models/ModelWithArray'; +import { ModelWithDictionary } from '../models/ModelWithDictionary'; +import { ModelWithEnum } from '../models/ModelWithEnum'; +import { ModelWithString } from '../models/ModelWithString'; +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ComplexService { + + /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @result ModelWithString Successful response + * @throws ApiError + */ + public static async complexTypes( + parameterObject: { + first?: { + second?: { + third?: string, + }, + }, + }, + parameterReference: ModelWithString, + ): Promise> { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/complex\`, + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + }); + + if (!result.ok) { + switch (result.status) { + case 400: throw new ApiError(result, \`400 server error\`); + case 500: throw new ApiError(result, \`500 server error\`); + } + } + + catchGenericError(result); + + return result.body; + } + + /** + * @param id + * @param requestBody + * @result ModelWithString Success + * @throws ApiError + */ + public static 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: ModelWithArray | ModelWithDictionary | ModelWithEnum | ModelWithString, + readonly user?: { + readonly id?: number, + readonly name?: string | null, + }, + }, + ): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/complex/\${id}\`, + body: requestBody, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/DefaultsService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from '../models/ModelWithString'; +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class DefaultsService { + + /** + * @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 static 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 __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + catchGenericError(result); + + 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 static 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 __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + catchGenericError(result); + + 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 static async callToTestOrderOfParams( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'hello', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'hello', + parameterStringWithEmptyDefault: string = '', + ): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/defaults\`, + query: { + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + }, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/DuplicateService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class DuplicateService { + + /** + * @throws ApiError + */ + public static async duplicateName(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName1(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName2(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async duplicateName3(): Promise { + + const result = await __request({ + method: 'delete', + path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/HeaderService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class HeaderService { + + /** + * @result string Successful response + * @throws ApiError + */ + public static async callWithResultFromHeader(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/header\`, + responseHeader: 'operation-location', + }); + + if (!result.ok) { + switch (result.status) { + case 400: throw new ApiError(result, \`400 server error\`); + case 500: throw new ApiError(result, \`500 server error\`); + } + } + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/MultipartService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class MultipartService { + + /** + * @result any OK + * @throws ApiError + */ + public static async multipartResponse(): Promise<{ + file?: string, + metadata?: { + foo?: string, + bar?: string, + }, + }> { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/multipart\`, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/ParametersService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelWithString } from '../models/ModelWithString'; +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ParametersService { + + /** + * @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 static async callWithParameters( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + parameterPath: string | null, + requestBody: ModelWithString | null, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath}\`, + cookies: { + 'parameterCookie': parameterCookie, + }, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: requestBody, + }); + + catchGenericError(result); + + 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 + * @throws ApiError + */ + public static async callWithWeirdParameterNames( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + requestBody: ModelWithString | null, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, + cookies: { + 'PARAMETER-COOKIE': parameterCookie, + }, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'parameter-query': parameterQuery, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: requestBody, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @param requestBody This is a required parameter + * @param parameter This is an optional parameter + * @throws ApiError + */ + public static async getCallWithOptionalParam( + requestBody: ModelWithString, + parameter?: string, + ): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\`, + query: { + 'parameter': parameter, + }, + body: requestBody, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @param parameter This is a required parameter + * @param requestBody This is an optional parameter + * @throws ApiError + */ + public static async postCallWithOptionalParam( + parameter: string, + requestBody?: ModelWithString, + ): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/parameters/\`, + query: { + 'parameter': parameter, + }, + body: requestBody, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/ResponseService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { ModelThatExtends } from '../models/ModelThatExtends'; +import { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends'; +import { ModelWithString } from '../models/ModelWithString'; +import { ApiError, catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class ResponseService { + + /** + * @result ModelWithString + * @throws ApiError + */ + public static async callWithResponse(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @result ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithDuplicateResponses(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + if (!result.ok) { + switch (result.status) { + case 500: throw new ApiError(result, \`Message for 500 error\`); + case 501: throw new ApiError(result, \`Message for 501 error\`); + case 502: throw new ApiError(result, \`Message for 502 error\`); + } + } + + catchGenericError(result); + + return result.body; + } + + /** + * @result ModelWithString Message for default response + * @result ModelThatExtends Message for 201 response + * @result ModelThatExtendsExtends Message for 202 response + * @throws ApiError + */ + public static async callWithResponses(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/response\`, + }); + + if (!result.ok) { + switch (result.status) { + case 500: throw new ApiError(result, \`Message for 500 error\`); + case 501: throw new ApiError(result, \`Message for 501 error\`); + case 502: throw new ApiError(result, \`Message for 502 error\`); + } + } + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/SimpleService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class SimpleService { + + /** + * @throws ApiError + */ + public static async getCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async putCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'put', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async postCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async deleteCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'delete', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async optionsCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'options', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async headCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'head', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + + /** + * @throws ApiError + */ + public static async patchCallWithoutParametersAndResponse(): Promise { + + const result = await __request({ + method: 'patch', + path: \`/api/v\${OpenAPI.VERSION}/simple\`, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/TypesService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +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 + * @result number Response is a simple number + * @result string Response is a simple string + * @result boolean Response is a simple boolean + * @result any Response is a simple object + * @throws ApiError + */ + public static 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 __request({ + method: 'get', + path: \`/api/v\${OpenAPI.VERSION}/types\`, + query: { + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, + }, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`; + +exports[`v3 should generate: ./test/result/v3/services/UploadService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import { catchGenericError } from '../core/ApiError'; +import { request as __request } from '../core/request'; +import { OpenAPI } from '../core/OpenAPI'; + +export class UploadService { + + /** + * @param file Supply a file reference for upload + * @result boolean + * @throws ApiError + */ + public static async uploadFile( + file: File, + ): Promise { + + const result = await __request({ + method: 'post', + path: \`/api/v\${OpenAPI.VERSION}/upload\`, + formData: { + 'file': file, + }, + }); + + catchGenericError(result); + + return result.body; + } + +}" +`;