From cc55414c1c38fb66d062c66a6393838a634099b8 Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 11:41:20 -0400 Subject: [PATCH 1/6] Remove codecov token --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 755cbc9e9..3f5ea729c 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,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", From 6822c52c4cd56d4f0683d3a3561e5ec4e9de7608 Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 13:32:53 -0400 Subject: [PATCH 2/6] Add Either support --- src/templates/core/ApiError.hbs | 11 ++- src/templates/core/ApiResult.hbs | 21 ++++- src/templates/exportService.hbs | 127 +++++++++++++++++++++++++++++++ test/e2e/client.node.spec.ts | 24 ++++++ 4 files changed, 176 insertions(+), 7 deletions(-) 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/exportService.hbs b/src/templates/exportService.hbs index 2fdd9af58..a59be62c1 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; {{/equals}} {{else}} import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; +import { Left, Right, Either } from '../core/ApiResult'; +import { 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}}): Promiseresult}}>> { + 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}}): Promiseresult}}>> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + return left; + } + } + {{/equals}} + + {{/each}} } diff --git a/test/e2e/client.node.spec.ts b/test/e2e/client.node.spec.ts index 9967cf019..d872db285 100644 --- a/test/e2e/client.node.spec.ts +++ b/test/e2e/client.node.spec.ts @@ -28,6 +28,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 +131,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 { From 408d619eb06e6e1b376813902444b13c74e9bcb8 Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 13:35:53 -0400 Subject: [PATCH 3/6] Update snapshots --- test/__snapshots__/index.spec.ts.snap | 2841 ++++++++++++++++++++++++- 1 file changed, 2791 insertions(+), 50 deletions(-) diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index cb3405f2a..18f5f3b7b 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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>> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class DefaultService { @@ -2351,6 +2467,33 @@ export class DefaultService { }); } + /** + * @throws ApiError + */ + public static async serviceWithEmptyTagEither(): Promise> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -2536,6 +2884,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateNameEither(): Promise> { + 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -2658,6 +3193,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise> { + 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, + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -2669,6 +3232,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -2694,6 +3287,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise> { + 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, + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -2705,6 +3326,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -2730,6 +3381,34 @@ export class MultipleTags3Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class NoContentService { @@ -2755,6 +3436,34 @@ export class NoContentService { }); } + /** + * @returns void + * @throws ApiError + */ + public static async callWithNoContentResponseEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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; + } | 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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> { + 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> { + 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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>> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class DefaultService { @@ -6259,6 +7611,33 @@ export class DefaultService { }); } + /** + * @throws ApiError + */ + public static async serviceWithEmptyTagEither(): Promise> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -6477,6 +8097,33 @@ export class DuplicateService { }); } + /** + * @throws ApiError + */ + public static async duplicateNameEither(): Promise> { + 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -6686,6 +8615,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise> { + 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, + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -6697,6 +8654,34 @@ export class MultipleTags1Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -6722,6 +8709,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyAEither(): Promise> { + 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, + }; + + return left; + } + } + + /** * @returns void * @throws ApiError @@ -6733,6 +8748,34 @@ export class MultipleTags2Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -6758,6 +8803,34 @@ export class MultipleTags3Service { }); } + /** + * @returns void + * @throws ApiError + */ + public static async dummyBEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class NoContentService { @@ -6783,6 +8858,34 @@ export class NoContentService { }); } + /** + * @returns void + * @throws ApiError + */ + public static async callWithNoContentResponseEither(): Promise> { + 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, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class ResponseService { @@ -6994,6 +9337,34 @@ export class ResponseService { }); } + /** + * @returns ModelWithString + * @throws ApiError + */ + public static async callWithResponseEither(): Promise> { + 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> { + 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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; + } | 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 = { + _tag: 'Left', + left: e as ApiError, + }; + + 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 { Left, Right, Either } from '../core/ApiResult'; +import { ApiError } from '../core/ApiError'; export class SimpleService { @@ -7057,6 +9511,33 @@ export class SimpleService { }); } + /** + * @throws ApiError + */ + public static async getCallWithoutParametersAndResponseEither(): Promise> { + 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> { + 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> { + 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> { + 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> { + 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> { + 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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 { Left, Right, Either } from '../core/ApiResult'; +import { 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> { + 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; + } + } + + } " `; From 65d4da354e627436331773a4c63c1eb7b500eb55 Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 16:36:35 -0400 Subject: [PATCH 4/6] Add types for ApiError, fix error for babel --- src/client/interfaces/Operation.d.ts | 1 + src/openApi/v2/parser/getOperation.ts | 9 ++++- src/openApi/v2/parser/getOperationResults.ts | 35 ++++++++++++++++++++ src/openApi/v3/parser/getOperation.ts | 1 + src/templates/exportService.hbs | 16 ++++----- src/templates/partials/errorResult.hbs | 8 +++++ src/utils/registerHandlebarTemplates.ts | 2 ++ 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/templates/partials/errorResult.hbs 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..3b32aba07 100644 --- a/src/openApi/v3/parser/getOperation.ts +++ b/src/openApi/v3/parser/getOperation.ts @@ -44,6 +44,7 @@ export const getOperation = ( imports: [], errors: [], results: [], + errorResults: [], responseHeader: null, }; diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index a59be62c1..25c21ab09 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -25,14 +25,14 @@ import type { CancelablePromise } from '../core/CancelablePromise'; import { BaseHttpRequest } from '../core/BaseHttpRequest'; {{else}} import type { BaseHttpRequest } from '../core/BaseHttpRequest'; -import { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; {{/if}} {{#equals @root.httpClient 'angular'}} @@ -180,7 +180,7 @@ export class {{{name}}}{{{@root.postfix}}} { try { const result: ({{>result}}) = await this.httpRequest.request({ {{else}} - public async {{{name}}}Either({{>parameters}}): Promiseresult}}>> { + public async {{{name}}}Either({{>parameters}}): PromiseerrorResult}}, {{>result}}>> { try { const result: ({{>result}}) = await this.httpRequest.request({ {{/equals}} @@ -190,7 +190,7 @@ export class {{{name}}}{{{@root.postfix}}} { try { const result: ({{>result}}) = await __request(OpenAPI, this.http, { {{else}} - public static async {{{name}}}Either({{>parameters}}): Promiseresult}}>> { + public static async {{{name}}}Either({{>parameters}}): PromiseerrorResult}}, {{>result}}>> { try { const result: ({{>result}}) = await __request(OpenAPI, { {{/equals}} @@ -262,9 +262,9 @@ export class {{{name}}}{{{@root.postfix}}} { return right; } catch (e) { - const left: Left = { + const left: Left<{{>errorResult}}> = { _tag: 'Left', - left: e as ApiError, + left: e as ({{>errorResult}}), }; return left; diff --git a/src/templates/partials/errorResult.hbs b/src/templates/partials/errorResult.hbs new file mode 100644 index 000000000..722630f86 --- /dev/null +++ b/src/templates/partials/errorResult.hbs @@ -0,0 +1,8 @@ +{{~#if errorResults~}} +{{#each results}}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)); From c4337dfdcfce3990bcf372d100d50e71e02717cf Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 16:37:08 -0400 Subject: [PATCH 5/6] Update snapshots --- test/__snapshots__/index.spec.ts.snap | 757 ++++++++++++++++---------- 1 file changed, 464 insertions(+), 293 deletions(-) diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 18f5f3b7b..9a1fedd8e 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -2268,8 +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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class CollectionFormatService { @@ -2315,7 +2315,7 @@ export class CollectionFormatService { parameterArrayTsv: Array, parameterArrayPipes: Array, parameterArrayMulti: Array, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -2336,9 +2336,9 @@ export class CollectionFormatService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2359,8 +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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ComplexService { @@ -2409,7 +2409,10 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): Promise>> { + ): Promise, Array>> { try { const result: (Array) = await __request(OpenAPI, { method: 'GET', @@ -2431,9 +2434,15 @@ export class ComplexService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + ModelWithString + >), }; return left; @@ -2452,8 +2461,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultService { @@ -2470,7 +2479,7 @@ export class DefaultService { /** * @throws ApiError */ - public static async serviceWithEmptyTagEither(): Promise> { + public static async serviceWithEmptyTagEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -2484,9 +2493,9 @@ export class DefaultService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2507,8 +2516,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultsService { @@ -2558,7 +2567,7 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -2579,9 +2588,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2635,7 +2644,7 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -2656,9 +2665,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2723,7 +2732,7 @@ export class DefaultsService { parameterStringWithEmptyDefault: string = '', parameterStringNullableWithNoDefault?: string | null, parameterStringNullableWithDefault: string | null = null, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -2747,9 +2756,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2768,8 +2777,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DescriptionsService { @@ -2826,7 +2835,7 @@ export class DescriptionsService { parameterWithExpressionPlaceholders?: string, parameterWithQuotes?: string, parameterWithReservedCharacters?: string, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -2848,9 +2857,9 @@ export class DescriptionsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2869,8 +2878,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -2887,7 +2896,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateNameEither(): Promise> { + public static async duplicateNameEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -2901,9 +2910,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2924,7 +2933,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName1Either(): Promise> { + public static async duplicateName1Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -2938,9 +2947,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2961,7 +2970,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName2Either(): Promise> { + public static async duplicateName2Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -2975,9 +2984,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -2998,7 +3007,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName3Either(): Promise> { + public static async duplicateName3Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'DELETE', @@ -3012,9 +3021,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3033,8 +3042,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ErrorService { @@ -3068,7 +3077,10 @@ export class ErrorService { */ public static async testErrorCodeEither( status: string, - ): Promise> { + ): Promise, any>> { try { const result: (any) = await __request(OpenAPI, { method: 'POST', @@ -3091,9 +3103,15 @@ export class ErrorService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + any + >), }; return left; @@ -3112,8 +3130,8 @@ exports[`v2 should generate: ./test/generated/v2/services/HeaderService.ts 1`] = import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; -import { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class HeaderService { @@ -3137,7 +3155,10 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static async callWithResultFromHeaderEither(): Promise> { + public static async callWithResultFromHeaderEither(): Promise, string>> { try { const result: (string) = await __request(OpenAPI, { method: 'POST', @@ -3156,9 +3177,15 @@ export class HeaderService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + string + >), }; return left; @@ -3177,8 +3204,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -3197,7 +3224,10 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3211,9 +3241,15 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3236,7 +3272,10 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3250,9 +3289,15 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3271,8 +3316,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -3291,7 +3336,10 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3305,9 +3353,15 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3330,7 +3384,10 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3344,9 +3401,15 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3365,8 +3428,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -3385,7 +3448,10 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3399,9 +3465,15 @@ export class MultipleTags3Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3420,8 +3492,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class NoContentService { @@ -3440,7 +3512,10 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static async callWithNoContentResponseEither(): Promise> { + public static async callWithNoContentResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3454,9 +3529,15 @@ export class NoContentService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + void + >), }; return left; @@ -3475,8 +3556,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ParametersService { @@ -3528,7 +3609,7 @@ export class ParametersService { parameterForm: string, parameterBody: string, parameterPath: string, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -3555,9 +3636,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3628,7 +3709,7 @@ export class ParametersService { parameterPath2?: string, parameterPath3?: string, _default?: string, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -3658,9 +3739,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3683,8 +3764,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ResponseService { @@ -3703,7 +3784,10 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithResponseEither(): Promise> { + public static async callWithResponseEither(): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'GET', @@ -3717,9 +3801,15 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + ModelWithString + >), }; return left; @@ -3747,7 +3837,10 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithDuplicateResponsesEither(): Promise> { + public static async callWithDuplicateResponsesEither(): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'POST', @@ -3766,9 +3859,15 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + ModelWithString + >), }; return left; @@ -3806,7 +3905,19 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static async callWithResponsesEither(): Promise | ApiError< + 200, + ModelWithString + > | ApiError< + 201, + ModelThatExtends + > | ApiError< + 202, + ModelThatExtendsExtends + >, { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; @@ -3837,9 +3948,33 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left | ApiError< + 200, + ModelWithString + > | ApiError< + 201, + ModelThatExtends + > | ApiError< + 202, + ModelThatExtendsExtends + >> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + any + > | ApiError< + 200, + ModelWithString + > | ApiError< + 201, + ModelThatExtends + > | ApiError< + 202, + ModelThatExtendsExtends + >), }; return left; @@ -3858,8 +3993,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class SimpleService { @@ -3876,7 +4011,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async getCallWithoutParametersAndResponseEither(): Promise> { + public static async getCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3890,9 +4025,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3913,7 +4048,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async putCallWithoutParametersAndResponseEither(): Promise> { + public static async putCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -3927,9 +4062,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3950,7 +4085,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async postCallWithoutParametersAndResponseEither(): Promise> { + public static async postCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -3964,9 +4099,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -3987,7 +4122,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async deleteCallWithoutParametersAndResponseEither(): Promise> { + public static async deleteCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'DELETE', @@ -4001,9 +4136,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -4024,7 +4159,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async optionsCallWithoutParametersAndResponseEither(): Promise> { + public static async optionsCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'OPTIONS', @@ -4038,9 +4173,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -4061,7 +4196,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async headCallWithoutParametersAndResponseEither(): Promise> { + public static async headCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'HEAD', @@ -4075,9 +4210,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -4098,7 +4233,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async patchCallWithoutParametersAndResponseEither(): Promise> { + public static async patchCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PATCH', @@ -4112,9 +4247,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -4133,8 +4268,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class TypesService { @@ -4205,7 +4340,19 @@ export class TypesService { parameterBoolean: boolean = true, parameterObject: any = null, id?: number, - ): Promise> { + ): Promise | ApiError< + 201, + string + > | ApiError< + 202, + boolean + > | ApiError< + 203, + any + >, number | string | boolean | any>> { try { const result: (number | string | boolean | any) = await __request(OpenAPI, { method: 'GET', @@ -4231,9 +4378,33 @@ export class TypesService { return right; } catch (e) { - const left: Left = { + const left: Left | ApiError< + 201, + string + > | ApiError< + 202, + boolean + > | ApiError< + 203, + any + >> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError< + 200, + number + > | ApiError< + 201, + string + > | ApiError< + 202, + boolean + > | ApiError< + 203, + any + >), }; return left; @@ -7326,8 +7497,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class CollectionFormatService { @@ -7373,7 +7544,7 @@ export class CollectionFormatService { parameterArrayTsv: Array | null, parameterArrayPipes: Array | null, parameterArrayMulti: Array | null, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -7394,9 +7565,9 @@ export class CollectionFormatService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7420,8 +7591,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ComplexService { @@ -7470,7 +7641,7 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): Promise>> { + ): Promise, Array>> { try { const result: (Array) = await __request(OpenAPI, { method: 'GET', @@ -7492,9 +7663,9 @@ export class ComplexService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7556,7 +7727,7 @@ export class ComplexService { readonly name?: string | null; }; }, - ): Promise> { + ): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'PUT', @@ -7575,9 +7746,9 @@ export class ComplexService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7596,8 +7767,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultService { @@ -7614,7 +7785,7 @@ export class DefaultService { /** * @throws ApiError */ - public static async serviceWithEmptyTagEither(): Promise> { + public static async serviceWithEmptyTagEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -7628,9 +7799,9 @@ export class DefaultService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7651,8 +7822,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DefaultsService { @@ -7702,7 +7873,7 @@ export class DefaultsService { parameterModel: ModelWithString | null = { \\"prop\\": \\"Hello World!\\" }, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -7723,9 +7894,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7779,7 +7950,7 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -7800,9 +7971,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7867,7 +8038,7 @@ export class DefaultsService { parameterStringWithEmptyDefault: string = '', parameterStringNullableWithNoDefault?: string | null, parameterStringNullableWithDefault: string | null = null, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -7891,9 +8062,9 @@ export class DefaultsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7914,8 +8085,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DeprecatedService { @@ -7943,7 +8114,7 @@ export class DeprecatedService { */ public static async deprecatedCallEither( parameter: DeprecatedModel | null, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -7960,9 +8131,9 @@ export class DeprecatedService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -7981,8 +8152,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DescriptionsService { @@ -8039,7 +8210,7 @@ export class DescriptionsService { parameterWithExpressionPlaceholders?: any, parameterWithQuotes?: any, parameterWithReservedCharacters?: any, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -8061,9 +8232,9 @@ export class DescriptionsService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8082,8 +8253,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class DuplicateService { @@ -8100,7 +8271,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateNameEither(): Promise> { + public static async duplicateNameEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8114,9 +8285,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8137,7 +8308,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName1Either(): Promise> { + public static async duplicateName1Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -8151,9 +8322,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8174,7 +8345,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName2Either(): Promise> { + public static async duplicateName2Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -8188,9 +8359,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8211,7 +8382,7 @@ export class DuplicateService { /** * @throws ApiError */ - public static async duplicateName3Either(): Promise> { + public static async duplicateName3Either(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'DELETE', @@ -8225,9 +8396,9 @@ export class DuplicateService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8246,8 +8417,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ErrorService { @@ -8281,7 +8452,7 @@ export class ErrorService { */ public static async testErrorCodeEither( status: number, - ): Promise> { + ): Promise, any>> { try { const result: (any) = await __request(OpenAPI, { method: 'POST', @@ -8304,9 +8475,9 @@ export class ErrorService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8327,8 +8498,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class FormDataService { @@ -8360,7 +8531,7 @@ export class FormDataService { public static async postApiFormDataEither( parameter?: string, formData?: ModelWithString, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -8379,9 +8550,9 @@ export class FormDataService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8400,8 +8571,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class HeaderService { @@ -8425,7 +8596,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static async callWithResultFromHeaderEither(): Promise> { + public static async callWithResultFromHeaderEither(): Promise, string>> { try { const result: (string) = await __request(OpenAPI, { method: 'POST', @@ -8444,9 +8615,9 @@ export class HeaderService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8467,8 +8638,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipartService { @@ -8499,7 +8670,7 @@ export class MultipartService { content?: Blob; data?: ModelWithString | null; }, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -8515,9 +8686,9 @@ export class MultipartService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8546,7 +8717,7 @@ export class MultipartService { * @returns any OK * @throws ApiError */ - public static async multipartResponseEither(): Promise, { file?: Blob; metadata?: { foo?: string; @@ -8578,9 +8749,9 @@ export class MultipartService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8599,8 +8770,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags1Service { @@ -8619,7 +8790,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8633,9 +8804,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8658,7 +8829,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8672,9 +8843,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8693,8 +8864,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags2Service { @@ -8713,7 +8884,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8727,9 +8898,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8752,7 +8923,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8766,9 +8937,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8787,8 +8958,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class MultipleTags3Service { @@ -8807,7 +8978,7 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8821,9 +8992,9 @@ export class MultipleTags3Service { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8842,8 +9013,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class NoContentService { @@ -8862,7 +9033,7 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static async callWithNoContentResponseEither(): Promise> { + public static async callWithNoContentResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8876,9 +9047,9 @@ export class NoContentService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -8900,8 +9071,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ParametersService { @@ -8961,7 +9132,7 @@ export class ParametersService { parameterCookie: string | null, parameterPath: string | null, requestBody: ModelWithString | null, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -8992,9 +9163,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9073,7 +9244,7 @@ export class ParametersService { parameterPath2?: string, parameterPath3?: string, _default?: string, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -9107,9 +9278,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9145,7 +9316,7 @@ export class ParametersService { public static async getCallWithOptionalParamEither( requestBody: ModelWithString, parameter?: string, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -9164,9 +9335,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9202,7 +9373,7 @@ export class ParametersService { public static async postCallWithOptionalParamEither( parameter: Pageable, requestBody?: ModelWithString, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -9221,9 +9392,9 @@ export class ParametersService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9244,8 +9415,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class RequestBodyService { @@ -9277,7 +9448,7 @@ export class RequestBodyService { public static async postApiRequestBodyEither( parameter?: string, requestBody?: ModelWithString, - ): Promise> { + ): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -9296,9 +9467,9 @@ export class RequestBodyService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9321,8 +9492,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class ResponseService { @@ -9341,7 +9512,7 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public static async callWithResponseEither(): Promise> { + public static async callWithResponseEither(): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'GET', @@ -9355,9 +9526,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9385,7 +9556,7 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithDuplicateResponsesEither(): Promise> { + public static async callWithDuplicateResponsesEither(): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'POST', @@ -9404,9 +9575,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9444,7 +9615,7 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static async callWithResponsesEither(): Promise, { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; @@ -9475,9 +9646,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9496,8 +9667,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class SimpleService { @@ -9514,7 +9685,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async getCallWithoutParametersAndResponseEither(): Promise> { + public static async getCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -9528,9 +9699,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9551,7 +9722,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async putCallWithoutParametersAndResponseEither(): Promise> { + public static async putCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PUT', @@ -9565,9 +9736,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9588,7 +9759,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async postCallWithoutParametersAndResponseEither(): Promise> { + public static async postCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'POST', @@ -9602,9 +9773,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9625,7 +9796,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async deleteCallWithoutParametersAndResponseEither(): Promise> { + public static async deleteCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'DELETE', @@ -9639,9 +9810,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9662,7 +9833,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async optionsCallWithoutParametersAndResponseEither(): Promise> { + public static async optionsCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'OPTIONS', @@ -9676,9 +9847,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9699,7 +9870,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async headCallWithoutParametersAndResponseEither(): Promise> { + public static async headCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'HEAD', @@ -9713,9 +9884,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9736,7 +9907,7 @@ export class SimpleService { /** * @throws ApiError */ - public static async patchCallWithoutParametersAndResponseEither(): Promise> { + public static async patchCallWithoutParametersAndResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'PATCH', @@ -9750,9 +9921,9 @@ export class SimpleService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9771,8 +9942,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class TypesService { @@ -9843,7 +10014,7 @@ export class TypesService { parameterBoolean: boolean | null = true, parameterObject: any = null, id?: number, - ): Promise> { + ): Promise, number | string | boolean | any>> { try { const result: (number | string | boolean | any) = await __request(OpenAPI, { method: 'GET', @@ -9869,9 +10040,9 @@ export class TypesService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; @@ -9890,8 +10061,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 { Left, Right, Either } from '../core/ApiResult'; -import { ApiError } from '../core/ApiError'; +import type { Left, Right, Either } from '../core/ApiResult'; +import type { ApiError } from '../core/ApiError'; export class UploadService { @@ -9919,7 +10090,7 @@ export class UploadService { */ public static async uploadFileEither( file: Blob, - ): Promise> { + ): Promise, boolean>> { try { const result: (boolean) = await __request(OpenAPI, { method: 'POST', @@ -9936,9 +10107,9 @@ export class UploadService { return right; } catch (e) { - const left: Left = { + const left: Left> = { _tag: 'Left', - left: e as ApiError, + left: e as (ApiError), }; return left; From b4d4040b498bf250ad1b1233a5d822b9d0b00347 Mon Sep 17 00:00:00 2001 From: Flyyn <_@rst.vn> Date: Wed, 22 Jun 2022 17:21:06 -0400 Subject: [PATCH 6/6] Apply changes to v3 parser too, fix formatting, reject with error results (not successes) --- src/openApi/v3/parser/getOperation.ts | 8 +- src/openApi/v3/parser/getOperationResults.ts | 35 +++ src/templates/partials/errorResult.hbs | 5 +- test/__snapshots__/index.spec.ts.snap | 315 +++++-------------- 4 files changed, 115 insertions(+), 248 deletions(-) diff --git a/src/openApi/v3/parser/getOperation.ts b/src/openApi/v3/parser/getOperation.ts index 3b32aba07..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'; @@ -73,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); @@ -80,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/partials/errorResult.hbs b/src/templates/partials/errorResult.hbs index 722630f86..4022a4c35 100644 --- a/src/templates/partials/errorResult.hbs +++ b/src/templates/partials/errorResult.hbs @@ -1,8 +1,5 @@ {{~#if errorResults~}} -{{#each results}}ApiError< - {{#equals code 0}}number{{else}}{{{code}}}{{/equals}}, - {{type}} ->{{#unless @last}} | {{/unless}}{{/each}} +{{#each errorResults}}ApiError<{{#equals code 0}}number{{else}}{{{code}}}{{/equals}}, {{type}}>{{#unless @last}} | {{/unless}}{{/each}} {{~else~}} ApiError {{~/if~}} diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 9a1fedd8e..4ac206ecf 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -2409,10 +2409,7 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): Promise, Array>> { + ): Promise | ApiError<500, any>, Array>> { try { const result: (Array) = await __request(OpenAPI, { method: 'GET', @@ -2434,15 +2431,9 @@ export class ComplexService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<500, any>> = { _tag: 'Left', - left: e as (ApiError< - 200, - ModelWithString - >), + left: e as (ApiError<400, any> | ApiError<500, any>), }; return left; @@ -3077,10 +3068,7 @@ export class ErrorService { */ public static async testErrorCodeEither( status: string, - ): Promise, any>> { + ): Promise | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>, any>> { try { const result: (any) = await __request(OpenAPI, { method: 'POST', @@ -3103,15 +3091,9 @@ export class ErrorService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>> = { _tag: 'Left', - left: e as (ApiError< - 200, - any - >), + left: e as (ApiError<500, any> | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>), }; return left; @@ -3155,10 +3137,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static async callWithResultFromHeaderEither(): Promise, string>> { + public static async callWithResultFromHeaderEither(): Promise | ApiError<500, any>, string>> { try { const result: (string) = await __request(OpenAPI, { method: 'POST', @@ -3177,15 +3156,9 @@ export class HeaderService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<500, any>> = { _tag: 'Left', - left: e as (ApiError< - 200, - string - >), + left: e as (ApiError<400, any> | ApiError<500, any>), }; return left; @@ -3224,10 +3197,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise, void>> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3241,15 +3211,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3272,10 +3236,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3289,15 +3250,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3336,10 +3291,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise, void>> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3353,15 +3305,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3384,10 +3330,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3401,15 +3344,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3448,10 +3385,7 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3465,15 +3399,9 @@ export class MultipleTags3Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3512,10 +3440,7 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static async callWithNoContentResponseEither(): Promise, void>> { + public static async callWithNoContentResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -3529,15 +3454,9 @@ export class NoContentService { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - void - >), + left: e as (ApiError<204, any>), }; return left; @@ -3784,10 +3703,7 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithResponseEither(): Promise, ModelWithString>> { + public static async callWithResponseEither(): Promise, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'GET', @@ -3801,15 +3717,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - ModelWithString - >), + left: e as (ApiError), }; return left; @@ -3837,10 +3747,7 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithDuplicateResponsesEither(): Promise, ModelWithString>> { + public static async callWithDuplicateResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'POST', @@ -3859,15 +3766,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { _tag: 'Left', - left: e as (ApiError< - 200, - ModelWithString - >), + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), }; return left; @@ -3905,19 +3806,7 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static async callWithResponsesEither(): Promise | ApiError< - 200, - ModelWithString - > | ApiError< - 201, - ModelThatExtends - > | ApiError< - 202, - ModelThatExtendsExtends - >, { + public static async callWithResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; @@ -3948,33 +3837,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left | ApiError< - 200, - ModelWithString - > | ApiError< - 201, - ModelThatExtends - > | ApiError< - 202, - ModelThatExtendsExtends - >> = { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { _tag: 'Left', - left: e as (ApiError< - 200, - any - > | ApiError< - 200, - ModelWithString - > | ApiError< - 201, - ModelThatExtends - > | ApiError< - 202, - ModelThatExtendsExtends - >), + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), }; return left; @@ -4340,19 +4205,7 @@ export class TypesService { parameterBoolean: boolean = true, parameterObject: any = null, id?: number, - ): Promise | ApiError< - 201, - string - > | ApiError< - 202, - boolean - > | ApiError< - 203, - any - >, number | string | boolean | any>> { + ): Promise, number | string | boolean | any>> { try { const result: (number | string | boolean | any) = await __request(OpenAPI, { method: 'GET', @@ -4378,33 +4231,9 @@ export class TypesService { return right; } catch (e) { - const left: Left | ApiError< - 201, - string - > | ApiError< - 202, - boolean - > | ApiError< - 203, - any - >> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError< - 200, - number - > | ApiError< - 201, - string - > | ApiError< - 202, - boolean - > | ApiError< - 203, - any - >), + left: e as (ApiError), }; return left; @@ -7641,7 +7470,7 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): Promise, Array>> { + ): Promise | ApiError<500, any>, Array>> { try { const result: (Array) = await __request(OpenAPI, { method: 'GET', @@ -7663,9 +7492,9 @@ export class ComplexService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<500, any>> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<400, any> | ApiError<500, any>), }; return left; @@ -8452,7 +8281,7 @@ export class ErrorService { */ public static async testErrorCodeEither( status: number, - ): Promise, any>> { + ): Promise | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>, any>> { try { const result: (any) = await __request(OpenAPI, { method: 'POST', @@ -8475,9 +8304,9 @@ export class ErrorService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<500, any> | ApiError<501, any> | ApiError<502, any> | ApiError<503, any>), }; return left; @@ -8596,7 +8425,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static async callWithResultFromHeaderEither(): Promise, string>> { + public static async callWithResultFromHeaderEither(): Promise | ApiError<500, any>, string>> { try { const result: (string) = await __request(OpenAPI, { method: 'POST', @@ -8615,9 +8444,9 @@ export class HeaderService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<500, any>> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<400, any> | ApiError<500, any>), }; return left; @@ -8790,7 +8619,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise, void>> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8804,9 +8633,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -8829,7 +8658,7 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8843,9 +8672,9 @@ export class MultipleTags1Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -8884,7 +8713,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyAEither(): Promise, void>> { + public static async dummyAEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8898,9 +8727,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -8923,7 +8752,7 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8937,9 +8766,9 @@ export class MultipleTags2Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -8978,7 +8807,7 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static async dummyBEither(): Promise, void>> { + public static async dummyBEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -8992,9 +8821,9 @@ export class MultipleTags3Service { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -9033,7 +8862,7 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static async callWithNoContentResponseEither(): Promise, void>> { + public static async callWithNoContentResponseEither(): Promise, void>> { try { const result: (void) = await __request(OpenAPI, { method: 'GET', @@ -9047,9 +8876,9 @@ export class NoContentService { return right; } catch (e) { - const left: Left> = { + const left: Left> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<204, any>), }; return left; @@ -9556,7 +9385,7 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static async callWithDuplicateResponsesEither(): Promise, ModelWithString>> { + public static async callWithDuplicateResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, ModelWithString>> { try { const result: (ModelWithString) = await __request(OpenAPI, { method: 'POST', @@ -9575,9 +9404,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), }; return left; @@ -9615,7 +9444,7 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static async callWithResponsesEither(): Promise, { + public static async callWithResponsesEither(): Promise | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>, { readonly '@namespace.string'?: string; readonly '@namespace.integer'?: number; readonly value?: Array; @@ -9646,9 +9475,9 @@ export class ResponseService { return right; } catch (e) { - const left: Left> = { + const left: Left | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>> = { _tag: 'Left', - left: e as (ApiError), + left: e as (ApiError<500, ModelWithString> | ApiError<501, ModelWithString> | ApiError<502, ModelWithString>), }; return left;