From bcc79b695926436de6ae5cafbd54e62811b77b38 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Fri, 14 Jul 2023 10:37:42 -0700 Subject: [PATCH] fix(codegen): don't surface error responses as method return types --- .../src/cli/codegen/languages/typescript.ts | 92 +++- packages/api/src/core/errors/fetchError.ts | 8 +- packages/api/src/core/index.ts | 7 +- .../api/test/__fixtures__/sdk/alby/index.ts | 425 ++++++------------ .../sdk/optional-payload/index.ts | 8 - .../test/__fixtures__/sdk/petstore/index.ts | 16 - .../api/test/__fixtures__/sdk/readme/index.ts | 246 +++++----- 7 files changed, 322 insertions(+), 480 deletions(-) diff --git a/packages/api/src/cli/codegen/languages/typescript.ts b/packages/api/src/cli/codegen/languages/typescript.ts index c478dde6..459123af 100644 --- a/packages/api/src/cli/codegen/languages/typescript.ts +++ b/packages/api/src/cli/codegen/languages/typescript.ts @@ -3,7 +3,13 @@ import type { InstallerOptions } from '../language'; import type Oas from 'oas'; import type { Operation } from 'oas'; import type { HttpMethods, SchemaObject } from 'oas/dist/rmoas.types'; -import type { ClassDeclaration, JSDocStructure, OptionalKind, ParameterDeclarationStructure } from 'ts-morph'; +import type { + ClassDeclaration, + JSDocStructure, + JSDocTagStructure, + OptionalKind, + ParameterDeclarationStructure, +} from 'ts-morph'; import type { PackageJson } from 'type-fest'; import fs from 'fs'; @@ -28,7 +34,13 @@ interface OperationTypeHousing { operation: Operation; types: { params?: false | Record<'body' | 'formData' | 'metadata', string>; - responses?: Record; + responses?: Record< + string | number, + { + description?: string; + type: string; + } + >; }; } @@ -502,6 +514,20 @@ sdk.server('https://eu.api.example.com/v14');`) return sourceFile; } + /** + * Add a new JSDoc `@tag` to an existing docblock. + * + */ + static addTagToDocblock(docblock: OptionalKind, tag: OptionalKind) { + const tags = docblock.tags ?? []; + tags.push(tag); + + return { + ...docblock, + tags, + }; + } + /** * Create operation accessors on the SDK. * @@ -512,7 +538,7 @@ sdk.server('https://eu.api.example.com/v14');`) paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses'] ) { - const docblock: OptionalKind = {}; + let docblock: OptionalKind = {}; const summary = operation.getSummary(); const description = operation.getDescription(); if (summary || description) { @@ -531,7 +557,10 @@ sdk.server('https://eu.api.example.com/v14');`) }; if (summary && description) { - docblock.tags = [{ tagName: 'summary', text: docblockEscape(wordWrap(summary)) }]; + docblock = TSGenerator.addTagToDocblock(docblock, { + tagName: 'summary', + text: docblockEscape(wordWrap(summary)), + }); } } @@ -568,8 +597,8 @@ sdk.server('https://eu.api.example.com/v14');`) let returnType = 'Promise>'; if (responseTypes) { - returnType = `Promise<${Object.entries(responseTypes) - .map(([status, responseType]) => { + const returnTypes = Object.entries(responseTypes) + .map(([status, { description: responseDescription, type: responseType }]) => { if (status.toLowerCase() === 'default') { return `FetchResponse`; } else if (status.length === 3 && status.toUpperCase().endsWith('XX')) { @@ -580,19 +609,54 @@ sdk.server('https://eu.api.example.com/v14');`) return `FetchResponse`; } + if (Number(statusPrefix) >= 4) { + docblock = TSGenerator.addTagToDocblock(docblock, { + tagName: 'throws', + text: `FetchError<${status}, ${responseType}>${ + responseDescription ? docblockEscape(wordWrap(` ${responseDescription}`)) : '' + }`, + }); + + return false; + } + this.usesHTTPMethodRangeInterface = true; return `FetchResponse, ${responseType}>`; } + // 400 and 500 status code families are thrown as exceptions so adding them as a possible + // return type isn't valid. + if (Number(status) >= 400) { + docblock = TSGenerator.addTagToDocblock(docblock, { + tagName: 'throws', + text: `FetchError<${status}, ${responseType}>${ + responseDescription ? docblockEscape(wordWrap(` ${responseDescription}`)) : '' + }`, + }); + + return false; + } + return `FetchResponse<${status}, ${responseType}>`; }) - .join(' | ')}>`; + .filter(Boolean) + .join(' | '); + + // If all of our documented responses are for error status codes then all we can document for + // anything else that might happen is `unknown`. + returnType = `Promise<${returnTypes.length ? returnTypes : 'FetchResponse'}>`; } + const shouldAddAltTypedOverloads = Object.keys(parameters).length === 2 && hasOptionalBody && !hasOptionalMetadata; const operationIdAccessor = this.sdk.addMethod({ name: operationId, returnType, - docs: Object.keys(docblock).length ? [docblock] : null, + + // If we're going to be creating typed method overloads for optional body an metadata handling + // we should only add a docblock to the first overload we create because IDE Intellisense will + // always use that and adding a docblock to all three will bloat the SDK with unused and + // unsurfaced method documentation. + docs: shouldAddAltTypedOverloads ? null : Object.keys(docblock).length ? [docblock] : null, statements: writer => { /** * @example return this.core.fetch('/pet/findByStatus', 'get', body, metadata); @@ -626,10 +690,6 @@ sdk.server('https://eu.api.example.com/v14');`) // If we have both body and metadata parameters but only body is optional we need to create // a couple function overloads as Typescript doesn't let us have an optional method parameter // come before one that's required. - // - // None of these accessor overloads will receive a docblock because the original will have - // that covered. - const shouldAddAltTypedOverloads = Object.keys(parameters).length === 2 && hasOptionalBody && !hasOptionalMetadata; if (shouldAddAltTypedOverloads) { // Create an overload that has both `body` and `metadata` parameters as required. operationIdAccessor.addOverload({ @@ -645,7 +705,6 @@ sdk.server('https://eu.api.example.com/v14');`) operationIdAccessor.addOverload({ parameters: [{ ...parameters.metadata }], returnType, - docs: Object.keys(docblock).length ? [docblock] : null, }); // Create an overload that has both `body` and `metadata` parameters as optional. Even though @@ -807,7 +866,7 @@ sdk.server('https://eu.api.example.com/v14');`) .reduce((prev, next) => Object.assign(prev, next)); const res = Object.entries(schemas) - .map(([status, { schema }]) => { + .map(([status, { description, schema }]) => { let typeName; if (typeof schema === 'string' && schema.startsWith('::convert::')) { @@ -826,7 +885,10 @@ sdk.server('https://eu.api.example.com/v14');`) return { // Types are prefixed with `types.` because that's how we're importing them from // `types.d.ts`. - [status]: `types.${typeName}`, + [status]: { + type: `types.${typeName}`, + description, + }, }; }) .reduce((prev, next) => Object.assign(prev, next), {}); diff --git a/packages/api/src/core/errors/fetchError.ts b/packages/api/src/core/errors/fetchError.ts index 1f995956..ef86011a 100644 --- a/packages/api/src/core/errors/fetchError.ts +++ b/packages/api/src/core/errors/fetchError.ts @@ -1,9 +1,9 @@ -class FetchError extends Error { +class FetchError extends Error { /** HTTP Status */ - status: number; + status: Status; /** The content of the response. */ - data: unknown; + data: Data; /** The Headers of the response. */ headers: Headers; @@ -11,7 +11,7 @@ class FetchError extends Error { /** The raw `Response` object. */ res: Response; - constructor(status: number, data: unknown, headers: Headers, res: Response) { + constructor(status: Status, data: Data, headers: Headers, res: Response) { super(res.statusText); this.name = 'FetchError'; diff --git a/packages/api/src/core/index.ts b/packages/api/src/core/index.ts index 1e8688d5..181bf059 100644 --- a/packages/api/src/core/index.ts +++ b/packages/api/src/core/index.ts @@ -128,7 +128,12 @@ export default class APICore { const parsed = await parseResponse(res); if (res.status >= 400 && res.status <= 599) { - throw new FetchError(parsed.status, parsed.data, parsed.headers, parsed.res); + throw new FetchError( + parsed.status, + parsed.data, + parsed.headers, + parsed.res + ); } return parsed; diff --git a/packages/api/test/__fixtures__/sdk/alby/index.ts b/packages/api/test/__fixtures__/sdk/alby/index.ts index 8723065c..7c612f43 100644 --- a/packages/api/test/__fixtures__/sdk/alby/index.ts +++ b/packages/api/test/__fixtures__/sdk/alby/index.ts @@ -77,15 +77,13 @@ class SDK { * List all applications for the specified account ID. * * @summary Lists apps + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Account not found + * @throws FetchError<500, types.Error> Internal server error */ getAccountsAccount_idApps( metadata: types.GetAccountsAccountIdAppsMetadataParam - ): Promise< - | FetchResponse<200, types.GetAccountsAccountIdAppsResponse200> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/accounts/{account_id}/apps', 'get', metadata); } @@ -93,18 +91,16 @@ class SDK { * Creates an application with the specified properties. * * @summary Creates an app + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Account not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error */ postAccountsAccount_idApps( body: types.AppPost, metadata: types.PostAccountsAccountIdAppsMetadataParam - ): Promise< - | FetchResponse<201, types.AppResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/accounts/{account_id}/apps', 'post', body, metadata); } @@ -112,16 +108,14 @@ class SDK { * Lists the API keys associated with the application ID. * * @summary Lists app keys + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ getAppsApp_idKeys( metadata: types.GetAppsAppIdKeysMetadataParam - ): Promise< - | FetchResponse<200, types.GetAppsAppIdKeysResponse200> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/keys', 'get', metadata); } @@ -129,18 +123,16 @@ class SDK { * Creates an API key for the application specified. * * @summary Creates a key + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error */ postAppsApp_idKeys( body: types.KeyPost, metadata: types.PostAppsAppIdKeysMetadataParam - ): Promise< - | FetchResponse<201, types.KeyResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/keys', 'post', body, metadata); } @@ -149,54 +141,24 @@ class SDK { * application ID. * * @summary Updates a key + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ patchAppsApp_idKeysKey_id( body: types.KeyPatch, metadata: types.PatchAppsAppIdKeysKeyIdMetadataParam - ): Promise< - | FetchResponse<200, types.KeyResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Update the API key with the specified key ID, for the application with the specified - * application ID. - * - * @summary Updates a key - */ + ): Promise>; patchAppsApp_idKeysKey_id( metadata: types.PatchAppsAppIdKeysKeyIdMetadataParam - ): Promise< - | FetchResponse<200, types.KeyResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Update the API key with the specified key ID, for the application with the specified - * application ID. - * - * @summary Updates a key - */ + ): Promise>; patchAppsApp_idKeysKey_id( body?: types.KeyPatch | types.PatchAppsAppIdKeysKeyIdMetadataParam, metadata?: types.PatchAppsAppIdKeysKeyIdMetadataParam - ): Promise< - | FetchResponse<200, types.KeyResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/keys/{key_id}', 'patch', body, metadata); } @@ -205,15 +167,14 @@ class SDK { * key. * * @summary Revokes a key + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ postAppsApp_idKeysKey_idRevoke( metadata: types.PostAppsAppIdKeysKeyIdRevokeMetadataParam - ): Promise< - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/keys/{key_id}/revoke', 'post', metadata); } @@ -221,16 +182,14 @@ class SDK { * List the namespaces for the specified application ID. * * @summary Lists namespaces + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ getAppsApp_idNamespaces( metadata: types.GetAppsAppIdNamespacesMetadataParam - ): Promise< - | FetchResponse<200, types.GetAppsAppIdNamespacesResponse200> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/namespaces', 'get', metadata); } @@ -238,18 +197,16 @@ class SDK { * Creates a namespace for the specified application ID. * * @summary Creates a namespace + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error */ postAppsApp_idNamespaces( body: types.NamespacePost, metadata: types.PostAppsAppIdNamespacesMetadataParam - ): Promise< - | FetchResponse<201, types.NamespaceResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/namespaces', 'post', body, metadata); } @@ -257,15 +214,14 @@ class SDK { * Deletes the namespace with the specified ID, for the specified application ID. * * @summary Deletes a namespace + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ deleteAppsApp_idNamespacesNamespace_id( metadata: types.DeleteAppsAppIdNamespacesNamespaceIdMetadataParam - ): Promise< - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/namespaces/{namespace_id}', 'delete', metadata); } @@ -274,51 +230,23 @@ class SDK { * application ID. * * @summary Updates a namespace + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ patchAppsApp_idNamespacesNamespace_id( body: types.NamespacePatch, metadata: types.PatchAppsAppIdNamespacesNamespaceIdMetadataParam - ): Promise< - | FetchResponse<200, types.NamespaceResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Updates the namespace with the specified ID, for the application with the specified - * application ID. - * - * @summary Updates a namespace - */ + ): Promise>; patchAppsApp_idNamespacesNamespace_id( metadata: types.PatchAppsAppIdNamespacesNamespaceIdMetadataParam - ): Promise< - | FetchResponse<200, types.NamespaceResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Updates the namespace with the specified ID, for the application with the specified - * application ID. - * - * @summary Updates a namespace - */ + ): Promise>; patchAppsApp_idNamespacesNamespace_id( body?: types.NamespacePatch | types.PatchAppsAppIdNamespacesNamespaceIdMetadataParam, metadata?: types.PatchAppsAppIdNamespacesNamespaceIdMetadataParam - ): Promise< - | FetchResponse<200, types.NamespaceResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/namespaces/{namespace_id}', 'patch', body, metadata); } @@ -326,17 +254,15 @@ class SDK { * Lists the queues associated with the specified application ID. * * @summary Lists queues + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<503, types.Error> 503 Service unavailable + * @throws FetchError<504, types.Error> Gateway timeout */ getAppsApp_idQueues( metadata: types.GetAppsAppIdQueuesMetadataParam - ): Promise< - | FetchResponse<200, types.GetAppsAppIdQueuesResponse200> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<503, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/queues', 'get', metadata); } @@ -345,18 +271,16 @@ class SDK { * queue to be created are specified in the request body. * * @summary Creates a queue + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error */ postAppsApp_idQueues( body: types.Queue, metadata: types.PostAppsAppIdQueuesMetadataParam - ): Promise< - | FetchResponse<201, types.QueueResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/queues', 'post', body, metadata); } @@ -365,16 +289,15 @@ class SDK { * application ID. * * @summary Deletes a queue + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<503, types.Error> 503 Service unavailable */ deleteAppsApp_idQueuesQueue_id( metadata: types.DeleteAppsAppIdQueuesQueueIdMetadataParam - ): Promise< - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<503, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/queues/{queue_id}', 'delete', metadata); } @@ -382,16 +305,14 @@ class SDK { * Lists the rules for the application specified by the application ID. * * @summary Lists Reactor rules + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ getAppsApp_idRules( metadata: types.GetAppsAppIdRulesMetadataParam - ): Promise< - | FetchResponse<200, types.GetAppsAppIdRulesResponse200> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/rules', 'get', metadata); } @@ -399,67 +320,38 @@ class SDK { * Creates a rule for the application with the specified application ID. * * @summary Creates a Reactor rule + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ postAppsApp_idRules( body: types.RulePost, metadata: types.PostAppsAppIdRulesMetadataParam - ): Promise< - | FetchResponse<201, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Creates a rule for the application with the specified application ID. - * - * @summary Creates a Reactor rule - */ + ): Promise>; postAppsApp_idRules( metadata: types.PostAppsAppIdRulesMetadataParam - ): Promise< - | FetchResponse<201, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Creates a rule for the application with the specified application ID. - * - * @summary Creates a Reactor rule - */ + ): Promise>; postAppsApp_idRules( body?: types.RulePost | types.PostAppsAppIdRulesMetadataParam, metadata?: types.PostAppsAppIdRulesMetadataParam - ): Promise< - | FetchResponse<201, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/rules', 'post', body, metadata); } /** * Deletes a Reactor rule * + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ deleteAppsApp_idRulesRule_id( metadata: types.DeleteAppsAppIdRulesRuleIdMetadataParam - ): Promise< - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/rules/{rule_id}', 'delete', metadata); } @@ -468,66 +360,38 @@ class SDK { * ID. * * @summary Gets a reactor rule by rule ID + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> Not found + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ getAppsApp_idRulesRule_id( metadata: types.GetAppsAppIdRulesRuleIdMetadataParam - ): Promise< - | FetchResponse<200, types.RuleResponse> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/rules/{rule_id}', 'get', metadata); } /** * Updates a Reactor rule * + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error + * @throws FetchError<504, types.Error> Gateway timeout */ patchAppsApp_idRulesRule_id( body: types.RulePatch, metadata: types.PatchAppsAppIdRulesRuleIdMetadataParam - ): Promise< - | FetchResponse<200, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Updates a Reactor rule - * - */ + ): Promise>; patchAppsApp_idRulesRule_id( metadata: types.PatchAppsAppIdRulesRuleIdMetadataParam - ): Promise< - | FetchResponse<200, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - >; - /** - * Updates a Reactor rule - * - */ + ): Promise>; patchAppsApp_idRulesRule_id( body?: types.RulePatch | types.PatchAppsAppIdRulesRuleIdMetadataParam, metadata?: types.PatchAppsAppIdRulesRuleIdMetadataParam - ): Promise< - | FetchResponse<200, types.RuleResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - | FetchResponse<504, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{app_id}/rules/{rule_id}', 'patch', body, metadata); } @@ -535,15 +399,12 @@ class SDK { * Deletes the application with the specified application ID. * * @summary Deletes an app + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<422, types.Error> Invalid request + * @throws FetchError<500, types.Error> Internal server error */ - deleteAppsId( - metadata: types.DeleteAppsIdMetadataParam - ): Promise< - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<422, types.Error> - | FetchResponse<500, types.Error> - > { + deleteAppsId(metadata: types.DeleteAppsIdMetadataParam): Promise> { return this.core.fetch('/apps/{id}', 'delete', metadata); } @@ -551,46 +412,22 @@ class SDK { * Updates the application with the specified application ID. * * @summary Updates an app + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error */ patchAppsId( body: types.AppPatch, metadata: types.PatchAppsIdMetadataParam - ): Promise< - | FetchResponse<200, types.AppResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - >; - /** - * Updates the application with the specified application ID. - * - * @summary Updates an app - */ + ): Promise>; patchAppsId( metadata: types.PatchAppsIdMetadataParam - ): Promise< - | FetchResponse<200, types.AppResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - >; - /** - * Updates the application with the specified application ID. - * - * @summary Updates an app - */ + ): Promise>; patchAppsId( body?: types.AppPatch | types.PatchAppsIdMetadataParam, metadata?: types.PatchAppsIdMetadataParam - ): Promise< - | FetchResponse<200, types.AppResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{id}', 'patch', body, metadata); } @@ -598,27 +435,25 @@ class SDK { * Updates the application's Apple Push Notification service (APNs) information. * * @summary Updates app's APNs info from a `.p12` file + * @throws FetchError<400, types.Error> Bad request + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<404, types.Error> App not found + * @throws FetchError<500, types.Error> Internal server error */ postAppsIdPkcs12( body: types.AppPkcs12, metadata: types.PostAppsIdPkcs12MetadataParam - ): Promise< - | FetchResponse<200, types.AppResponse> - | FetchResponse<400, types.Error> - | FetchResponse<401, types.Error> - | FetchResponse<404, types.Error> - | FetchResponse<500, types.Error> - > { + ): Promise> { return this.core.fetch('/apps/{id}/pkcs12', 'post', body, metadata); } /** * Get token details * + * @throws FetchError<401, types.Error> Authentication failed + * @throws FetchError<500, types.Error> Internal server error */ - getMe(): Promise< - FetchResponse<200, types.Me> | FetchResponse<401, types.Error> | FetchResponse<500, types.Error> - > { + getMe(): Promise> { return this.core.fetch('/me', 'get'); } } diff --git a/packages/api/test/__fixtures__/sdk/optional-payload/index.ts b/packages/api/test/__fixtures__/sdk/optional-payload/index.ts index 5e035233..7fa110a1 100644 --- a/packages/api/test/__fixtures__/sdk/optional-payload/index.ts +++ b/packages/api/test/__fixtures__/sdk/optional-payload/index.ts @@ -81,17 +81,9 @@ class SDK { body: types.UpdatePetWithFormFormDataParam, metadata: types.UpdatePetWithFormMetadataParam ): Promise>; - /** - * Updates a pet in the store with form data - * - */ updatePetWithForm( metadata: types.UpdatePetWithFormMetadataParam ): Promise>; - /** - * Updates a pet in the store with form data - * - */ updatePetWithForm( body?: types.UpdatePetWithFormFormDataParam | types.UpdatePetWithFormMetadataParam, metadata?: types.UpdatePetWithFormMetadataParam diff --git a/packages/api/test/__fixtures__/sdk/petstore/index.ts b/packages/api/test/__fixtures__/sdk/petstore/index.ts index 2d1bd98b..c0d3cf8c 100644 --- a/packages/api/test/__fixtures__/sdk/petstore/index.ts +++ b/packages/api/test/__fixtures__/sdk/petstore/index.ts @@ -129,17 +129,9 @@ class SDK { body: types.UpdatePetWithFormFormDataParam, metadata: types.UpdatePetWithFormMetadataParam ): Promise>; - /** - * Updates a pet in the store with form data - * - */ updatePetWithForm( metadata: types.UpdatePetWithFormMetadataParam ): Promise>; - /** - * Updates a pet in the store with form data - * - */ updatePetWithForm( body?: types.UpdatePetWithFormFormDataParam | types.UpdatePetWithFormMetadataParam, metadata?: types.UpdatePetWithFormMetadataParam @@ -163,17 +155,9 @@ class SDK { body: types.UploadFileBodyParam, metadata: types.UploadFileMetadataParam ): Promise>; - /** - * Uploads an image - * - */ uploadFile( metadata: types.UploadFileMetadataParam ): Promise>; - /** - * Uploads an image - * - */ uploadFile( body?: types.UploadFileBodyParam | types.UploadFileMetadataParam, metadata?: types.UploadFileMetadataParam diff --git a/packages/api/test/__fixtures__/sdk/readme/index.ts b/packages/api/test/__fixtures__/sdk/readme/index.ts index 0d391ad6..e6ae07e6 100644 --- a/packages/api/test/__fixtures__/sdk/readme/index.ts +++ b/packages/api/test/__fixtures__/sdk/readme/index.ts @@ -77,13 +77,11 @@ class SDK { * Get an API definition file that's been uploaded to ReadMe. * * @summary Retrieve an entry from the API Registry + * @throws FetchError<404, types.ErrorRegistryNotfound> The registry entry couldn't be found. */ getAPIRegistry( metadata: types.GetApiRegistryMetadataParam - ): Promise< - | FetchResponse<200, types.GetApiRegistryResponse200> - | FetchResponse<404, types.ErrorRegistryNotfound> - > { + ): Promise> { return this.core.fetch('/api-registry/{uuid}', 'get', metadata); } @@ -91,16 +89,14 @@ class SDK { * Get API specification metadata. * * @summary Get metadata + * @throws FetchError<400, types.ErrorVersionEmpty> No version was supplied. + * @throws FetchError<401, types.GetApiSpecificationResponse401> Unauthorized + * @throws FetchError<403, types.GetApiSpecificationResponse403> Unauthorized + * @throws FetchError<404, types.ErrorVersionNotfound> The version couldn't be found. */ getAPISpecification( metadata?: types.GetApiSpecificationMetadataParam - ): Promise< - | FetchResponse<200, types.GetApiSpecificationResponse200> - | FetchResponse<400, types.ErrorVersionEmpty> - | FetchResponse<401, types.GetApiSpecificationResponse401> - | FetchResponse<403, types.GetApiSpecificationResponse403> - | FetchResponse<404, types.ErrorVersionNotfound> - > { + ): Promise> { return this.core.fetch('/api-specification', 'get', metadata); } @@ -109,16 +105,15 @@ class SDK { * https://docs.readme.com/docs/automatically-sync-api-specification-with-github. * * @summary Upload specification + * @throws FetchError<400, types.UploadApiSpecificationResponse400> There was a validation error during upload. + * @throws FetchError<401, types.UploadApiSpecificationResponse401> Unauthorized + * @throws FetchError<403, types.UploadApiSpecificationResponse403> Unauthorized + * @throws FetchError<408, types.ErrorSpecTimeout> The spec upload timed out. */ uploadAPISpecification( body: types.UploadApiSpecificationBodyParam, metadata?: types.UploadApiSpecificationMetadataParam - ): Promise< - | FetchResponse<400, types.UploadApiSpecificationResponse400> - | FetchResponse<401, types.UploadApiSpecificationResponse401> - | FetchResponse<403, types.UploadApiSpecificationResponse403> - | FetchResponse<408, types.ErrorSpecTimeout> - > { + ): Promise> { return this.core.fetch('/api-specification', 'post', body, metadata); } @@ -126,16 +121,15 @@ class SDK { * Update an API specification in ReadMe. * * @summary Update specification + * @throws FetchError<400, types.UpdateApiSpecificationResponse400> There was a validation error during upload. + * @throws FetchError<401, types.UpdateApiSpecificationResponse401> Unauthorized + * @throws FetchError<403, types.UpdateApiSpecificationResponse403> Unauthorized + * @throws FetchError<408, types.ErrorSpecTimeout> The spec upload timed out. */ updateAPISpecification( body: types.UpdateApiSpecificationBodyParam, metadata: types.UpdateApiSpecificationMetadataParam - ): Promise< - | FetchResponse<400, types.UpdateApiSpecificationResponse400> - | FetchResponse<401, types.UpdateApiSpecificationResponse401> - | FetchResponse<403, types.UpdateApiSpecificationResponse403> - | FetchResponse<408, types.ErrorSpecTimeout> - > { + ): Promise> { return this.core.fetch('/api-specification/{id}', 'put', body, metadata); } @@ -143,15 +137,14 @@ class SDK { * Delete an API specification in ReadMe. * * @summary Delete specification + * @throws FetchError<400, types.ErrorSpecIdInvalid> The spec ID isn't valid. + * @throws FetchError<401, types.DeleteApiSpecificationResponse401> Unauthorized + * @throws FetchError<403, types.DeleteApiSpecificationResponse403> Unauthorized + * @throws FetchError<404, types.ErrorSpecNotfound> The spec couldn't be found. */ deleteAPISpecification( metadata: types.DeleteApiSpecificationMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorSpecIdInvalid> - | FetchResponse<401, types.DeleteApiSpecificationResponse401> - | FetchResponse<403, types.DeleteApiSpecificationResponse403> - | FetchResponse<404, types.ErrorSpecNotfound> - > { + ): Promise> { return this.core.fetch('/api-specification/{id}', 'delete', metadata); } @@ -189,11 +182,12 @@ class SDK { * Create a new category inside of this project. * * @summary Create category + * @throws FetchError<400, types.ErrorCategoryInvalid> The category couldn't be saved. */ createCategory( body: types.Category, metadata?: types.CreateCategoryMetadataParam - ): Promise> { + ): Promise> { return this.core.fetch('/categories', 'post', body, metadata); } @@ -201,10 +195,9 @@ class SDK { * Returns the category with this slug. * * @summary Get category + * @throws FetchError<404, types.ErrorCategoryNotfound> The category couldn't be found. */ - getCategory( - metadata: types.GetCategoryMetadataParam - ): Promise> { + getCategory(metadata: types.GetCategoryMetadataParam): Promise> { return this.core.fetch('/categories/{slug}', 'get', metadata); } @@ -212,13 +205,13 @@ class SDK { * Change the properties of a category. * * @summary Update category + * @throws FetchError<400, types.ErrorCategoryInvalid> The category couldn't be saved. + * @throws FetchError<404, types.ErrorCategoryNotfound> The category couldn't be found. */ updateCategory( body: types.Category, metadata: types.UpdateCategoryMetadataParam - ): Promise< - FetchResponse<400, types.ErrorCategoryInvalid> | FetchResponse<404, types.ErrorCategoryNotfound> - > { + ): Promise> { return this.core.fetch('/categories/{slug}', 'put', body, metadata); } @@ -228,10 +221,11 @@ class SDK { * > This will also delete all of the docs within this category. * * @summary Delete category + * @throws FetchError<404, types.ErrorCategoryNotfound> The category couldn't be found. */ deleteCategory( metadata: types.DeleteCategoryMetadataParam - ): Promise> { + ): Promise> { return this.core.fetch('/categories/{slug}', 'delete', metadata); } @@ -239,10 +233,11 @@ class SDK { * Returns the docs and children docs within this category. * * @summary Get docs for category + * @throws FetchError<404, types.ErrorCategoryNotfound> The category couldn't be found. */ getCategoryDocs( metadata: types.GetCategoryDocsMetadataParam - ): Promise> { + ): Promise> { return this.core.fetch('/categories/{slug}/docs', 'get', metadata); } @@ -302,14 +297,12 @@ class SDK { * Returns a list of custom pages. * * @summary Get custom pages + * @throws FetchError<401, types.GetCustomPagesResponse401> Unauthorized + * @throws FetchError<403, types.GetCustomPagesResponse403> Unauthorized */ getCustomPages( metadata?: types.GetCustomPagesMetadataParam - ): Promise< - | FetchResponse<200, types.GetCustomPagesResponse200> - | FetchResponse<401, types.GetCustomPagesResponse401> - | FetchResponse<403, types.GetCustomPagesResponse403> - > { + ): Promise> { return this.core.fetch('/custompages', 'get', metadata); } @@ -317,14 +310,11 @@ class SDK { * Create a new custom page inside of this project. * * @summary Create custom page + * @throws FetchError<400, types.ErrorCustompageInvalid> The page couldn't be saved. + * @throws FetchError<401, types.CreateCustomPageResponse401> Unauthorized + * @throws FetchError<403, types.CreateCustomPageResponse403> Unauthorized */ - createCustomPage( - body: types.CustomPage - ): Promise< - | FetchResponse<400, types.ErrorCustompageInvalid> - | FetchResponse<401, types.CreateCustomPageResponse401> - | FetchResponse<403, types.CreateCustomPageResponse403> - > { + createCustomPage(body: types.CustomPage): Promise> { return this.core.fetch('/custompages', 'post', body); } @@ -332,14 +322,13 @@ class SDK { * Returns the custom page with this slug. * * @summary Get custom page + * @throws FetchError<401, types.GetCustomPageResponse401> Unauthorized + * @throws FetchError<403, types.GetCustomPageResponse403> Unauthorized + * @throws FetchError<404, types.ErrorCustompageNotfound> The custom page couldn't be found. */ getCustomPage( metadata: types.GetCustomPageMetadataParam - ): Promise< - | FetchResponse<401, types.GetCustomPageResponse401> - | FetchResponse<403, types.GetCustomPageResponse403> - | FetchResponse<404, types.ErrorCustompageNotfound> - > { + ): Promise> { return this.core.fetch('/custompages/{slug}', 'get', metadata); } @@ -347,16 +336,15 @@ class SDK { * Update a custom page with this slug. * * @summary Update custom page + * @throws FetchError<400, types.ErrorCustompageInvalid> The page couldn't be saved. + * @throws FetchError<401, types.UpdateCustomPageResponse401> Unauthorized + * @throws FetchError<403, types.UpdateCustomPageResponse403> Unauthorized + * @throws FetchError<404, types.ErrorCustompageNotfound> The custom page couldn't be found. */ updateCustomPage( body: types.CustomPage, metadata: types.UpdateCustomPageMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorCustompageInvalid> - | FetchResponse<401, types.UpdateCustomPageResponse401> - | FetchResponse<403, types.UpdateCustomPageResponse403> - | FetchResponse<404, types.ErrorCustompageNotfound> - > { + ): Promise> { return this.core.fetch('/custompages/{slug}', 'put', body, metadata); } @@ -364,14 +352,13 @@ class SDK { * Delete the custom page with this slug. * * @summary Delete custom page + * @throws FetchError<401, types.DeleteCustomPageResponse401> Unauthorized + * @throws FetchError<403, types.DeleteCustomPageResponse403> Unauthorized + * @throws FetchError<404, types.ErrorCustompageNotfound> The custom page couldn't be found. */ deleteCustomPage( metadata: types.DeleteCustomPageMetadataParam - ): Promise< - | FetchResponse<401, types.DeleteCustomPageResponse401> - | FetchResponse<403, types.DeleteCustomPageResponse403> - | FetchResponse<404, types.ErrorCustompageNotfound> - > { + ): Promise> { return this.core.fetch('/custompages/{slug}', 'delete', metadata); } @@ -379,14 +366,11 @@ class SDK { * Returns the doc with this slug. * * @summary Get doc + * @throws FetchError<401, types.GetDocResponse401> Unauthorized + * @throws FetchError<403, types.GetDocResponse403> Unauthorized + * @throws FetchError<404, types.ErrorDocNotfound> The doc couldn't be found. */ - getDoc( - metadata: types.GetDocMetadataParam - ): Promise< - | FetchResponse<401, types.GetDocResponse401> - | FetchResponse<403, types.GetDocResponse403> - | FetchResponse<404, types.ErrorDocNotfound> - > { + getDoc(metadata: types.GetDocMetadataParam): Promise> { return this.core.fetch('/docs/{slug}', 'get', metadata); } @@ -394,16 +378,15 @@ class SDK { * Update a doc with this slug. * * @summary Update doc + * @throws FetchError<400, types.ErrorDocInvalid> The doc couldn't be saved. + * @throws FetchError<401, types.UpdateDocResponse401> Unauthorized + * @throws FetchError<403, types.UpdateDocResponse403> Unauthorized + * @throws FetchError<404, types.ErrorDocNotfound> The doc couldn't be found. */ updateDoc( body: types.Doc, metadata: types.UpdateDocMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorDocInvalid> - | FetchResponse<401, types.UpdateDocResponse401> - | FetchResponse<403, types.UpdateDocResponse403> - | FetchResponse<404, types.ErrorDocNotfound> - > { + ): Promise> { return this.core.fetch('/docs/{slug}', 'put', body, metadata); } @@ -411,14 +394,11 @@ class SDK { * Delete the doc with this slug. * * @summary Delete doc + * @throws FetchError<401, types.DeleteDocResponse401> Unauthorized + * @throws FetchError<403, types.DeleteDocResponse403> Unauthorized + * @throws FetchError<404, types.ErrorDocNotfound> The doc couldn't be found. */ - deleteDoc( - metadata: types.DeleteDocMetadataParam - ): Promise< - | FetchResponse<401, types.DeleteDocResponse401> - | FetchResponse<403, types.DeleteDocResponse403> - | FetchResponse<404, types.ErrorDocNotfound> - > { + deleteDoc(metadata: types.DeleteDocMetadataParam): Promise> { return this.core.fetch('/docs/{slug}', 'delete', metadata); } @@ -428,14 +408,13 @@ class SDK { * return staging. * * @summary Get production doc + * @throws FetchError<401, types.GetProductionDocResponse401> Unauthorized + * @throws FetchError<403, types.GetProductionDocResponse403> Unauthorized + * @throws FetchError<404, types.ErrorDocNotfound> The doc couldn't be found. */ getProductionDoc( metadata: types.GetProductionDocMetadataParam - ): Promise< - | FetchResponse<401, types.GetProductionDocResponse401> - | FetchResponse<403, types.GetProductionDocResponse403> - | FetchResponse<404, types.ErrorDocNotfound> - > { + ): Promise> { return this.core.fetch('/docs/{slug}/production', 'get', metadata); } @@ -443,15 +422,14 @@ class SDK { * Create a new doc inside of this project. * * @summary Create doc + * @throws FetchError<400, types.ErrorDocInvalid> The doc couldn't be saved. + * @throws FetchError<401, types.CreateDocResponse401> Unauthorized + * @throws FetchError<403, types.CreateDocResponse403> Unauthorized */ createDoc( body: types.Doc, metadata?: types.CreateDocMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorDocInvalid> - | FetchResponse<401, types.CreateDocResponse401> - | FetchResponse<403, types.CreateDocResponse403> - > { + ): Promise> { return this.core.fetch('/docs', 'post', body, metadata); } @@ -459,13 +437,10 @@ class SDK { * Returns all docs that match the search. * * @summary Search docs + * @throws FetchError<401, types.SearchDocsResponse401> Unauthorized + * @throws FetchError<403, types.SearchDocsResponse403> Unauthorized */ - searchDocs( - metadata: types.SearchDocsMetadataParam - ): Promise< - | FetchResponse<401, types.SearchDocsResponse401> - | FetchResponse<403, types.SearchDocsResponse403> - > { + searchDocs(metadata: types.SearchDocsMetadataParam): Promise> { return this.core.fetch('/docs/search', 'post', metadata); } @@ -473,10 +448,10 @@ class SDK { * Returns with all of the error page types for this project. * * @summary Get errors + * @throws FetchError<401, types.GetErrorsResponse401> Unauthorized + * @throws FetchError<403, types.GetErrorsResponse403> Unauthorized */ - getErrors(): Promise< - FetchResponse<401, types.GetErrorsResponse401> | FetchResponse<403, types.GetErrorsResponse403> - > { + getErrors(): Promise> { return this.core.fetch('/errors', 'get'); } @@ -484,12 +459,10 @@ class SDK { * Returns project data for the API key. * * @summary Get metadata about the current project + * @throws FetchError<401, types.GetProjectResponse401> Unauthorized + * @throws FetchError<403, types.GetProjectResponse403> Unauthorized */ - getProject(): Promise< - | FetchResponse<200, types.CondensedProjectData> - | FetchResponse<401, types.GetProjectResponse401> - | FetchResponse<403, types.GetProjectResponse403> - > { + getProject(): Promise> { return this.core.fetch('/', 'get'); } @@ -497,11 +470,10 @@ class SDK { * Retrieve a list of versions associated with a project API key. * * @summary Get versions + * @throws FetchError<401, types.GetVersionsResponse401> Unauthorized + * @throws FetchError<403, types.GetVersionsResponse403> Unauthorized */ - getVersions(): Promise< - | FetchResponse<401, types.GetVersionsResponse401> - | FetchResponse<403, types.GetVersionsResponse403> - > { + getVersions(): Promise> { return this.core.fetch('/version', 'get'); } @@ -509,15 +481,12 @@ class SDK { * Create a new version. * * @summary Create version + * @throws FetchError<400, types.CreateVersionResponse400> There was a validation error during creation. + * @throws FetchError<401, types.CreateVersionResponse401> Unauthorized + * @throws FetchError<403, types.CreateVersionResponse403> Unauthorized + * @throws FetchError<404, types.ErrorVersionForkNotfound> The version couldn't be found. */ - createVersion( - body: types.Version - ): Promise< - | FetchResponse<400, types.CreateVersionResponse400> - | FetchResponse<401, types.CreateVersionResponse401> - | FetchResponse<403, types.CreateVersionResponse403> - | FetchResponse<404, types.ErrorVersionForkNotfound> - > { + createVersion(body: types.Version): Promise> { return this.core.fetch('/version', 'post', body); } @@ -525,14 +494,11 @@ class SDK { * Returns the version with this version ID. * * @summary Get version + * @throws FetchError<401, types.GetVersionResponse401> Unauthorized + * @throws FetchError<403, types.GetVersionResponse403> Unauthorized + * @throws FetchError<404, types.ErrorVersionNotfound> The version couldn't be found. */ - getVersion( - metadata: types.GetVersionMetadataParam - ): Promise< - | FetchResponse<401, types.GetVersionResponse401> - | FetchResponse<403, types.GetVersionResponse403> - | FetchResponse<404, types.ErrorVersionNotfound> - > { + getVersion(metadata: types.GetVersionMetadataParam): Promise> { return this.core.fetch('/version/{versionId}', 'get', metadata); } @@ -540,16 +506,15 @@ class SDK { * Update an existing version. * * @summary Update version + * @throws FetchError<400, types.ErrorVersionCantDemoteStable> A stable version can't be demoted. + * @throws FetchError<401, types.UpdateVersionResponse401> Unauthorized + * @throws FetchError<403, types.UpdateVersionResponse403> Unauthorized + * @throws FetchError<404, types.ErrorVersionNotfound> The version couldn't be found. */ updateVersion( body: types.Version, metadata: types.UpdateVersionMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorVersionCantDemoteStable> - | FetchResponse<401, types.UpdateVersionResponse401> - | FetchResponse<403, types.UpdateVersionResponse403> - | FetchResponse<404, types.ErrorVersionNotfound> - > { + ): Promise> { return this.core.fetch('/version/{versionId}', 'put', body, metadata); } @@ -557,15 +522,14 @@ class SDK { * Delete a version * * @summary Delete version + * @throws FetchError<400, types.ErrorVersionCantRemoveStable> A stable version can't be removed. + * @throws FetchError<401, types.DeleteVersionResponse401> Unauthorized + * @throws FetchError<403, types.DeleteVersionResponse403> Unauthorized + * @throws FetchError<404, types.ErrorVersionNotfound> The version couldn't be found. */ deleteVersion( metadata: types.DeleteVersionMetadataParam - ): Promise< - | FetchResponse<400, types.ErrorVersionCantRemoveStable> - | FetchResponse<401, types.DeleteVersionResponse401> - | FetchResponse<403, types.DeleteVersionResponse403> - | FetchResponse<404, types.ErrorVersionNotfound> - > { + ): Promise> { return this.core.fetch('/version/{versionId}', 'delete', metadata); } }