diff --git a/package.json b/package.json index 755cbc9e9..ded5870f0 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "openapi-typescript-codegen", - "version": "0.23.0", + "name": "@codelenny/openapi-typescript-codegen", + "version": "0.23.1", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", - "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", + "homepage": "https://github.com/codelenny/openapi-typescript-codegen", "repository": { "type": "git", - "url": "git+https://github.com/ferdikoomen/openapi-typescript-codegen.git" + "url": "git+https://github.com/codelenny/openapi-typescript-codegen.git" }, "bugs": { - "url": "https://github.com/ferdikoomen/openapi-typescript-codegen/issues" + "url": "https://github.com/codelenny/openapi-typescript-codegen/issues" }, "license": "MIT", "keywords": [ @@ -27,8 +27,7 @@ ], "maintainers": [ { - "name": "Ferdi Koomen", - "email": "info@madebyferdi.com" + "name": "Flyyn Leonard" } ], "main": "dist/index.js", @@ -56,7 +55,7 @@ "eslint": "eslint .", "eslint:fix": "eslint . --fix", "prepublishOnly": "npm run clean && npm run release", - "codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b" + "codecov": "codecov" }, "dependencies": { "camelcase": "^6.3.0", diff --git a/src/client/interfaces/Operation.d.ts b/src/client/interfaces/Operation.d.ts index 779144325..7fd1417ee 100644 --- a/src/client/interfaces/Operation.d.ts +++ b/src/client/interfaces/Operation.d.ts @@ -12,5 +12,6 @@ export interface Operation extends OperationParameters { path: string; errors: OperationError[]; results: OperationResponse[]; + errorResults: OperationResponse[]; responseHeader: string | null; } diff --git a/src/openApi/v2/parser/getOperation.ts b/src/openApi/v2/parser/getOperation.ts index 9aa157460..d9db5d1fd 100644 --- a/src/openApi/v2/parser/getOperation.ts +++ b/src/openApi/v2/parser/getOperation.ts @@ -7,7 +7,7 @@ import { getOperationName } from './getOperationName'; import { getOperationParameters } from './getOperationParameters'; import { getOperationResponseHeader } from './getOperationResponseHeader'; import { getOperationResponses } from './getOperationResponses'; -import { getOperationResults } from './getOperationResults'; +import { getOperationErrorResults, getOperationResults } from './getOperationResults'; import { getServiceName } from './getServiceName'; import { sortByRequired } from './sortByRequired'; @@ -41,6 +41,7 @@ export const getOperation = ( imports: [], errors: [], results: [], + errorResults: [], responseHeader: null, }; @@ -61,6 +62,7 @@ export const getOperation = ( if (op.responses) { const operationResponses = getOperationResponses(openApi, op.responses); const operationResults = getOperationResults(operationResponses); + const operationErrorResults = getOperationErrorResults(operationResponses); operation.errors = getOperationErrors(operationResponses); operation.responseHeader = getOperationResponseHeader(operationResults); @@ -68,6 +70,11 @@ export const getOperation = ( operation.results.push(operationResult); operation.imports.push(...operationResult.imports); }); + + operationErrorResults.forEach(operationResult => { + operation.errorResults.push(operationResult); + operation.imports.push(...operationResult.imports); + }); } operation.parameters = operation.parameters.sort(sortByRequired); diff --git a/src/openApi/v2/parser/getOperationResults.ts b/src/openApi/v2/parser/getOperationResults.ts index 9d8111fe8..f8b619658 100644 --- a/src/openApi/v2/parser/getOperationResults.ts +++ b/src/openApi/v2/parser/getOperationResults.ts @@ -9,6 +9,41 @@ const areEqual = (a: Model, b: Model): boolean => { return equal; }; +export const getOperationErrorResults = (operationResponses: OperationResponse[]): OperationResponse[] => { + const operationResults: OperationResponse[] = []; + + operationResponses.forEach(operationResponse => { + const { code } = operationResponse; + if (code && (code === 204 || code < 200 || code >= 300)) { + operationResults.push(operationResponse); + } + }); + + if (!operationResults.length) { + operationResults.push({ + in: 'response', + name: '', + code: 0, + description: '', + export: 'generic', + type: 'any', + base: 'any', + template: null, + link: null, + isDefinition: false, + isReadOnly: false, + isRequired: false, + isNullable: false, + imports: [], + enum: [], + enums: [], + properties: [], + }); + } + + return operationResults; +}; + export const getOperationResults = (operationResponses: OperationResponse[]): OperationResponse[] => { const operationResults: OperationResponse[] = []; diff --git a/src/openApi/v3/parser/getOperation.ts b/src/openApi/v3/parser/getOperation.ts index aee4bd0c2..152280a5e 100644 --- a/src/openApi/v3/parser/getOperation.ts +++ b/src/openApi/v3/parser/getOperation.ts @@ -9,7 +9,7 @@ import { getOperationParameters } from './getOperationParameters'; import { getOperationRequestBody } from './getOperationRequestBody'; import { getOperationResponseHeader } from './getOperationResponseHeader'; import { getOperationResponses } from './getOperationResponses'; -import { getOperationResults } from './getOperationResults'; +import { getOperationErrorResults, getOperationResults } from './getOperationResults'; import { getRef } from './getRef'; import { getServiceName } from './getServiceName'; import { sortByRequired } from './sortByRequired'; @@ -44,6 +44,7 @@ export const getOperation = ( imports: [], errors: [], results: [], + errorResults: [], responseHeader: null, }; @@ -72,6 +73,7 @@ export const getOperation = ( if (op.responses) { const operationResponses = getOperationResponses(openApi, op.responses); const operationResults = getOperationResults(operationResponses); + const operationErrorResults = getOperationErrorResults(operationResponses); operation.errors = getOperationErrors(operationResponses); operation.responseHeader = getOperationResponseHeader(operationResults); @@ -79,6 +81,11 @@ export const getOperation = ( operation.results.push(operationResult); operation.imports.push(...operationResult.imports); }); + + operationErrorResults.forEach(operationResult => { + operation.errorResults.push(operationResult); + operation.imports.push(...operationResult.imports); + }); } operation.parameters = operation.parameters.sort(sortByRequired); diff --git a/src/openApi/v3/parser/getOperationResults.ts b/src/openApi/v3/parser/getOperationResults.ts index 9d8111fe8..f8b619658 100644 --- a/src/openApi/v3/parser/getOperationResults.ts +++ b/src/openApi/v3/parser/getOperationResults.ts @@ -9,6 +9,41 @@ const areEqual = (a: Model, b: Model): boolean => { return equal; }; +export const getOperationErrorResults = (operationResponses: OperationResponse[]): OperationResponse[] => { + const operationResults: OperationResponse[] = []; + + operationResponses.forEach(operationResponse => { + const { code } = operationResponse; + if (code && (code === 204 || code < 200 || code >= 300)) { + operationResults.push(operationResponse); + } + }); + + if (!operationResults.length) { + operationResults.push({ + in: 'response', + name: '', + code: 0, + description: '', + export: 'generic', + type: 'any', + base: 'any', + template: null, + link: null, + isDefinition: false, + isReadOnly: false, + isRequired: false, + isNullable: false, + imports: [], + enum: [], + enums: [], + properties: [], + }); + } + + return operationResults; +}; + export const getOperationResults = (operationResponses: OperationResponse[]): OperationResponse[] => { const operationResults: OperationResponse[] = []; diff --git a/src/templates/core/ApiError.hbs b/src/templates/core/ApiError.hbs index ab6849d18..4e58769e1 100644 --- a/src/templates/core/ApiError.hbs +++ b/src/templates/core/ApiError.hbs @@ -3,14 +3,17 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; -export class ApiError extends Error { +export class ApiError< + StatusCode extends number = number, + ApiErrorBody = any, +> extends Error { public readonly url: string; - public readonly status: number; + public readonly status: StatusCode; public readonly statusText: string; - public readonly body: any; + public readonly body: ApiErrorBody; public readonly request: ApiRequestOptions; - constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { super(message); this.name = 'ApiError'; diff --git a/src/templates/core/ApiResult.hbs b/src/templates/core/ApiResult.hbs index a768b8c5a..debfb689e 100644 --- a/src/templates/core/ApiResult.hbs +++ b/src/templates/core/ApiResult.hbs @@ -1,9 +1,24 @@ {{>header}} -export type ApiResult = { +export type ApiResult< + StatusCode extends number = number, + ApiErrorBody = any, +> = { readonly url: string; readonly ok: boolean; - readonly status: number; + readonly status: StatusCode; readonly statusText: string; - readonly body: any; + readonly body: ApiErrorBody; }; + +export interface Left { + readonly _tag: 'Left'; + readonly left: E; +} + +export interface Right { + readonly _tag: 'Right'; + readonly right: A; +} + +export type Either = Left | Right; diff --git a/src/templates/core/node/request.hbs b/src/templates/core/node/request.hbs index 8e6f6110e..5ba20cb15 100644 --- a/src/templates/core/node/request.hbs +++ b/src/templates/core/node/request.hbs @@ -67,7 +67,7 @@ import type { OpenAPIConfig } from './OpenAPI'; * @returns CancelablePromise * @throws ApiError */ -export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { +export const request = (config: OpenAPIConfig, options: ApiRequestOptions, fetchFunction?: typeof fetch): CancelablePromise => { return new CancelablePromise(async (resolve, reject, onCancel) => { try { const url = getUrl(config, options); @@ -76,7 +76,7 @@ export const request = (config: OpenAPIConfig, options: ApiRequestOptions): C const headers = await getHeaders(config, options); if (!onCancel.isCancelled) { - const response = await sendRequest(options, url, body, formData, headers, onCancel); + const response = await sendRequest(options, url, body, formData, headers, onCancel, fetchFunction); const responseBody = await getResponseBody(response); const responseHeader = getResponseHeader(response, options.responseHeader); diff --git a/src/templates/core/node/sendRequest.hbs b/src/templates/core/node/sendRequest.hbs index a2ebf86d4..d50dd4590 100644 --- a/src/templates/core/node/sendRequest.hbs +++ b/src/templates/core/node/sendRequest.hbs @@ -4,7 +4,8 @@ export const sendRequest = async ( body: any, formData: FormData | undefined, headers: Headers, - onCancel: OnCancel + onCancel: OnCancel, + fetchFunction: typeof fetch = fetch ): Promise => { const controller = new AbortController(); @@ -17,5 +18,5 @@ export const sendRequest = async ( onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetchFunction(url, request); }; diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index 2fdd9af58..25c21ab09 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -25,10 +25,14 @@ import type { CancelablePromise } from '../core/CancelablePromise'; import { BaseHttpRequest } from '../core/BaseHttpRequest'; {{else}} import type { BaseHttpRequest } from '../core/BaseHttpRequest'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; {{/equals}} {{else}} import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; {{/if}} {{#equals @root.httpClient 'angular'}} @@ -146,5 +150,128 @@ export class {{{name}}}{{{@root.postfix}}} { }); } + {{#equals @root.httpClient 'angular'}} + {{else}} + /** + {{#if deprecated}} + * @deprecated + {{/if}} + {{#if summary}} + * {{{escapeComment summary}}} + {{/if}} + {{#if description}} + * {{{escapeComment description}}} + {{/if}} + {{#unless @root.useOptions}} + {{#if parameters}} + {{#each parameters}} + * @param {{{name}}} {{#if description}}{{{escapeComment description}}}{{/if}} + {{/each}} + {{/if}} + {{/unless}} + {{#each results}} + * @returns {{{type}}} {{#if description}}{{{escapeComment description}}}{{/if}} + {{/each}} + * @throws ApiError + */ + {{#if @root.exportClient}} + {{#equals @root.httpClient 'angular'}} + public async {{{name}}}Either({{>parameters}}): Observable<{{>result}}> { + try { + const result: ({{>result}}) = await this.httpRequest.request({ + {{else}} + public async {{{name}}}Either({{>parameters}}): PromiseerrorResult}}, {{>result}}>> { + try { + const result: ({{>result}}) = await this.httpRequest.request({ + {{/equals}} + {{else}} + {{#equals @root.httpClient 'angular'}} + public async {{{name}}}Either({{>parameters}}): Observable<{{>result}}> { + try { + const result: ({{>result}}) = await __request(OpenAPI, this.http, { + {{else}} + public static async {{{name}}}Either({{>parameters}}): PromiseerrorResult}}, {{>result}}>> { + try { + const result: ({{>result}}) = await __request(OpenAPI, { + {{/equals}} + {{/if}} + method: '{{{method}}}', + url: '{{{path}}}', + {{#if parametersPath}} + path: { + {{#each parametersPath}} + '{{{prop}}}': {{{name}}}, + {{/each}} + }, + {{/if}} + {{#if parametersCookie}} + cookies: { + {{#each parametersCookie}} + '{{{prop}}}': {{{name}}}, + {{/each}} + }, + {{/if}} + {{#if parametersHeader}} + headers: { + {{#each parametersHeader}} + '{{{prop}}}': {{{name}}}, + {{/each}} + }, + {{/if}} + {{#if parametersQuery}} + query: { + {{#each parametersQuery}} + '{{{prop}}}': {{{name}}}, + {{/each}} + }, + {{/if}} + {{#if parametersForm}} + formData: { + {{#each parametersForm}} + '{{{prop}}}': {{{name}}}, + {{/each}} + }, + {{/if}} + {{#if parametersBody}} + {{#equals parametersBody.in 'formData'}} + formData: {{{parametersBody.name}}}, + {{/equals}} + {{#equals parametersBody.in 'body'}} + body: {{{parametersBody.name}}}, + {{/equals}} + {{#if parametersBody.mediaType}} + mediaType: '{{{parametersBody.mediaType}}}', + {{/if}} + {{/if}} + {{#if responseHeader}} + responseHeader: '{{{responseHeader}}}', + {{/if}} + {{#if errors}} + errors: { + {{#each errors}} + {{{code}}}: `{{{escapeDescription description}}}`, + {{/each}} + }, + {{/if}} + }); + + const right: Right<{{>result}}> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left<{{>errorResult}}> = { + _tag: 'Left', + left: e as ({{>errorResult}}), + }; + + return left; + } + } + {{/equals}} + + {{/each}} } diff --git a/src/templates/partials/errorResult.hbs b/src/templates/partials/errorResult.hbs new file mode 100644 index 000000000..4022a4c35 --- /dev/null +++ b/src/templates/partials/errorResult.hbs @@ -0,0 +1,5 @@ +{{~#if errorResults~}} +{{#each errorResults}}ApiError<{{#equals code 0}}number{{else}}{{{code}}}{{/equals}}, {{type}}>{{#unless @last}} | {{/unless}}{{/each}} +{{~else~}} +ApiError +{{~/if~}} diff --git a/src/utils/registerHandlebarTemplates.ts b/src/utils/registerHandlebarTemplates.ts index bf77cbdc1..78c109e65 100644 --- a/src/utils/registerHandlebarTemplates.ts +++ b/src/utils/registerHandlebarTemplates.ts @@ -57,6 +57,7 @@ import templateExportSchema from '../templates/exportSchema.hbs'; import templateExportService from '../templates/exportService.hbs'; import templateIndex from '../templates/index.hbs'; import partialBase from '../templates/partials/base.hbs'; +import partialErrorResult from '../templates/partials/errorResult.hbs'; import partialExportComposition from '../templates/partials/exportComposition.hbs'; import partialExportEnum from '../templates/partials/exportEnum.hbs'; import partialExportInterface from '../templates/partials/exportInterface.hbs'; @@ -148,6 +149,7 @@ export const registerHandlebarTemplates = (root: { Handlebars.registerPartial('isRequired', Handlebars.template(partialIsRequired)); Handlebars.registerPartial('parameters', Handlebars.template(partialParameters)); Handlebars.registerPartial('result', Handlebars.template(partialResult)); + Handlebars.registerPartial('errorResult', Handlebars.template(partialErrorResult)); Handlebars.registerPartial('schema', Handlebars.template(partialSchema)); Handlebars.registerPartial('schemaArray', Handlebars.template(partialSchemaArray)); Handlebars.registerPartial('schemaDictionary', Handlebars.template(partialSchemaDictionary)); diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index cb3405f2a..4ac206ecf 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -7,14 +7,17 @@ exports[`v2 should generate: ./test/generated/v2/core/ApiError.ts 1`] = ` import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; -export class ApiError extends Error { +export class ApiError< + StatusCode extends number = number, + ApiErrorBody = any, +> extends Error { public readonly url: string; - public readonly status: number; + public readonly status: StatusCode; public readonly statusText: string; - public readonly body: any; + public readonly body: ApiErrorBody; public readonly request: ApiRequestOptions; - constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { super(message); this.name = 'ApiError'; @@ -52,13 +55,28 @@ exports[`v2 should generate: ./test/generated/v2/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export type ApiResult = { +export type ApiResult< + StatusCode extends number = number, + ApiErrorBody = any, +> = { readonly url: string; readonly ok: boolean; - readonly status: number; + readonly status: StatusCode; readonly statusText: string; - readonly body: any; + readonly body: ApiErrorBody; }; + +export interface Left { + readonly _tag: 'Left'; + readonly left: E; +} + +export interface Right { + readonly _tag: 'Right'; + readonly right: A; +} + +export type Either = Left | Right; " `; @@ -2250,6 +2268,8 @@ exports[`v2 should generate: ./test/generated/v2/services/CollectionFormatServic import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class CollectionFormatService { @@ -2281,6 +2301,51 @@ export class CollectionFormatService { }); } + /** + * @param parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public static async collectionFormatEither( + parameterArrayCsv: Array, + parameterArraySsv: Array, + parameterArrayTsv: Array, + parameterArrayPipes: Array, + parameterArrayMulti: Array, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + 'parameterArrayCSV': parameterArrayCsv, + 'parameterArraySSV': parameterArraySsv, + 'parameterArrayTSV': parameterArrayTsv, + 'parameterArrayPipes': parameterArrayPipes, + 'parameterArrayMulti': parameterArrayMulti, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2294,6 +2359,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ComplexService { @@ -2327,6 +2394,53 @@ export class ComplexService { }); } + /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static async complexTypesEither( + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }, + parameterReference: ModelWithString, + ): Promise | ApiError<500, any>, Array>> { + try { + const result: (Array) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + + const right: Right> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<500, any>> = { + _tag: 'Left', + left: e as (ApiError<400, any> | ApiError<500, any>), + }; + + return left; + } + } + + } " `; @@ -2338,6 +2452,8 @@ exports[`v2 should generate: ./test/generated/v2/services/DefaultService.ts 1`] import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultService { @@ -2351,6 +2467,33 @@ export class DefaultService { }); } + /** + * @throws ApiError + */ + public static async serviceWithEmptyTagEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2364,6 +2507,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultsService { @@ -2397,6 +2542,53 @@ 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 callWithDefaultParametersEither( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @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 @@ -2427,6 +2619,53 @@ export class DefaultsService { }); } + /** + * @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 callWithDefaultOptionalParametersEither( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @param parameterStringWithNoDefault This is a string with no default * @param parameterOptionalStringWithDefault This is a optional string with default @@ -2464,6 +2703,60 @@ export class DefaultsService { }); } + /** + * @param parameterStringWithNoDefault This is a string with no default + * @param parameterOptionalStringWithDefault This is a optional string with default + * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param parameterOptionalStringWithNoDefault This is a optional string with no default + * @param parameterStringWithDefault This is a string with default + * @param parameterStringWithEmptyDefault This is a string with empty default + * @param parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static async callToTestOrderOfParamsEither( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'Hello World!', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'Hello World!', + parameterStringWithEmptyDefault: string = '', + parameterStringNullableWithNoDefault?: string | null, + parameterStringNullableWithDefault: string | null = null, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault, + 'parameterStringNullableWithDefault': parameterStringNullableWithDefault, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2475,6 +2768,8 @@ exports[`v2 should generate: ./test/generated/v2/services/DescriptionsService.ts import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DescriptionsService { @@ -2512,6 +2807,57 @@ export class DescriptionsService { }); } + /** + * @param parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work + * @param parameterWithSlashes Testing slashes in string: \\\\backwards\\\\\\\\\\\\ and /forwards/// should work + * @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work + * @param parameterWithQuotes Testing quotes in string: 'single quote''' and \\"double quotes\\"\\"\\" should work + * @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public static async callWithDescriptionsEither( + parameterWithBreaks?: string, + parameterWithBackticks?: string, + parameterWithSlashes?: string, + parameterWithExpressionPlaceholders?: string, + parameterWithQuotes?: string, + parameterWithReservedCharacters?: string, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + 'parameterWithBreaks': parameterWithBreaks, + 'parameterWithBackticks': parameterWithBackticks, + 'parameterWithSlashes': parameterWithSlashes, + 'parameterWithExpressionPlaceholders': parameterWithExpressionPlaceholders, + 'parameterWithQuotes': parameterWithQuotes, + 'parameterWithReservedCharacters': parameterWithReservedCharacters, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2523,6 +2869,8 @@ exports[`v2 should generate: ./test/generated/v2/services/DuplicateService.ts 1` import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -2536,6 +2884,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateNameEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2546,6 +2921,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName1Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2556,6 +2958,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName2Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2566,6 +2995,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName3Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2577,6 +3033,8 @@ exports[`v2 should generate: ./test/generated/v2/services/ErrorService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ErrorService { @@ -2603,20 +3061,62 @@ export class ErrorService { }); } -} -" -`; - -exports[`v2 should generate: ./test/generated/v2/services/HeaderService.ts 1`] = ` -"/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { CancelablePromise } from '../core/CancelablePromise'; -import { OpenAPI } from '../core/OpenAPI'; -import { request as __request } from '../core/request'; - -export class HeaderService { - + /** + * @param status Status code to return + * @returns any Custom message: Successful response + * @throws ApiError + */ + public static async testErrorCodeEither( + status: string, + ): Promise | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>, any>> { + try { + const result: (any) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + 'status': status, + }, + errors: { + 500: \`Custom message: Internal Server Error\`, + 501: \`Custom message: Not Implemented\`, + 502: \`Custom message: Bad Gateway\`, + 503: \`Custom message: Service Unavailable\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>> = { + _tag: 'Left', + left: e as (ApiError<500, any> | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>), + }; + + return left; + } + } + + +} +" +`; + +exports[`v2 should generate: ./test/generated/v2/services/HeaderService.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; + +export class HeaderService { + /** * @returns string Successful response * @throws ApiError @@ -2633,6 +3133,39 @@ export class HeaderService { }); } + /** + * @returns string Successful response + * @throws ApiError + */ + public static async callWithResultFromHeaderEither(): Promise | ApiError<500, any>, string>> { + try { + const result: (string) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<500, any>> = { + _tag: 'Left', + left: e as (ApiError<400, any> | ApiError<500, any>), + }; + + return left; + } + } + + } " `; @@ -2644,6 +3177,8 @@ exports[`v2 should generate: ./test/generated/v2/services/MultipleTags1Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -2658,6 +3193,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -2669,6 +3232,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -2680,6 +3271,8 @@ exports[`v2 should generate: ./test/generated/v2/services/MultipleTags2Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -2694,6 +3287,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -2705,6 +3326,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -2716,6 +3365,8 @@ exports[`v2 should generate: ./test/generated/v2/services/MultipleTags3Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -2730,6 +3381,34 @@ export class MultipleTags3Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -2741,6 +3420,8 @@ exports[`v2 should generate: ./test/generated/v2/services/NoContentService.ts 1` import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class NoContentService { @@ -2755,6 +3436,34 @@ export class NoContentService { }); } + /** + * @returns void + * @throws ApiError + */ + public static async callWithNoContentResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -2766,6 +3475,8 @@ exports[`v2 should generate: ./test/generated/v2/services/ParametersService.ts 1 import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ParametersService { @@ -2803,6 +3514,57 @@ 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 sent as request body + * @param parameterPath This is the parameter that goes into the path + * @throws ApiError + */ + public static async callWithParametersEither( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath: string, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + 'parameterPath': parameterPath, + }, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: parameterBody, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @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 @@ -2846,6 +3608,66 @@ export class ParametersService { }); } + /** + * @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 sent as request body + * @param parameterPath1 This is the parameter that goes into the path + * @param parameterPath2 This is the parameter that goes into the path + * @param parameterPath3 This is the parameter that goes into the path + * @param _default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static async callWithWeirdParameterNamesEither( + parameterHeader: string, + parameterQuery: string, + parameterForm: string, + parameterBody: string, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + _default?: string, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': parameterPath1, + 'parameter-path-2': parameterPath2, + 'PARAMETER-PATH-3': parameterPath3, + }, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'default': _default, + 'parameter-query': parameterQuery, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: parameterBody, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -2861,6 +3683,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ResponseService { @@ -2875,6 +3699,34 @@ export class ResponseService { }); } + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithResponseEither(): Promise, ModelWithString>> { + try { + const result: (ModelWithString) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @returns ModelWithString Message for default response * @throws ApiError @@ -2891,6 +3743,39 @@ export class ResponseService { }); } + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithDuplicateResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, ModelWithString>> { + try { + const result: (ModelWithString) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/response', + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { + _tag: 'Left', + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), + }; + + return left; + } + } + + /** * @returns any Message for 200 response * @returns ModelWithString Message for default response @@ -2914,6 +3799,54 @@ export class ResponseService { }); } + /** + * @returns any Message for 200 response + * @returns ModelWithString Message for default response + * @returns ModelThatExtends Message for 201 response + * @returns ModelThatExtendsExtends Message for 202 response + * @throws ApiError + */ + public static async callWithResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends>> { + try { + const result: ({ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/response', + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + + const right: Right<{ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { + _tag: 'Left', + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), + }; + + return left; + } + } + + } " `; @@ -2925,6 +3858,8 @@ exports[`v2 should generate: ./test/generated/v2/services/SimpleService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class SimpleService { @@ -2941,13 +3876,67 @@ export class SimpleService { /** * @throws ApiError */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { + public static async getCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/simple', }); } + /** + * @throws ApiError + */ + public static async putCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2958,6 +3947,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async postCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2968,6 +3984,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async deleteCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2978,6 +4021,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async optionsCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2988,6 +4058,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async headCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -2998,6 +4095,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async patchCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -3009,6 +4133,8 @@ exports[`v2 should generate: ./test/generated/v2/services/TypesService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class TypesService { @@ -3055,6 +4181,66 @@ export class TypesService { }); } + /** + * @param parameterArray This is an array parameter + * @param parameterDictionary This is a dictionary parameter + * @param parameterEnum This is an enum parameter + * @param parameterNumber This is a number parameter + * @param parameterString This is a string parameter + * @param parameterBoolean This is a boolean parameter + * @param parameterObject This is an object parameter + * @param id This is a number parameter + * @returns number Response is a simple number + * @returns string Response is a simple string + * @returns boolean Response is a simple boolean + * @returns any Response is a simple object + * @throws ApiError + */ + public static async typesEither( + parameterArray: Array, + parameterDictionary: Record, + parameterEnum: 'Success' | 'Warning' | 'Error', + parameterNumber: number = 123, + parameterString: string = 'default', + parameterBoolean: boolean = true, + parameterObject: any = null, + id?: number, + ): Promise, number | string | boolean | any>> { + try { + const result: (number | string | boolean | any) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + 'id': id, + }, + query: { + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -3066,14 +4252,17 @@ exports[`v3 should generate: ./test/generated/v3/core/ApiError.ts 1`] = ` import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; -export class ApiError extends Error { +export class ApiError< + StatusCode extends number = number, + ApiErrorBody = any, +> extends Error { public readonly url: string; - public readonly status: number; + public readonly status: StatusCode; public readonly statusText: string; - public readonly body: any; + public readonly body: ApiErrorBody; public readonly request: ApiRequestOptions; - constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { super(message); this.name = 'ApiError'; @@ -3111,13 +4300,28 @@ exports[`v3 should generate: ./test/generated/v3/core/ApiResult.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -export type ApiResult = { +export type ApiResult< + StatusCode extends number = number, + ApiErrorBody = any, +> = { readonly url: string; readonly ok: boolean; - readonly status: number; + readonly status: StatusCode; readonly statusText: string; - readonly body: any; + readonly body: ApiErrorBody; }; + +export interface Left { + readonly _tag: 'Left'; + readonly left: E; +} + +export interface Right { + readonly _tag: 'Right'; + readonly right: A; +} + +export type Either = Left | Right; " `; @@ -6122,6 +7326,8 @@ exports[`v3 should generate: ./test/generated/v3/services/CollectionFormatServic import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class CollectionFormatService { @@ -6153,6 +7359,51 @@ export class CollectionFormatService { }); } + /** + * @param parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public static async collectionFormatEither( + parameterArrayCsv: Array | null, + parameterArraySsv: Array | null, + parameterArrayTsv: Array | null, + parameterArrayPipes: Array | null, + parameterArrayMulti: Array | null, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + 'parameterArrayCSV': parameterArrayCsv, + 'parameterArraySSV': parameterArraySsv, + 'parameterArrayTSV': parameterArrayTsv, + 'parameterArrayPipes': parameterArrayPipes, + 'parameterArrayMulti': parameterArrayMulti, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6169,6 +7420,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ComplexService { @@ -6202,6 +7455,53 @@ export class ComplexService { }); } + /** + * @param parameterObject Parameter containing object + * @param parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static async complexTypesEither( + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }, + parameterReference: ModelWithString, + ): Promise | ApiError<500, any>, Array>> { + try { + const result: (Array) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + 'parameterObject': parameterObject, + 'parameterReference': parameterReference, + }, + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + + const right: Right> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<500, any>> = { + _tag: 'Left', + left: e as (ApiError<400, any> | ApiError<500, any>), + }; + + return left; + } + } + + /** * @param id * @param requestBody @@ -6235,6 +7535,56 @@ export class ComplexService { }); } + /** + * @param id + * @param requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public static async complexParamsEither( + id: number, + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }, + ): Promise, ModelWithString>> { + try { + const result: (ModelWithString) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: { + 'id': id, + }, + body: requestBody, + mediaType: 'application/json-patch+json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6246,6 +7596,8 @@ exports[`v3 should generate: ./test/generated/v3/services/DefaultService.ts 1`] import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultService { @@ -6259,6 +7611,33 @@ export class DefaultService { }); } + /** + * @throws ApiError + */ + public static async serviceWithEmptyTagEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6272,6 +7651,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultsService { @@ -6306,17 +7687,64 @@ export class DefaultsService { } /** - * @param parameterString This is a simple string that is optional with default value - * @param parameterNumber This is a simple number that is optional with default value - * @param parameterBoolean This is a simple boolean that is optional with default value - * @param parameterEnum This is a simple enum that is optional with default value - * @param parameterModel This is a simple model that is optional with default value + * @param 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 callWithDefaultOptionalParameters( - parameterString: string = 'Hello World!', - parameterNumber: number = 123, - parameterBoolean: boolean = true, + public static async callWithDefaultParametersEither( + 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, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + + /** + * @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 callWithDefaultOptionalParameters( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" @@ -6335,6 +7763,53 @@ export class DefaultsService { }); } + /** + * @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 callWithDefaultOptionalParametersEither( + parameterString: string = 'Hello World!', + parameterNumber: number = 123, + parameterBoolean: boolean = true, + parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', + parameterModel: ModelWithString = { + \\"prop\\": \\"Hello World!\\" + }, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + 'parameterString': parameterString, + 'parameterNumber': parameterNumber, + 'parameterBoolean': parameterBoolean, + 'parameterEnum': parameterEnum, + 'parameterModel': parameterModel, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @param parameterStringWithNoDefault This is a string with no default * @param parameterOptionalStringWithDefault This is a optional string with default @@ -6372,6 +7847,60 @@ export class DefaultsService { }); } + /** + * @param parameterStringWithNoDefault This is a string with no default + * @param parameterOptionalStringWithDefault This is a optional string with default + * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param parameterOptionalStringWithNoDefault This is a optional string with no default + * @param parameterStringWithDefault This is a string with default + * @param parameterStringWithEmptyDefault This is a string with empty default + * @param parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static async callToTestOrderOfParamsEither( + parameterStringWithNoDefault: string, + parameterOptionalStringWithDefault: string = 'Hello World!', + parameterOptionalStringWithEmptyDefault: string = '', + parameterOptionalStringWithNoDefault?: string, + parameterStringWithDefault: string = 'Hello World!', + parameterStringWithEmptyDefault: string = '', + parameterStringNullableWithNoDefault?: string | null, + parameterStringNullableWithDefault: string | null = null, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + 'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault, + 'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault, + 'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault, + 'parameterStringWithDefault': parameterStringWithDefault, + 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, + 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault, + 'parameterStringNullableWithDefault': parameterStringNullableWithDefault, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6385,6 +7914,8 @@ import type { DeprecatedModel } from '../models/DeprecatedModel'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DeprecatedService { @@ -6405,6 +7936,40 @@ export class DeprecatedService { }); } + /** + * @deprecated + * @param parameter This parameter is deprecated + * @throws ApiError + */ + public static async deprecatedCallEither( + parameter: DeprecatedModel | null, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: { + 'parameter': parameter, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6416,6 +7981,8 @@ exports[`v3 should generate: ./test/generated/v3/services/DescriptionsService.ts import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DescriptionsService { @@ -6453,6 +8020,57 @@ export class DescriptionsService { }); } + /** + * @param parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work + * @param parameterWithSlashes Testing slashes in string: \\\\backwards\\\\\\\\\\\\ and /forwards/// should work + * @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work + * @param parameterWithQuotes Testing quotes in string: 'single quote''' and \\"double quotes\\"\\"\\" should work + * @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public static async callWithDescriptionsEither( + parameterWithBreaks?: any, + parameterWithBackticks?: any, + parameterWithSlashes?: any, + parameterWithExpressionPlaceholders?: any, + parameterWithQuotes?: any, + parameterWithReservedCharacters?: any, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + 'parameterWithBreaks': parameterWithBreaks, + 'parameterWithBackticks': parameterWithBackticks, + 'parameterWithSlashes': parameterWithSlashes, + 'parameterWithExpressionPlaceholders': parameterWithExpressionPlaceholders, + 'parameterWithQuotes': parameterWithQuotes, + 'parameterWithReservedCharacters': parameterWithReservedCharacters, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6464,6 +8082,8 @@ exports[`v3 should generate: ./test/generated/v3/services/DuplicateService.ts 1` import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -6477,6 +8097,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateNameEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -6487,6 +8134,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName1Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -6497,6 +8171,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName2Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -6507,6 +8208,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateName3Either(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6518,6 +8246,8 @@ exports[`v3 should generate: ./test/generated/v3/services/ErrorService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ErrorService { @@ -6544,6 +8274,46 @@ export class ErrorService { }); } + /** + * @param status Status code to return + * @returns any Custom message: Successful response + * @throws ApiError + */ + public static async testErrorCodeEither( + status: number, + ): Promise | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>, any>> { + try { + const result: (any) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + 'status': status, + }, + errors: { + 500: \`Custom message: Internal Server Error\`, + 501: \`Custom message: Not Implemented\`, + 502: \`Custom message: Bad Gateway\`, + 503: \`Custom message: Service Unavailable\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>> = { + _tag: 'Left', + left: e as (ApiError<500, any> | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>), + }; + + return left; + } + } + + } " `; @@ -6557,6 +8327,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class FormDataService { @@ -6580,6 +8352,43 @@ export class FormDataService { }); } + /** + * @param parameter This is a reusable parameter + * @param formData A reusable request body + * @throws ApiError + */ + public static async postApiFormDataEither( + parameter?: string, + formData?: ModelWithString, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + 'parameter': parameter, + }, + formData: formData, + mediaType: 'multipart/form-data', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6591,6 +8400,8 @@ exports[`v3 should generate: ./test/generated/v3/services/HeaderService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class HeaderService { @@ -6610,6 +8421,39 @@ export class HeaderService { }); } + /** + * @returns string Successful response + * @throws ApiError + */ + public static async callWithResultFromHeaderEither(): Promise | ApiError<500, any>, string>> { + try { + const result: (string) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: \`400 server error\`, + 500: \`500 server error\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<500, any>> = { + _tag: 'Left', + left: e as (ApiError<400, any> | ApiError<500, any>), + }; + + return left; + } + } + + } " `; @@ -6623,6 +8467,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipartService { @@ -6645,22 +8491,103 @@ export class MultipartService { } /** - * @returns any OK + * @param formData * @throws ApiError */ - public static multipartResponse(): CancelablePromise<{ - file?: Blob; - metadata?: { - foo?: string; - bar?: string; - }; - }> { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multipart', + public static async multipartRequestEither( + formData?: { + content?: Blob; + data?: ModelWithString | null; + }, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/multipart', + formData: formData, + mediaType: 'multipart/form-data', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + + /** + * @returns any OK + * @throws ApiError + */ + public static multipartResponse(): CancelablePromise<{ + file?: Blob; + metadata?: { + foo?: string; + bar?: string; + }; + }> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multipart', }); } + /** + * @returns any OK + * @throws ApiError + */ + public static async multipartResponseEither(): Promise, { + file?: Blob; + metadata?: { + foo?: string; + bar?: string; + }; + }>> { + try { + const result: ({ + file?: Blob; + metadata?: { + foo?: string; + bar?: string; + }; + }) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multipart', + }); + + const right: Right<{ + file?: Blob; + metadata?: { + foo?: string; + bar?: string; + }; + }> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6672,6 +8599,8 @@ exports[`v3 should generate: ./test/generated/v3/services/MultipleTags1Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -6686,6 +8615,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -6697,6 +8654,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -6708,6 +8693,8 @@ exports[`v3 should generate: ./test/generated/v3/services/MultipleTags2Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -6722,6 +8709,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -6733,6 +8748,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -6744,6 +8787,8 @@ exports[`v3 should generate: ./test/generated/v3/services/MultipleTags3Service.t import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -6758,6 +8803,34 @@ export class MultipleTags3Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -6769,6 +8842,8 @@ exports[`v3 should generate: ./test/generated/v3/services/NoContentService.ts 1` import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class NoContentService { @@ -6783,6 +8858,34 @@ export class NoContentService { }); } + /** + * @returns void + * @throws ApiError + */ + public static async callWithNoContentResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError<204, any>), + }; + + return left; + } + } + + } " `; @@ -6797,6 +8900,8 @@ import type { Pageable } from '../models/Pageable'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ParametersService { @@ -6840,6 +8945,63 @@ 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 callWithParametersEither( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + parameterPath: string | null, + requestBody: ModelWithString | null, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + 'parameterPath': parameterPath, + }, + cookies: { + 'parameterCookie': parameterCookie, + }, + headers: { + 'parameterHeader': parameterHeader, + }, + query: { + 'parameterQuery': parameterQuery, + }, + formData: { + 'parameterForm': parameterForm, + }, + body: requestBody, + mediaType: 'application/json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @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 @@ -6889,6 +9051,72 @@ export class ParametersService { }); } + /** + * @param parameterHeader This is the parameter that goes into the request header + * @param parameterQuery This is the parameter that goes into the request query params + * @param parameterForm This is the parameter that goes into the request form data + * @param parameterCookie This is the parameter that goes into the cookie + * @param requestBody This is the parameter that goes into the body + * @param parameterPath1 This is the parameter that goes into the path + * @param parameterPath2 This is the parameter that goes into the path + * @param parameterPath3 This is the parameter that goes into the path + * @param _default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static async callWithWeirdParameterNamesEither( + parameterHeader: string | null, + parameterQuery: string | null, + parameterForm: string | null, + parameterCookie: string | null, + requestBody: ModelWithString | null, + parameterPath1?: string, + parameterPath2?: string, + parameterPath3?: string, + _default?: string, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': parameterPath1, + 'parameter-path-2': parameterPath2, + 'PARAMETER-PATH-3': parameterPath3, + }, + cookies: { + 'PARAMETER-COOKIE': parameterCookie, + }, + headers: { + 'parameter.header': parameterHeader, + }, + query: { + 'default': _default, + 'parameter-query': parameterQuery, + }, + formData: { + 'parameter_form': parameterForm, + }, + body: requestBody, + mediaType: 'application/json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @param requestBody This is a required parameter * @param parameter This is an optional parameter @@ -6909,6 +9137,43 @@ export class ParametersService { }); } + /** + * @param requestBody This is a required parameter + * @param parameter This is an optional parameter + * @throws ApiError + */ + public static async getCallWithOptionalParamEither( + requestBody: ModelWithString, + parameter?: string, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + 'parameter': parameter, + }, + body: requestBody, + mediaType: 'application/json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @param parameter This is a required parameter * @param requestBody This is an optional parameter @@ -6929,6 +9194,43 @@ export class ParametersService { }); } + /** + * @param parameter This is a required parameter + * @param requestBody This is an optional parameter + * @throws ApiError + */ + public static async postCallWithOptionalParamEither( + parameter: Pageable, + requestBody?: ModelWithString, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + 'parameter': parameter, + }, + body: requestBody, + mediaType: 'application/json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6942,6 +9244,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class RequestBodyService { @@ -6965,6 +9269,43 @@ export class RequestBodyService { }); } + /** + * @param parameter This is a reusable parameter + * @param requestBody A reusable request body + * @throws ApiError + */ + public static async postApiRequestBodyEither( + parameter?: string, + requestBody?: ModelWithString, + ): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + 'parameter': parameter, + }, + body: requestBody, + mediaType: 'application/json', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -6980,6 +9321,8 @@ import type { ModelWithString } from '../models/ModelWithString'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ResponseService { @@ -6994,6 +9337,34 @@ export class ResponseService { }); } + /** + * @returns ModelWithString + * @throws ApiError + */ + public static async callWithResponseEither(): Promise, ModelWithString>> { + try { + const result: (ModelWithString) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @returns ModelWithString Message for default response * @throws ApiError @@ -7010,6 +9381,39 @@ export class ResponseService { }); } + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static async callWithDuplicateResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, ModelWithString>> { + try { + const result: (ModelWithString) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/response', + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { + _tag: 'Left', + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), + }; + + return left; + } + } + + /** * @returns any Message for 200 response * @returns ModelWithString Message for default response @@ -7033,6 +9437,54 @@ export class ResponseService { }); } + /** + * @returns any Message for 200 response + * @returns ModelWithString Message for default response + * @returns ModelThatExtends Message for 201 response + * @returns ModelThatExtendsExtends Message for 202 response + * @throws ApiError + */ + public static async callWithResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends>> { + try { + const result: ({ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/response', + errors: { + 500: \`Message for 500 error\`, + 501: \`Message for 501 error\`, + 502: \`Message for 502 error\`, + }, + }); + + const right: Right<{ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { + _tag: 'Left', + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), + }; + + return left; + } + } + + } " `; @@ -7044,6 +9496,8 @@ exports[`v3 should generate: ./test/generated/v3/services/SimpleService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class SimpleService { @@ -7057,6 +9511,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async getCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7067,6 +9548,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async putCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7077,6 +9585,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async postCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7087,6 +9622,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async deleteCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7097,6 +9659,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async optionsCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7107,6 +9696,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async headCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + /** * @throws ApiError */ @@ -7117,6 +9733,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async patchCallWithoutParametersAndResponseEither(): Promise, void>> { + try { + const result: (void) = await __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple', + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -7128,6 +9771,8 @@ exports[`v3 should generate: ./test/generated/v3/services/TypesService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class TypesService { @@ -7174,6 +9819,66 @@ export class TypesService { }); } + /** + * @param parameterArray This is an array parameter + * @param parameterDictionary This is a dictionary parameter + * @param parameterEnum This is an enum parameter + * @param parameterNumber This is a number parameter + * @param parameterString This is a string parameter + * @param parameterBoolean This is a boolean parameter + * @param parameterObject This is an object parameter + * @param id This is a number parameter + * @returns number Response is a simple number + * @returns string Response is a simple string + * @returns boolean Response is a simple boolean + * @returns any Response is a simple object + * @throws ApiError + */ + public static async typesEither( + 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, number | string | boolean | any>> { + try { + const result: (number | string | boolean | any) = await __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + 'id': id, + }, + query: { + 'parameterNumber': parameterNumber, + 'parameterString': parameterString, + 'parameterBoolean': parameterBoolean, + 'parameterObject': parameterObject, + 'parameterArray': parameterArray, + 'parameterDictionary': parameterDictionary, + 'parameterEnum': parameterEnum, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; @@ -7185,6 +9890,8 @@ exports[`v3 should generate: ./test/generated/v3/services/UploadService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class UploadService { @@ -7205,6 +9912,40 @@ export class UploadService { }); } + /** + * @param file Supply a file reference for upload + * @returns boolean + * @throws ApiError + */ + public static async uploadFileEither( + file: Blob, + ): Promise, boolean>> { + try { + const result: (boolean) = await __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/upload', + formData: { + 'file': file, + }, + }); + + const right: Right = { + _tag: 'Right', + right: result, + }; + + return right; + } catch (e) { + const left: Left> = { + _tag: 'Left', + left: e as (ApiError), + }; + + return left; + } + } + + } " `; diff --git a/test/e2e/client.node.spec.ts b/test/e2e/client.node.spec.ts index 9967cf019..7112685e3 100644 --- a/test/e2e/client.node.spec.ts +++ b/test/e2e/client.node.spec.ts @@ -1,3 +1,4 @@ +import fetch from 'node-fetch'; import { cleanup } from './scripts/cleanup'; import { compileWithTypescript } from './scripts/compileWithTypescript'; import { generateClient } from './scripts/generateClient'; @@ -28,6 +29,21 @@ describe('client.node', () => { expect(result.headers.authorization).toBe('Bearer MY_TOKEN'); }); + it('can return an Either', async () => { + const { ApiClient } = require('./generated/client/node/index.js'); + const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN'); + const client = new ApiClient({ + TOKEN: tokenRequest, + USERNAME: undefined, + PASSWORD: undefined, + }); + const resultEither = await client.simple.getCallWithoutParametersAndResponseEither(); + expect(resultEither._tag).toBe('Right'); + const result = resultEither.right; + expect(tokenRequest.mock.calls.length).toBe(1); + expect(result.headers.authorization).toBe('Bearer MY_TOKEN'); + }); + it('uses credentials', async () => { const { ApiClient } = require('./generated/client/node/index.js'); const client = new ApiClient({ @@ -116,6 +132,15 @@ describe('client.node', () => { ); }); + it('can return errors as Either', async () => { + const { ApiClient } = require('./generated/client/node/index.js'); + const client = new ApiClient(); + const result = await client.error.testErrorCodeEither(500); + expect(result._tag).toBe('Left'); + expect(result.left.name).toBe('ApiError'); + expect(result.left.body.message).toBe('hello world'); + }); + it('should throw unknown error (409)', async () => { let error; try { @@ -147,4 +172,32 @@ describe('client.node', () => { }) ); }); + + it('can override fetch', async () => { + const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN'); + const { ApiClient, BaseHttpRequest } = require('./generated/client/node/index.js'); + const { request } = require('./generated/client/node/core/request'); + const customFetch = jest.fn().mockImplementation((url, init) => fetch(url, init)); + class MockHttpRequest extends BaseHttpRequest { + constructor(config) { + super(config); + } + + public request(options) { + return request(this.config, options, customFetch); + } + } + const client = new ApiClient( + { + TOKEN: tokenRequest, + USERNAME: undefined, + PASSWORD: undefined, + }, + MockHttpRequest + ); + const result = await client.simple.getCallWithoutParametersAndResponse(); + expect(tokenRequest.mock.calls.length).toBe(1); + expect(customFetch.mock.calls.length).toBe(1); + expect(result.headers.authorization).toBe('Bearer MY_TOKEN'); + }); });