From 6e1244f7fccdb60d42d217b07ddf106fae64ce00 Mon Sep 17 00:00:00 2001 From: Jordan Shatford Date: Sun, 21 Apr 2024 16:16:21 +1000 Subject: [PATCH] feat: disable formatting with prettier by default --- .changeset/famous-bugs-laugh.md | 5 + docs/openapi-ts/configuration.md | 14 +- docs/openapi-ts/migrating.md | 2 +- packages/openapi-ts/src/compiler/classes.ts | 12 +- packages/openapi-ts/src/compiler/index.ts | 9 +- packages/openapi-ts/src/compiler/typedef.ts | 6 +- packages/openapi-ts/src/compiler/types.ts | 8 +- packages/openapi-ts/src/compiler/utils.ts | 38 +- packages/openapi-ts/src/index.ts | 2 +- .../openapi-ts/src/templates/core/OpenAPI.hbs | 42 +- packages/openapi-ts/src/types/config.ts | 2 +- packages/openapi-ts/src/utils/enum.ts | 9 +- packages/openapi-ts/src/utils/escape.ts | 9 +- packages/openapi-ts/src/utils/write/models.ts | 4 +- .../openapi-ts/src/utils/write/services.ts | 4 +- .../test/generated/v2/core/ApiError.ts.snap | 34 +- .../v2/core/ApiRequestOptions.ts.snap | 31 +- .../test/generated/v2/core/ApiResult.ts.snap | 12 +- .../v2/core/CancelablePromise.ts.snap | 236 +- .../test/generated/v2/core/OpenAPI.ts.snap | 52 +- .../test/generated/v2/core/request.ts.snap | 608 ++-- .../test/generated/v2/enums.gen.ts.snap | 88 +- .../test/generated/v2/index.ts.snap | 3 +- .../test/generated/v2/schemas.gen.ts.snap | 930 +++--- .../test/generated/v2/services.gen.ts.snap | 1167 ++++--- .../test/generated/v2/types.gen.ts.snap | 1152 ++++--- .../test/generated/v3/core/ApiError.ts.snap | 34 +- .../v3/core/ApiRequestOptions.ts.snap | 31 +- .../test/generated/v3/core/ApiResult.ts.snap | 12 +- .../v3/core/CancelablePromise.ts.snap | 236 +- .../test/generated/v3/core/OpenAPI.ts.snap | 52 +- .../test/generated/v3/core/request.ts.snap | 608 ++-- .../test/generated/v3/enums.gen.ts.snap | 128 +- .../test/generated/v3/index.ts.snap | 3 +- .../test/generated/v3/schemas.gen.ts.snap | 2670 ++++++++--------- .../test/generated/v3/services.gen.ts.snap | 1637 +++++----- .../test/generated/v3/types.gen.ts.snap | 1920 ++++++------ .../v3_angular/core/ApiError.ts.snap | 34 +- .../v3_angular/core/ApiRequestOptions.ts.snap | 31 +- .../v3_angular/core/ApiResult.ts.snap | 12 +- .../generated/v3_angular/core/OpenAPI.ts.snap | 46 +- .../generated/v3_angular/core/request.ts.snap | 576 ++-- .../test/generated/v3_angular/index.ts.snap | 3 +- .../generated/v3_angular/services.gen.ts.snap | 1767 ++++++----- .../generated/v3_angular/types.gen.ts.snap | 1920 ++++++------ .../generated/v3_axios/core/ApiError.ts.snap | 34 +- .../v3_axios/core/ApiRequestOptions.ts.snap | 31 +- .../generated/v3_axios/core/ApiResult.ts.snap | 12 +- .../v3_axios/core/CancelablePromise.ts.snap | 236 +- .../generated/v3_axios/core/OpenAPI.ts.snap | 51 +- .../generated/v3_axios/core/request.ts.snap | 590 ++-- .../test/generated/v3_axios/index.ts.snap | 3 +- .../generated/v3_client/ApiClient.ts.snap | 130 +- .../generated/v3_client/core/ApiError.ts.snap | 34 +- .../v3_client/core/ApiRequestOptions.ts.snap | 31 +- .../v3_client/core/ApiResult.ts.snap | 12 +- .../v3_client/core/BaseHttpRequest.ts.snap | 7 +- .../v3_client/core/CancelablePromise.ts.snap | 236 +- .../v3_client/core/FetchHttpRequest.ts.snap | 27 +- .../generated/v3_client/core/OpenAPI.ts.snap | 52 +- .../generated/v3_client/core/request.ts.snap | 608 ++-- .../generated/v3_client/enums.gen.ts.snap | 128 +- .../test/generated/v3_client/index.ts.snap | 3 +- .../generated/v3_client/services.gen.ts.snap | 1729 +++++------ .../generated/v3_client/types.gen.ts.snap | 1920 ++++++------ .../test/generated/v3_date/index.ts.snap | 3 +- .../test/generated/v3_date/types.gen.ts.snap | 20 +- .../v3_enums_typescript/core/ApiError.ts.snap | 34 +- .../core/ApiRequestOptions.ts.snap | 31 +- .../core/ApiResult.ts.snap | 12 +- .../core/CancelablePromise.ts.snap | 236 +- .../v3_enums_typescript/core/OpenAPI.ts.snap | 52 +- .../v3_enums_typescript/core/request.ts.snap | 608 ++-- .../v3_enums_typescript/enums.gen.ts.snap | 128 +- .../v3_enums_typescript/index.ts.snap | 3 +- .../v3_enums_typescript/services.gen.ts.snap | 1637 +++++----- .../v3_enums_typescript/types.gen.ts.snap | 1920 ++++++------ .../core/ApiError.ts.snap | 34 +- .../core/ApiRequestOptions.ts.snap | 31 +- .../core/ApiResult.ts.snap | 12 +- .../core/CancelablePromise.ts.snap | 236 +- .../core/OpenAPI.ts.snap | 52 +- .../core/request.ts.snap | 608 ++-- .../v3_legacy_positional_args/index.ts.snap | 3 +- .../services.gen.ts.snap | 174 +- .../types.gen.ts.snap | 188 +- .../test/generated/v3_models/index.ts.snap | 3 +- .../generated/v3_models/types.gen.ts.snap | 668 ++--- .../generated/v3_node/core/ApiError.ts.snap | 34 +- .../v3_node/core/ApiRequestOptions.ts.snap | 31 +- .../generated/v3_node/core/ApiResult.ts.snap | 12 +- .../v3_node/core/CancelablePromise.ts.snap | 236 +- .../generated/v3_node/core/OpenAPI.ts.snap | 51 +- .../generated/v3_node/core/request.ts.snap | 603 ++-- .../test/generated/v3_node/index.ts.snap | 3 +- .../v3_options/core/ApiError.ts.snap | 34 +- .../v3_options/core/ApiRequestOptions.ts.snap | 31 +- .../v3_options/core/ApiResult.ts.snap | 12 +- .../v3_options/core/CancelablePromise.ts.snap | 236 +- .../generated/v3_options/core/OpenAPI.ts.snap | 52 +- .../generated/v3_options/core/request.ts.snap | 608 ++-- .../test/generated/v3_options/index.ts.snap | 3 +- .../generated/v3_options/services.gen.ts.snap | 162 +- .../generated/v3_options/types.gen.ts.snap | 188 +- .../generated/v3_pascalcase/index.ts.snap | 3 +- .../generated/v3_pascalcase/types.gen.ts.snap | 6 +- .../generated/v3_schemas_form/index.ts.snap | 3 +- .../v3_schemas_form/schemas.gen.ts.snap | 2418 ++++++++------- .../generated/v3_schemas_json/index.ts.snap | 3 +- .../v3_schemas_json/schemas.gen.ts.snap | 2670 ++++++++--------- .../generated/v3_services_name/index.ts.snap | 3 +- .../v3_services_name/services.gen.ts.snap | 436 ++- .../generated/v3_xhr/core/ApiError.ts.snap | 34 +- .../v3_xhr/core/ApiRequestOptions.ts.snap | 31 +- .../generated/v3_xhr/core/ApiResult.ts.snap | 12 +- .../v3_xhr/core/CancelablePromise.ts.snap | 236 +- .../generated/v3_xhr/core/OpenAPI.ts.snap | 52 +- .../generated/v3_xhr/core/request.ts.snap | 595 ++-- .../test/generated/v3_xhr/index.ts.snap | 3 +- packages/openapi-ts/test/bin.spec.ts | 3 +- 120 files changed, 18034 insertions(+), 19536 deletions(-) create mode 100644 .changeset/famous-bugs-laugh.md diff --git a/.changeset/famous-bugs-laugh.md b/.changeset/famous-bugs-laugh.md new file mode 100644 index 000000000..d4ab3c5de --- /dev/null +++ b/.changeset/famous-bugs-laugh.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": minor +--- + +change: disable formatting with prettier by default diff --git a/docs/openapi-ts/configuration.md b/docs/openapi-ts/configuration.md index e86fe6af0..944a1cec6 100644 --- a/docs/openapi-ts/configuration.md +++ b/docs/openapi-ts/configuration.md @@ -103,29 +103,29 @@ You might not need a `node` client. Fetch API is [experimental](https://nodejs.o ## Formatting -By default, `openapi-ts` will automatically format your client according to your project configuration. To disable automatic formatting, set `format` to false. +By default, `openapi-ts` will not automatically format your client. To enable this feature, set `format` to a valid formatter. ::: code-group -```js{2} [prettier] +```js{2} [disabled] export default { - format: 'prettier', + format: false, input: 'path/to/openapi.json', output: 'src/client', } ``` -```js{2} [biome] +```js{2} [prettier] export default { - format: 'biome', + format: 'prettier', input: 'path/to/openapi.json', output: 'src/client', } ``` -```js{2} [disabled] +```js{2} [biome] export default { - format: false, + format: 'biome', input: 'path/to/openapi.json', output: 'src/client', } diff --git a/docs/openapi-ts/migrating.md b/docs/openapi-ts/migrating.md index 1c968265d..9296df789 100644 --- a/docs/openapi-ts/migrating.md +++ b/docs/openapi-ts/migrating.md @@ -52,7 +52,7 @@ This config option is deprecated and will be removed. ### Changed `format` -This config option has changed. You now need to specify a value (`biome` or `prettier`) to format the output (default: `prettier`). +This config option has changed. You now need to specify a value (`biome` or `prettier`) to format the output (default: `false`). ```js{2} export default { diff --git a/packages/openapi-ts/src/compiler/classes.ts b/packages/openapi-ts/src/compiler/classes.ts index 2b5586991..8b27132f8 100644 --- a/packages/openapi-ts/src/compiler/classes.ts +++ b/packages/openapi-ts/src/compiler/classes.ts @@ -2,7 +2,7 @@ import ts from 'typescript'; import { createTypeNode } from './typedef'; import { toExpression } from './types'; -import { addLeadingComment, Comments, isType } from './utils'; +import { addLeadingJSDocComment, Comments, isType } from './utils'; type AccessLevel = 'public' | 'protected' | 'private'; @@ -87,7 +87,7 @@ export const createConstructorDeclaration = ({ ts.factory.createBlock(statements, multiLine), ); if (comment?.length) { - addLeadingComment(node, comment); + addLeadingJSDocComment(node, comment); } return node; }; @@ -138,7 +138,7 @@ export const createMethodDeclaration = ({ ts.factory.createBlock(statements, multiLine), ); if (comment?.length) { - addLeadingComment(node, comment); + addLeadingJSDocComment(node, comment); } return node; }; @@ -214,7 +214,9 @@ export const createReturnFunctionCall = ({ ts.factory.createIdentifier(name), undefined, args - .map((arg) => ts.factory.createIdentifier(arg)) - .filter(isType), + .map((arg) => + ts.isExpression(arg) ? arg : ts.factory.createIdentifier(arg), + ) + .filter(isType), ), ); diff --git a/packages/openapi-ts/src/compiler/index.ts b/packages/openapi-ts/src/compiler/index.ts index 0d2be1a99..e10c62748 100644 --- a/packages/openapi-ts/src/compiler/index.ts +++ b/packages/openapi-ts/src/compiler/index.ts @@ -7,7 +7,7 @@ import * as classes from './classes'; import * as module from './module'; import * as typedef from './typedef'; import * as types from './types'; -import { addLeadingComment, stringToTsNodes, tsNodeToString } from './utils'; +import { stringToTsNodes, tsNodeToString } from './utils'; export type { FunctionParameter } from './classes'; export type { Property } from './typedef'; @@ -44,9 +44,10 @@ export class TypeScriptFile { this._path = path.resolve(dir, this.getName()); if (header) { - const text = 'This file is auto-generated by @hey-api/openapi-ts'; - const comment = addLeadingComment(undefined, [text], true, false); - this._headers = [...this._headers, comment]; + this._headers = [ + ...this._headers, + '// This file is auto-generated by @hey-api/openapi-ts', + ]; } } diff --git a/packages/openapi-ts/src/compiler/typedef.ts b/packages/openapi-ts/src/compiler/typedef.ts index 85917bfd7..6d6caa07b 100644 --- a/packages/openapi-ts/src/compiler/typedef.ts +++ b/packages/openapi-ts/src/compiler/typedef.ts @@ -1,6 +1,6 @@ import ts from 'typescript'; -import { addLeadingComment, type Comments, tsNodeToString } from './utils'; +import { addLeadingJSDocComment, type Comments, tsNodeToString } from './utils'; export const createTypeNode = ( base: any | ts.TypeNode, @@ -41,7 +41,7 @@ export const createTypeAliasDeclaration = ( createTypeNode(type), ); if (comments?.length) { - addLeadingComment(node, comments); + addLeadingJSDocComment(node, comments); } return node; }; @@ -79,7 +79,7 @@ export const createTypeInterfaceNode = ( ); const comment = property.comment; if (comment) { - addLeadingComment(signature, comment); + addLeadingJSDocComment(signature, comment); } return signature; }), diff --git a/packages/openapi-ts/src/compiler/types.ts b/packages/openapi-ts/src/compiler/types.ts index 5fc911cfd..706591dab 100644 --- a/packages/openapi-ts/src/compiler/types.ts +++ b/packages/openapi-ts/src/compiler/types.ts @@ -1,6 +1,6 @@ import ts from 'typescript'; -import { addLeadingComment, type Comments, isType, ots } from './utils'; +import { addLeadingJSDocComment, type Comments, isType, ots } from './utils'; /** * Convert an unknown value to an expression. @@ -120,7 +120,7 @@ export const createObjectType = ({ : ts.factory.createPropertyAssignment(key, initializer); const c = comments?.[key]; if (c?.length) { - addLeadingComment(assignment, c); + addLeadingJSDocComment(assignment, c); } return assignment; }) @@ -158,13 +158,13 @@ export const createEnumDeclaration = ({ const assignment = ts.factory.createEnumMember(key, initializer); const c = comments?.[key]; if (c) { - addLeadingComment(assignment, c); + addLeadingJSDocComment(assignment, c); } return assignment; }), ); if (leadingComment.length) { - addLeadingComment(declaration, leadingComment); + addLeadingJSDocComment(declaration, leadingComment); } return declaration; }; diff --git a/packages/openapi-ts/src/compiler/utils.ts b/packages/openapi-ts/src/compiler/utils.ts index f517bb029..a33e2adab 100644 --- a/packages/openapi-ts/src/compiler/utils.ts +++ b/packages/openapi-ts/src/compiler/utils.ts @@ -116,38 +116,26 @@ export const isType = (value: T | undefined): value is T => export type Comments = Array; -export const addLeadingComment = ( - node: ts.Node | undefined, - text: Comments, - hasTrailingNewLine: boolean = true, - useJSDocStyle = true, -): string => { +export const addLeadingJSDocComment = (node: ts.Node, text: Comments) => { const comments = text.filter(Boolean); - if (!comments.length) { - return ''; + return; } - // if node is falsy, assume string mode - if (!node) { - if (useJSDocStyle) { - const result = ['/**', ...comments.map((row) => ` * ${row}`), ' */'].join( - '\n', - ); - return hasTrailingNewLine ? `${result}\n` : result; - } - - const result = comments.map((row) => `// ${row}`).join('\n'); - return hasTrailingNewLine ? `${result}\n` : result; - } + const jsdocTexts = comments.map((c, l) => + ts.factory.createJSDocText(`${c}${l !== comments.length ? '\n' : ''}`), + ); + const jsdoc = ts.factory.createJSDocComment( + ts.factory.createNodeArray(jsdocTexts), + ); + const cleanedJsdoc = tsNodeToString(jsdoc) + .replace('/*', '') + .replace('* */', ''); ts.addSyntheticLeadingComment( node, ts.SyntaxKind.MultiLineCommentTrivia, - encodeURIComponent( - ['*', ...comments.map((row) => ` * ${row}`), ' '].join('\n'), - ), - hasTrailingNewLine, + cleanedJsdoc, + true, ); - return ''; }; diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index 11db87cf0..c4a538387 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -206,7 +206,7 @@ const initConfig = async ( dryRun = false, enums = false, exportCore = true, - format = 'prettier', + format = false, input, lint = false, name, diff --git a/packages/openapi-ts/src/templates/core/OpenAPI.hbs b/packages/openapi-ts/src/templates/core/OpenAPI.hbs index d99c7ec24..2fcf933bf 100644 --- a/packages/openapi-ts/src/templates/core/OpenAPI.hbs +++ b/packages/openapi-ts/src/templates/core/OpenAPI.hbs @@ -1,13 +1,12 @@ -{{~#equals @root.$config.client 'angular'~}} +{{#equals @root.$config.client 'angular'}} import type { HttpResponse } from '@angular/common/http'; -{{~/equals~}} -{{~#equals @root.$config.client 'axios'~}} +{{/equals}} +{{#equals @root.$config.client 'axios'}} import type { AxiosRequestConfig, AxiosResponse } from 'axios'; -{{~/equals~}} -{{~#equals @root.$config.client 'node'~}} +{{/equals}} +{{#equals @root.$config.client 'node'}} import type { RequestInit, Response } from 'node-fetch'; -{{~/equals~}} - +{{/equals}} import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,10 +23,7 @@ export class Interceptors { eject(fn: Middleware) { const index = this._fns.indexOf(fn); if (index !== -1) { - this._fns = [ - ...this._fns.slice(0, index), - ...this._fns.slice(index + 1), - ]; + this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; } } @@ -47,25 +43,25 @@ export type OpenAPIConfig = { VERSION: string; WITH_CREDENTIALS: boolean; interceptors: { - {{~#equals @root.$config.client 'angular'~}} + {{#equals @root.$config.client 'angular'}} response: Interceptors>; - {{~/equals~}} - {{~#equals @root.$config.client 'axios'~}} + {{/equals}} + {{#equals @root.$config.client 'axios'}} request: Interceptors; response: Interceptors; - {{~/equals~}} - {{~#equals @root.$config.client 'fetch'~}} + {{/equals}} + {{#equals @root.$config.client 'fetch'}} request: Interceptors; response: Interceptors; - {{~/equals~}} - {{~#equals @root.$config.client 'node'~}} + {{/equals}} + {{#equals @root.$config.client 'node'}} request: Interceptors; response: Interceptors; - {{~/equals~}} - {{~#equals @root.$config.client 'xhr'~}} + {{/equals}} + {{#equals @root.$config.client 'xhr'}} request: Interceptors; response: Interceptors; - {{~/equals~}} + {{/equals}} }; }; @@ -80,9 +76,9 @@ export const OpenAPI: OpenAPIConfig = { VERSION: '{{{version}}}', WITH_CREDENTIALS: false, interceptors: { - {{~#notEquals @root.$config.client 'angular'~}} + {{#notEquals @root.$config.client 'angular'}} request: new Interceptors(), - {{~/notEquals~}} + {{/notEquals}} response: new Interceptors(), }, }; diff --git a/packages/openapi-ts/src/types/config.ts b/packages/openapi-ts/src/types/config.ts index 26914fb86..2074b6ecb 100644 --- a/packages/openapi-ts/src/types/config.ts +++ b/packages/openapi-ts/src/types/config.ts @@ -30,7 +30,7 @@ export interface UserConfig { exportCore?: boolean; /** * Process output folder with formatter? - * @default 'prettier' + * @default false */ format?: 'biome' | 'prettier' | false; /** diff --git a/packages/openapi-ts/src/utils/enum.ts b/packages/openapi-ts/src/utils/enum.ts index bd80e485f..d3f436b7b 100644 --- a/packages/openapi-ts/src/utils/enum.ts +++ b/packages/openapi-ts/src/utils/enum.ts @@ -59,13 +59,16 @@ export const enumName = (client: Client, name?: string) => { export const enumUnionType = (enums: Enum[]) => enums - .map((enumerator) => enumValue(enumerator.value)) + .map((enumerator) => enumValue(enumerator.value, true)) .filter(unique) .join(' | '); -export const enumValue = (value?: string | number) => { +export const enumValue = (value?: string | number, union: boolean = false) => { if (typeof value === 'string') { - return `'${value.replace(/'/g, "\\'")}'`; + if (value.includes("'") && union) { + return `"${value}"`; + } + return `'${value}'`; } return value; }; diff --git a/packages/openapi-ts/src/utils/escape.ts b/packages/openapi-ts/src/utils/escape.ts index 1e72f76a2..6746cf31e 100644 --- a/packages/openapi-ts/src/utils/escape.ts +++ b/packages/openapi-ts/src/utils/escape.ts @@ -24,16 +24,11 @@ export const unescapeName = (value: string): string => { return value; }; -export const escapeComment = (value: string, insertAsterisk = true) => +export const escapeComment = (value: string) => value .replace(/\*\//g, '*') .replace(/\/\*/g, '*') - .replace(/\r?\n(.*)/g, (_, w) => { - if (insertAsterisk) { - return `${EOL} * ${w.trim()}`; - } - return EOL + w.trim(); - }); + .replace(/\r?\n(.*)/g, (_l, w) => EOL + w.trim()); export const escapeDescription = (value: string) => value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${'); diff --git a/packages/openapi-ts/src/utils/write/models.ts b/packages/openapi-ts/src/utils/write/models.ts index b6b3df6b2..87b569117 100644 --- a/packages/openapi-ts/src/utils/write/models.ts +++ b/packages/openapi-ts/src/utils/write/models.ts @@ -4,7 +4,7 @@ import { type Node, TypeScriptFile, } from '../../compiler'; -import { addLeadingComment } from '../../compiler/utils'; +import { addLeadingJSDocComment } from '../../compiler/utils'; import type { Model, OperationParameter, Service } from '../../openApi'; import { ensureValidTypeScriptJavaScriptIdentifier } from '../../openApi/common/parser/sanitize'; import type { Client } from '../../types/client'; @@ -100,7 +100,7 @@ const processEnum = ( unescape: true, }); const node = compiler.export.asConst(name, expression); - addLeadingComment(node, comment); + addLeadingJSDocComment(node, comment); onNode(node, 'enum'); } }; diff --git a/packages/openapi-ts/src/utils/write/services.ts b/packages/openapi-ts/src/utils/write/services.ts index 3a5cfcea5..6466d3235 100644 --- a/packages/openapi-ts/src/utils/write/services.ts +++ b/packages/openapi-ts/src/utils/write/services.ts @@ -170,7 +170,7 @@ const toRequestOptions = (operation: Operation) => { const toOperationStatements = (operation: Operation) => { const config = getConfig(); const statements: any[] = []; - const requestOptions = compiler.utils.toString(toRequestOptions(operation)); + const requestOptions = toRequestOptions(operation); if (config.name) { statements.push( compiler.class.return({ @@ -217,6 +217,7 @@ export const processService = (service: Service) => { if (config.name) { members.unshift( compiler.class.constructor({ + multiLine: false, parameters: [ { accessLevel: 'public', @@ -230,6 +231,7 @@ export const processService = (service: Service) => { } else if (config.client === 'angular') { members.unshift( compiler.class.constructor({ + multiLine: false, parameters: [ { accessLevel: 'public', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/enums.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/enums.gen.ts.snap index a803e72b8..1846b946a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/enums.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/enums.gen.ts.snap @@ -4,71 +4,71 @@ * This is a simple enum with strings */ export const EnumWithStringsEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - _SINGLE_QUOTE_: "'Single Quote'", - _DOUBLE_QUOTES_: '"Double Quotes"', - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + _SINGLE_QUOTE_: "'Single Quote'", + _DOUBLE_QUOTES_: '"Double Quotes"', + 'NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串': 'Non-ascii: øæåôöØÆÅÔÖ字符串' } as const; /** * This is a simple enum with numbers */ export const EnumWithNumbersEnum = { - _1: 1, - _2: 2, - _3: 3, - '_1.1': 1.1, - '_1.2': 1.2, - '_1.3': 1.3, - _100: 100, - _200: 200, - _300: 300, - '_-100': -100, - '_-200': -200, - '_-300': -300, - '_-1.1': -1.1, - '_-1.2': -1.2, - '_-1.3': -1.3, + '_1': 1, + '_2': 2, + '_3': 3, + '_1.1': 1.1, + '_1.2': 1.2, + '_1.3': 1.3, + '_100': 100, + '_200': 200, + '_300': 300, + '_-100': -100, + '_-200': -200, + '_-300': -300, + '_-1.1': -1.1, + '_-1.2': -1.2, + '_-1.3': -1.3 } as const; /** * This is a simple enum with numbers */ export const EnumWithExtensionsEnum = { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS: 200, - /** - * Used when the status of something has a warning - */ - CUSTOM_WARNING: 400, - /** - * Used when the status of something has an error - */ - CUSTOM_ERROR: 500, + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS: 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING: 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR: 500 } as const; /** * This is a simple enum with strings */ export const TestEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - ØÆÅ字符串: 'ØÆÅ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + 'ØÆÅ字符串': 'ØÆÅ字符串' } as const; /** * These are the HTTP error code enums */ export const StatusCodeEnum = { - _100: '100', - _200_FOO: '200 FOO', - _300_FOO_BAR: '300 FOO_BAR', - _400_FOO_BAR: '400 foo-bar', - _500_FOO_BAR: '500 foo.bar', - _600_FOO_BAR: '600 foo&bar', -} as const; + _100: '100', + _200_FOO: '200 FOO', + _300_FOO_BAR: '300 FOO_BAR', + _400_FOO_BAR: '400 foo-bar', + _500_FOO_BAR: '500 foo.bar', + _600_FOO_BAR: '600 foo&bar' +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/index.ts.snap index 2d4902304..6eb4b0c3a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/index.ts.snap @@ -1,9 +1,8 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './enums.gen'; export * from './schemas.gen'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/schemas.gen.ts.snap index 0d2240112..50e7f544b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/schemas.gen.ts.snap @@ -1,639 +1,613 @@ // This file is auto-generated by @hey-api/openapi-ts export const $CommentWithBreaks = { - description: `Testing multiline comments in string: First line + description: `Testing multiline comments in string: First line Second line Fourth line`, - type: 'integer', + type: 'integer' } as const; export const $CommentWithBackticks = { - description: - 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', - type: 'integer', + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', + type: 'integer' } as const; export const $CommentWithBackticksAndQuotes = { - description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, - type: 'integer', + description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, + type: 'integer' } as const; export const $CommentWithSlashes = { - description: - 'Testing slashes in string: \backwards\\ and /forwards/// should work', - type: 'integer', + description: 'Testing slashes in string: \backwards\\\ and /forwards/// should work', + type: 'integer' } as const; export const $CommentWithExpressionPlaceholders = { - description: - 'Testing expression placeholders in string: ${expression} should work', - type: 'integer', + description: 'Testing expression placeholders in string: ${expression} should work', + type: 'integer' } as const; export const $CommentWithQuotes = { - description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, - type: 'integer', + description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, + type: 'integer' } as const; export const $CommentWithReservedCharacters = { - description: - 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', - type: 'integer', + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', + type: 'integer' } as const; export const $SimpleInteger = { - description: 'This is a simple number', - type: 'integer', + description: 'This is a simple number', + type: 'integer' } as const; export const $SimpleBoolean = { - description: 'This is a simple boolean', - type: 'boolean', + description: 'This is a simple boolean', + type: 'boolean' } as const; export const $SimpleString = { - description: 'This is a simple string', - type: 'string', + description: 'This is a simple string', + type: 'string' } as const; export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { - description: - 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', - type: 'string', + description: 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', + type: 'string' } as const; export const $SimpleFile = { - description: 'This is a simple file', - type: 'file', + description: 'This is a simple file', + type: 'file' } as const; export const $SimpleReference = { - description: 'This is a simple reference', - $ref: '#/definitions/ModelWithString', + description: 'This is a simple reference', + '$ref': '#/definitions/ModelWithString' } as const; export const $SimpleStringWithPattern = { - description: 'This is a simple string', - type: 'string', - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', + description: 'This is a simple string', + type: 'string', + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$' } as const; export const $EnumWithStrings = { - description: 'This is a simple enum with strings', - enum: [ - 'Success', - 'Warning', - 'Error', - "'Single Quote'", - '"Double Quotes"', - 'Non-ascii: øæåôöØÆÅÔÖ字符串', - ], + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'] } as const; export const $EnumWithNumbers = { - description: 'This is a simple enum with numbers', - enum: [ - 1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3, - ], + description: 'This is a simple enum with numbers', + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3] } as const; export const $EnumFromDescription = { - description: 'Success=1,Warning=2,Error=3', - type: 'number', + description: 'Success=1,Warning=2,Error=3', + type: 'number' } as const; export const $EnumWithExtensions = { - description: 'This is a simple enum with numbers', - enum: [200, 400, 500], - 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], - 'x-enum-descriptions': [ - 'Used when the status of something is successful', - 'Used when the status of something has a warning', - 'Used when the status of something has an error', - ], + description: 'This is a simple enum with numbers', + enum: [200, 400, 500], + 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], + 'x-enum-descriptions': ['Used when the status of something is successful', 'Used when the status of something has a warning', 'Used when the status of something has an error'] } as const; export const $ArrayWithNumbers = { - description: 'This is a simple array with numbers', - type: 'array', - items: { - type: 'integer', - }, + description: 'This is a simple array with numbers', + type: 'array', + items: { + type: 'integer' + } } as const; export const $ArrayWithBooleans = { - description: 'This is a simple array with booleans', - type: 'array', - items: { - type: 'boolean', - }, + description: 'This is a simple array with booleans', + type: 'array', + items: { + type: 'boolean' + } } as const; export const $ArrayWithStrings = { - description: 'This is a simple array with strings', - type: 'array', - items: { - type: 'string', - }, + description: 'This is a simple array with strings', + type: 'array', + items: { + type: 'string' + } } as const; export const $ArrayWithReferences = { - description: 'This is a simple array with references', - type: 'array', - items: { - $ref: '#/definitions/ModelWithString', - }, + description: 'This is a simple array with references', + type: 'array', + items: { + '$ref': '#/definitions/ModelWithString' + } } as const; export const $ArrayWithArray = { - description: 'This is a simple array containing an array', - type: 'array', - items: { + description: 'This is a simple array containing an array', type: 'array', items: { - $ref: '#/definitions/ModelWithString', - }, - }, + type: 'array', + items: { + '$ref': '#/definitions/ModelWithString' + } + } } as const; export const $ArrayWithProperties = { - description: 'This is a simple array with properties', - type: 'array', - items: { - type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, + description: 'This is a simple array with properties', + type: 'array', + items: { + type: 'object', + properties: { + foo: { + type: 'string' + }, + bar: { + type: 'string' + } + } + } } as const; export const $DictionaryWithString = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { - type: 'string', - }, + description: 'This is a string dictionary', + type: 'object', + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithReference = { - description: 'This is a string reference', - type: 'object', - additionalProperties: { - $ref: '#/definitions/ModelWithString', - }, + description: 'This is a string reference', + type: 'object', + additionalProperties: { + '$ref': '#/definitions/ModelWithString' + } } as const; export const $DictionaryWithArray = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { - type: 'array', - items: { - $ref: '#/definitions/ModelWithString', - }, - }, + description: 'This is a complex dictionary', + type: 'object', + additionalProperties: { + type: 'array', + items: { + '$ref': '#/definitions/ModelWithString' + } + } } as const; export const $DictionaryWithDictionary = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { + description: 'This is a string dictionary', type: 'object', additionalProperties: { - type: 'string', - }, - }, + type: 'object', + additionalProperties: { + type: 'string' + } + } } as const; export const $DictionaryWithProperties = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { + description: 'This is a complex dictionary', type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, + additionalProperties: { + type: 'object', + properties: { + foo: { + type: 'string' + }, + bar: { + type: 'string' + } + } + } } as const; export const $Date = { - description: 'This is a type-only model that defines Date as a string', - type: 'string', + description: 'This is a type-only model that defines Date as a string', + type: 'string' } as const; export const $ModelWithInteger = { - description: 'This is a model with one number property', - type: 'object', - properties: { - prop: { - description: 'This is a simple number property', - type: 'integer', - }, - }, + description: 'This is a model with one number property', + type: 'object', + properties: { + prop: { + description: 'This is a simple number property', + type: 'integer' + } + } } as const; export const $ModelWithBoolean = { - description: 'This is a model with one boolean property', - type: 'object', - properties: { - prop: { - description: 'This is a simple boolean property', - type: 'boolean', - }, - }, + description: 'This is a model with one boolean property', + type: 'object', + properties: { + prop: { + description: 'This is a simple boolean property', + type: 'boolean' + } + } } as const; export const $ModelWithString = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $ModelWithStringError = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $ModelWithNullableString = { - description: 'This is a model with one string property', - type: 'object', - required: ['nullableRequiredProp'], - properties: { - nullableProp: { - description: 'This is a simple string property', - type: 'string', - 'x-nullable': true, - }, - nullableRequiredProp: { - description: 'This is a simple string property', - type: 'string', - 'x-nullable': true, - }, - }, + description: 'This is a model with one string property', + type: 'object', + required: ['nullableRequiredProp'], + properties: { + nullableProp: { + description: 'This is a simple string property', + type: 'string', + 'x-nullable': true + }, + nullableRequiredProp: { + description: 'This is a simple string property', + type: 'string', + 'x-nullable': true + } + } } as const; export const $ModelWithEnum = { - description: 'This is a model with one enum', - type: 'object', - properties: { - test: { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - statusCode: { - description: 'These are the HTTP error code enums', - enum: [ - '100', - '200 FOO', - '300 FOO_BAR', - '400 foo-bar', - '500 foo.bar', - '600 foo&bar', - ], - }, - bool: { - description: 'Simple boolean enum', - type: 'boolean', - enum: [true], - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + test: { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + }, + statusCode: { + description: 'These are the HTTP error code enums', + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'] + }, + bool: { + description: 'Simple boolean enum', + type: 'boolean', + enum: [true] + } + } } as const; export const $ModelWithEnumFromDescription = { - description: 'This is a model with one enum', - type: 'object', - properties: { - test: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + test: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + } } as const; export const $ModelWithNestedEnums = { - description: 'This is a model with nested enums', - type: 'object', - properties: { - dictionaryWithEnum: { - type: 'object', - additionalProperties: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - dictionaryWithEnumFromDescription: { - type: 'object', - additionalProperties: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - arrayWithEnum: { - type: 'array', - items: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - arrayWithDescription: { - type: 'array', - items: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - }, + description: 'This is a model with nested enums', + type: 'object', + properties: { + dictionaryWithEnum: { + type: 'object', + additionalProperties: { + enum: ['Success', 'Warning', 'Error'] + } + }, + dictionaryWithEnumFromDescription: { + type: 'object', + additionalProperties: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + }, + arrayWithEnum: { + type: 'array', + items: { + enum: ['Success', 'Warning', 'Error'] + } + }, + arrayWithDescription: { + type: 'array', + items: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + } + } } as const; export const $ModelWithReference = { - description: 'This is a model with one property containing a reference', - type: 'object', - properties: { - prop: { - $ref: '#/definitions/ModelWithProperties', - }, - }, + description: 'This is a model with one property containing a reference', + type: 'object', + properties: { + prop: { + '$ref': '#/definitions/ModelWithProperties' + } + } } as const; export const $ModelWithArray = { - description: 'This is a model with one property containing an array', - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/definitions/ModelWithString', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + description: 'This is a model with one property containing an array', + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/definitions/ModelWithString' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithDictionary = { - description: 'This is a model with one property containing a dictionary', - type: 'object', - properties: { - prop: { - type: 'object', - additionalProperties: { - type: 'string', - }, - }, - }, + description: 'This is a model with one property containing a dictionary', + type: 'object', + properties: { + prop: { + type: 'object', + additionalProperties: { + type: 'string' + } + } + } } as const; export const $ModelWithCircularReference = { - description: - 'This is a model with one property containing a circular reference', - type: 'object', - properties: { - prop: { - $ref: '#/definitions/ModelWithCircularReference', - }, - }, + description: 'This is a model with one property containing a circular reference', + type: 'object', + properties: { + prop: { + '$ref': '#/definitions/ModelWithCircularReference' + } + } } as const; export const $ModelWithProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['required', 'requiredAndReadOnly'], - properties: { - required: { - type: 'string', - }, - requiredAndReadOnly: { - type: 'string', - readOnly: true, - }, - string: { - type: 'string', - }, - number: { - type: 'number', - }, - boolean: { - type: 'boolean', - }, - reference: { - $ref: '#/definitions/ModelWithString', - }, - 'property with space': { - type: 'string', - }, - default: { - type: 'string', - }, - try: { - type: 'string', - }, - '@namespace.string': { - type: 'string', - readOnly: true, - }, - '@namespace.integer': { - type: 'integer', - readOnly: true, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['required', 'requiredAndReadOnly'], + properties: { + required: { + type: 'string' + }, + requiredAndReadOnly: { + type: 'string', + readOnly: true + }, + string: { + type: 'string' + }, + number: { + type: 'number' + }, + boolean: { + type: 'boolean' + }, + reference: { + '$ref': '#/definitions/ModelWithString' + }, + 'property with space': { + type: 'string' + }, + default: { + type: 'string' + }, + try: { + type: 'string' + }, + '@namespace.string': { + type: 'string', + readOnly: true + }, + '@namespace.integer': { + type: 'integer', + readOnly: true + } + } } as const; export const $ModelWithNestedProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['first'], - properties: { - first: { - type: 'object', - required: ['second'], - readOnly: true, - properties: { - second: { - type: 'object', - required: ['third'], - readOnly: true, - properties: { - third: { - type: 'string', - readOnly: true, - }, - }, - }, - }, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['first'], + properties: { + first: { + type: 'object', + required: ['second'], + readOnly: true, + properties: { + second: { + type: 'object', + required: ['third'], + readOnly: true, + properties: { + third: { + type: 'string', + readOnly: true + } + } + } + } + } + } } as const; export const $ModelWithDuplicateProperties = { - description: 'This is a model with duplicated properties', - type: 'object', - properties: { - prop: { - $ref: '#/definitions/ModelWithString', - }, - }, + description: 'This is a model with duplicated properties', + type: 'object', + properties: { + prop: { + '$ref': '#/definitions/ModelWithString' + } + } } as const; export const $ModelWithOrderedProperties = { - description: 'This is a model with ordered properties', - type: 'object', - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, + description: 'This is a model with ordered properties', + type: 'object', + properties: { + zebra: { + type: 'string' + }, + apple: { + type: 'string' + }, + hawaii: { + type: 'string' + } + } } as const; export const $ModelWithDuplicateImports = { - description: 'This is a model with duplicated imports', - type: 'object', - properties: { - propA: { - $ref: '#/definitions/ModelWithString', - }, - propB: { - $ref: '#/definitions/ModelWithString', - }, - propC: { - $ref: '#/definitions/ModelWithString', - }, - }, + description: 'This is a model with duplicated imports', + type: 'object', + properties: { + propA: { + '$ref': '#/definitions/ModelWithString' + }, + propB: { + '$ref': '#/definitions/ModelWithString' + }, + propC: { + '$ref': '#/definitions/ModelWithString' + } + } } as const; export const $ModelThatExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/definitions/ModelWithString', - }, - { - type: 'object', - properties: { - propExtendsA: { - type: 'string', - }, - propExtendsB: { - $ref: '#/definitions/ModelWithString', - }, - }, - }, - ], + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/definitions/ModelWithString' + }, + { + type: 'object', + properties: { + propExtendsA: { + type: 'string' + }, + propExtendsB: { + '$ref': '#/definitions/ModelWithString' + } + } + } + ] } as const; export const $ModelThatExtendsExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/definitions/ModelWithString', - }, - { - $ref: '#/definitions/ModelThatExtends', - }, - { - type: 'object', - properties: { - propExtendsC: { - type: 'string', - }, - propExtendsD: { - $ref: '#/definitions/ModelWithString', - }, - }, - }, - ], + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/definitions/ModelWithString' + }, + { + '$ref': '#/definitions/ModelThatExtends' + }, + { + type: 'object', + properties: { + propExtendsC: { + type: 'string' + }, + propExtendsD: { + '$ref': '#/definitions/ModelWithString' + } + } + } + ] } as const; export const $default = { - type: 'object', - properties: { - name: { - type: 'string', - }, - }, + type: 'object', + properties: { + name: { + type: 'string' + } + } } as const; export const $ModelWithPattern = { - description: 'This is a model that contains a some patterns', - type: 'object', - required: ['key', 'name'], - properties: { - key: { - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', - type: 'string', - }, - name: { - maxLength: 255, - type: 'string', - }, - enabled: { - type: 'boolean', - readOnly: true, - }, - modified: { - type: 'string', - format: 'date-time', - readOnly: true, - }, - id: { - type: 'string', - pattern: '^d{2}-d{3}-d{4}$', - }, - text: { - type: 'string', - pattern: '^w+$', - }, - patternWithSingleQuotes: { - type: 'string', - pattern: "^[a-zA-Z0-9']*$", - }, - patternWithNewline: { - type: 'string', - pattern: `aaa -bbb`, - }, - patternWithBacktick: { - type: 'string', - pattern: 'aaa`bbb', - }, - }, -} as const; + description: 'This is a model that contains a some patterns', + type: 'object', + required: ['key', 'name'], + properties: { + key: { + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', + type: 'string' + }, + name: { + maxLength: 255, + type: 'string' + }, + enabled: { + type: 'boolean', + readOnly: true + }, + modified: { + type: 'string', + format: 'date-time', + readOnly: true + }, + id: { + type: 'string', + pattern: '^\d{2}-\d{3}-\d{4}$' + }, + text: { + type: 'string', + pattern: '^\w+$' + }, + patternWithSingleQuotes: { + type: 'string', + pattern: "^[a-zA-Z0-9']*$" + }, + patternWithNewline: { + type: 'string', + pattern: `aaa +bbb` + }, + patternWithBacktick: { + type: 'string', + pattern: 'aaa`bbb' + } + } +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap index 63b5b70f2..4860db45b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap @@ -6,660 +6,609 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; export class DefaultService { - /** - * @throws ApiError - */ - public static serviceWithEmptyTag(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-tag', - }); - } + /** + * @throws ApiError + */ + public static serviceWithEmptyTag(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag' + }); + } + } export class SimpleService { - /** - * @throws ApiError - */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + /** + * @throws ApiError + */ + public static getCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static postCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static deleteCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static optionsCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static headCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static patchCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } export class DescriptionsService { - /** - * @param data The data for the request. - * @param data.parameterWithBreaks Testing multiline comments in string: First line - * Second line - * - * Fourth line - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work - * @throws ApiError - */ - public static callWithDescriptions( - data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/descriptions/', - query: { - parameterWithBreaks: data.parameterWithBreaks, - parameterWithBackticks: data.parameterWithBackticks, - parameterWithSlashes: data.parameterWithSlashes, - parameterWithExpressionPlaceholders: - data.parameterWithExpressionPlaceholders, - parameterWithQuotes: data.parameterWithQuotes, - parameterWithReservedCharacters: data.parameterWithReservedCharacters, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work + * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work + * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work + * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work + * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + parameterWithBreaks: data.parameterWithBreaks, + parameterWithBackticks: data.parameterWithBackticks, + parameterWithSlashes: data.parameterWithSlashes, + parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, + parameterWithQuotes: data.parameterWithQuotes, + parameterWithReservedCharacters: data.parameterWithReservedCharacters + } + }); + } + } export class ParametersService { - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterBody This is the parameter that is sent as request body - * @param data.parameterPath This is the parameter that goes into the path - * @throws ApiError - */ - public static callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: parameterBody, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterBody This is the parameter that is sent as request body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public static callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: parameterBody, - }); - } + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterBody This is the parameter that is sent as request body + * @param data.parameterPath This is the parameter that goes into the path + * @throws ApiError + */ + public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: parameterBody + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterBody This is the parameter that is sent as request body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: parameterBody + }); + } + } export class DefaultsService { - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public static callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public static callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public static callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + } export class DuplicateService { - /** - * @throws ApiError - */ - public static duplicateName(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName1(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName2(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName3(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/duplicate', - }); - } + /** + * @throws ApiError + */ + public static duplicateName(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName1(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName2(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName3(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate' + }); + } + } export class NoContentService { - /** - * @returns void Success - * @throws ApiError - */ - public static callWithNoContentResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-content', - }); - } - - /** - * @returns unknown Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content' + }); + } + + /** + * @returns unknown Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + } export class ResponseService { - /** - * @returns unknown Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public static callWithResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/response', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public static callWithDuplicateResponses(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['post']['res'][200] - > { - return __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', - }, - }); - } - - /** - * @returns unknown 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 callWithResponses(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202] - > { - return __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', - }, - }); - } + /** + * @returns unknown Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + return __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' + } + }); + } + + /** + * @returns unknown 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 callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + return __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' + } + }); + } + } export class MultipleTags1Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags2Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags3Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class CollectionFormatService { - /** - * @param data The data for the request. - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) - * @throws ApiError - */ - public static collectionFormat( - data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/collectionFormat', - query: { - parameterArrayCSV: data.parameterArrayCsv, - parameterArraySSV: data.parameterArraySsv, - parameterArrayTSV: data.parameterArrayTsv, - parameterArrayPipes: data.parameterArrayPipes, - parameterArrayMulti: data.parameterArrayMulti, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + parameterArrayCSV: data.parameterArrayCsv, + parameterArraySSV: data.parameterArraySsv, + parameterArrayTSV: data.parameterArrayTsv, + parameterArrayPipes: data.parameterArrayPipes, + parameterArrayMulti: data.parameterArrayMulti + } + }); + } + } export class TypesService { - /** - * @param data The data for the request. - * @param data.parameterArray This is an array parameter - * @param data.parameterDictionary This is a dictionary parameter - * @param data.parameterEnum This is an enum parameter - * @param data.parameterNumber This is a number parameter - * @param data.parameterString This is a string parameter - * @param data.parameterBoolean This is a boolean parameter - * @param data.parameterObject This is an object parameter - * @param data.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 unknown Response is a simple object - * @throws ApiError - */ - public static types( - data: $OpenApiTs['/api/v{api-version}/types']['get']['req'], - ): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/types', - path: { - id: data.id, - }, - query: { - parameterNumber: data.parameterNumber, - parameterString: data.parameterString, - parameterBoolean: data.parameterBoolean, - parameterObject: data.parameterObject, - parameterArray: data.parameterArray, - parameterDictionary: data.parameterDictionary, - parameterEnum: data.parameterEnum, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArray This is an array parameter + * @param data.parameterDictionary This is a dictionary parameter + * @param data.parameterEnum This is an enum parameter + * @param data.parameterNumber This is a number parameter + * @param data.parameterString This is a string parameter + * @param data.parameterBoolean This is a boolean parameter + * @param data.parameterObject This is an object parameter + * @param data.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 unknown Response is a simple object + * @throws ApiError + */ + public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + id: data.id + }, + query: { + parameterNumber: data.parameterNumber, + parameterString: data.parameterString, + parameterBoolean: data.parameterBoolean, + parameterObject: data.parameterObject, + parameterArray: data.parameterArray, + parameterDictionary: data.parameterDictionary, + parameterEnum: data.parameterEnum + } + }); + } + } export class ComplexService { - /** - * @param data The data for the request. - * @param data.parameterObject Parameter containing object - * @param data.parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public static complexTypes( - data: $OpenApiTs['/api/v{api-version}/complex']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/complex', - query: { - parameterObject: data.parameterObject, - parameterReference: data.parameterReference, - }, - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterObject Parameter containing object + * @param data.parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + parameterObject: data.parameterObject, + parameterReference: data.parameterReference + }, + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } export class HeaderService { - /** - * @returns string Successful response - * @throws ApiError - */ - public static callWithResultFromHeader(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/header']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/header', - responseHeader: 'operation-location', - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + /** + * @returns string Successful response + * @throws ApiError + */ + public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } export class ErrorService { - /** - * @param data The data for the request. - * @param data.status Status code to return - * @returns unknown Custom message: Successful response - * @throws ApiError - */ - public static testErrorCode( - data: $OpenApiTs['/api/v{api-version}/error']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/error']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/error', - query: { - status: data.status, - }, - errors: { - 500: 'Custom message: Internal Server Error', - 501: 'Custom message: Not Implemented', - 502: 'Custom message: Bad Gateway', - 503: 'Custom message: Service Unavailable', - }, - }); - } + /** + * @param data The data for the request. + * @param data.status Status code to return + * @returns unknown Custom message: Successful response + * @throws ApiError + */ + public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + status: data.status + }, + errors: { + 500: 'Custom message: Internal Server Error', + 501: 'Custom message: Not Implemented', + 502: 'Custom message: Bad Gateway', + 503: 'Custom message: Service Unavailable' + } + }); + } + } export class NonAsciiÆøåÆøÅöôêÊService { - /** - * @param data The data for the request. - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response - * @throws ApiError - */ - public static nonAsciiæøåÆøÅöôêÊ字符串( - data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - query: { - nonAsciiParamæøåÆØÅöôêÊ: data.nonAsciiParamæøåÆøÅöôêÊ, - }, - }); - } -} + /** + * @param data The data for the request. + * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap index ab06b3071..f69b10429 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap @@ -61,7 +61,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -76,33 +76,12 @@ export type SimpleStringWithPattern = string; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -117,17 +96,17 @@ export type EnumWithExtensions = 200 | 400 | 500; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -143,48 +122,48 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: string; - bar?: string; + foo?: string; + bar?: string; }>; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** @@ -196,693 +175,686 @@ export type Date = string; * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp: string | null; + /** + * This is a simple string property + */ + nullableProp?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp: string | null; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string; + readonly first: { + readonly second: { + readonly third: string; + }; }; - }; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; export type _default = { - name?: string; + name?: string; }; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type $OpenApiTs = { - '/api/v{api-version}/descriptions/': { - post: { - req: { - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: string; - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: string; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: string; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: string; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: string; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameterPath}': { - post: { - req: { - /** - * This is the parameter that is sent as request body - */ - parameterBody: string; - /** - * This is the parameter that goes into the form data - */ - parameterForm: string; - /** - * This is the parameter that goes into the header - */ - parameterHeader: string; - /** - * This is the parameter that goes into the path - */ - parameterPath: string; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { - post: { - req: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that is sent as request body - */ - parameterBody: string; - /** - * This is the parameter that goes into the request form data - */ - parameterForm: string; - /** - * This is the parameter that goes into the request header - */ - parameterHeader: string; - /** - * This is the parameter that goes into the path - */ - parameterPath1?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath2?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath3?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string; - }; - }; - }; - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean: boolean; - /** - * This is a simple enum with default value - */ - parameterEnum: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel: ModelWithString; - /** - * This is a simple number with default value - */ - parameterNumber: number; - /** - * This is a simple string with default value - */ - parameterString: string; - }; - }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; + '/api/v{api-version}/descriptions/': { + post: { + req: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + }; + }; }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: { + /** + * This is the parameter that is sent as request body + */ + parameterBody: string; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string; + /** + * This is the parameter that goes into the path + */ + parameterPath: string; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string; + }; + }; }; - }; - '/api/v{api-version}/no-content': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that is sent as request body + */ + parameterBody: string; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/response-and-no-content': { - get: { - res: { - /** - * Response is a simple number - */ - 200: unknown; - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel: ModelWithString; + /** + * This is a simple number with default value + */ + parameterNumber: number; + /** + * This is a simple string with default value + */ + parameterString: string; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - }; - '/api/v{api-version}/response': { - get: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - post: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: unknown; + /** + * Success + */ + 204: void; + }; + }; }; - put: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 201 response - */ - 201: ModelThatExtends; - /** - * Message for 202 response - */ - 202: ModelThatExtendsExtends; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/response': { + get: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; + put: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/a': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/b': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/collectionFormat': { - get: { - req: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCsv: Array; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySsv: Array; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTsv: Array; - }; + '/api/v{api-version}/collectionFormat': { + get: { + req: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array; + }; + }; }; - }; - '/api/v{api-version}/types': { - get: { - req: { - /** - * This is a number parameter - */ - id?: number; - /** - * This is an array parameter - */ - parameterArray: Array; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean; - /** - * This is a dictionary parameter - */ - parameterDictionary: { - [key: string]: string; + '/api/v{api-version}/types': { + get: { + req: { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: string; + }; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: unknown; + /** + * This is a string parameter + */ + parameterString: string; + }; + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: unknown; + }; }; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error'; - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is an object parameter - */ - parameterObject: unknown; - /** - * This is a string parameter - */ - parameterString: string; - }; - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Response is a simple string - */ - 201: string; - /** - * Response is a simple boolean - */ - 202: boolean; - /** - * Response is a simple object - */ - 203: unknown; - }; }; - }; - '/api/v{api-version}/complex': { - get: { - req: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; + '/api/v{api-version}/complex': { + get: { + req: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; }; - }; }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; - res: { - /** - * Successful response - */ - 200: Array; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; }; - }; - '/api/v{api-version}/header': { - post: { - res: { - /** - * Successful response - */ - 200: string; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; }; - }; - '/api/v{api-version}/error': { - post: { - req: { - /** - * Status code to return - */ - status: string; - }; - res: { - /** - * Custom message: Successful response - */ - 200: unknown; - /** - * Custom message: Internal Server Error - */ - 500: unknown; - /** - * Custom message: Not Implemented - */ - 501: unknown; - /** - * Custom message: Bad Gateway - */ - 502: unknown; - /** - * Custom message: Service Unavailable - */ - 503: unknown; - }; + '/api/v{api-version}/error': { + post: { + req: { + /** + * Status code to return + */ + status: string; + }; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; + }; + }; }; - }; - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { - post: { - req: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; - res: { - /** - * Successful response - */ - 200: NonAsciiStringæøåÆØÅöôêÊ字符串; - }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + res: { + /** + * Successful response + */ + 200: NonAsciiStringæøåÆØÅöôêÊ字符串; + }; + }; }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap index e3117fd1b..73bd72f36 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/enums.gen.ts.snap @@ -4,118 +4,118 @@ * This is a simple enum with strings */ export const EnumWithStringsEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - _SINGLE_QUOTE_: "'Single Quote'", - _DOUBLE_QUOTES_: '"Double Quotes"', - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + _SINGLE_QUOTE_: "'Single Quote'", + _DOUBLE_QUOTES_: '"Double Quotes"', + 'NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串': 'Non-ascii: øæåôöØÆÅÔÖ字符串' } as const; export const EnumWithReplacedCharactersEnum = { - _SINGLE_QUOTE_: "'Single Quote'", - _DOUBLE_QUOTES_: '"Double Quotes"', - ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', - '_3.1': 3.1, - EMPTY_STRING: '', + _SINGLE_QUOTE_: "'Single Quote'", + _DOUBLE_QUOTES_: '"Double Quotes"', + 'ØÆÅÔÖ_ØÆÅÔÖ字符串': 'øæåôöØÆÅÔÖ字符串', + '_3.1': 3.1, + EMPTY_STRING: '' } as const; /** * This is a simple enum with numbers */ export const EnumWithNumbersEnum = { - _1: 1, - _2: 2, - _3: 3, - '_1.1': 1.1, - '_1.2': 1.2, - '_1.3': 1.3, - _100: 100, - _200: 200, - _300: 300, - '_-100': -100, - '_-200': -200, - '_-300': -300, - '_-1.1': -1.1, - '_-1.2': -1.2, - '_-1.3': -1.3, + '_1': 1, + '_2': 2, + '_3': 3, + '_1.1': 1.1, + '_1.2': 1.2, + '_1.3': 1.3, + '_100': 100, + '_200': 200, + '_300': 300, + '_-100': -100, + '_-200': -200, + '_-300': -300, + '_-1.1': -1.1, + '_-1.2': -1.2, + '_-1.3': -1.3 } as const; /** * This is a simple enum with numbers */ export const EnumWithExtensionsEnum = { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS: 200, - /** - * Used when the status of something has a warning - */ - CUSTOM_WARNING: 400, - /** - * Used when the status of something has an error - */ - CUSTOM_ERROR: 500, + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS: 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING: 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR: 500 } as const; export const EnumWithXEnumNamesEnum = { - zero: 0, - one: 1, - two: 2, + zero: 0, + one: 1, + two: 2 } as const; /** * This is a simple enum with strings */ export const FooBarEnumEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - ØÆÅ字符串: 'ØÆÅ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + 'ØÆÅ字符串': 'ØÆÅ字符串' } as const; /** * These are the HTTP error code enums */ export const StatusCodeEnum = { - _100: '100', - _200_FOO: '200 FOO', - _300_FOO_BAR: '300 FOO_BAR', - _400_FOO_BAR: '400 foo-bar', - _500_FOO_BAR: '500 foo.bar', - _600_FOO_BAR: '600 foo&bar', + _100: '100', + _200_FOO: '200 FOO', + _300_FOO_BAR: '300 FOO_BAR', + _400_FOO_BAR: '400 foo-bar', + _500_FOO_BAR: '500 foo.bar', + _600_FOO_BAR: '600 foo&bar' } as const; export const FooBarBazQuxEnum = { - _3_0: '3.0', + _3_0: '3.0' } as const; export const Enum1Enum = { - BIRD: 'Bird', - DOG: 'Dog', + BIRD: 'Bird', + DOG: 'Dog' } as const; export const FooEnum = { - BAR: 'Bar', + BAR: 'Bar' } as const; export const ModelWithNestedArrayEnumsDataFooEnum = { - FOO: 'foo', - BAR: 'bar', + FOO: 'foo', + BAR: 'bar' } as const; export const ModelWithNestedArrayEnumsDataBarEnum = { - BAZ: 'baz', - QUX: 'qux', + BAZ: 'baz', + QUX: 'qux' } as const; /** * Период */ export const ValueEnum = { - _1: 1, - _3: 3, - _6: 6, - _12: 12, -} as const; + '_1': 1, + '_3': 3, + '_6': 6, + '_12': 12 +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/index.ts.snap index 2d4902304..6eb4b0c3a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/index.ts.snap @@ -1,9 +1,8 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './enums.gen'; export * from './schemas.gen'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap index 6ada30768..4af40c30e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap @@ -1,1694 +1,1660 @@ // This file is auto-generated by @hey-api/openapi-ts export const $camelCaseCommentWithBreaks = { - description: `Testing multiline comments in string: First line + description: `Testing multiline comments in string: First line Second line Fourth line`, - type: 'integer', + type: 'integer' } as const; export const $CommentWithBreaks = { - description: `Testing multiline comments in string: First line + description: `Testing multiline comments in string: First line Second line Fourth line`, - type: 'integer', + type: 'integer' } as const; export const $CommentWithBackticks = { - description: - 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', - type: 'integer', + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', + type: 'integer' } as const; export const $CommentWithBackticksAndQuotes = { - description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, - type: 'integer', + description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, + type: 'integer' } as const; export const $CommentWithSlashes = { - description: - 'Testing slashes in string: \backwards\\ and /forwards/// should work', - type: 'integer', + description: 'Testing slashes in string: \backwards\\\ and /forwards/// should work', + type: 'integer' } as const; export const $CommentWithExpressionPlaceholders = { - description: - 'Testing expression placeholders in string: ${expression} should work', - type: 'integer', + description: 'Testing expression placeholders in string: ${expression} should work', + type: 'integer' } as const; export const $CommentWithQuotes = { - description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, - type: 'integer', + description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, + type: 'integer' } as const; export const $CommentWithReservedCharacters = { - description: - 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', - type: 'integer', + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', + type: 'integer' } as const; export const $SimpleInteger = { - description: 'This is a simple number', - type: 'integer', + description: 'This is a simple number', + type: 'integer' } as const; export const $SimpleBoolean = { - description: 'This is a simple boolean', - type: 'boolean', + description: 'This is a simple boolean', + type: 'boolean' } as const; export const $SimpleString = { - description: 'This is a simple string', - type: 'string', + description: 'This is a simple string', + type: 'string' } as const; export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { - description: - 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', - type: 'string', + description: 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', + type: 'string' } as const; export const $SimpleFile = { - description: 'This is a simple file', - type: 'file', + description: 'This is a simple file', + type: 'file' } as const; export const $SimpleReference = { - description: 'This is a simple reference', - $ref: '#/components/schemas/ModelWithString', + description: 'This is a simple reference', + '$ref': '#/components/schemas/ModelWithString' } as const; export const $SimpleStringWithPattern = { - description: 'This is a simple string', - type: 'string', - nullable: true, - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', + description: 'This is a simple string', + type: 'string', + nullable: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$' } as const; export const $EnumWithStrings = { - description: 'This is a simple enum with strings', - enum: [ - 'Success', - 'Warning', - 'Error', - "'Single Quote'", - '"Double Quotes"', - 'Non-ascii: øæåôöØÆÅÔÖ字符串', - ], + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'] } as const; export const $EnumWithReplacedCharacters = { - enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], - type: 'string', + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], + type: 'string' } as const; export const $EnumWithNumbers = { - description: 'This is a simple enum with numbers', - enum: [ - 1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3, - ], - default: 200, + description: 'This is a simple enum with numbers', + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], + default: 200 } as const; export const $EnumFromDescription = { - description: 'Success=1,Warning=2,Error=3', - type: 'number', + description: 'Success=1,Warning=2,Error=3', + type: 'number' } as const; export const $EnumWithExtensions = { - description: 'This is a simple enum with numbers', - enum: [200, 400, 500], - 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], - 'x-enum-descriptions': [ - 'Used when the status of something is successful', - 'Used when the status of something has a warning', - 'Used when the status of something has an error', - ], + description: 'This is a simple enum with numbers', + enum: [200, 400, 500], + 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], + 'x-enum-descriptions': ['Used when the status of something is successful', 'Used when the status of something has a warning', 'Used when the status of something has an error'] } as const; export const $EnumWithXEnumNames = { - enum: [0, 1, 2], - 'x-enumNames': ['zero', 'one', 'two'], + enum: [0, 1, 2], + 'x-enumNames': ['zero', 'one', 'two'] } as const; export const $ArrayWithNumbers = { - description: 'This is a simple array with numbers', - type: 'array', - items: { - type: 'integer', - }, + description: 'This is a simple array with numbers', + type: 'array', + items: { + type: 'integer' + } } as const; export const $ArrayWithBooleans = { - description: 'This is a simple array with booleans', - type: 'array', - items: { - type: 'boolean', - }, + description: 'This is a simple array with booleans', + type: 'array', + items: { + type: 'boolean' + } } as const; export const $ArrayWithStrings = { - description: 'This is a simple array with strings', - type: 'array', - items: { - type: 'string', - }, - default: ['test'], + description: 'This is a simple array with strings', + type: 'array', + items: { + type: 'string' + }, + default: ['test'] } as const; export const $ArrayWithReferences = { - description: 'This is a simple array with references', - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, + description: 'This is a simple array with references', + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $ArrayWithArray = { - description: 'This is a simple array containing an array', - type: 'array', - items: { + description: 'This is a simple array containing an array', type: 'array', items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ArrayWithProperties = { - description: 'This is a simple array with properties', - type: 'array', - items: { - type: 'object', - properties: { - foo: { - $ref: '#/components/schemas/camelCaseCommentWithBreaks', - }, - bar: { - type: 'string', - }, - }, - }, + description: 'This is a simple array with properties', + type: 'array', + items: { + type: 'object', + properties: { + foo: { + '$ref': '#/components/schemas/camelCaseCommentWithBreaks' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ArrayWithAnyOfProperties = { - description: 'This is a simple array with any of properties', - type: 'array', - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - default: 'test', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, - }, - }, - ], - }, + description: 'This is a simple array with any of properties', + type: 'array', + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string', + default: 'test' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] + } } as const; export const $AnyOfAnyAndNull = { - type: 'object', - properties: { - data: { - anyOf: [ - {}, - { - type: 'null', - }, - ], - }, - }, + type: 'object', + properties: { + data: { + anyOf: [ + {}, + { + type: 'null' + } + ] + } + } } as const; export const $AnyOfArrays = { - description: 'This is a simple array with any of properties', - type: 'object', - properties: { - results: { - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, + description: 'This is a simple array with any of properties', + type: 'object', + properties: { + results: { + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] }, - }, - ], - }, - type: 'array', - }, - }, + type: 'array' + } + } } as const; export const $DictionaryWithString = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { - type: 'string', - }, + description: 'This is a string dictionary', + type: 'object', + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithPropertiesAndAdditionalProperties = { - type: 'object', - properties: { - foo: { - type: 'string', + type: 'object', + properties: { + foo: { + type: 'string' + } }, - }, - additionalProperties: { - type: 'string', - }, + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithReference = { - description: 'This is a string reference', - type: 'object', - additionalProperties: { - $ref: '#/components/schemas/ModelWithString', - }, + description: 'This is a string reference', + type: 'object', + additionalProperties: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $DictionaryWithArray = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a complex dictionary', + type: 'object', + additionalProperties: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $DictionaryWithDictionary = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { + description: 'This is a string dictionary', type: 'object', additionalProperties: { - type: 'string', - }, - }, + type: 'object', + additionalProperties: { + type: 'string' + } + } } as const; export const $DictionaryWithProperties = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { + description: 'This is a complex dictionary', type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, + additionalProperties: { + type: 'object', + properties: { + foo: { + type: 'string' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ModelWithInteger = { - description: 'This is a model with one number property', - type: 'object', - properties: { - prop: { - description: 'This is a simple number property', - type: 'integer', - }, - }, + description: 'This is a model with one number property', + type: 'object', + properties: { + prop: { + description: 'This is a simple number property', + type: 'integer' + } + } } as const; export const $ModelWithBoolean = { - description: 'This is a model with one boolean property', - type: 'object', - properties: { - prop: { - description: 'This is a simple boolean property', - type: 'boolean', - }, - }, + description: 'This is a model with one boolean property', + type: 'object', + properties: { + prop: { + description: 'This is a simple boolean property', + type: 'boolean' + } + } } as const; export const $ModelWithString = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $ModelWithStringError = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $Model_From_Zendesk = { - description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`, - type: 'string', + description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`, + type: 'string' } as const; export const $ModelWithNullableString = { - description: 'This is a model with one string property', - type: 'object', - required: ['nullableRequiredProp1', 'nullableRequiredProp2'], - properties: { - nullableProp1: { - description: 'This is a simple string property', - type: 'string', - nullable: true, - }, - nullableRequiredProp1: { - description: 'This is a simple string property', - type: 'string', - nullable: true, - }, - nullableProp2: { - description: 'This is a simple string property', - type: ['string', 'null'], - }, - nullableRequiredProp2: { - description: 'This is a simple string property', - type: ['string', 'null'], - }, - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + description: 'This is a model with one string property', + type: 'object', + required: ['nullableRequiredProp1', 'nullableRequiredProp2'], + properties: { + nullableProp1: { + description: 'This is a simple string property', + type: 'string', + nullable: true + }, + nullableRequiredProp1: { + description: 'This is a simple string property', + type: 'string', + nullable: true + }, + nullableProp2: { + description: 'This is a simple string property', + type: ['string', 'null'] + }, + nullableRequiredProp2: { + description: 'This is a simple string property', + type: ['string', 'null'] + }, + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithEnum = { - description: 'This is a model with one enum', - type: 'object', - properties: { - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - statusCode: { - description: 'These are the HTTP error code enums', - enum: [ - '100', - '200 FOO', - '300 FOO_BAR', - '400 foo-bar', - '500 foo.bar', - '600 foo&bar', - ], - }, - bool: { - description: 'Simple boolean enum', - type: 'boolean', - enum: [true], - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + }, + statusCode: { + description: 'These are the HTTP error code enums', + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'] + }, + bool: { + description: 'Simple boolean enum', + type: 'boolean', + enum: [true] + } + } } as const; export const $ModelWithEnumWithHyphen = { - description: 'This is a model with one enum with escaped name', - type: 'object', - properties: { - 'foo-bar-baz-qux': { - type: 'string', - enum: ['3.0'], - title: 'Foo-Bar-Baz-Qux', - default: '3.0', - }, - }, + description: 'This is a model with one enum with escaped name', + type: 'object', + properties: { + 'foo-bar-baz-qux': { + type: 'string', + enum: ['3.0'], + title: 'Foo-Bar-Baz-Qux', + default: '3.0' + } + } } as const; export const $ModelWithEnumFromDescription = { - description: 'This is a model with one enum', - type: 'object', - properties: { - test: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + test: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + } } as const; export const $ModelWithNestedEnums = { - description: 'This is a model with nested enums', - type: 'object', - properties: { - dictionaryWithEnum: { - type: 'object', - additionalProperties: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - dictionaryWithEnumFromDescription: { - type: 'object', - additionalProperties: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - arrayWithEnum: { - type: 'array', - items: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - arrayWithDescription: { - type: 'array', - items: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + description: 'This is a model with nested enums', + type: 'object', + properties: { + dictionaryWithEnum: { + type: 'object', + additionalProperties: { + enum: ['Success', 'Warning', 'Error'] + } + }, + dictionaryWithEnumFromDescription: { + type: 'object', + additionalProperties: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + }, + arrayWithEnum: { + type: 'array', + items: { + enum: ['Success', 'Warning', 'Error'] + } + }, + arrayWithDescription: { + type: 'array', + items: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + }, + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithReference = { - description: 'This is a model with one property containing a reference', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithProperties', - }, - }, + description: 'This is a model with one property containing a reference', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithProperties' + } + } } as const; export const $ModelWithArrayReadOnlyAndWriteOnly = { - description: 'This is a model with one property containing an array', - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithReadOnlyAndWriteOnly', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + description: 'This is a model with one property containing an array', + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithReadOnlyAndWriteOnly' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithArray = { - description: 'This is a model with one property containing an array', - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + description: 'This is a model with one property containing an array', + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithDictionary = { - description: 'This is a model with one property containing a dictionary', - type: 'object', - properties: { - prop: { - type: 'object', - additionalProperties: { - type: 'string', - }, - }, - }, + description: 'This is a model with one property containing a dictionary', + type: 'object', + properties: { + prop: { + type: 'object', + additionalProperties: { + type: 'string' + } + } + } } as const; export const $DeprecatedModel = { - deprecated: true, - description: 'This is a deprecated model with a deprecated property', - type: 'object', - properties: { - prop: { - deprecated: true, - description: 'This is a deprecated property', - type: 'string', - }, - }, + deprecated: true, + description: 'This is a deprecated model with a deprecated property', + type: 'object', + properties: { + prop: { + deprecated: true, + description: 'This is a deprecated property', + type: 'string' + } + } } as const; export const $ModelWithCircularReference = { - description: - 'This is a model with one property containing a circular reference', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithCircularReference', - }, - }, + description: 'This is a model with one property containing a circular reference', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithCircularReference' + } + } } as const; export const $CompositionWithOneOf = { - description: "This is a model with one property with a 'one of' relationship", - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'one of' relationship", + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAnonymous = { - description: - "This is a model with one property with a 'one of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - description: 'Anonymous object type', - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - description: 'Anonymous string type', - type: 'string', - }, - { - description: 'Anonymous integer type', - type: 'integer', - }, - ], - }, - }, -} as const; - -export const $ModelCircle = { - description: 'Circle', - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - radius: { - type: 'number', - }, - }, + description: "This is a model with one property with a 'one of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + description: 'Anonymous object type', + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + description: 'Anonymous string type', + type: 'string' + }, + { + description: 'Anonymous integer type', + type: 'integer' + } + ] + } + } } as const; -export const $ModelSquare = { - description: 'Square', - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - sideLength: { - type: 'number', - }, - }, +export const $ModelCircle = { + description: 'Circle', + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + radius: { + type: 'number' + } + } } as const; -export const $CompositionWithOneOfDiscriminator = { - description: - "This is a model with one property with a 'one of' relationship where the options are not $ref", - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelCircle', - }, - { - $ref: '#/components/schemas/ModelSquare', - }, - ], - discriminator: { - propertyName: 'kind', - mapping: { - circle: '#/components/schemas/ModelCircle', - square: '#/components/schemas/ModelSquare', - }, - }, +export const $ModelSquare = { + description: 'Square', + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + sideLength: { + type: 'number' + } + } } as const; -export const $CompositionWithAnyOf = { - description: "This is a model with one property with a 'any of' relationship", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, +export const $CompositionWithOneOfDiscriminator = { + description: "This is a model with one property with a 'one of' relationship where the options are not $ref", + type: 'object', + oneOf: [ { - $ref: '#/components/schemas/ModelWithArray', + '$ref': '#/components/schemas/ModelCircle' }, { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + '$ref': '#/components/schemas/ModelSquare' + } + ], + discriminator: { + propertyName: 'kind', + mapping: { + circle: '#/components/schemas/ModelCircle', + square: '#/components/schemas/ModelSquare' + } + } +} as const; + +export const $CompositionWithAnyOf = { + description: "This is a model with one property with a 'any of' relationship", + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithAnyOfAnonymous = { - description: - "This is a model with one property with a 'any of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - description: 'Anonymous object type', - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - description: 'Anonymous string type', - type: 'string', - }, - { - description: 'Anonymous integer type', - type: 'integer', - }, - ], - }, - }, + description: "This is a model with one property with a 'any of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + description: 'Anonymous object type', + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + description: 'Anonymous string type', + type: 'string' + }, + { + description: 'Anonymous integer type', + type: 'integer' + } + ] + } + } } as const; export const $CompositionWithNestedAnyAndTypeNull = { - description: "This is a model with nested 'any of' property with a type null", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - items: { - anyOf: [ - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - { - items: { + description: "This is a model with nested 'any of' property with a type null", + type: 'object', + properties: { + propA: { + type: 'object', anyOf: [ - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - ], - }, - }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithDictionary' + }, + { + type: 'null' + } + ] + }, + type: 'array' + }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + type: 'null' + } + ] + }, + type: 'array' + } + ] + } + } } as const; export const $Enum1 = { - enum: ['Bird', 'Dog'], - type: 'string', + enum: ['Bird', 'Dog'], + type: 'string' } as const; export const $ConstValue = { - type: 'string', - const: 'ConstValue', + type: 'string', + const: 'ConstValue' } as const; export const $CompositionWithNestedAnyOfAndNull = { - description: - "This is a model with one property with a 'any of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - anyOf: [ - { - items: { + description: "This is a model with one property with a 'any of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { anyOf: [ - { - $ref: '#/components/schemas/Enum1', - }, - { - $ref: '#/components/schemas/ConstValue', - }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/Enum1' + }, + { + '$ref': '#/components/schemas/ConstValue' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], - title: 'Scopes', - }, - }, + title: 'Scopes' + } + } } as const; export const $CompositionWithOneOfAndNullable = { - description: "This is a model with one property with a 'one of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - oneOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'one of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + oneOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleDictionary = { - description: - 'This is a model that contains a simple dictionary within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'number', - }, - }, - ], - }, - }, + description: 'This is a model that contains a simple dictionary within composition', + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'number' + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleArrayDictionary = { - description: - 'This is a model that contains a dictionary of simple arrays within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - type: 'boolean', - }, - }, - }, - ], - }, - }, + description: 'This is a model that contains a dictionary of simple arrays within composition', + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'array', + items: { + type: 'boolean' + } + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndComplexArrayDictionary = { - description: - 'This is a model that contains a dictionary of complex arrays (composited) within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - oneOf: [ + description: 'This is a model that contains a dictionary of complex arrays (composited) within composition', + type: 'object', + properties: { + propA: { + oneOf: [ { - type: 'number', + type: 'boolean' }, { - type: 'string', - }, - ], - }, - }, - }, - ], - }, - }, + type: 'object', + additionalProperties: { + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + } + } + } + ] + } + } } as const; export const $CompositionWithAllOfAndNullable = { - description: "This is a model with one property with a 'all of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - allOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'all of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + allOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithAnyOfAndNullable = { - description: "This is a model with one property with a 'any of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - anyOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'any of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + anyOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionBaseModel = { - description: 'This is a base model with two simple optional properties', - type: 'object', - properties: { - firstName: { - type: 'string', - }, - lastname: { - type: 'string', - }, - }, + description: 'This is a base model with two simple optional properties', + type: 'object', + properties: { + firstName: { + type: 'string' + }, + lastname: { + type: 'string' + } + } } as const; export const $CompositionExtendedModel = { - description: 'This is a model that extends the base model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/CompositionBaseModel', - }, - ], - properties: { - age: { - type: 'number', + description: 'This is a model that extends the base model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/CompositionBaseModel' + } + ], + properties: { + age: { + type: 'number' + } }, - }, - required: ['firstName', 'lastname', 'age'], + required: ['firstName', 'lastname', 'age'] } as const; export const $ModelWithProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], - properties: { - required: { - type: 'string', - }, - requiredAndReadOnly: { - type: 'string', - readOnly: true, - }, - requiredAndNullable: { - type: 'string', - nullable: true, - }, - string: { - type: 'string', - }, - number: { - type: 'number', - }, - boolean: { - type: 'boolean', - }, - reference: { - $ref: '#/components/schemas/ModelWithString', - }, - 'property with space': { - type: 'string', - }, - default: { - type: 'string', - }, - try: { - type: 'string', - }, - '@namespace.string': { - type: 'string', - readOnly: true, - }, - '@namespace.integer': { - type: 'integer', - readOnly: true, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], + properties: { + required: { + type: 'string' + }, + requiredAndReadOnly: { + type: 'string', + readOnly: true + }, + requiredAndNullable: { + type: 'string', + nullable: true + }, + string: { + type: 'string' + }, + number: { + type: 'number' + }, + boolean: { + type: 'boolean' + }, + reference: { + '$ref': '#/components/schemas/ModelWithString' + }, + 'property with space': { + type: 'string' + }, + default: { + type: 'string' + }, + try: { + type: 'string' + }, + '@namespace.string': { + type: 'string', + readOnly: true + }, + '@namespace.integer': { + type: 'integer', + readOnly: true + } + } } as const; export const $ModelWithNestedProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['first'], - properties: { - first: { - type: 'object', - required: ['second'], - readOnly: true, - nullable: true, - properties: { - second: { - type: 'object', - required: ['third'], - readOnly: true, - nullable: true, - properties: { - third: { - type: 'string', - required: true, - readOnly: true, - nullable: true, - }, - }, - }, - }, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['first'], + properties: { + first: { + type: 'object', + required: ['second'], + readOnly: true, + nullable: true, + properties: { + second: { + type: 'object', + required: ['third'], + readOnly: true, + nullable: true, + properties: { + third: { + type: 'string', + required: true, + readOnly: true, + nullable: true + } + } + } + } + } + } } as const; export const $ModelWithDuplicateProperties = { - description: 'This is a model with duplicated properties', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a model with duplicated properties', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ModelWithOrderedProperties = { - description: 'This is a model with ordered properties', - type: 'object', - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, + description: 'This is a model with ordered properties', + type: 'object', + properties: { + zebra: { + type: 'string' + }, + apple: { + type: 'string' + }, + hawaii: { + type: 'string' + } + } } as const; export const $ModelWithDuplicateImports = { - description: 'This is a model with duplicated imports', - type: 'object', - properties: { - propA: { - $ref: '#/components/schemas/ModelWithString', - }, - propB: { - $ref: '#/components/schemas/ModelWithString', - }, - propC: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a model with duplicated imports', + type: 'object', + properties: { + propA: { + '$ref': '#/components/schemas/ModelWithString' + }, + propB: { + '$ref': '#/components/schemas/ModelWithString' + }, + propC: { + '$ref': '#/components/schemas/ModelWithString' + } + } +} as const; + +export const $ModelThatExtends = { + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + type: 'object', + properties: { + propExtendsA: { + type: 'string' + }, + propExtendsB: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] +} as const; + +export const $ModelThatExtendsExtends = { + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelThatExtends' + }, + { + type: 'object', + properties: { + propExtendsC: { + type: 'string' + }, + propExtendsD: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] } as const; -export const $ModelThatExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - type: 'object', - properties: { - propExtendsA: { - type: 'string', +export const $ModelWithPattern = { + description: 'This is a model that contains a some patterns', + type: 'object', + required: ['key', 'name'], + properties: { + key: { + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', + type: 'string' }, - propExtendsB: { - $ref: '#/components/schemas/ModelWithString', + name: { + maxLength: 255, + type: 'string' }, - }, - }, - ], -} as const; - -export const $ModelThatExtendsExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelThatExtends', - }, - { - type: 'object', - properties: { - propExtendsC: { - type: 'string', + enabled: { + type: 'boolean', + readOnly: true }, - propExtendsD: { - $ref: '#/components/schemas/ModelWithString', + modified: { + type: 'string', + format: 'date-time', + readOnly: true }, - }, - }, - ], -} as const; - -export const $ModelWithPattern = { - description: 'This is a model that contains a some patterns', - type: 'object', - required: ['key', 'name'], - properties: { - key: { - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', - type: 'string', - }, - name: { - maxLength: 255, - type: 'string', - }, - enabled: { - type: 'boolean', - readOnly: true, - }, - modified: { - type: 'string', - format: 'date-time', - readOnly: true, - }, - id: { - type: 'string', - pattern: '^d{2}-d{3}-d{4}$', - }, - text: { - type: 'string', - pattern: '^w+$', - }, - patternWithSingleQuotes: { - type: 'string', - pattern: "^[a-zA-Z0-9']*$", - }, - patternWithNewline: { - type: 'string', - pattern: `aaa -bbb`, - }, - patternWithBacktick: { - type: 'string', - pattern: 'aaa`bbb', - }, - }, + id: { + type: 'string', + pattern: '^\d{2}-\d{3}-\d{4}$' + }, + text: { + type: 'string', + pattern: '^\w+$' + }, + patternWithSingleQuotes: { + type: 'string', + pattern: "^[a-zA-Z0-9']*$" + }, + patternWithNewline: { + type: 'string', + pattern: `aaa +bbb` + }, + patternWithBacktick: { + type: 'string', + pattern: 'aaa`bbb' + } + } } as const; export const $File = { - required: ['mime'], - type: 'object', - properties: { - id: { - title: 'Id', - type: 'string', - readOnly: true, - minLength: 1, - }, - updated_at: { - title: 'Updated at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - created_at: { - title: 'Created at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - mime: { - title: 'Mime', - type: 'string', - maxLength: 24, - minLength: 1, - }, - file: { - title: 'File', - type: 'string', - readOnly: true, - format: 'uri', - }, - }, + required: ['mime'], + type: 'object', + properties: { + id: { + title: 'Id', + type: 'string', + readOnly: true, + minLength: 1 + }, + updated_at: { + title: 'Updated at', + type: 'string', + format: 'date-time', + readOnly: true + }, + created_at: { + title: 'Created at', + type: 'string', + format: 'date-time', + readOnly: true + }, + mime: { + title: 'Mime', + type: 'string', + maxLength: 24, + minLength: 1 + }, + file: { + title: 'File', + type: 'string', + readOnly: true, + format: 'uri' + } + } } as const; export const $default = { - type: 'object', - properties: { - name: { - type: 'string', - }, - }, + type: 'object', + properties: { + name: { + type: 'string' + } + } } as const; export const $Pageable = { - type: 'object', - properties: { - page: { - minimum: 0, - type: 'integer', - format: 'int32', - default: 0, - }, - size: { - minimum: 1, - type: 'integer', - format: 'int32', - }, - sort: { - type: 'array', - items: { - type: 'string', - }, - }, - }, + type: 'object', + properties: { + page: { + minimum: 0, + type: 'integer', + format: 'int32', + default: 0 + }, + size: { + minimum: 1, + type: 'integer', + format: 'int32' + }, + sort: { + type: 'array', + items: { + type: 'string' + } + } + } } as const; export const $FreeFormObjectWithoutAdditionalProperties = { - description: 'This is a free-form object without additionalProperties.', - type: 'object', + description: 'This is a free-form object without additionalProperties.', + type: 'object' } as const; export const $FreeFormObjectWithAdditionalPropertiesEqTrue = { - description: 'This is a free-form object with additionalProperties: true.', - type: 'object', - additionalProperties: true, + description: 'This is a free-form object with additionalProperties: true.', + type: 'object', + additionalProperties: true } as const; export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - description: 'This is a free-form object with additionalProperties: {}.', - type: 'object', - additionalProperties: {}, + description: 'This is a free-form object with additionalProperties: {}.', + type: 'object', + additionalProperties: {} } as const; export const $ModelWithConst = { - type: 'object', - properties: { - String: { - const: 'String', - }, - number: { - const: 0, - }, - null: { - const: null, - }, - withType: { - type: 'string', - const: 'Some string', - }, - }, + type: 'object', + properties: { + String: { + const: 'String' + }, + number: { + const: 0 + }, + null: { + const: null + }, + withType: { + type: 'string', + const: 'Some string' + } + } } as const; export const $ModelWithAdditionalPropertiesEqTrue = { - description: - 'This is a model with one property and additionalProperties: true', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', + description: 'This is a model with one property and additionalProperties: true', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } }, - }, - additionalProperties: true, + additionalProperties: true } as const; export const $NestedAnyOfArraysNullable = { - properties: { - nullableArray: { - anyOf: [ - { - items: { + properties: { + nullableArray: { anyOf: [ - { - type: 'string', - }, - { - type: 'boolean', - }, - ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], + { + items: { + anyOf: [ + { + type: 'string' + }, + { + type: 'boolean' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } + ] + } }, - }, - type: 'object', + type: 'object' } as const; export const $CompositionWithOneOfAndProperties = { - type: 'object', - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - $ref: '#/components/parameters/SimpleParameter', + type: 'object', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + '$ref': '#/components/parameters/SimpleParameter' + } + }, + additionalProperties: false }, - }, - additionalProperties: false, - }, - { - type: 'object', - required: ['bar'], - properties: { - bar: { - $ref: '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2', + { + type: 'object', + required: ['bar'], + properties: { + bar: { + '$ref': '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2' + } + }, + additionalProperties: false + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true }, - }, - additionalProperties: false, - }, - ], - required: ['baz', 'qux'], - properties: { - baz: { - type: 'integer', - format: 'uint16', - minimum: 0, - nullable: true, - }, - qux: { - type: 'integer', - format: 'uint8', - minimum: 0, - }, - }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } } as const; export const $NullableObject = { - type: 'object', - nullable: true, - description: 'An object that can be null', - properties: { - foo: { - type: 'string', + type: 'object', + nullable: true, + description: 'An object that can be null', + properties: { + foo: { + type: 'string' + } }, - }, - default: null, + default: null } as const; export const $CharactersInDescription = { - type: 'string', - description: 'Some % character', + type: 'string', + description: 'Some % character' } as const; export const $ModelWithNullableObject = { - type: 'object', - properties: { - data: { - $ref: '#/components/schemas/NullableObject', - }, - }, + type: 'object', + properties: { + data: { + '$ref': '#/components/schemas/NullableObject' + } + } } as const; export const $ModelWithOneOfEnum = { - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Bar'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Baz'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Qux'], - }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'string', - format: 'date-time', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Bar'] + } + } }, - foo: { - type: 'string', - enum: ['Quux'], + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Baz'] + } + } }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'array', - items: [ - { - type: 'string', - format: 'date-time', - }, - { - type: 'string', - }, - ], - maxItems: 2, - minItems: 2, + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Qux'] + } + } }, - foo: { - type: 'string', - enum: ['Corge'], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'string', + format: 'date-time' + }, + foo: { + type: 'string', + enum: ['Quux'] + } + } }, - }, - }, - ], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'array', + items: [ + { + type: 'string', + format: 'date-time' + }, + { + type: 'string' + } + ], + maxItems: 2, + minItems: 2 + }, + foo: { + type: 'string', + enum: ['Corge'] + } + } + } + ] } as const; export const $ModelWithNestedArrayEnumsDataFoo = { - enum: ['foo', 'bar'], - type: 'string', + enum: ['foo', 'bar'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsDataBar = { - enum: ['baz', 'qux'], - type: 'string', + enum: ['baz', 'qux'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsData = { - type: 'object', - properties: { - foo: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - }, - bar: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataBar', - }, - }, - }, + type: 'object', + properties: { + foo: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + }, + bar: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataBar' + } + } + } } as const; export const $ModelWithNestedArrayEnums = { - type: 'object', - properties: { - array_strings: { - type: 'array', - items: { - type: 'string', - }, - }, - data: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsData', + type: 'object', + properties: { + array_strings: { + type: 'array', + items: { + type: 'string' + } }, - ], - }, - }, + data: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsData' + } + ] + } + } } as const; export const $ModelWithNestedCompositionEnums = { - type: 'object', - properties: { - foo: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - ], - }, - }, + type: 'object', + properties: { + foo: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + ] + } + } } as const; export const $ModelWithReadOnlyAndWriteOnly = { - type: 'object', - required: ['foo', 'bar', 'baz'], - properties: { - foo: { - type: 'string', - }, - bar: { - readOnly: true, - type: 'string', - }, - baz: { - type: 'string', - writeOnly: true, - }, - }, + type: 'object', + required: ['foo', 'bar', 'baz'], + properties: { + foo: { + type: 'string' + }, + bar: { + readOnly: true, + type: 'string' + }, + baz: { + type: 'string', + writeOnly: true + } + } } as const; export const $ModelWithConstantSizeArray = { - type: 'array', - items: { - type: 'number', - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + type: 'number' + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArray = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayNullable = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - nullable: true, - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number', + nullable: true + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArrayAndIntersect = { - type: 'array', - items: { - allOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + allOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithNumericEnumUnion = { - type: 'object', - properties: { - value: { - type: 'number', - description: 'Период', - enum: [1, 3, 6, 12], - }, - }, + type: 'object', + properties: { + value: { + type: 'number', + description: 'Период', + enum: [1, 3, 6, 12] + } + } } as const; export const $ModelWithBackticksInDescription = { - description: 'Some description with `back ticks`', - type: 'object', - properties: { - template: { - type: 'string', - description: `The template \`that\` should be used for parsing and importing the contents of the CSV file. + description: 'Some description with `back ticks`', + type: 'object', + properties: { + template: { + type: 'string', + description: `The template \`that\` should be used for parsing and importing the contents of the CSV file.

There is one placeholder currently supported:

  • \${x} - refers to the n-th column in the CSV file, e.g. \${1}, \${2}, ...)

Example of a correct JSON template:

@@ -1714,7 +1680,7 @@ export const $ModelWithBackticksInDescription = {
     }
   }
 ]
-
`, - }, - }, -} as const; +` + } + } +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap index 5f20cd246..8e759f30b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap @@ -6,927 +6,848 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; export class DefaultService { - /** - * @throws ApiError - */ - public static serviceWithEmptyTag(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-tag', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody - * @returns ModelWithReadOnlyAndWriteOnly - * @throws ApiError - */ - public static postServiceWithEmptyTag( - data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/no-tag', - body: requestBody, - mediaType: 'application/json', - }); - } + /** + * @throws ApiError + */ + public static serviceWithEmptyTag(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody + * @returns ModelWithReadOnlyAndWriteOnly + * @throws ApiError + */ + public static postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/no-tag', + body: requestBody, + mediaType: 'application/json' + }); + } + } export class SimpleService { - /** - * @returns Model_From_Zendesk Success - * @throws ApiError - */ - public static apiVVersionOdataControllerCount(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple/$count', - }); - } - - /** - * @throws ApiError - */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + /** + * @returns Model_From_Zendesk Success + * @throws ApiError + */ + public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple/$count' + }); + } + + /** + * @throws ApiError + */ + public static getCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static postCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static deleteCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static optionsCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static headCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static patchCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } export class ParametersService { - /** - * @param data The data for the request. - * @param data.foo foo in method - * @param data.bar bar in method - * @throws ApiError - */ - public static deleteFoo( - data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', - path: { - foo: data.foo, - bar: data.bar, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.fooAllOfEnum - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.parameterPath This is the parameter that goes into the path - * @param data.requestBody This is the parameter that goes into the body - * @param data.fooRefEnum - * @throws ApiError - */ - public static callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - cookies: { - parameterCookie: data.parameterCookie, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - foo_ref_enum: data.fooRefEnum, - foo_all_of_enum: data.fooAllOfEnum, - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.requestBody This is the parameter that goes into the body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public static callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - cookies: { - 'PARAMETER-COOKIE': data.parameterCookie, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody This is a required parameter - * @param data.parameter This is an optional parameter - * @throws ApiError - */ - public static getCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameter This is a required parameter - * @param data.requestBody This is an optional parameter - * @throws ApiError - */ - public static postCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } + /** + * @param data The data for the request. + * @param data.foo foo in method + * @param data.bar bar in method + * @throws ApiError + */ + public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: { + foo: data.foo, + bar: data.bar + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.fooAllOfEnum + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.parameterPath This is the parameter that goes into the path + * @param data.requestBody This is the parameter that goes into the body + * @param data.fooRefEnum + * @throws ApiError + */ + public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + cookies: { + parameterCookie: data.parameterCookie + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + foo_ref_enum: data.fooRefEnum, + foo_all_of_enum: data.fooAllOfEnum, + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.requestBody This is the parameter that goes into the body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + cookies: { + 'PARAMETER-COOKIE': data.parameterCookie + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody This is a required parameter + * @param data.parameter This is an optional parameter + * @throws ApiError + */ + public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameter This is a required parameter + * @param data.requestBody This is an optional parameter + * @throws ApiError + */ + public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + } export class DescriptionsService { - /** - * @param data The data for the request. - * @param data.parameterWithBreaks Testing multiline comments in string: First line - * Second line - * - * Fourth line - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work - * @throws ApiError - */ - public static callWithDescriptions( - data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/descriptions/', - query: { - parameterWithBreaks: data.parameterWithBreaks, - parameterWithBackticks: data.parameterWithBackticks, - parameterWithSlashes: data.parameterWithSlashes, - parameterWithExpressionPlaceholders: - data.parameterWithExpressionPlaceholders, - parameterWithQuotes: data.parameterWithQuotes, - parameterWithReservedCharacters: data.parameterWithReservedCharacters, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work + * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work + * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work + * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work + * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + parameterWithBreaks: data.parameterWithBreaks, + parameterWithBackticks: data.parameterWithBackticks, + parameterWithSlashes: data.parameterWithSlashes, + parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, + parameterWithQuotes: data.parameterWithQuotes, + parameterWithReservedCharacters: data.parameterWithReservedCharacters + } + }); + } + } export class DeprecatedService { - /** - * @deprecated - * @param data The data for the request. - * @param data.parameter This parameter is deprecated - * @throws ApiError - */ - public static deprecatedCall( - data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/deprecated', - headers: { - parameter: data.parameter, - }, - }); - } + /** + * @deprecated + * @param data The data for the request. + * @param data.parameter This parameter is deprecated + * @throws ApiError + */ + public static deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: { + parameter: data.parameter + } + }); + } + } export class RequestBodyService { - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.foo A reusable request body - * @throws ApiError - */ - public static postApiRequestBody( - data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/requestBody/', - query: { - parameter: data.parameter, - }, - body: foo, - mediaType: 'application/json', - }); - } + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.foo A reusable request body + * @throws ApiError + */ + public static postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + parameter: data.parameter + }, + body: foo, + mediaType: 'application/json' + }); + } + } export class FormDataService { - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.formData A reusable request body - * @throws ApiError - */ - public static postApiFormData( - data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/formData/', - query: { - parameter: data.parameter, - }, - formData, - mediaType: 'multipart/form-data', - }); - } + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.formData A reusable request body + * @throws ApiError + */ + public static postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + parameter: data.parameter + }, + formData, + mediaType: 'multipart/form-data' + }); + } + } export class DefaultsService { - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public static callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public static callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public static callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + } export class DuplicateService { - /** - * @throws ApiError - */ - public static duplicateName(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName1(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName2(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName3(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/duplicate', - }); - } + /** + * @throws ApiError + */ + public static duplicateName(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName1(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName2(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName3(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate' + }); + } + } export class NoContentService { - /** - * @returns void Success - * @throws ApiError - */ - public static callWithNoContentResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-content', - }); - } - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content' + }); + } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + } export class ResponseService { - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } - - /** - * @returns ModelWithString - * @throws ApiError - */ - public static callWithResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/response', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public static callWithDuplicateResponses(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['post']['res'][200] - > { - return __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', - }, - }); - } - - /** - * @returns unknown 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 callWithResponses(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202] - > { - return __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', - }, - }); - } + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + return __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' + } + }); + } + + /** + * @returns unknown 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 callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + return __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' + } + }); + } + } export class MultipleTags1Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags2Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags3Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class CollectionFormatService { - /** - * @param data The data for the request. - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) - * @throws ApiError - */ - public static collectionFormat( - data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/collectionFormat', - query: { - parameterArrayCSV: data.parameterArrayCsv, - parameterArraySSV: data.parameterArraySsv, - parameterArrayTSV: data.parameterArrayTsv, - parameterArrayPipes: data.parameterArrayPipes, - parameterArrayMulti: data.parameterArrayMulti, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + parameterArrayCSV: data.parameterArrayCsv, + parameterArraySSV: data.parameterArraySsv, + parameterArrayTSV: data.parameterArrayTsv, + parameterArrayPipes: data.parameterArrayPipes, + parameterArrayMulti: data.parameterArrayMulti + } + }); + } + } export class TypesService { - /** - * @param data The data for the request. - * @param data.parameterArray This is an array parameter - * @param data.parameterDictionary This is a dictionary parameter - * @param data.parameterEnum This is an enum parameter - * @param data.parameterNumber This is a number parameter - * @param data.parameterString This is a string parameter - * @param data.parameterBoolean This is a boolean parameter - * @param data.parameterObject This is an object parameter - * @param data.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 unknown Response is a simple object - * @throws ApiError - */ - public static types( - data: $OpenApiTs['/api/v{api-version}/types']['get']['req'], - ): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/types', - path: { - id: data.id, - }, - query: { - parameterNumber: data.parameterNumber, - parameterString: data.parameterString, - parameterBoolean: data.parameterBoolean, - parameterObject: data.parameterObject, - parameterArray: data.parameterArray, - parameterDictionary: data.parameterDictionary, - parameterEnum: data.parameterEnum, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArray This is an array parameter + * @param data.parameterDictionary This is a dictionary parameter + * @param data.parameterEnum This is an enum parameter + * @param data.parameterNumber This is a number parameter + * @param data.parameterString This is a string parameter + * @param data.parameterBoolean This is a boolean parameter + * @param data.parameterObject This is an object parameter + * @param data.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 unknown Response is a simple object + * @throws ApiError + */ + public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + id: data.id + }, + query: { + parameterNumber: data.parameterNumber, + parameterString: data.parameterString, + parameterBoolean: data.parameterBoolean, + parameterObject: data.parameterObject, + parameterArray: data.parameterArray, + parameterDictionary: data.parameterDictionary, + parameterEnum: data.parameterEnum + } + }); + } + } export class UploadService { - /** - * @param data The data for the request. - * @param data.file Supply a file reference for upload - * @returns boolean - * @throws ApiError - */ - public static uploadFile( - data: $OpenApiTs['/api/v{api-version}/upload']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/upload']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/upload', - formData: { - file: data.file, - }, - }); - } + /** + * @param data The data for the request. + * @param data.file Supply a file reference for upload + * @returns boolean + * @throws ApiError + */ + public static uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/upload', + formData: { + file: data.file + } + }); + } + } export class FileResponseService { - /** - * @param data The data for the request. - * @param data.id - * @returns binary Success - * @throws ApiError - */ - public static fileResponse( - data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/file/{id}', - path: { - id: data.id, - }, - }); - } + /** + * @param data The data for the request. + * @param data.id + * @returns binary Success + * @throws ApiError + */ + public static fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/file/{id}', + path: { + id: data.id + } + }); + } + } export class ComplexService { - /** - * @param data The data for the request. - * @param data.parameterObject Parameter containing object - * @param data.parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public static complexTypes( - data: $OpenApiTs['/api/v{api-version}/complex']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/complex', - query: { - parameterObject: data.parameterObject, - parameterReference: data.parameterReference, - }, - errors: { - 400: '400 `server` error', - 500: '500 server error', - }, - }); - } - - /** - * @param data The data for the request. - * @param data.id - * @param data.requestBody - * @returns ModelWithString Success - * @throws ApiError - */ - public static complexParams( - data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200] - > { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/complex/{id}', - path: { - id: data.id, - }, - body: requestBody, - mediaType: 'application/json-patch+json', - }); - } + /** + * @param data The data for the request. + * @param data.parameterObject Parameter containing object + * @param data.parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + parameterObject: data.parameterObject, + parameterReference: data.parameterReference + }, + errors: { + 400: '400 \`server\` error', + 500: '500 server error' + } + }); + } + + /** + * @param data The data for the request. + * @param data.id + * @param data.requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public static complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: { + id: data.id + }, + body: requestBody, + mediaType: 'application/json-patch+json' + }); + } + } export class MultipartService { - /** - * @param data The data for the request. - * @param data.formData - * @throws ApiError - */ - public static multipartRequest( - data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/multipart', - formData, - mediaType: 'multipart/form-data', - }); - } - - /** - * @returns unknown OK - * @throws ApiError - */ - public static multipartResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multipart', - }); - } + /** + * @param data The data for the request. + * @param data.formData + * @throws ApiError + */ + public static multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/multipart', + formData, + mediaType: 'multipart/form-data' + }); + } + + /** + * @returns unknown OK + * @throws ApiError + */ + public static multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multipart' + }); + } + } export class HeaderService { - /** - * @returns string Successful response - * @throws ApiError - */ - public static callWithResultFromHeader(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/header']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/header', - responseHeader: 'operation-location', - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + /** + * @returns string Successful response + * @throws ApiError + */ + public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } export class ErrorService { - /** - * @param data The data for the request. - * @param data.status Status code to return - * @returns unknown Custom message: Successful response - * @throws ApiError - */ - public static testErrorCode( - data: $OpenApiTs['/api/v{api-version}/error']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/error']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/error', - query: { - status: data.status, - }, - errors: { - 500: 'Custom message: Internal Server Error', - 501: 'Custom message: Not Implemented', - 502: 'Custom message: Bad Gateway', - 503: 'Custom message: Service Unavailable', - }, - }); - } + /** + * @param data The data for the request. + * @param data.status Status code to return + * @returns unknown Custom message: Successful response + * @throws ApiError + */ + public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + status: data.status + }, + errors: { + 500: 'Custom message: Internal Server Error', + 501: 'Custom message: Not Implemented', + 502: 'Custom message: Bad Gateway', + 503: 'Custom message: Service Unavailable' + } + }); + } + } export class NonAsciiÆøåÆøÅöôêÊService { - /** - * @param data The data for the request. - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response - * @throws ApiError - */ - public static nonAsciiæøåÆøÅöôêÊ字符串( - data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - query: { - nonAsciiParamæøåÆØÅöôêÊ: data.nonAsciiParamæøåÆøÅöôêÊ, - }, - }); - } -} + /** + * @param data The data for the request. + * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap index f6f2afd4d..5c29a38ea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap @@ -69,7 +69,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -84,40 +84,14 @@ export type SimpleStringWithPattern = string | null; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; -export type EnumWithReplacedCharacters = - | "'Single Quote'" - | '"Double Quotes"' - | 'øæåôöØÆÅÔÖ字符串' - | 3.1 - | ''; +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -134,17 +108,17 @@ export type EnumWithXEnumNames = 0 | 1 | 2; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -160,123 +134,117 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: camelCaseCommentWithBreaks; - bar?: string; + foo?: camelCaseCommentWithBreaks; + bar?: string; }>; /** * This is a simple array with any of properties */ -export type ArrayWithAnyOfProperties = Array< - | { - foo?: string; - } - | { - bar?: string; - } ->; +export type ArrayWithAnyOfProperties = Array<({ + foo?: string; +} | { + bar?: string; +})>; export type AnyOfAnyAndNull = { - data?: unknown | null; + data?: unknown | null; }; /** * This is a simple array with any of properties */ export type AnyOfArrays = { - results?: Array< - | { - foo?: string; - } - | { - bar?: string; - } - >; + results?: Array<({ + foo?: string; +} | { + bar?: string; +})>; }; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: string; - [key: string]: string | undefined; + foo?: string; + [key: string]: (string) | undefined; }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** @@ -288,119 +256,113 @@ export type Model_From_Zendesk = string; * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum with escaped name */ export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; + 'foo-bar-baz-qux'?: '3.0'; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** @@ -408,57 +370,50 @@ export type ModelWithDictionary = { * @deprecated */ export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * Circle */ export type ModelCircle = { - kind: 'circle'; - radius?: number; + kind: 'circle'; + radius?: number; }; /** * Square */ export type ModelSquare = { - kind: 'square'; - sideLength?: number; + kind: 'square'; + sideLength?: number; }; /** @@ -470,298 +425,268 @@ export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithAnyOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * This is a model with nested 'any of' property with a type null */ export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; + propA?: Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; }; export type Enum1 = 'Bird' | 'Dog'; -export type ConstValue = 'ConstValue'; +export type ConstValue = "ConstValue"; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithNestedAnyOfAndNull = { - propA?: Array | null; + propA?: Array<(Enum1 | ConstValue)> | null; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a model that contains a simple dictionary within composition */ export type CompositionWithOneOfAndSimpleDictionary = { - propA?: - | boolean - | { - [key: string]: number; - }; + propA?: boolean | { + [key: string]: (number); +}; }; /** * This is a model that contains a dictionary of simple arrays within composition */ export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(boolean)>; +}; }; /** * This is a model that contains a dictionary of complex arrays (composited) within composition */ export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; }; /** * This is a model with one property with a 'all of' relationship */ export type CompositionWithAllOfAndNullable = { - propA?: - | ({ - boolean?: boolean; - } & ModelWithEnum & - ModelWithArray & - ModelWithDictionary) - | null; + propA?: ({ + boolean?: boolean; +} & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; }; /** * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a base model with two simple optional properties */ export type CompositionBaseModel = { - firstName?: string; - lastname?: string; + firstName?: string; + lastname?: string; }; /** * This is a model that extends the base model */ export type CompositionExtendedModel = CompositionBaseModel & { - firstName: string; - lastname: string; - age: number; + firstName: string; + lastname: string; + age: number; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; + readonly first: { + readonly second: { + readonly third: string | null; + } | null; } | null; - } | null; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; }; export type _default = { - name?: string; + name?: string; }; export type Pageable = { - page?: number; - size?: number; - sort?: Array; + page?: number; + size?: number; + sort?: Array<(string)>; }; /** * This is a free-form object without additionalProperties. */ export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: true. */ export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: {}. */ export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - [key: string]: unknown; + [key: string]: unknown; }; export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; + String?: "String"; + number?: 0; + null?: null; + withType?: "Some string"; }; /** * This is a model with one property and additionalProperties: true */ export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown; + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; }; export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = - | { - foo: SimpleParameter; - baz: number | null; - qux: number; - } - | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; - baz: number | null; - qux: number; - }; + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: SimpleParameter; + baz: number | null; + qux: number; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; +}; /** * An object that can be null */ export type NullableObject = { - foo?: string; + foo?: string; } | null; /** @@ -770,117 +695,118 @@ export type NullableObject = { export type CharactersInDescription = string; export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = - | { - foo: 'Bar'; - } - | { - foo: 'Baz'; - } - | { - foo: 'Qux'; - } - | { - content: string; - foo: 'Quux'; - } - | { - content: [string, string]; - foo: 'Corge'; - }; + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; + foo?: Array; + bar?: Array; }; export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; + array_strings?: Array<(string)>; + data?: ModelWithNestedArrayEnumsData; }; export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; + foo?: ModelWithNestedArrayEnumsDataFoo; }; export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; + foo: string; + readonly bar: string; + baz: string; }; -export type ModelWithConstantSizeArray = [number, number]; +export type ModelWithConstantSizeArray = [ + number, + number +]; export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string, + number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string, + number | null | string, + number | null | string, + number | null | string ]; export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | string, - number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string, + number & string, + number & string ]; export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: 1 | 3 | 6 | 12; + /** + * Период + */ + value?: 1 | 3 | 6 | 12; }; /** * Some description with `back ticks` */ export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-   * [
-   * {
-   * "resourceType": "Asset",
-   * "identifier": {
-   * "name": "${1}",
-   * "domain": {
-   * "name": "${2}",
-   * "community": {
-   * "name": "Some Community"
-   * }
-   * }
-   * },
-   * "attributes" : {
-   * "00000000-0000-0000-0000-000000003115" : [ {
-   * "value" : "${3}"
-   * } ],
-   * "00000000-0000-0000-0000-000000000222" : [ {
-   * "value" : "${4}"
-   * } ]
-   * }
-   * }
-   * ]
-   * 
- */ - template?: string; + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; }; /** @@ -894,665 +820,659 @@ export type SimpleParameter = string; export type x_Foo_Bar = string; export type $OpenApiTs = { - '/api/v{api-version}/no-tag': { - post: { - req: { - requestBody: - | ModelWithReadOnlyAndWriteOnly - | ModelWithArrayReadOnlyAndWriteOnly; - }; - res: { - 200: ModelWithReadOnlyAndWriteOnly; - }; - }; - }; - '/api/v{api-version}/simple/$count': { - get: { - res: { - /** - * Success - */ - 200: Model_From_Zendesk; - }; - }; - }; - '/api/v{api-version}/foo/{foo}/bar/{bar}': { - delete: { - req: { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameterPath}': { - post: { - req: { - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { - post: { - req: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the request form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the request header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath1?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath2?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath3?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/': { - get: { - req: { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; - }; - }; - post: { - req: { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; - }; + '/api/v{api-version}/no-tag': { + post: { + req: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; + res: { + 200: ModelWithReadOnlyAndWriteOnly; + }; + }; }; - }; - '/api/v{api-version}/descriptions/': { - post: { - req: { - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: unknown; - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: unknown; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: unknown; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: unknown; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: unknown; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: unknown; - }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; }; - }; - '/api/v{api-version}/parameters/deprecated': { - post: { - req: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + '/api/v{api-version}/foo/{foo}/bar/{bar}': { + delete: { + req: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + }; }; - }; - '/api/v{api-version}/requestBody/': { - post: { - req: { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/formData/': { - post: { - req: { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple string with default value - */ - parameterString?: string | null; - }; + '/api/v{api-version}/parameters/': { + get: { + req: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + }; + post: { + req: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; + '/api/v{api-version}/descriptions/': { + post: { + req: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; + }; + }; }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }; }; - }; - '/api/v{api-version}/no-content': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/requestBody/': { + post: { + req: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/response-and-no-content': { - get: { - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/formData/': { + post: { + req: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/response': { - get: { - res: { - 200: ModelWithString; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - put: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 201 response - */ - 201: ModelThatExtends; - /** - * Message for 202 response - */ - 202: ModelThatExtendsExtends; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/a': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/response': { + get: { + res: { + 200: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; + put: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/b': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/collectionFormat': { - get: { - req: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCsv: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySsv: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTsv: Array | null; - }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/types': { - get: { - req: { - /** - * This is a number parameter - */ - id?: number; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: { - [key: string]: unknown; - } | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is an object parameter - */ - parameterObject: { - [key: string]: unknown; - } | null; - /** - * This is a string parameter - */ - parameterString: string | null; - }; - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Response is a simple string - */ - 201: string; - /** - * Response is a simple boolean - */ - 202: boolean; - /** - * Response is a simple object - */ - 203: { - [key: string]: unknown; + '/api/v{api-version}/collectionFormat': { + get: { + req: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; + }; }; - }; }; - }; - '/api/v{api-version}/upload': { - post: { - req: { - /** - * Supply a file reference for upload - */ - file: Blob | File; - }; - res: { - 200: boolean; - }; + '/api/v{api-version}/types': { + get: { + req: { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; + }; + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; + }; + }; }; - }; - '/api/v{api-version}/file/{id}': { - get: { - req: { - id: string; - }; - res: { - /** - * Success - */ - 200: Blob | File; - }; + '/api/v{api-version}/upload': { + post: { + req: { + /** + * Supply a file reference for upload + */ + file: (Blob | File); + }; + res: { + 200: boolean; + }; + }; }; - }; - '/api/v{api-version}/complex': { - get: { - req: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; + '/api/v{api-version}/file/{id}': { + get: { + req: { + id: string; + }; + res: { + /** + * Success + */ + 200: (Blob | File); }; - }; }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; - res: { - /** - * Successful response - */ - 200: Array; - /** - * 400 `server` error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; }; - }; - '/api/v{api-version}/complex/{id}': { - put: { - req: { - 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; - }; + '/api/v{api-version}/complex': { + get: { + req: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; }; - }; - res: { - /** - * Success - */ - 200: ModelWithString; - }; }; - }; - '/api/v{api-version}/multipart': { - post: { - req: { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; + '/api/v{api-version}/complex/{id}': { + put: { + req: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; + res: { + /** + * Success + */ + 200: ModelWithString; + }; }; - }; }; - get: { - res: { - /** - * OK - */ - 200: { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; + '/api/v{api-version}/multipart': { + post: { + req: { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; + }; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; }; - }; }; - }; - '/api/v{api-version}/header': { - post: { - res: { - /** - * Successful response - */ - 200: string; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; }; - }; - '/api/v{api-version}/error': { - post: { - req: { - /** - * Status code to return - */ - status: number; - }; - res: { - /** - * Custom message: Successful response - */ - 200: unknown; - /** - * Custom message: Internal Server Error - */ - 500: unknown; - /** - * Custom message: Not Implemented - */ - 501: unknown; - /** - * Custom message: Bad Gateway - */ - 502: unknown; - /** - * Custom message: Service Unavailable - */ - 503: unknown; - }; + '/api/v{api-version}/error': { + post: { + req: { + /** + * Status code to return + */ + status: number; + }; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; + }; + }; }; - }; - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { - post: { - req: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; - res: { - /** - * Successful response - */ - 200: Array; - }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/OpenAPI.ts.snap index 48897c2af..5f049af07 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/OpenAPI.ts.snap @@ -25,27 +25,31 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { response: Interceptors> }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + response: Interceptors>; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap index 0efb9aaa9..251cb7933 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap @@ -10,296 +10,267 @@ import type { ApiResult } from './ApiResult'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Observable => { - return forkJoin({ - token: resolve(options, config.TOKEN), - username: resolve(options, config.USERNAME), - password: resolve(options, config.PASSWORD), - additionalHeaders: resolve(options, config.HEADERS), - }).pipe( - map(({ token, username, password, additionalHeaders }) => { - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = - options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new HttpHeaders(headers); - }), - ); +export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { + return forkJoin({ + token: resolve(options, config.TOKEN), + username: resolve(options, config.USERNAME), + password: resolve(options, config.PASSWORD), + additionalHeaders: resolve(options, config.HEADERS), + }).pipe( + map(({ token, username, password, additionalHeaders }) => { + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new HttpHeaders(headers); + }), + ); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = ( - config: OpenAPIConfig, - options: ApiRequestOptions, - http: HttpClient, - url: string, - body: unknown, - formData: FormData | undefined, - headers: HttpHeaders, + config: OpenAPIConfig, + options: ApiRequestOptions, + http: HttpClient, + url: string, + body: unknown, + formData: FormData | undefined, + headers: HttpHeaders ): Observable> => { - return http.request(options.method, url, { - headers, - body: body ?? formData, - withCredentials: config.WITH_CREDENTIALS, - observe: 'response', - }); + return http.request(options.method, url, { + headers, + body: body ?? formData, + withCredentials: config.WITH_CREDENTIALS, + observe: 'response', + }); }; -export const getResponseHeader = ( - response: HttpResponse, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const value = response.headers.get(responseHeader); - if (isString(value)) { - return value; - } - } - return undefined; +export const getResponseHeader = (response: HttpResponse, responseHeader?: string): string | undefined => { + if (responseHeader) { + const value = response.headers.get(responseHeader); + if (isString(value)) { + return value; + } + } + return undefined; }; -export const getResponseBody = ( - response: HttpResponse, -): T | undefined => { - if (response.status !== 204 && response.body !== null) { - return response.body; - } - return undefined; +export const getResponseBody = (response: HttpResponse): T | undefined => { + if (response.status !== 204 && response.body !== null) { + return response.body; + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -310,62 +281,47 @@ export const catchErrorCodes = ( * @returns Observable * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - http: HttpClient, - options: ApiRequestOptions, -): Observable => { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - - return getHeaders(config, options).pipe( - switchMap((headers) => { - return sendRequest( - config, - options, - http, - url, - body, - formData, - headers, - ); - }), - switchMap(async (response) => { - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - const responseBody = getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - return { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - } as ApiResult; - }), - catchError((error: HttpErrorResponse) => { - if (!error.status) { - return throwError(() => error); - } - return of({ - url, - ok: error.ok, - status: error.status, - statusText: error.statusText, - body: error.error ?? error.statusText, - } as ApiResult); - }), - map((result) => { - catchErrorCodes(options, result); - return result.body as T; - }), - catchError((error: ApiError) => { - return throwError(() => error); - }), - ); -}; +export const request = (config: OpenAPIConfig, http: HttpClient, options: ApiRequestOptions): Observable => { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + + return getHeaders(config, options).pipe( + switchMap(headers => { + return sendRequest(config, options, http, url, body, formData, headers); + }), + switchMap(async response => { + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + const responseBody = getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + return { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + } as ApiResult; + }), + catchError((error: HttpErrorResponse) => { + if (!error.status) { + return throwError(() => error); + } + return of({ + url, + ok: error.ok, + status: error.status, + statusText: error.statusText, + body: error.error ?? error.statusText, + } as ApiResult); + }), + map(result => { + catchErrorCodes(options, result); + return result.body as T; + }), + catchError((error: ApiError) => { + return throwError(() => error); + }), + ); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/index.ts.snap index 8c01d0674..d23426032 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/index.ts.snap @@ -1,6 +1,5 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap index 28898f8af..2ff91a23e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap @@ -8,1034 +8,963 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DefaultService { - constructor(public readonly http: HttpClient) {} - - /** - * @throws ApiError - */ - public serviceWithEmptyTag(): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/no-tag', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody - * @returns ModelWithReadOnlyAndWriteOnly - * @throws ApiError - */ - public postServiceWithEmptyTag( - data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req'], - ): Observable<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/no-tag', - body: requestBody, - mediaType: 'application/json', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @throws ApiError + */ + public serviceWithEmptyTag(): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/no-tag' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody + * @returns ModelWithReadOnlyAndWriteOnly + * @throws ApiError + */ + public postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/no-tag', + body: requestBody, + mediaType: 'application/json' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class SimpleService { - constructor(public readonly http: HttpClient) {} - - /** - * @returns Model_From_Zendesk Success - * @throws ApiError - */ - public apiVVersionOdataControllerCount(): Observable< - $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/simple/$count', - }); - } - - /** - * @throws ApiError - */ - public getCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public putCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public postCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public deleteCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public optionsCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public headCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public patchCallWithoutParametersAndResponse(): Observable { - return __request(OpenAPI, this.http, { - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns Model_From_Zendesk Success + * @throws ApiError + */ + public apiVVersionOdataControllerCount(): Observable<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/simple/$count' + }); + } + + /** + * @throws ApiError + */ + public getCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public putCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public postCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public deleteCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public optionsCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public headCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public patchCallWithoutParametersAndResponse(): Observable { + return __request(OpenAPI, this.http, { + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class ParametersService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.foo foo in method - * @param data.bar bar in method - * @throws ApiError - */ - public deleteFoo( - data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'DELETE', - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', - path: { - foo: data.foo, - bar: data.bar, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.fooAllOfEnum - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.parameterPath This is the parameter that goes into the path - * @param data.requestBody This is the parameter that goes into the body - * @param data.fooRefEnum - * @throws ApiError - */ - public callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - cookies: { - parameterCookie: data.parameterCookie, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - foo_ref_enum: data.fooRefEnum, - foo_all_of_enum: data.fooAllOfEnum, - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.requestBody This is the parameter that goes into the body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - cookies: { - 'PARAMETER-COOKIE': data.parameterCookie, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody This is a required parameter - * @param data.parameter This is an optional parameter - * @throws ApiError - */ - public getCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameter This is a required parameter - * @param data.requestBody This is an optional parameter - * @throws ApiError - */ - public postCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.foo foo in method + * @param data.bar bar in method + * @throws ApiError + */ + public deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: { + foo: data.foo, + bar: data.bar + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.fooAllOfEnum + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.parameterPath This is the parameter that goes into the path + * @param data.requestBody This is the parameter that goes into the body + * @param data.fooRefEnum + * @throws ApiError + */ + public callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + cookies: { + parameterCookie: data.parameterCookie + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + foo_ref_enum: data.fooRefEnum, + foo_all_of_enum: data.fooAllOfEnum, + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.requestBody This is the parameter that goes into the body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + cookies: { + 'PARAMETER-COOKIE': data.parameterCookie + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody This is a required parameter + * @param data.parameter This is an optional parameter + * @throws ApiError + */ + public getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameter This is a required parameter + * @param data.requestBody This is an optional parameter + * @throws ApiError + */ + public postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DescriptionsService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameterWithBreaks Testing multiline comments in string: First line - * Second line - * - * Fourth line - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work - * @throws ApiError - */ - public callWithDescriptions( - data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/descriptions/', - query: { - parameterWithBreaks: data.parameterWithBreaks, - parameterWithBackticks: data.parameterWithBackticks, - parameterWithSlashes: data.parameterWithSlashes, - parameterWithExpressionPlaceholders: - data.parameterWithExpressionPlaceholders, - parameterWithQuotes: data.parameterWithQuotes, - parameterWithReservedCharacters: data.parameterWithReservedCharacters, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work + * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work + * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work + * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work + * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + parameterWithBreaks: data.parameterWithBreaks, + parameterWithBackticks: data.parameterWithBackticks, + parameterWithSlashes: data.parameterWithSlashes, + parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, + parameterWithQuotes: data.parameterWithQuotes, + parameterWithReservedCharacters: data.parameterWithReservedCharacters + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DeprecatedService { - constructor(public readonly http: HttpClient) {} - - /** - * @deprecated - * @param data The data for the request. - * @param data.parameter This parameter is deprecated - * @throws ApiError - */ - public deprecatedCall( - data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/parameters/deprecated', - headers: { - parameter: data.parameter, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @deprecated + * @param data The data for the request. + * @param data.parameter This parameter is deprecated + * @throws ApiError + */ + public deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: { + parameter: data.parameter + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class RequestBodyService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.foo A reusable request body - * @throws ApiError - */ - public postApiRequestBody( - data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/requestBody/', - query: { - parameter: data.parameter, - }, - body: foo, - mediaType: 'application/json', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.foo A reusable request body + * @throws ApiError + */ + public postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + parameter: data.parameter + }, + body: foo, + mediaType: 'application/json' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class FormDataService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.formData A reusable request body - * @throws ApiError - */ - public postApiFormData( - data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/formData/', - query: { - parameter: data.parameter, - }, - formData, - mediaType: 'multipart/form-data', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.formData A reusable request body + * @throws ApiError + */ + public postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + parameter: data.parameter + }, + formData, + mediaType: 'multipart/form-data' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DefaultsService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DuplicateService { - constructor(public readonly http: HttpClient) {} - - /** - * @throws ApiError - */ - public duplicateName(): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName1(): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName2(): Observable { - return __request(OpenAPI, this.http, { - method: 'PUT', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName3(): Observable { - return __request(OpenAPI, this.http, { - method: 'DELETE', - url: '/api/v{api-version}/duplicate', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @throws ApiError + */ + public duplicateName(): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName1(): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName2(): Observable { + return __request(OpenAPI, this.http, { + method: 'PUT', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName3(): Observable { + return __request(OpenAPI, this.http, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class NoContentService { - constructor(public readonly http: HttpClient) {} - - /** - * @returns void Success - * @throws ApiError - */ - public callWithNoContentResponse(): Observable< - $OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/no-content', - }); - } - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public callWithResponseAndNoContentResponse(): Observable< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns void Success + * @throws ApiError + */ + public callWithNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/no-content' + }); + } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public callWithResponseAndNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class ResponseService { - constructor(public readonly http: HttpClient) {} - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public callWithResponseAndNoContentResponse(): Observable< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } - - /** - * @returns ModelWithString - * @throws ApiError - */ - public callWithResponse(): Observable< - $OpenApiTs['/api/v{api-version}/response']['get']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/response', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public callWithDuplicateResponses(): Observable< - $OpenApiTs['/api/v{api-version}/response']['post']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/response', - errors: { - 500: 'Message for 500 error', - 501: 'Message for 501 error', - 502: 'Message for 502 error', - }, - }); - } - - /** - * @returns unknown 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 callWithResponses(): Observable< - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202] - > { - return __request(OpenAPI, this.http, { - method: 'PUT', - url: '/api/v{api-version}/response', - errors: { - 500: 'Message for 500 error', - 501: 'Message for 501 error', - 502: 'Message for 502 error', - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public callWithResponseAndNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public callWithResponse(): Observable<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/response' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public callWithDuplicateResponses(): Observable<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/response', + errors: { + 500: 'Message for 500 error', + 501: 'Message for 501 error', + 502: 'Message for 502 error' + } + }); + } + + /** + * @returns unknown 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 callWithResponses(): Observable<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + return __request(OpenAPI, this.http, { + method: 'PUT', + url: '/api/v{api-version}/response', + errors: { + 500: 'Message for 500 error', + 501: 'Message for 501 error', + 502: 'Message for 502 error' + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class MultipleTags1Service { - constructor(public readonly http: HttpClient) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyA(): Observable< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): Observable< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyA(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class MultipleTags2Service { - constructor(public readonly http: HttpClient) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyA(): Observable< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): Observable< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyA(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class MultipleTags3Service { - constructor(public readonly http: HttpClient) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): Observable< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class CollectionFormatService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) - * @throws ApiError - */ - public collectionFormat( - data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req'], - ): Observable { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/collectionFormat', - query: { - parameterArrayCSV: data.parameterArrayCsv, - parameterArraySSV: data.parameterArraySsv, - parameterArrayTSV: data.parameterArrayTsv, - parameterArrayPipes: data.parameterArrayPipes, - parameterArrayMulti: data.parameterArrayMulti, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): Observable { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + parameterArrayCSV: data.parameterArrayCsv, + parameterArraySSV: data.parameterArraySsv, + parameterArrayTSV: data.parameterArrayTsv, + parameterArrayPipes: data.parameterArrayPipes, + parameterArrayMulti: data.parameterArrayMulti + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class TypesService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameterArray This is an array parameter - * @param data.parameterDictionary This is a dictionary parameter - * @param data.parameterEnum This is an enum parameter - * @param data.parameterNumber This is a number parameter - * @param data.parameterString This is a string parameter - * @param data.parameterBoolean This is a boolean parameter - * @param data.parameterObject This is an object parameter - * @param data.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 unknown Response is a simple object - * @throws ApiError - */ - public types( - data: $OpenApiTs['/api/v{api-version}/types']['get']['req'], - ): Observable< - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/types', - path: { - id: data.id, - }, - query: { - parameterNumber: data.parameterNumber, - parameterString: data.parameterString, - parameterBoolean: data.parameterBoolean, - parameterObject: data.parameterObject, - parameterArray: data.parameterArray, - parameterDictionary: data.parameterDictionary, - parameterEnum: data.parameterEnum, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameterArray This is an array parameter + * @param data.parameterDictionary This is a dictionary parameter + * @param data.parameterEnum This is an enum parameter + * @param data.parameterNumber This is a number parameter + * @param data.parameterString This is a string parameter + * @param data.parameterBoolean This is a boolean parameter + * @param data.parameterObject This is an object parameter + * @param data.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 unknown Response is a simple object + * @throws ApiError + */ + public types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + id: data.id + }, + query: { + parameterNumber: data.parameterNumber, + parameterString: data.parameterString, + parameterBoolean: data.parameterBoolean, + parameterObject: data.parameterObject, + parameterArray: data.parameterArray, + parameterDictionary: data.parameterDictionary, + parameterEnum: data.parameterEnum + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class UploadService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.file Supply a file reference for upload - * @returns boolean - * @throws ApiError - */ - public uploadFile( - data: $OpenApiTs['/api/v{api-version}/upload']['post']['req'], - ): Observable<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/upload', - formData: { - file: data.file, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.file Supply a file reference for upload + * @returns boolean + * @throws ApiError + */ + public uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/upload', + formData: { + file: data.file + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class FileResponseService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.id - * @returns binary Success - * @throws ApiError - */ - public fileResponse( - data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req'], - ): Observable< - $OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/file/{id}', - path: { - id: data.id, - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.id + * @returns binary Success + * @throws ApiError + */ + public fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/file/{id}', + path: { + id: data.id + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class ComplexService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.parameterObject Parameter containing object - * @param data.parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public complexTypes( - data: $OpenApiTs['/api/v{api-version}/complex']['get']['req'], - ): Observable<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/complex', - query: { - parameterObject: data.parameterObject, - parameterReference: data.parameterReference, - }, - errors: { - 400: '400 `server` error', - 500: '500 server error', - }, - }); - } - - /** - * @param data The data for the request. - * @param data.id - * @param data.requestBody - * @returns ModelWithString Success - * @throws ApiError - */ - public complexParams( - data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req'], - ): Observable< - $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'PUT', - url: '/api/v{api-version}/complex/{id}', - path: { - id: data.id, - }, - body: requestBody, - mediaType: 'application/json-patch+json', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.parameterObject Parameter containing object + * @param data.parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + parameterObject: data.parameterObject, + parameterReference: data.parameterReference + }, + errors: { + 400: '400 \`server\` error', + 500: '500 server error' + } + }); + } + + /** + * @param data The data for the request. + * @param data.id + * @param data.requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): Observable<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: { + id: data.id + }, + body: requestBody, + mediaType: 'application/json-patch+json' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class MultipartService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.formData - * @throws ApiError - */ - public multipartRequest( - data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}, - ): Observable { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/multipart', - formData, - mediaType: 'multipart/form-data', - }); - } - - /** - * @returns unknown OK - * @throws ApiError - */ - public multipartResponse(): Observable< - $OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'GET', - url: '/api/v{api-version}/multipart', - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.formData + * @throws ApiError + */ + public multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): Observable { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/multipart', + formData, + mediaType: 'multipart/form-data' + }); + } + + /** + * @returns unknown OK + * @throws ApiError + */ + public multipartResponse(): Observable<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/v{api-version}/multipart' + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class HeaderService { - constructor(public readonly http: HttpClient) {} - - /** - * @returns string Successful response - * @throws ApiError - */ - public callWithResultFromHeader(): Observable< - $OpenApiTs['/api/v{api-version}/header']['post']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/header', - responseHeader: 'operation-location', - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @returns string Successful response + * @throws ApiError + */ + public callWithResultFromHeader(): Observable<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class ErrorService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.status Status code to return - * @returns unknown Custom message: Successful response - * @throws ApiError - */ - public testErrorCode( - data: $OpenApiTs['/api/v{api-version}/error']['post']['req'], - ): Observable<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/error', - query: { - status: data.status, - }, - errors: { - 500: 'Custom message: Internal Server Error', - 501: 'Custom message: Not Implemented', - 502: 'Custom message: Bad Gateway', - 503: 'Custom message: Service Unavailable', - }, - }); - } + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.status Status code to return + * @returns unknown Custom message: Successful response + * @throws ApiError + */ + public testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + status: data.status + }, + errors: { + 500: 'Custom message: Internal Server Error', + 501: 'Custom message: Not Implemented', + 502: 'Custom message: Bad Gateway', + 503: 'Custom message: Service Unavailable' + } + }); + } + } @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class NonAsciiÆøåÆøÅöôêÊService { - constructor(public readonly http: HttpClient) {} - - /** - * @param data The data for the request. - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response - * @throws ApiError - */ - public nonAsciiæøåÆøÅöôêÊ字符串( - data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req'], - ): Observable< - $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200] - > { - return __request(OpenAPI, this.http, { - method: 'POST', - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - query: { - nonAsciiParamæøåÆØÅöôêÊ: data.nonAsciiParamæøåÆøÅöôêÊ, - }, - }); - } -} + constructor(public readonly http: HttpClient) { } + + /** + * @param data The data for the request. + * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + return __request(OpenAPI, this.http, { + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap index f6f2afd4d..5c29a38ea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap @@ -69,7 +69,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -84,40 +84,14 @@ export type SimpleStringWithPattern = string | null; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; -export type EnumWithReplacedCharacters = - | "'Single Quote'" - | '"Double Quotes"' - | 'øæåôöØÆÅÔÖ字符串' - | 3.1 - | ''; +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -134,17 +108,17 @@ export type EnumWithXEnumNames = 0 | 1 | 2; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -160,123 +134,117 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: camelCaseCommentWithBreaks; - bar?: string; + foo?: camelCaseCommentWithBreaks; + bar?: string; }>; /** * This is a simple array with any of properties */ -export type ArrayWithAnyOfProperties = Array< - | { - foo?: string; - } - | { - bar?: string; - } ->; +export type ArrayWithAnyOfProperties = Array<({ + foo?: string; +} | { + bar?: string; +})>; export type AnyOfAnyAndNull = { - data?: unknown | null; + data?: unknown | null; }; /** * This is a simple array with any of properties */ export type AnyOfArrays = { - results?: Array< - | { - foo?: string; - } - | { - bar?: string; - } - >; + results?: Array<({ + foo?: string; +} | { + bar?: string; +})>; }; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: string; - [key: string]: string | undefined; + foo?: string; + [key: string]: (string) | undefined; }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** @@ -288,119 +256,113 @@ export type Model_From_Zendesk = string; * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum with escaped name */ export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; + 'foo-bar-baz-qux'?: '3.0'; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** @@ -408,57 +370,50 @@ export type ModelWithDictionary = { * @deprecated */ export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * Circle */ export type ModelCircle = { - kind: 'circle'; - radius?: number; + kind: 'circle'; + radius?: number; }; /** * Square */ export type ModelSquare = { - kind: 'square'; - sideLength?: number; + kind: 'square'; + sideLength?: number; }; /** @@ -470,298 +425,268 @@ export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithAnyOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * This is a model with nested 'any of' property with a type null */ export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; + propA?: Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; }; export type Enum1 = 'Bird' | 'Dog'; -export type ConstValue = 'ConstValue'; +export type ConstValue = "ConstValue"; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithNestedAnyOfAndNull = { - propA?: Array | null; + propA?: Array<(Enum1 | ConstValue)> | null; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a model that contains a simple dictionary within composition */ export type CompositionWithOneOfAndSimpleDictionary = { - propA?: - | boolean - | { - [key: string]: number; - }; + propA?: boolean | { + [key: string]: (number); +}; }; /** * This is a model that contains a dictionary of simple arrays within composition */ export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(boolean)>; +}; }; /** * This is a model that contains a dictionary of complex arrays (composited) within composition */ export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; }; /** * This is a model with one property with a 'all of' relationship */ export type CompositionWithAllOfAndNullable = { - propA?: - | ({ - boolean?: boolean; - } & ModelWithEnum & - ModelWithArray & - ModelWithDictionary) - | null; + propA?: ({ + boolean?: boolean; +} & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; }; /** * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a base model with two simple optional properties */ export type CompositionBaseModel = { - firstName?: string; - lastname?: string; + firstName?: string; + lastname?: string; }; /** * This is a model that extends the base model */ export type CompositionExtendedModel = CompositionBaseModel & { - firstName: string; - lastname: string; - age: number; + firstName: string; + lastname: string; + age: number; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; + readonly first: { + readonly second: { + readonly third: string | null; + } | null; } | null; - } | null; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; }; export type _default = { - name?: string; + name?: string; }; export type Pageable = { - page?: number; - size?: number; - sort?: Array; + page?: number; + size?: number; + sort?: Array<(string)>; }; /** * This is a free-form object without additionalProperties. */ export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: true. */ export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: {}. */ export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - [key: string]: unknown; + [key: string]: unknown; }; export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; + String?: "String"; + number?: 0; + null?: null; + withType?: "Some string"; }; /** * This is a model with one property and additionalProperties: true */ export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown; + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; }; export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = - | { - foo: SimpleParameter; - baz: number | null; - qux: number; - } - | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; - baz: number | null; - qux: number; - }; + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: SimpleParameter; + baz: number | null; + qux: number; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; +}; /** * An object that can be null */ export type NullableObject = { - foo?: string; + foo?: string; } | null; /** @@ -770,117 +695,118 @@ export type NullableObject = { export type CharactersInDescription = string; export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = - | { - foo: 'Bar'; - } - | { - foo: 'Baz'; - } - | { - foo: 'Qux'; - } - | { - content: string; - foo: 'Quux'; - } - | { - content: [string, string]; - foo: 'Corge'; - }; + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; + foo?: Array; + bar?: Array; }; export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; + array_strings?: Array<(string)>; + data?: ModelWithNestedArrayEnumsData; }; export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; + foo?: ModelWithNestedArrayEnumsDataFoo; }; export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; + foo: string; + readonly bar: string; + baz: string; }; -export type ModelWithConstantSizeArray = [number, number]; +export type ModelWithConstantSizeArray = [ + number, + number +]; export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string, + number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string, + number | null | string, + number | null | string, + number | null | string ]; export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | string, - number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string, + number & string, + number & string ]; export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: 1 | 3 | 6 | 12; + /** + * Период + */ + value?: 1 | 3 | 6 | 12; }; /** * Some description with `back ticks` */ export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-   * [
-   * {
-   * "resourceType": "Asset",
-   * "identifier": {
-   * "name": "${1}",
-   * "domain": {
-   * "name": "${2}",
-   * "community": {
-   * "name": "Some Community"
-   * }
-   * }
-   * },
-   * "attributes" : {
-   * "00000000-0000-0000-0000-000000003115" : [ {
-   * "value" : "${3}"
-   * } ],
-   * "00000000-0000-0000-0000-000000000222" : [ {
-   * "value" : "${4}"
-   * } ]
-   * }
-   * }
-   * ]
-   * 
- */ - template?: string; + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; }; /** @@ -894,665 +820,659 @@ export type SimpleParameter = string; export type x_Foo_Bar = string; export type $OpenApiTs = { - '/api/v{api-version}/no-tag': { - post: { - req: { - requestBody: - | ModelWithReadOnlyAndWriteOnly - | ModelWithArrayReadOnlyAndWriteOnly; - }; - res: { - 200: ModelWithReadOnlyAndWriteOnly; - }; - }; - }; - '/api/v{api-version}/simple/$count': { - get: { - res: { - /** - * Success - */ - 200: Model_From_Zendesk; - }; - }; - }; - '/api/v{api-version}/foo/{foo}/bar/{bar}': { - delete: { - req: { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameterPath}': { - post: { - req: { - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { - post: { - req: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the request form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the request header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath1?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath2?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath3?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/': { - get: { - req: { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; - }; - }; - post: { - req: { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; - }; + '/api/v{api-version}/no-tag': { + post: { + req: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; + res: { + 200: ModelWithReadOnlyAndWriteOnly; + }; + }; }; - }; - '/api/v{api-version}/descriptions/': { - post: { - req: { - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: unknown; - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: unknown; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: unknown; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: unknown; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: unknown; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: unknown; - }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; }; - }; - '/api/v{api-version}/parameters/deprecated': { - post: { - req: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + '/api/v{api-version}/foo/{foo}/bar/{bar}': { + delete: { + req: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + }; }; - }; - '/api/v{api-version}/requestBody/': { - post: { - req: { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/formData/': { - post: { - req: { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple string with default value - */ - parameterString?: string | null; - }; + '/api/v{api-version}/parameters/': { + get: { + req: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + }; + post: { + req: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; + '/api/v{api-version}/descriptions/': { + post: { + req: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; + }; + }; }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }; }; - }; - '/api/v{api-version}/no-content': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/requestBody/': { + post: { + req: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/response-and-no-content': { - get: { - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/formData/': { + post: { + req: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/response': { - get: { - res: { - 200: ModelWithString; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - put: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 201 response - */ - 201: ModelThatExtends; - /** - * Message for 202 response - */ - 202: ModelThatExtendsExtends; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/a': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/response': { + get: { + res: { + 200: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; + put: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/b': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/collectionFormat': { - get: { - req: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCsv: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySsv: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTsv: Array | null; - }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/types': { - get: { - req: { - /** - * This is a number parameter - */ - id?: number; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: { - [key: string]: unknown; - } | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is an object parameter - */ - parameterObject: { - [key: string]: unknown; - } | null; - /** - * This is a string parameter - */ - parameterString: string | null; - }; - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Response is a simple string - */ - 201: string; - /** - * Response is a simple boolean - */ - 202: boolean; - /** - * Response is a simple object - */ - 203: { - [key: string]: unknown; + '/api/v{api-version}/collectionFormat': { + get: { + req: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; + }; }; - }; }; - }; - '/api/v{api-version}/upload': { - post: { - req: { - /** - * Supply a file reference for upload - */ - file: Blob | File; - }; - res: { - 200: boolean; - }; + '/api/v{api-version}/types': { + get: { + req: { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; + }; + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; + }; + }; }; - }; - '/api/v{api-version}/file/{id}': { - get: { - req: { - id: string; - }; - res: { - /** - * Success - */ - 200: Blob | File; - }; + '/api/v{api-version}/upload': { + post: { + req: { + /** + * Supply a file reference for upload + */ + file: (Blob | File); + }; + res: { + 200: boolean; + }; + }; }; - }; - '/api/v{api-version}/complex': { - get: { - req: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; + '/api/v{api-version}/file/{id}': { + get: { + req: { + id: string; + }; + res: { + /** + * Success + */ + 200: (Blob | File); }; - }; }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; - res: { - /** - * Successful response - */ - 200: Array; - /** - * 400 `server` error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; }; - }; - '/api/v{api-version}/complex/{id}': { - put: { - req: { - 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; - }; + '/api/v{api-version}/complex': { + get: { + req: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; }; - }; - res: { - /** - * Success - */ - 200: ModelWithString; - }; }; - }; - '/api/v{api-version}/multipart': { - post: { - req: { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; + '/api/v{api-version}/complex/{id}': { + put: { + req: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; + res: { + /** + * Success + */ + 200: ModelWithString; + }; }; - }; }; - get: { - res: { - /** - * OK - */ - 200: { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; + '/api/v{api-version}/multipart': { + post: { + req: { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; + }; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; }; - }; }; - }; - '/api/v{api-version}/header': { - post: { - res: { - /** - * Successful response - */ - 200: string; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; }; - }; - '/api/v{api-version}/error': { - post: { - req: { - /** - * Status code to return - */ - status: number; - }; - res: { - /** - * Custom message: Successful response - */ - 200: unknown; - /** - * Custom message: Internal Server Error - */ - 500: unknown; - /** - * Custom message: Not Implemented - */ - 501: unknown; - /** - * Custom message: Bad Gateway - */ - 502: unknown; - /** - * Custom message: Service Unavailable - */ - 503: unknown; - }; + '/api/v{api-version}/error': { + post: { + req: { + /** + * Status code to return + */ + status: number; + }; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; + }; + }; }; - }; - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { - post: { - req: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; - res: { - /** - * Successful response - */ - 200: Array; - }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/OpenAPI.ts.snap index a3de5a06e..f08bd7576 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/OpenAPI.ts.snap @@ -25,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap index 86ceceef4..1df3281f1 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap @@ -1,10 +1,5 @@ import axios from 'axios'; -import type { - AxiosError, - AxiosRequestConfig, - AxiosResponse, - AxiosInstance, -} from 'axios'; +import type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios'; import { ApiError } from './ApiError'; import type { ApiRequestOptions } from './ApiRequestOptions'; @@ -14,307 +9,288 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const isSuccess = (status: number): boolean => { - return status >= 200 && status < 300; + return status >= 200 && status < 300; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise> => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } else if (options.formData !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } - } - - return headers; +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } else if (options.formData !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } + } + + return headers; }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body) { - return options.body; - } - return undefined; + if (options.body) { + return options.body; + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: unknown, - formData: FormData | undefined, - headers: Record, - onCancel: OnCancel, - axiosClient: AxiosInstance, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: unknown, + formData: FormData | undefined, + headers: Record, + onCancel: OnCancel, + axiosClient: AxiosInstance ): Promise> => { - const controller = new AbortController(); - - let requestConfig: AxiosRequestConfig = { - data: body ?? formData, - headers, - method: options.method, - signal: controller.signal, - url, - withCredentials: config.WITH_CREDENTIALS, - }; - - onCancel(() => controller.abort()); - - for (const fn of config.interceptors.request._fns) { - requestConfig = await fn(requestConfig); - } - - try { - return await axiosClient.request(requestConfig); - } catch (error) { - const axiosError = error as AxiosError; - if (axiosError.response) { - return axiosError.response; - } - throw error; - } + const controller = new AbortController(); + + let requestConfig: AxiosRequestConfig = { + data: body ?? formData, + headers, + method: options.method, + signal: controller.signal, + url, + withCredentials: config.WITH_CREDENTIALS, + }; + + onCancel(() => controller.abort()); + + for (const fn of config.interceptors.request._fns) { + requestConfig = await fn(requestConfig); + } + + try { + return await axiosClient.request(requestConfig); + } catch (error) { + const axiosError = error as AxiosError; + if (axiosError.response) { + return axiosError.response; + } + throw error; + } }; -export const getResponseHeader = ( - response: AxiosResponse, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers[responseHeader]; - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: AxiosResponse, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers[responseHeader]; + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = (response: AxiosResponse): unknown => { - if (response.status !== 204) { - return response.data; - } - return undefined; + if (response.status !== 204) { + return response.data; + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -325,54 +301,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, - axiosClient: AxiosInstance = axios, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - axiosClient, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: isSuccess(response.status), - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions, axiosClient: AxiosInstance = axios): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel, axiosClient); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: isSuccess(response.status), + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/index.ts.snap index f073fa9c4..d22d07cd0 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/index.ts.snap @@ -1,5 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; -export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; +export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/ApiClient.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/ApiClient.ts.snap index 6aadfb6bd..6dcdc2226 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/ApiClient.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/ApiClient.ts.snap @@ -30,74 +30,72 @@ import { UploadService } from './services.gen'; type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest; export class ApiClient { - public readonly collectionFormat: CollectionFormatService; - public readonly complex: ComplexService; - public readonly default: DefaultService; - public readonly defaults: DefaultsService; - public readonly deprecated: DeprecatedService; - public readonly descriptions: DescriptionsService; - public readonly duplicate: DuplicateService; - public readonly error: ErrorService; - public readonly fileResponse: FileResponseService; - public readonly formData: FormDataService; - public readonly header: HeaderService; - public readonly multipart: MultipartService; - public readonly multipleTags1: MultipleTags1Service; - public readonly multipleTags2: MultipleTags2Service; - public readonly multipleTags3: MultipleTags3Service; - public readonly noContent: NoContentService; - public readonly nonAsciiÆøåÆøÅöôêÊ: NonAsciiÆøåÆøÅöôêÊService; - public readonly parameters: ParametersService; - public readonly requestBody: RequestBodyService; - public readonly response: ResponseService; - public readonly simple: SimpleService; - public readonly types: TypesService; - public readonly upload: UploadService; - public readonly request: BaseHttpRequest; + public readonly collectionFormat: CollectionFormatService; + public readonly complex: ComplexService; + public readonly default: DefaultService; + public readonly defaults: DefaultsService; + public readonly deprecated: DeprecatedService; + public readonly descriptions: DescriptionsService; + public readonly duplicate: DuplicateService; + public readonly error: ErrorService; + public readonly fileResponse: FileResponseService; + public readonly formData: FormDataService; + public readonly header: HeaderService; + public readonly multipart: MultipartService; + public readonly multipleTags1: MultipleTags1Service; + public readonly multipleTags2: MultipleTags2Service; + public readonly multipleTags3: MultipleTags3Service; + public readonly noContent: NoContentService; + public readonly nonAsciiÆøåÆøÅöôêÊ: NonAsciiÆøåÆøÅöôêÊService; + public readonly parameters: ParametersService; + public readonly requestBody: RequestBodyService; + public readonly response: ResponseService; + public readonly simple: SimpleService; + public readonly types: TypesService; + public readonly upload: UploadService; - constructor( - config?: Partial, - HttpRequest: HttpRequestConstructor = FetchHttpRequest, - ) { - this.request = new HttpRequest({ - BASE: config?.BASE ?? 'http://localhost:3000/base', - VERSION: config?.VERSION ?? '1.0', - WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false, - CREDENTIALS: config?.CREDENTIALS ?? 'include', - TOKEN: config?.TOKEN, - USERNAME: config?.USERNAME, - PASSWORD: config?.PASSWORD, - HEADERS: config?.HEADERS, - ENCODE_PATH: config?.ENCODE_PATH, - interceptors: { - request: config?.interceptors?.request ?? new Interceptors(), - response: config?.interceptors?.response ?? new Interceptors(), + public readonly request: BaseHttpRequest; + + constructor(config?: Partial, HttpRequest: HttpRequestConstructor = FetchHttpRequest) { + this.request = new HttpRequest({ + BASE: config?.BASE ?? 'http://localhost:3000/base', + VERSION: config?.VERSION ?? '1.0', + WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false, + CREDENTIALS: config?.CREDENTIALS ?? 'include', + TOKEN: config?.TOKEN, + USERNAME: config?.USERNAME, + PASSWORD: config?.PASSWORD, + HEADERS: config?.HEADERS, + ENCODE_PATH: config?.ENCODE_PATH, + interceptors: { + request: config?.interceptors?.request ?? new Interceptors(), + response: config?.interceptors?.response ?? new Interceptors(), }, - }); + }); - this.collectionFormat = new CollectionFormatService(this.request); - this.complex = new ComplexService(this.request); - this.default = new DefaultService(this.request); - this.defaults = new DefaultsService(this.request); - this.deprecated = new DeprecatedService(this.request); - this.descriptions = new DescriptionsService(this.request); - this.duplicate = new DuplicateService(this.request); - this.error = new ErrorService(this.request); - this.fileResponse = new FileResponseService(this.request); - this.formData = new FormDataService(this.request); - this.header = new HeaderService(this.request); - this.multipart = new MultipartService(this.request); - this.multipleTags1 = new MultipleTags1Service(this.request); - this.multipleTags2 = new MultipleTags2Service(this.request); - this.multipleTags3 = new MultipleTags3Service(this.request); - this.noContent = new NoContentService(this.request); - this.nonAsciiÆøåÆøÅöôêÊ = new NonAsciiÆøåÆøÅöôêÊService(this.request); - this.parameters = new ParametersService(this.request); - this.requestBody = new RequestBodyService(this.request); - this.response = new ResponseService(this.request); - this.simple = new SimpleService(this.request); - this.types = new TypesService(this.request); - this.upload = new UploadService(this.request); - } + this.collectionFormat = new CollectionFormatService(this.request); + this.complex = new ComplexService(this.request); + this.default = new DefaultService(this.request); + this.defaults = new DefaultsService(this.request); + this.deprecated = new DeprecatedService(this.request); + this.descriptions = new DescriptionsService(this.request); + this.duplicate = new DuplicateService(this.request); + this.error = new ErrorService(this.request); + this.fileResponse = new FileResponseService(this.request); + this.formData = new FormDataService(this.request); + this.header = new HeaderService(this.request); + this.multipart = new MultipartService(this.request); + this.multipleTags1 = new MultipleTags1Service(this.request); + this.multipleTags2 = new MultipleTags2Service(this.request); + this.multipleTags3 = new MultipleTags3Service(this.request); + this.noContent = new NoContentService(this.request); + this.nonAsciiÆøåÆøÅöôêÊ = new NonAsciiÆøåÆøÅöôêÊService(this.request); + this.parameters = new ParametersService(this.request); + this.requestBody = new RequestBodyService(this.request); + this.response = new ResponseService(this.request); + this.simple = new SimpleService(this.request); + this.types = new TypesService(this.request); + this.upload = new UploadService(this.request); + } } diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/BaseHttpRequest.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/BaseHttpRequest.ts.snap index b5ce58da6..bc428debc 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/BaseHttpRequest.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/BaseHttpRequest.ts.snap @@ -3,7 +3,8 @@ import type { CancelablePromise } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export abstract class BaseHttpRequest { - constructor(public readonly config: OpenAPIConfig) {} - public abstract request(options: ApiRequestOptions): CancelablePromise; -} + constructor(public readonly config: OpenAPIConfig) {} + + public abstract request(options: ApiRequestOptions): CancelablePromise; +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/FetchHttpRequest.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/FetchHttpRequest.ts.snap index 48651871b..f9d4a4354 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/FetchHttpRequest.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/FetchHttpRequest.ts.snap @@ -5,17 +5,18 @@ import type { OpenAPIConfig } from './OpenAPI'; import { request as __request } from './request'; export class FetchHttpRequest extends BaseHttpRequest { - constructor(config: OpenAPIConfig) { - super(config); - } - /** - * Request method - * @param options The request options from the service - * @returns CancelablePromise - * @throws ApiError - */ - public override request(options: ApiRequestOptions): CancelablePromise { - return __request(this.config, options); - } -} + constructor(config: OpenAPIConfig) { + super(config); + } + + /** + * Request method + * @param options The request options from the service + * @returns CancelablePromise + * @throws ApiError + */ + public override request(options: ApiRequestOptions): CancelablePromise { + return __request(this.config, options); + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap index e3117fd1b..73bd72f36 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/enums.gen.ts.snap @@ -4,118 +4,118 @@ * This is a simple enum with strings */ export const EnumWithStringsEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - _SINGLE_QUOTE_: "'Single Quote'", - _DOUBLE_QUOTES_: '"Double Quotes"', - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串: 'Non-ascii: øæåôöØÆÅÔÖ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + _SINGLE_QUOTE_: "'Single Quote'", + _DOUBLE_QUOTES_: '"Double Quotes"', + 'NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串': 'Non-ascii: øæåôöØÆÅÔÖ字符串' } as const; export const EnumWithReplacedCharactersEnum = { - _SINGLE_QUOTE_: "'Single Quote'", - _DOUBLE_QUOTES_: '"Double Quotes"', - ØÆÅÔÖ_ØÆÅÔÖ字符串: 'øæåôöØÆÅÔÖ字符串', - '_3.1': 3.1, - EMPTY_STRING: '', + _SINGLE_QUOTE_: "'Single Quote'", + _DOUBLE_QUOTES_: '"Double Quotes"', + 'ØÆÅÔÖ_ØÆÅÔÖ字符串': 'øæåôöØÆÅÔÖ字符串', + '_3.1': 3.1, + EMPTY_STRING: '' } as const; /** * This is a simple enum with numbers */ export const EnumWithNumbersEnum = { - _1: 1, - _2: 2, - _3: 3, - '_1.1': 1.1, - '_1.2': 1.2, - '_1.3': 1.3, - _100: 100, - _200: 200, - _300: 300, - '_-100': -100, - '_-200': -200, - '_-300': -300, - '_-1.1': -1.1, - '_-1.2': -1.2, - '_-1.3': -1.3, + '_1': 1, + '_2': 2, + '_3': 3, + '_1.1': 1.1, + '_1.2': 1.2, + '_1.3': 1.3, + '_100': 100, + '_200': 200, + '_300': 300, + '_-100': -100, + '_-200': -200, + '_-300': -300, + '_-1.1': -1.1, + '_-1.2': -1.2, + '_-1.3': -1.3 } as const; /** * This is a simple enum with numbers */ export const EnumWithExtensionsEnum = { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS: 200, - /** - * Used when the status of something has a warning - */ - CUSTOM_WARNING: 400, - /** - * Used when the status of something has an error - */ - CUSTOM_ERROR: 500, + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS: 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING: 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR: 500 } as const; export const EnumWithXEnumNamesEnum = { - zero: 0, - one: 1, - two: 2, + zero: 0, + one: 1, + two: 2 } as const; /** * This is a simple enum with strings */ export const FooBarEnumEnum = { - SUCCESS: 'Success', - WARNING: 'Warning', - ERROR: 'Error', - ØÆÅ字符串: 'ØÆÅ字符串', + SUCCESS: 'Success', + WARNING: 'Warning', + ERROR: 'Error', + 'ØÆÅ字符串': 'ØÆÅ字符串' } as const; /** * These are the HTTP error code enums */ export const StatusCodeEnum = { - _100: '100', - _200_FOO: '200 FOO', - _300_FOO_BAR: '300 FOO_BAR', - _400_FOO_BAR: '400 foo-bar', - _500_FOO_BAR: '500 foo.bar', - _600_FOO_BAR: '600 foo&bar', + _100: '100', + _200_FOO: '200 FOO', + _300_FOO_BAR: '300 FOO_BAR', + _400_FOO_BAR: '400 foo-bar', + _500_FOO_BAR: '500 foo.bar', + _600_FOO_BAR: '600 foo&bar' } as const; export const FooBarBazQuxEnum = { - _3_0: '3.0', + _3_0: '3.0' } as const; export const Enum1Enum = { - BIRD: 'Bird', - DOG: 'Dog', + BIRD: 'Bird', + DOG: 'Dog' } as const; export const FooEnum = { - BAR: 'Bar', + BAR: 'Bar' } as const; export const ModelWithNestedArrayEnumsDataFooEnum = { - FOO: 'foo', - BAR: 'bar', + FOO: 'foo', + BAR: 'bar' } as const; export const ModelWithNestedArrayEnumsDataBarEnum = { - BAZ: 'baz', - QUX: 'qux', + BAZ: 'baz', + QUX: 'qux' } as const; /** * Период */ export const ValueEnum = { - _1: 1, - _3: 3, - _6: 6, - _12: 12, -} as const; + '_1': 1, + '_3': 3, + '_6': 6, + '_12': 12 +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/index.ts.snap index cc07b6aab..c3cdcd1d4 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/index.ts.snap @@ -1,5 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiClient } from './ApiClient'; export { ApiError } from './core/ApiError'; export { BaseHttpRequest } from './core/BaseHttpRequest'; @@ -7,4 +6,4 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './enums.gen'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap index c9c958bd8..7ddcb29db 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap @@ -5,973 +5,894 @@ import type { BaseHttpRequest } from './core/BaseHttpRequest'; import type { $OpenApiTs } from './types.gen'; export class DefaultService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @throws ApiError - */ - public serviceWithEmptyTag(): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/no-tag', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody - * @returns ModelWithReadOnlyAndWriteOnly - * @throws ApiError - */ - public postServiceWithEmptyTag( - data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/no-tag', - body: requestBody, - mediaType: 'application/json', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @throws ApiError + */ + public serviceWithEmptyTag(): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/no-tag' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody + * @returns ModelWithReadOnlyAndWriteOnly + * @throws ApiError + */ + public postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/no-tag', + body: requestBody, + mediaType: 'application/json' + }); + } + } export class SimpleService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns Model_From_Zendesk Success - * @throws ApiError - */ - public apiVVersionOdataControllerCount(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/simple/$count', - }); - } - - /** - * @throws ApiError - */ - public getCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public putCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public postCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public deleteCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public optionsCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public headCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public patchCallWithoutParametersAndResponse(): CancelablePromise { - return this.httpRequest.request({ - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns Model_From_Zendesk Success + * @throws ApiError + */ + public apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/simple/$count' + }); + } + + /** + * @throws ApiError + */ + public getCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public putCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public postCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public deleteCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public optionsCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public headCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public patchCallWithoutParametersAndResponse(): CancelablePromise { + return this.httpRequest.request({ + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } export class ParametersService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.foo foo in method - * @param data.bar bar in method - * @throws ApiError - */ - public deleteFoo( - data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'DELETE', - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', - path: { - foo: data.foo, - bar: data.bar, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.fooAllOfEnum - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.parameterPath This is the parameter that goes into the path - * @param data.requestBody This is the parameter that goes into the body - * @param data.fooRefEnum - * @throws ApiError - */ - public callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - cookies: { - parameterCookie: data.parameterCookie, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - foo_ref_enum: data.fooRefEnum, - foo_all_of_enum: data.fooAllOfEnum, - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.requestBody This is the parameter that goes into the body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - cookies: { - 'PARAMETER-COOKIE': data.parameterCookie, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody This is a required parameter - * @param data.parameter This is an optional parameter - * @throws ApiError - */ - public getCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameter This is a required parameter - * @param data.requestBody This is an optional parameter - * @throws ApiError - */ - public postCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.foo foo in method + * @param data.bar bar in method + * @throws ApiError + */ + public deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: { + foo: data.foo, + bar: data.bar + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.fooAllOfEnum + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.parameterPath This is the parameter that goes into the path + * @param data.requestBody This is the parameter that goes into the body + * @param data.fooRefEnum + * @throws ApiError + */ + public callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + cookies: { + parameterCookie: data.parameterCookie + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + foo_ref_enum: data.fooRefEnum, + foo_all_of_enum: data.fooAllOfEnum, + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.requestBody This is the parameter that goes into the body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + cookies: { + 'PARAMETER-COOKIE': data.parameterCookie + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody This is a required parameter + * @param data.parameter This is an optional parameter + * @throws ApiError + */ + public getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameter This is a required parameter + * @param data.requestBody This is an optional parameter + * @throws ApiError + */ + public postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + } export class DescriptionsService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameterWithBreaks Testing multiline comments in string: First line - * Second line - * - * Fourth line - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work - * @throws ApiError - */ - public callWithDescriptions( - data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/descriptions/', - query: { - parameterWithBreaks: data.parameterWithBreaks, - parameterWithBackticks: data.parameterWithBackticks, - parameterWithSlashes: data.parameterWithSlashes, - parameterWithExpressionPlaceholders: - data.parameterWithExpressionPlaceholders, - parameterWithQuotes: data.parameterWithQuotes, - parameterWithReservedCharacters: data.parameterWithReservedCharacters, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work + * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work + * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work + * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work + * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + parameterWithBreaks: data.parameterWithBreaks, + parameterWithBackticks: data.parameterWithBackticks, + parameterWithSlashes: data.parameterWithSlashes, + parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, + parameterWithQuotes: data.parameterWithQuotes, + parameterWithReservedCharacters: data.parameterWithReservedCharacters + } + }); + } + } export class DeprecatedService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @deprecated - * @param data The data for the request. - * @param data.parameter This parameter is deprecated - * @throws ApiError - */ - public deprecatedCall( - data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/parameters/deprecated', - headers: { - parameter: data.parameter, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @deprecated + * @param data The data for the request. + * @param data.parameter This parameter is deprecated + * @throws ApiError + */ + public deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: { + parameter: data.parameter + } + }); + } + } export class RequestBodyService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.foo A reusable request body - * @throws ApiError - */ - public postApiRequestBody( - data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/requestBody/', - query: { - parameter: data.parameter, - }, - body: foo, - mediaType: 'application/json', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.foo A reusable request body + * @throws ApiError + */ + public postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + parameter: data.parameter + }, + body: foo, + mediaType: 'application/json' + }); + } + } export class FormDataService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.formData A reusable request body - * @throws ApiError - */ - public postApiFormData( - data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/formData/', - query: { - parameter: data.parameter, - }, - formData, - mediaType: 'multipart/form-data', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.formData A reusable request body + * @throws ApiError + */ + public postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + parameter: data.parameter + }, + formData, + mediaType: 'multipart/form-data' + }); + } + } export class DefaultsService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + } export class DuplicateService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @throws ApiError - */ - public duplicateName(): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName1(): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName2(): CancelablePromise { - return this.httpRequest.request({ - method: 'PUT', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public duplicateName3(): CancelablePromise { - return this.httpRequest.request({ - method: 'DELETE', - url: '/api/v{api-version}/duplicate', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @throws ApiError + */ + public duplicateName(): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName1(): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName2(): CancelablePromise { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public duplicateName3(): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/api/v{api-version}/duplicate' + }); + } + } export class NoContentService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns void Success - * @throws ApiError - */ - public callWithNoContentResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/no-content', - }); - } - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns void Success + * @throws ApiError + */ + public callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/no-content' + }); + } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + } export class ResponseService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } - - /** - * @returns ModelWithString - * @throws ApiError - */ - public callWithResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['get']['res'][200] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/response', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public callWithDuplicateResponses(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/response', - errors: { - 500: 'Message for 500 error', - 501: 'Message for 501 error', - 502: 'Message for 502 error', - }, - }); - } - - /** - * @returns unknown 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 callWithResponses(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202] - > { - return this.httpRequest.request({ - method: 'PUT', - url: '/api/v{api-version}/response', - errors: { - 500: 'Message for 500 error', - 501: 'Message for 501 error', - 502: 'Message for 502 error', - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/response' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/response', + errors: { + 500: 'Message for 500 error', + 501: 'Message for 501 error', + 502: 'Message for 502 error' + } + }); + } + + /** + * @returns unknown 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 callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/v{api-version}/response', + errors: { + 500: 'Message for 500 error', + 501: 'Message for 501 error', + 502: 'Message for 502 error' + } + }); + } + } export class MultipleTags1Service { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags2Service { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags3Service { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns void Success - * @throws ApiError - */ - public dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns void Success + * @throws ApiError + */ + public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class CollectionFormatService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) - * @throws ApiError - */ - public collectionFormat( - data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req'], - ): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/collectionFormat', - query: { - parameterArrayCSV: data.parameterArrayCsv, - parameterArraySSV: data.parameterArraySsv, - parameterArrayTSV: data.parameterArrayTsv, - parameterArrayPipes: data.parameterArrayPipes, - parameterArrayMulti: data.parameterArrayMulti, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + parameterArrayCSV: data.parameterArrayCsv, + parameterArraySSV: data.parameterArraySsv, + parameterArrayTSV: data.parameterArrayTsv, + parameterArrayPipes: data.parameterArrayPipes, + parameterArrayMulti: data.parameterArrayMulti + } + }); + } + } export class TypesService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameterArray This is an array parameter - * @param data.parameterDictionary This is a dictionary parameter - * @param data.parameterEnum This is an enum parameter - * @param data.parameterNumber This is a number parameter - * @param data.parameterString This is a string parameter - * @param data.parameterBoolean This is a boolean parameter - * @param data.parameterObject This is an object parameter - * @param data.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 unknown Response is a simple object - * @throws ApiError - */ - public types( - data: $OpenApiTs['/api/v{api-version}/types']['get']['req'], - ): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/types', - path: { - id: data.id, - }, - query: { - parameterNumber: data.parameterNumber, - parameterString: data.parameterString, - parameterBoolean: data.parameterBoolean, - parameterObject: data.parameterObject, - parameterArray: data.parameterArray, - parameterDictionary: data.parameterDictionary, - parameterEnum: data.parameterEnum, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameterArray This is an array parameter + * @param data.parameterDictionary This is a dictionary parameter + * @param data.parameterEnum This is an enum parameter + * @param data.parameterNumber This is a number parameter + * @param data.parameterString This is a string parameter + * @param data.parameterBoolean This is a boolean parameter + * @param data.parameterObject This is an object parameter + * @param data.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 unknown Response is a simple object + * @throws ApiError + */ + public types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/types', + path: { + id: data.id + }, + query: { + parameterNumber: data.parameterNumber, + parameterString: data.parameterString, + parameterBoolean: data.parameterBoolean, + parameterObject: data.parameterObject, + parameterArray: data.parameterArray, + parameterDictionary: data.parameterDictionary, + parameterEnum: data.parameterEnum + } + }); + } + } export class UploadService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.file Supply a file reference for upload - * @returns boolean - * @throws ApiError - */ - public uploadFile( - data: $OpenApiTs['/api/v{api-version}/upload']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/upload']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/upload', - formData: { - file: data.file, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.file Supply a file reference for upload + * @returns boolean + * @throws ApiError + */ + public uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/upload', + formData: { + file: data.file + } + }); + } + } export class FileResponseService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.id - * @returns binary Success - * @throws ApiError - */ - public fileResponse( - data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/file/{id}', - path: { - id: data.id, - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.id + * @returns binary Success + * @throws ApiError + */ + public fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/file/{id}', + path: { + id: data.id + } + }); + } + } export class ComplexService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.parameterObject Parameter containing object - * @param data.parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public complexTypes( - data: $OpenApiTs['/api/v{api-version}/complex']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex']['get']['res'][200] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/complex', - query: { - parameterObject: data.parameterObject, - parameterReference: data.parameterReference, - }, - errors: { - 400: '400 `server` error', - 500: '500 server error', - }, - }); - } - - /** - * @param data The data for the request. - * @param data.id - * @param data.requestBody - * @returns ModelWithString Success - * @throws ApiError - */ - public complexParams( - data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200] - > { - return this.httpRequest.request({ - method: 'PUT', - url: '/api/v{api-version}/complex/{id}', - path: { - id: data.id, - }, - body: requestBody, - mediaType: 'application/json-patch+json', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.parameterObject Parameter containing object + * @param data.parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + parameterObject: data.parameterObject, + parameterReference: data.parameterReference + }, + errors: { + 400: '400 \`server\` error', + 500: '500 server error' + } + }); + } + + /** + * @param data The data for the request. + * @param data.id + * @param data.requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + return this.httpRequest.request({ + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: { + id: data.id + }, + body: requestBody, + mediaType: 'application/json-patch+json' + }); + } + } export class MultipartService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.formData - * @throws ApiError - */ - public multipartRequest( - data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/multipart', - formData, - mediaType: 'multipart/form-data', - }); - } - - /** - * @returns unknown OK - * @throws ApiError - */ - public multipartResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200] - > { - return this.httpRequest.request({ - method: 'GET', - url: '/api/v{api-version}/multipart', - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.formData + * @throws ApiError + */ + public multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/multipart', + formData, + mediaType: 'multipart/form-data' + }); + } + + /** + * @returns unknown OK + * @throws ApiError + */ + public multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + return this.httpRequest.request({ + method: 'GET', + url: '/api/v{api-version}/multipart' + }); + } + } export class HeaderService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @returns string Successful response - * @throws ApiError - */ - public callWithResultFromHeader(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/header']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/header', - responseHeader: 'operation-location', - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @returns string Successful response + * @throws ApiError + */ + public callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } export class ErrorService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.status Status code to return - * @returns unknown Custom message: Successful response - * @throws ApiError - */ - public testErrorCode( - data: $OpenApiTs['/api/v{api-version}/error']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/error']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/error', - query: { - status: data.status, - }, - errors: { - 500: 'Custom message: Internal Server Error', - 501: 'Custom message: Not Implemented', - 502: 'Custom message: Bad Gateway', - 503: 'Custom message: Service Unavailable', - }, - }); - } + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.status Status code to return + * @returns unknown Custom message: Successful response + * @throws ApiError + */ + public testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/error', + query: { + status: data.status + }, + errors: { + 500: 'Custom message: Internal Server Error', + 501: 'Custom message: Not Implemented', + 502: 'Custom message: Bad Gateway', + 503: 'Custom message: Service Unavailable' + } + }); + } + } export class NonAsciiÆøåÆøÅöôêÊService { - constructor(public readonly httpRequest: BaseHttpRequest) {} - - /** - * @param data The data for the request. - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response - * @throws ApiError - */ - public nonAsciiæøåÆøÅöôêÊ字符串( - data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200] - > { - return this.httpRequest.request({ - method: 'POST', - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - query: { - nonAsciiParamæøåÆØÅöôêÊ: data.nonAsciiParamæøåÆøÅöôêÊ, - }, - }); - } -} + constructor(public readonly httpRequest: BaseHttpRequest) { } + + /** + * @param data The data for the request. + * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + return this.httpRequest.request({ + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap index 54122b684..2e4256553 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap @@ -69,7 +69,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -84,40 +84,14 @@ export type SimpleStringWithPattern = string | null; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; -export type EnumWithReplacedCharacters = - | "'Single Quote'" - | '"Double Quotes"' - | 'øæåôöØÆÅÔÖ字符串' - | 3.1 - | ''; +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -134,17 +108,17 @@ export type EnumWithXEnumNames = 0 | 1 | 2; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -160,123 +134,117 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: camelCaseCommentWithBreaks; - bar?: string; + foo?: camelCaseCommentWithBreaks; + bar?: string; }>; /** * This is a simple array with any of properties */ -export type ArrayWithAnyOfProperties = Array< - | { - foo?: string; - } - | { - bar?: string; - } ->; +export type ArrayWithAnyOfProperties = Array<({ + foo?: string; +} | { + bar?: string; +})>; export type AnyOfAnyAndNull = { - data?: unknown | null; + data?: unknown | null; }; /** * This is a simple array with any of properties */ export type AnyOfArrays = { - results?: Array< - | { - foo?: string; - } - | { - bar?: string; - } - >; + results?: Array<({ + foo?: string; +} | { + bar?: string; +})>; }; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: string; - [key: string]: string | undefined; + foo?: string; + [key: string]: (string) | undefined; }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** @@ -288,119 +256,113 @@ export type Model_From_Zendesk = string; * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum with escaped name */ export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; + 'foo-bar-baz-qux'?: '3.0'; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** @@ -408,57 +370,50 @@ export type ModelWithDictionary = { * @deprecated */ export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * Circle */ export type ModelCircle = { - kind: 'circle'; - radius?: number; + kind: 'circle'; + radius?: number; }; /** * Square */ export type ModelSquare = { - kind: 'square'; - sideLength?: number; + kind: 'square'; + sideLength?: number; }; /** @@ -470,298 +425,268 @@ export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithAnyOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * This is a model with nested 'any of' property with a type null */ export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; + propA?: Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; }; export type Enum1 = 'Bird' | 'Dog'; -export type ConstValue = 'ConstValue'; +export type ConstValue = "ConstValue"; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithNestedAnyOfAndNull = { - propA?: Array | null; + propA?: Array<(Enum1 | ConstValue)> | null; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a model that contains a simple dictionary within composition */ export type CompositionWithOneOfAndSimpleDictionary = { - propA?: - | boolean - | { - [key: string]: number; - }; + propA?: boolean | { + [key: string]: (number); +}; }; /** * This is a model that contains a dictionary of simple arrays within composition */ export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(boolean)>; +}; }; /** * This is a model that contains a dictionary of complex arrays (composited) within composition */ export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; }; /** * This is a model with one property with a 'all of' relationship */ export type CompositionWithAllOfAndNullable = { - propA?: - | ({ - boolean?: boolean; - } & ModelWithEnum & - ModelWithArray & - ModelWithDictionary) - | null; + propA?: ({ + boolean?: boolean; +} & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; }; /** * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a base model with two simple optional properties */ export type CompositionBaseModel = { - firstName?: string; - lastname?: string; + firstName?: string; + lastname?: string; }; /** * This is a model that extends the base model */ export type CompositionExtendedModel = CompositionBaseModel & { - firstName: string; - lastname: string; - age: number; + firstName: string; + lastname: string; + age: number; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; + readonly first: { + readonly second: { + readonly third: string | null; + } | null; } | null; - } | null; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: Date; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: Date; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type File = { - readonly id?: string; - readonly updated_at?: Date; - readonly created_at?: Date; - mime: string; - readonly file?: string; + readonly id?: string; + readonly updated_at?: Date; + readonly created_at?: Date; + mime: string; + readonly file?: string; }; export type _default = { - name?: string; + name?: string; }; export type Pageable = { - page?: number; - size?: number; - sort?: Array; + page?: number; + size?: number; + sort?: Array<(string)>; }; /** * This is a free-form object without additionalProperties. */ export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: true. */ export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: {}. */ export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - [key: string]: unknown; + [key: string]: unknown; }; export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; + String?: "String"; + number?: 0; + null?: null; + withType?: "Some string"; }; /** * This is a model with one property and additionalProperties: true */ export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown; + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; }; export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = - | { - foo: SimpleParameter; - baz: number | null; - qux: number; - } - | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; - baz: number | null; - qux: number; - }; + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: SimpleParameter; + baz: number | null; + qux: number; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; +}; /** * An object that can be null */ export type NullableObject = { - foo?: string; + foo?: string; } | null; /** @@ -770,117 +695,118 @@ export type NullableObject = { export type CharactersInDescription = string; export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = - | { - foo: 'Bar'; - } - | { - foo: 'Baz'; - } - | { - foo: 'Qux'; - } - | { - content: Date; - foo: 'Quux'; - } - | { - content: [Date | string, Date | string]; - foo: 'Corge'; - }; + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: Date; + foo: 'Quux'; +} | { + content: [ + Date | string, + Date | string + ]; + foo: 'Corge'; +}; export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; + foo?: Array; + bar?: Array; }; export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; + array_strings?: Array<(string)>; + data?: ModelWithNestedArrayEnumsData; }; export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; + foo?: ModelWithNestedArrayEnumsDataFoo; }; export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; + foo: string; + readonly bar: string; + baz: string; }; -export type ModelWithConstantSizeArray = [number, number]; +export type ModelWithConstantSizeArray = [ + number, + number +]; export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string, + number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string, + number | null | string, + number | null | string, + number | null | string ]; export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | string, - number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string, + number & string, + number & string ]; export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: 1 | 3 | 6 | 12; + /** + * Период + */ + value?: 1 | 3 | 6 | 12; }; /** * Some description with `back ticks` */ export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-   * [
-   * {
-   * "resourceType": "Asset",
-   * "identifier": {
-   * "name": "${1}",
-   * "domain": {
-   * "name": "${2}",
-   * "community": {
-   * "name": "Some Community"
-   * }
-   * }
-   * },
-   * "attributes" : {
-   * "00000000-0000-0000-0000-000000003115" : [ {
-   * "value" : "${3}"
-   * } ],
-   * "00000000-0000-0000-0000-000000000222" : [ {
-   * "value" : "${4}"
-   * } ]
-   * }
-   * }
-   * ]
-   * 
- */ - template?: string; + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; }; /** @@ -894,665 +820,659 @@ export type SimpleParameter = string; export type x_Foo_Bar = string; export type $OpenApiTs = { - '/api/v{api-version}/no-tag': { - post: { - req: { - requestBody: - | ModelWithReadOnlyAndWriteOnly - | ModelWithArrayReadOnlyAndWriteOnly; - }; - res: { - 200: ModelWithReadOnlyAndWriteOnly; - }; - }; - }; - '/api/v{api-version}/simple/$count': { - get: { - res: { - /** - * Success - */ - 200: Model_From_Zendesk; - }; - }; - }; - '/api/v{api-version}/foo/{foo}/bar/{bar}': { - delete: { - req: { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameterPath}': { - post: { - req: { - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { - post: { - req: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the request form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the request header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath1?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath2?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath3?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/': { - get: { - req: { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; - }; - }; - post: { - req: { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; - }; + '/api/v{api-version}/no-tag': { + post: { + req: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; + res: { + 200: ModelWithReadOnlyAndWriteOnly; + }; + }; }; - }; - '/api/v{api-version}/descriptions/': { - post: { - req: { - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: unknown; - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: unknown; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: unknown; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: unknown; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: unknown; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: unknown; - }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; }; - }; - '/api/v{api-version}/parameters/deprecated': { - post: { - req: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + '/api/v{api-version}/foo/{foo}/bar/{bar}': { + delete: { + req: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + }; }; - }; - '/api/v{api-version}/requestBody/': { - post: { - req: { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/formData/': { - post: { - req: { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple string with default value - */ - parameterString?: string | null; - }; + '/api/v{api-version}/parameters/': { + get: { + req: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + }; + post: { + req: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; + '/api/v{api-version}/descriptions/': { + post: { + req: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; + }; + }; }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }; }; - }; - '/api/v{api-version}/no-content': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/requestBody/': { + post: { + req: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/response-and-no-content': { - get: { - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/formData/': { + post: { + req: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/response': { - get: { - res: { - 200: ModelWithString; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - put: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 201 response - */ - 201: ModelThatExtends; - /** - * Message for 202 response - */ - 202: ModelThatExtendsExtends; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/a': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/response': { + get: { + res: { + 200: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; + put: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/b': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/collectionFormat': { - get: { - req: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCsv: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySsv: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTsv: Array | null; - }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/types': { - get: { - req: { - /** - * This is a number parameter - */ - id?: number; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: { - [key: string]: unknown; - } | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is an object parameter - */ - parameterObject: { - [key: string]: unknown; - } | null; - /** - * This is a string parameter - */ - parameterString: string | null; - }; - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Response is a simple string - */ - 201: string; - /** - * Response is a simple boolean - */ - 202: boolean; - /** - * Response is a simple object - */ - 203: { - [key: string]: unknown; + '/api/v{api-version}/collectionFormat': { + get: { + req: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; + }; }; - }; }; - }; - '/api/v{api-version}/upload': { - post: { - req: { - /** - * Supply a file reference for upload - */ - file: Blob | File; - }; - res: { - 200: boolean; - }; + '/api/v{api-version}/types': { + get: { + req: { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; + }; + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; + }; + }; }; - }; - '/api/v{api-version}/file/{id}': { - get: { - req: { - id: string; - }; - res: { - /** - * Success - */ - 200: Blob | File; - }; + '/api/v{api-version}/upload': { + post: { + req: { + /** + * Supply a file reference for upload + */ + file: (Blob | File); + }; + res: { + 200: boolean; + }; + }; }; - }; - '/api/v{api-version}/complex': { - get: { - req: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; + '/api/v{api-version}/file/{id}': { + get: { + req: { + id: string; + }; + res: { + /** + * Success + */ + 200: (Blob | File); }; - }; }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; - res: { - /** - * Successful response - */ - 200: Array; - /** - * 400 `server` error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; }; - }; - '/api/v{api-version}/complex/{id}': { - put: { - req: { - 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; - }; + '/api/v{api-version}/complex': { + get: { + req: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; }; - }; - res: { - /** - * Success - */ - 200: ModelWithString; - }; }; - }; - '/api/v{api-version}/multipart': { - post: { - req: { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; + '/api/v{api-version}/complex/{id}': { + put: { + req: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; + res: { + /** + * Success + */ + 200: ModelWithString; + }; }; - }; }; - get: { - res: { - /** - * OK - */ - 200: { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; + '/api/v{api-version}/multipart': { + post: { + req: { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; + }; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; }; - }; }; - }; - '/api/v{api-version}/header': { - post: { - res: { - /** - * Successful response - */ - 200: string; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; }; - }; - '/api/v{api-version}/error': { - post: { - req: { - /** - * Status code to return - */ - status: number; - }; - res: { - /** - * Custom message: Successful response - */ - 200: unknown; - /** - * Custom message: Internal Server Error - */ - 500: unknown; - /** - * Custom message: Not Implemented - */ - 501: unknown; - /** - * Custom message: Bad Gateway - */ - 502: unknown; - /** - * Custom message: Service Unavailable - */ - 503: unknown; - }; + '/api/v{api-version}/error': { + post: { + req: { + /** + * Status code to return + */ + status: number; + }; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; + }; + }; }; - }; - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { - post: { - req: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; - res: { - /** - * Successful response - */ - 200: Array; - }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/index.ts.snap index 0339b6e31..56bade120 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap index 76a30ee48..c47f050ea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap @@ -4,13 +4,13 @@ * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: Date; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; -}; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: Date; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap index 25d54e4cd..8482663b5 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/enums.gen.ts.snap @@ -4,118 +4,118 @@ * This is a simple enum with strings */ export enum EnumWithStringsEnum { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', - _SINGLE_QUOTE_ = "'Single Quote'", - _DOUBLE_QUOTES_ = '"Double Quotes"', - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'Non-ascii: øæåôöØÆÅÔÖ字符串', + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', + _SINGLE_QUOTE_ = "'Single Quote'", + _DOUBLE_QUOTES_ = '"Double Quotes"', + NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'Non-ascii: øæåôöØÆÅÔÖ字符串' } export enum EnumWithReplacedCharactersEnum { - _SINGLE_QUOTE_ = "'Single Quote'", - _DOUBLE_QUOTES_ = '"Double Quotes"', - ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'øæåôöØÆÅÔÖ字符串', - '_3.1' = 3.1, - EMPTY_STRING = '', + _SINGLE_QUOTE_ = "'Single Quote'", + _DOUBLE_QUOTES_ = '"Double Quotes"', + ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'øæåôöØÆÅÔÖ字符串', + '_3.1' = 3.1, + EMPTY_STRING = '' } /** * This is a simple enum with numbers */ export enum EnumWithNumbersEnum { - '_1' = 1, - '_2' = 2, - '_3' = 3, - '_1.1' = 1.1, - '_1.2' = 1.2, - '_1.3' = 1.3, - '_100' = 100, - '_200' = 200, - '_300' = 300, - '_-100' = -100, - '_-200' = -200, - '_-300' = -300, - '_-1.1' = -1.1, - '_-1.2' = -1.2, - '_-1.3' = -1.3, + '_1' = 1, + '_2' = 2, + '_3' = 3, + '_1.1' = 1.1, + '_1.2' = 1.2, + '_1.3' = 1.3, + '_100' = 100, + '_200' = 200, + '_300' = 300, + '_-100' = -100, + '_-200' = -200, + '_-300' = -300, + '_-1.1' = -1.1, + '_-1.2' = -1.2, + '_-1.3' = -1.3 } /** * This is a simple enum with numbers */ export enum EnumWithExtensionsEnum { - /** - * Used when the status of something is successful - */ - CUSTOM_SUCCESS = 200, - /** - * Used when the status of something has a warning - */ - CUSTOM_WARNING = 400, - /** - * Used when the status of something has an error - */ - CUSTOM_ERROR = 500, + /** + * Used when the status of something is successful + */ + CUSTOM_SUCCESS = 200, + /** + * Used when the status of something has a warning + */ + CUSTOM_WARNING = 400, + /** + * Used when the status of something has an error + */ + CUSTOM_ERROR = 500 } export enum EnumWithXEnumNamesEnum { - zero = 0, - one = 1, - two = 2, + zero = 0, + one = 1, + two = 2 } /** * This is a simple enum with strings */ export enum FooBarEnumEnum { - SUCCESS = 'Success', - WARNING = 'Warning', - ERROR = 'Error', - ØÆÅ字符串 = 'ØÆÅ字符串', + SUCCESS = 'Success', + WARNING = 'Warning', + ERROR = 'Error', + ØÆÅ字符串 = 'ØÆÅ字符串' } /** * These are the HTTP error code enums */ export enum StatusCodeEnum { - _100 = '100', - _200_FOO = '200 FOO', - _300_FOO_BAR = '300 FOO_BAR', - _400_FOO_BAR = '400 foo-bar', - _500_FOO_BAR = '500 foo.bar', - _600_FOO_BAR = '600 foo&bar', + _100 = '100', + _200_FOO = '200 FOO', + _300_FOO_BAR = '300 FOO_BAR', + _400_FOO_BAR = '400 foo-bar', + _500_FOO_BAR = '500 foo.bar', + _600_FOO_BAR = '600 foo&bar' } export enum FooBarBazQuxEnum { - _3_0 = '3.0', + _3_0 = '3.0' } export enum Enum1Enum { - BIRD = 'Bird', - DOG = 'Dog', + BIRD = 'Bird', + DOG = 'Dog' } export enum FooEnum { - BAR = 'Bar', + BAR = 'Bar' } export enum ModelWithNestedArrayEnumsDataFooEnum { - FOO = 'foo', - BAR = 'bar', + FOO = 'foo', + BAR = 'bar' } export enum ModelWithNestedArrayEnumsDataBarEnum { - BAZ = 'baz', - QUX = 'qux', + BAZ = 'baz', + QUX = 'qux' } /** * Период */ export enum ValueEnum { - '_1' = 1, - '_3' = 3, - '_6' = 6, - '_12' = 12, -} + '_1' = 1, + '_3' = 3, + '_6' = 6, + '_12' = 12 +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/index.ts.snap index 3c11a08ea..48a15033a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/index.ts.snap @@ -1,8 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './enums.gen'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap index 5f20cd246..8e759f30b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap @@ -6,927 +6,848 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; export class DefaultService { - /** - * @throws ApiError - */ - public static serviceWithEmptyTag(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-tag', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody - * @returns ModelWithReadOnlyAndWriteOnly - * @throws ApiError - */ - public static postServiceWithEmptyTag( - data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/no-tag', - body: requestBody, - mediaType: 'application/json', - }); - } + /** + * @throws ApiError + */ + public static serviceWithEmptyTag(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-tag' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody + * @returns ModelWithReadOnlyAndWriteOnly + * @throws ApiError + */ + public static postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/no-tag', + body: requestBody, + mediaType: 'application/json' + }); + } + } export class SimpleService { - /** - * @returns Model_From_Zendesk Success - * @throws ApiError - */ - public static apiVVersionOdataControllerCount(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple/$count', - }); - } - - /** - * @throws ApiError - */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + /** + * @returns Model_From_Zendesk Success + * @throws ApiError + */ + public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple/$count' + }); + } + + /** + * @throws ApiError + */ + public static getCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static postCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static deleteCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static optionsCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static headCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static patchCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } export class ParametersService { - /** - * @param data The data for the request. - * @param data.foo foo in method - * @param data.bar bar in method - * @throws ApiError - */ - public static deleteFoo( - data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', - path: { - foo: data.foo, - bar: data.bar, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.fooAllOfEnum - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.parameterPath This is the parameter that goes into the path - * @param data.requestBody This is the parameter that goes into the body - * @param data.fooRefEnum - * @throws ApiError - */ - public static callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - cookies: { - parameterCookie: data.parameterCookie, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - foo_ref_enum: data.fooRefEnum, - foo_all_of_enum: data.fooAllOfEnum, - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.requestBody This is the parameter that goes into the body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public static callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - cookies: { - 'PARAMETER-COOKIE': data.parameterCookie, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody This is a required parameter - * @param data.parameter This is an optional parameter - * @throws ApiError - */ - public static getCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameter This is a required parameter - * @param data.requestBody This is an optional parameter - * @throws ApiError - */ - public static postCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } + /** + * @param data The data for the request. + * @param data.foo foo in method + * @param data.bar bar in method + * @throws ApiError + */ + public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: { + foo: data.foo, + bar: data.bar + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.fooAllOfEnum + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.parameterPath This is the parameter that goes into the path + * @param data.requestBody This is the parameter that goes into the body + * @param data.fooRefEnum + * @throws ApiError + */ + public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + cookies: { + parameterCookie: data.parameterCookie + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + foo_ref_enum: data.fooRefEnum, + foo_all_of_enum: data.fooAllOfEnum, + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.requestBody This is the parameter that goes into the body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + cookies: { + 'PARAMETER-COOKIE': data.parameterCookie + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody This is a required parameter + * @param data.parameter This is an optional parameter + * @throws ApiError + */ + public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameter This is a required parameter + * @param data.requestBody This is an optional parameter + * @throws ApiError + */ + public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + } export class DescriptionsService { - /** - * @param data The data for the request. - * @param data.parameterWithBreaks Testing multiline comments in string: First line - * Second line - * - * Fourth line - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work - * @throws ApiError - */ - public static callWithDescriptions( - data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/descriptions/', - query: { - parameterWithBreaks: data.parameterWithBreaks, - parameterWithBackticks: data.parameterWithBackticks, - parameterWithSlashes: data.parameterWithSlashes, - parameterWithExpressionPlaceholders: - data.parameterWithExpressionPlaceholders, - parameterWithQuotes: data.parameterWithQuotes, - parameterWithReservedCharacters: data.parameterWithReservedCharacters, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterWithBreaks Testing multiline comments in string: First line + * Second line + * + * Fourth line + * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work + * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work + * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work + * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work + * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work + * @throws ApiError + */ + public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/descriptions/', + query: { + parameterWithBreaks: data.parameterWithBreaks, + parameterWithBackticks: data.parameterWithBackticks, + parameterWithSlashes: data.parameterWithSlashes, + parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, + parameterWithQuotes: data.parameterWithQuotes, + parameterWithReservedCharacters: data.parameterWithReservedCharacters + } + }); + } + } export class DeprecatedService { - /** - * @deprecated - * @param data The data for the request. - * @param data.parameter This parameter is deprecated - * @throws ApiError - */ - public static deprecatedCall( - data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/deprecated', - headers: { - parameter: data.parameter, - }, - }); - } + /** + * @deprecated + * @param data The data for the request. + * @param data.parameter This parameter is deprecated + * @throws ApiError + */ + public static deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/deprecated', + headers: { + parameter: data.parameter + } + }); + } + } export class RequestBodyService { - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.foo A reusable request body - * @throws ApiError - */ - public static postApiRequestBody( - data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/requestBody/', - query: { - parameter: data.parameter, - }, - body: foo, - mediaType: 'application/json', - }); - } + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.foo A reusable request body + * @throws ApiError + */ + public static postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/requestBody/', + query: { + parameter: data.parameter + }, + body: foo, + mediaType: 'application/json' + }); + } + } export class FormDataService { - /** - * @param data The data for the request. - * @param data.parameter This is a reusable parameter - * @param data.formData A reusable request body - * @throws ApiError - */ - public static postApiFormData( - data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/formData/', - query: { - parameter: data.parameter, - }, - formData, - mediaType: 'multipart/form-data', - }); - } + /** + * @param data The data for the request. + * @param data.parameter This is a reusable parameter + * @param data.formData A reusable request body + * @throws ApiError + */ + public static postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/formData/', + query: { + parameter: data.parameter + }, + formData, + mediaType: 'multipart/form-data' + }); + } + } export class DefaultsService { - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public static callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public static callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public static callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + } export class DuplicateService { - /** - * @throws ApiError - */ - public static duplicateName(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName1(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName2(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/duplicate', - }); - } - - /** - * @throws ApiError - */ - public static duplicateName3(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/duplicate', - }); - } + /** + * @throws ApiError + */ + public static duplicateName(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName1(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName2(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/duplicate' + }); + } + + /** + * @throws ApiError + */ + public static duplicateName3(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/duplicate' + }); + } + } export class NoContentService { - /** - * @returns void Success - * @throws ApiError - */ - public static callWithNoContentResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/no-content', - }); - } - - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/no-content' + }); + } + + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + } export class ResponseService { - /** - * @returns number Response is a simple number - * @returns void Success - * @throws ApiError - */ - public static callWithResponseAndNoContentResponse(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/response-and-no-content', - }); - } - - /** - * @returns ModelWithString - * @throws ApiError - */ - public static callWithResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/response', - }); - } - - /** - * @returns ModelWithString Message for default response - * @throws ApiError - */ - public static callWithDuplicateResponses(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/response']['post']['res'][200] - > { - return __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', - }, - }); - } - - /** - * @returns unknown 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 callWithResponses(): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] - | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202] - > { - return __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', - }, - }); - } + /** + * @returns number Response is a simple number + * @returns void Success + * @throws ApiError + */ + public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/response-and-no-content' + }); + } + + /** + * @returns ModelWithString + * @throws ApiError + */ + public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/response' + }); + } + + /** + * @returns ModelWithString Message for default response + * @throws ApiError + */ + public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + return __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' + } + }); + } + + /** + * @returns unknown 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 callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + return __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' + } + }); + } + } export class MultipleTags1Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags2Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyA(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/a', - }); - } - - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/a' + }); + } + + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class MultipleTags3Service { - /** - * @returns void Success - * @throws ApiError - */ - public static dummyB(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multiple-tags/b', - }); - } + /** + * @returns void Success + * @throws ApiError + */ + public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multiple-tags/b' + }); + } + } export class CollectionFormatService { - /** - * @param data The data for the request. - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) - * @throws ApiError - */ - public static collectionFormat( - data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/collectionFormat', - query: { - parameterArrayCSV: data.parameterArrayCsv, - parameterArraySSV: data.parameterArraySsv, - parameterArrayTSV: data.parameterArrayTsv, - parameterArrayPipes: data.parameterArrayPipes, - parameterArrayMulti: data.parameterArrayMulti, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) + * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) + * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) + * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) + * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) + * @throws ApiError + */ + public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/collectionFormat', + query: { + parameterArrayCSV: data.parameterArrayCsv, + parameterArraySSV: data.parameterArraySsv, + parameterArrayTSV: data.parameterArrayTsv, + parameterArrayPipes: data.parameterArrayPipes, + parameterArrayMulti: data.parameterArrayMulti + } + }); + } + } export class TypesService { - /** - * @param data The data for the request. - * @param data.parameterArray This is an array parameter - * @param data.parameterDictionary This is a dictionary parameter - * @param data.parameterEnum This is an enum parameter - * @param data.parameterNumber This is a number parameter - * @param data.parameterString This is a string parameter - * @param data.parameterBoolean This is a boolean parameter - * @param data.parameterObject This is an object parameter - * @param data.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 unknown Response is a simple object - * @throws ApiError - */ - public static types( - data: $OpenApiTs['/api/v{api-version}/types']['get']['req'], - ): CancelablePromise< - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][200] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] - | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/types', - path: { - id: data.id, - }, - query: { - parameterNumber: data.parameterNumber, - parameterString: data.parameterString, - parameterBoolean: data.parameterBoolean, - parameterObject: data.parameterObject, - parameterArray: data.parameterArray, - parameterDictionary: data.parameterDictionary, - parameterEnum: data.parameterEnum, - }, - }); - } + /** + * @param data The data for the request. + * @param data.parameterArray This is an array parameter + * @param data.parameterDictionary This is a dictionary parameter + * @param data.parameterEnum This is an enum parameter + * @param data.parameterNumber This is a number parameter + * @param data.parameterString This is a string parameter + * @param data.parameterBoolean This is a boolean parameter + * @param data.parameterObject This is an object parameter + * @param data.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 unknown Response is a simple object + * @throws ApiError + */ + public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/types', + path: { + id: data.id + }, + query: { + parameterNumber: data.parameterNumber, + parameterString: data.parameterString, + parameterBoolean: data.parameterBoolean, + parameterObject: data.parameterObject, + parameterArray: data.parameterArray, + parameterDictionary: data.parameterDictionary, + parameterEnum: data.parameterEnum + } + }); + } + } export class UploadService { - /** - * @param data The data for the request. - * @param data.file Supply a file reference for upload - * @returns boolean - * @throws ApiError - */ - public static uploadFile( - data: $OpenApiTs['/api/v{api-version}/upload']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/upload']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/upload', - formData: { - file: data.file, - }, - }); - } + /** + * @param data The data for the request. + * @param data.file Supply a file reference for upload + * @returns boolean + * @throws ApiError + */ + public static uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/upload', + formData: { + file: data.file + } + }); + } + } export class FileResponseService { - /** - * @param data The data for the request. - * @param data.id - * @returns binary Success - * @throws ApiError - */ - public static fileResponse( - data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/file/{id}', - path: { - id: data.id, - }, - }); - } + /** + * @param data The data for the request. + * @param data.id + * @returns binary Success + * @throws ApiError + */ + public static fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/file/{id}', + path: { + id: data.id + } + }); + } + } export class ComplexService { - /** - * @param data The data for the request. - * @param data.parameterObject Parameter containing object - * @param data.parameterReference Parameter containing reference - * @returns ModelWithString Successful response - * @throws ApiError - */ - public static complexTypes( - data: $OpenApiTs['/api/v{api-version}/complex']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/complex', - query: { - parameterObject: data.parameterObject, - parameterReference: data.parameterReference, - }, - errors: { - 400: '400 `server` error', - 500: '500 server error', - }, - }); - } - - /** - * @param data The data for the request. - * @param data.id - * @param data.requestBody - * @returns ModelWithString Success - * @throws ApiError - */ - public static complexParams( - data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200] - > { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/complex/{id}', - path: { - id: data.id, - }, - body: requestBody, - mediaType: 'application/json-patch+json', - }); - } + /** + * @param data The data for the request. + * @param data.parameterObject Parameter containing object + * @param data.parameterReference Parameter containing reference + * @returns ModelWithString Successful response + * @throws ApiError + */ + public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/complex', + query: { + parameterObject: data.parameterObject, + parameterReference: data.parameterReference + }, + errors: { + 400: '400 \`server\` error', + 500: '500 server error' + } + }); + } + + /** + * @param data The data for the request. + * @param data.id + * @param data.requestBody + * @returns ModelWithString Success + * @throws ApiError + */ + public static complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/complex/{id}', + path: { + id: data.id + }, + body: requestBody, + mediaType: 'application/json-patch+json' + }); + } + } export class MultipartService { - /** - * @param data The data for the request. - * @param data.formData - * @throws ApiError - */ - public static multipartRequest( - data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/multipart', - formData, - mediaType: 'multipart/form-data', - }); - } - - /** - * @returns unknown OK - * @throws ApiError - */ - public static multipartResponse(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/multipart', - }); - } + /** + * @param data The data for the request. + * @param data.formData + * @throws ApiError + */ + public static multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/multipart', + formData, + mediaType: 'multipart/form-data' + }); + } + + /** + * @returns unknown OK + * @throws ApiError + */ + public static multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/multipart' + }); + } + } export class HeaderService { - /** - * @returns string Successful response - * @throws ApiError - */ - public static callWithResultFromHeader(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/header']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/header', - responseHeader: 'operation-location', - errors: { - 400: '400 server error', - 500: '500 server error', - }, - }); - } + /** + * @returns string Successful response + * @throws ApiError + */ + public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/header', + responseHeader: 'operation-location', + errors: { + 400: '400 server error', + 500: '500 server error' + } + }); + } + } export class ErrorService { - /** - * @param data The data for the request. - * @param data.status Status code to return - * @returns unknown Custom message: Successful response - * @throws ApiError - */ - public static testErrorCode( - data: $OpenApiTs['/api/v{api-version}/error']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/error']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/error', - query: { - status: data.status, - }, - errors: { - 500: 'Custom message: Internal Server Error', - 501: 'Custom message: Not Implemented', - 502: 'Custom message: Bad Gateway', - 503: 'Custom message: Service Unavailable', - }, - }); - } + /** + * @param data The data for the request. + * @param data.status Status code to return + * @returns unknown Custom message: Successful response + * @throws ApiError + */ + public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/error', + query: { + status: data.status + }, + errors: { + 500: 'Custom message: Internal Server Error', + 501: 'Custom message: Not Implemented', + 502: 'Custom message: Bad Gateway', + 503: 'Custom message: Service Unavailable' + } + }); + } + } export class NonAsciiÆøåÆøÅöôêÊService { - /** - * @param data The data for the request. - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response - * @throws ApiError - */ - public static nonAsciiæøåÆøÅöôêÊ字符串( - data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200] - > { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - query: { - nonAsciiParamæøåÆØÅöôêÊ: data.nonAsciiParamæøåÆøÅöôêÊ, - }, - }); - } -} + /** + * @param data The data for the request. + * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param + * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response + * @throws ApiError + */ + public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + query: { + 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap index f6f2afd4d..5c29a38ea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap @@ -69,7 +69,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -84,40 +84,14 @@ export type SimpleStringWithPattern = string | null; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; -export type EnumWithReplacedCharacters = - | "'Single Quote'" - | '"Double Quotes"' - | 'øæåôöØÆÅÔÖ字符串' - | 3.1 - | ''; +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -134,17 +108,17 @@ export type EnumWithXEnumNames = 0 | 1 | 2; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -160,123 +134,117 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: camelCaseCommentWithBreaks; - bar?: string; + foo?: camelCaseCommentWithBreaks; + bar?: string; }>; /** * This is a simple array with any of properties */ -export type ArrayWithAnyOfProperties = Array< - | { - foo?: string; - } - | { - bar?: string; - } ->; +export type ArrayWithAnyOfProperties = Array<({ + foo?: string; +} | { + bar?: string; +})>; export type AnyOfAnyAndNull = { - data?: unknown | null; + data?: unknown | null; }; /** * This is a simple array with any of properties */ export type AnyOfArrays = { - results?: Array< - | { - foo?: string; - } - | { - bar?: string; - } - >; + results?: Array<({ + foo?: string; +} | { + bar?: string; +})>; }; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: string; - [key: string]: string | undefined; + foo?: string; + [key: string]: (string) | undefined; }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** @@ -288,119 +256,113 @@ export type Model_From_Zendesk = string; * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum with escaped name */ export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; + 'foo-bar-baz-qux'?: '3.0'; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** @@ -408,57 +370,50 @@ export type ModelWithDictionary = { * @deprecated */ export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * Circle */ export type ModelCircle = { - kind: 'circle'; - radius?: number; + kind: 'circle'; + radius?: number; }; /** * Square */ export type ModelSquare = { - kind: 'square'; - sideLength?: number; + kind: 'square'; + sideLength?: number; }; /** @@ -470,298 +425,268 @@ export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithAnyOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * This is a model with nested 'any of' property with a type null */ export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; + propA?: Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; }; export type Enum1 = 'Bird' | 'Dog'; -export type ConstValue = 'ConstValue'; +export type ConstValue = "ConstValue"; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithNestedAnyOfAndNull = { - propA?: Array | null; + propA?: Array<(Enum1 | ConstValue)> | null; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a model that contains a simple dictionary within composition */ export type CompositionWithOneOfAndSimpleDictionary = { - propA?: - | boolean - | { - [key: string]: number; - }; + propA?: boolean | { + [key: string]: (number); +}; }; /** * This is a model that contains a dictionary of simple arrays within composition */ export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(boolean)>; +}; }; /** * This is a model that contains a dictionary of complex arrays (composited) within composition */ export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; }; /** * This is a model with one property with a 'all of' relationship */ export type CompositionWithAllOfAndNullable = { - propA?: - | ({ - boolean?: boolean; - } & ModelWithEnum & - ModelWithArray & - ModelWithDictionary) - | null; + propA?: ({ + boolean?: boolean; +} & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; }; /** * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a base model with two simple optional properties */ export type CompositionBaseModel = { - firstName?: string; - lastname?: string; + firstName?: string; + lastname?: string; }; /** * This is a model that extends the base model */ export type CompositionExtendedModel = CompositionBaseModel & { - firstName: string; - lastname: string; - age: number; + firstName: string; + lastname: string; + age: number; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; + readonly first: { + readonly second: { + readonly third: string | null; + } | null; } | null; - } | null; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; }; export type _default = { - name?: string; + name?: string; }; export type Pageable = { - page?: number; - size?: number; - sort?: Array; + page?: number; + size?: number; + sort?: Array<(string)>; }; /** * This is a free-form object without additionalProperties. */ export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: true. */ export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: {}. */ export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - [key: string]: unknown; + [key: string]: unknown; }; export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; + String?: "String"; + number?: 0; + null?: null; + withType?: "Some string"; }; /** * This is a model with one property and additionalProperties: true */ export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown; + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; }; export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = - | { - foo: SimpleParameter; - baz: number | null; - qux: number; - } - | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; - baz: number | null; - qux: number; - }; + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: SimpleParameter; + baz: number | null; + qux: number; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; +}; /** * An object that can be null */ export type NullableObject = { - foo?: string; + foo?: string; } | null; /** @@ -770,117 +695,118 @@ export type NullableObject = { export type CharactersInDescription = string; export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = - | { - foo: 'Bar'; - } - | { - foo: 'Baz'; - } - | { - foo: 'Qux'; - } - | { - content: string; - foo: 'Quux'; - } - | { - content: [string, string]; - foo: 'Corge'; - }; + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; + foo?: Array; + bar?: Array; }; export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; + array_strings?: Array<(string)>; + data?: ModelWithNestedArrayEnumsData; }; export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; + foo?: ModelWithNestedArrayEnumsDataFoo; }; export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; + foo: string; + readonly bar: string; + baz: string; }; -export type ModelWithConstantSizeArray = [number, number]; +export type ModelWithConstantSizeArray = [ + number, + number +]; export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string, + number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string, + number | null | string, + number | null | string, + number | null | string ]; export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | string, - number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string, + number & string, + number & string ]; export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: 1 | 3 | 6 | 12; + /** + * Период + */ + value?: 1 | 3 | 6 | 12; }; /** * Some description with `back ticks` */ export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-   * [
-   * {
-   * "resourceType": "Asset",
-   * "identifier": {
-   * "name": "${1}",
-   * "domain": {
-   * "name": "${2}",
-   * "community": {
-   * "name": "Some Community"
-   * }
-   * }
-   * },
-   * "attributes" : {
-   * "00000000-0000-0000-0000-000000003115" : [ {
-   * "value" : "${3}"
-   * } ],
-   * "00000000-0000-0000-0000-000000000222" : [ {
-   * "value" : "${4}"
-   * } ]
-   * }
-   * }
-   * ]
-   * 
- */ - template?: string; + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; }; /** @@ -894,665 +820,659 @@ export type SimpleParameter = string; export type x_Foo_Bar = string; export type $OpenApiTs = { - '/api/v{api-version}/no-tag': { - post: { - req: { - requestBody: - | ModelWithReadOnlyAndWriteOnly - | ModelWithArrayReadOnlyAndWriteOnly; - }; - res: { - 200: ModelWithReadOnlyAndWriteOnly; - }; - }; - }; - '/api/v{api-version}/simple/$count': { - get: { - res: { - /** - * Success - */ - 200: Model_From_Zendesk; - }; - }; - }; - '/api/v{api-version}/foo/{foo}/bar/{bar}': { - delete: { - req: { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; - }; - }; - }; - '/api/v{api-version}/parameters/{parameterPath}': { - post: { - req: { - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath: string | null; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { - post: { - req: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that goes into the cookie - */ - parameterCookie: string | null; - /** - * This is the parameter that goes into the request form data - */ - parameterForm: string | null; - /** - * This is the parameter that goes into the request header - */ - parameterHeader: string | null; - /** - * This is the parameter that goes into the path - */ - parameterPath1?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath2?: string; - /** - * This is the parameter that goes into the path - */ - parameterPath3?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string | null; - /** - * This is the parameter that goes into the body - */ - requestBody: ModelWithString | null; - }; - }; - }; - '/api/v{api-version}/parameters/': { - get: { - req: { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; - }; - }; - post: { - req: { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; - }; + '/api/v{api-version}/no-tag': { + post: { + req: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; + res: { + 200: ModelWithReadOnlyAndWriteOnly; + }; + }; }; - }; - '/api/v{api-version}/descriptions/': { - post: { - req: { - /** - * Testing backticks in string: `backticks` and ```multiple backticks``` should work - */ - parameterWithBackticks?: unknown; - /** - * Testing multiline comments in string: First line - * Second line - * - * Fourth line - */ - parameterWithBreaks?: unknown; - /** - * Testing expression placeholders in string: ${expression} should work - */ - parameterWithExpressionPlaceholders?: unknown; - /** - * Testing quotes in string: 'single quote''' and "double quotes""" should work - */ - parameterWithQuotes?: unknown; - /** - * Testing reserved characters in string: * inline * and ** inline ** should work - */ - parameterWithReservedCharacters?: unknown; - /** - * Testing slashes in string: \backwards\\\ and /forwards/// should work - */ - parameterWithSlashes?: unknown; - }; + '/api/v{api-version}/simple/$count': { + get: { + res: { + /** + * Success + */ + 200: Model_From_Zendesk; + }; + }; }; - }; - '/api/v{api-version}/parameters/deprecated': { - post: { - req: { - /** - * This parameter is deprecated - * @deprecated - */ - parameter: DeprecatedModel | null; - }; + '/api/v{api-version}/foo/{foo}/bar/{bar}': { + delete: { + req: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + }; }; - }; - '/api/v{api-version}/requestBody/': { - post: { - req: { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameterPath}': { + post: { + req: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/formData/': { - post: { - req: { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; - }; + '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}': { + post: { + req: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; + }; + }; }; - }; - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple string with default value - */ - parameterString?: string | null; - }; + '/api/v{api-version}/parameters/': { + get: { + req: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + }; + post: { + req: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; + '/api/v{api-version}/descriptions/': { + post: { + req: { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; + }; + }; }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; + '/api/v{api-version}/parameters/deprecated': { + post: { + req: { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + }; }; - }; - '/api/v{api-version}/no-content': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/requestBody/': { + post: { + req: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/response-and-no-content': { - get: { - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/formData/': { + post: { + req: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; }; - }; - '/api/v{api-version}/response': { - get: { - res: { - 200: ModelWithString; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/no-content': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - put: { - res: { - /** - * Message for default response - */ - 200: ModelWithString; - /** - * Message for 201 response - */ - 201: ModelThatExtends; - /** - * Message for 202 response - */ - 202: ModelThatExtendsExtends; - /** - * Message for 500 error - */ - 500: ModelWithStringError; - /** - * Message for 501 error - */ - 501: ModelWithStringError; - /** - * Message for 502 error - */ - 502: ModelWithStringError; - }; + '/api/v{api-version}/multiple-tags/response-and-no-content': { + get: { + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/a': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/response': { + get: { + res: { + 200: ModelWithString; + }; + }; + post: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; + put: { + res: { + /** + * Message for default response + */ + 200: ModelWithString; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + }; + }; }; - }; - '/api/v{api-version}/multiple-tags/b': { - get: { - res: { - /** - * Success - */ - 204: void; - }; + '/api/v{api-version}/multiple-tags/a': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/collectionFormat': { - get: { - req: { - /** - * This is an array parameter that is sent as csv format (comma-separated values) - */ - parameterArrayCsv: Array | null; - /** - * This is an array parameter that is sent as multi format (multiple parameter instances) - */ - parameterArrayMulti: Array | null; - /** - * This is an array parameter that is sent as pipes format (pipe-separated values) - */ - parameterArrayPipes: Array | null; - /** - * This is an array parameter that is sent as ssv format (space-separated values) - */ - parameterArraySsv: Array | null; - /** - * This is an array parameter that is sent as tsv format (tab-separated values) - */ - parameterArrayTsv: Array | null; - }; + '/api/v{api-version}/multiple-tags/b': { + get: { + res: { + /** + * Success + */ + 204: void; + }; + }; }; - }; - '/api/v{api-version}/types': { - get: { - req: { - /** - * This is a number parameter - */ - id?: number; - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a boolean parameter - */ - parameterBoolean: boolean | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: { - [key: string]: unknown; - } | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber: number; - /** - * This is an object parameter - */ - parameterObject: { - [key: string]: unknown; - } | null; - /** - * This is a string parameter - */ - parameterString: string | null; - }; - res: { - /** - * Response is a simple number - */ - 200: number; - /** - * Response is a simple string - */ - 201: string; - /** - * Response is a simple boolean - */ - 202: boolean; - /** - * Response is a simple object - */ - 203: { - [key: string]: unknown; + '/api/v{api-version}/collectionFormat': { + get: { + req: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; + }; }; - }; }; - }; - '/api/v{api-version}/upload': { - post: { - req: { - /** - * Supply a file reference for upload - */ - file: Blob | File; - }; - res: { - 200: boolean; - }; + '/api/v{api-version}/types': { + get: { + req: { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; + }; + res: { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; + }; + }; }; - }; - '/api/v{api-version}/file/{id}': { - get: { - req: { - id: string; - }; - res: { - /** - * Success - */ - 200: Blob | File; - }; + '/api/v{api-version}/upload': { + post: { + req: { + /** + * Supply a file reference for upload + */ + file: (Blob | File); + }; + res: { + 200: boolean; + }; + }; }; - }; - '/api/v{api-version}/complex': { - get: { - req: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; + '/api/v{api-version}/file/{id}': { + get: { + req: { + id: string; + }; + res: { + /** + * Success + */ + 200: (Blob | File); }; - }; }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; - res: { - /** - * Successful response - */ - 200: Array; - /** - * 400 `server` error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; }; - }; - '/api/v{api-version}/complex/{id}': { - put: { - req: { - 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; - }; + '/api/v{api-version}/complex': { + get: { + req: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + res: { + /** + * Successful response + */ + 200: Array; + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; }; - }; - res: { - /** - * Success - */ - 200: ModelWithString; - }; }; - }; - '/api/v{api-version}/multipart': { - post: { - req: { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; + '/api/v{api-version}/complex/{id}': { + put: { + req: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; + res: { + /** + * Success + */ + 200: ModelWithString; + }; }; - }; }; - get: { - res: { - /** - * OK - */ - 200: { - file?: Blob | File; - metadata?: { - foo?: string; - bar?: string; - }; + '/api/v{api-version}/multipart': { + post: { + req: { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; + }; + }; + get: { + res: { + /** + * OK + */ + 200: { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; + }; + }; }; - }; }; - }; - '/api/v{api-version}/header': { - post: { - res: { - /** - * Successful response - */ - 200: string; - /** - * 400 server error - */ - 400: unknown; - /** - * 500 server error - */ - 500: unknown; - }; + '/api/v{api-version}/header': { + post: { + res: { + /** + * Successful response + */ + 200: string; + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; + }; + }; }; - }; - '/api/v{api-version}/error': { - post: { - req: { - /** - * Status code to return - */ - status: number; - }; - res: { - /** - * Custom message: Successful response - */ - 200: unknown; - /** - * Custom message: Internal Server Error - */ - 500: unknown; - /** - * Custom message: Not Implemented - */ - 501: unknown; - /** - * Custom message: Bad Gateway - */ - 502: unknown; - /** - * Custom message: Service Unavailable - */ - 503: unknown; - }; + '/api/v{api-version}/error': { + post: { + req: { + /** + * Status code to return + */ + status: number; + }; + res: { + /** + * Custom message: Successful response + */ + 200: unknown; + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; + }; + }; }; - }; - '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { - post: { - req: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; - res: { - /** - * Successful response - */ - 200: Array; - }; + '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串': { + post: { + req: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + res: { + /** + * Successful response + */ + 200: Array; + }; + }; }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/index.ts.snap index 832d67208..3e1f0b35c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/index.ts.snap @@ -1,7 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap index 4d65152d9..1736b514e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap @@ -6,100 +6,80 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; 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 callWithDefaultParameters( - parameterString: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterString'] = 'Hello World!', - parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterNumber'] = 123, - parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterBoolean'] = true, - parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterEnum'] = 'Success', - parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterModel'] = { - prop: 'Hello World!', - }, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString, - parameterNumber, - parameterBoolean, - parameterEnum, - parameterModel, - }, - }); - } - - /** - * @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: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterString'] = 'Hello World!', - parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterNumber'] = 123, - parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterBoolean'] = true, - parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterEnum'] = 'Success', - parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterModel'] = { - prop: 'Hello World!', - }, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString, - parameterNumber, - parameterBoolean, - parameterEnum, - parameterModel, - }, - }); - } - - /** - * @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 callToTestOrderOfParams( - parameterStringWithNoDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithNoDefault'], - parameterOptionalStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithDefault'] = 'Hello World!', - parameterOptionalStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithEmptyDefault'] = '', - parameterOptionalStringWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithNoDefault'], - parameterStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithDefault'] = 'Hello World!', - parameterStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithEmptyDefault'] = '', - parameterStringNullableWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithNoDefault'], - parameterStringNullableWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithDefault'] = null, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault, - parameterStringWithDefault, - parameterStringWithEmptyDefault, - parameterStringWithNoDefault, - parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault, - }, - }); - } -} + /** + * @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 callWithDefaultParameters(parameterString: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterString'] = 'Hello World!', parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterNumber'] = 123, parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterBoolean'] = true, parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterEnum'] = 'Success', parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterModel'] = { + prop: 'Hello World!' + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString, + parameterNumber, + parameterBoolean, + parameterEnum, + parameterModel + } + }); + } + + /** + * @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: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterString'] = 'Hello World!', parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterNumber'] = 123, parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterBoolean'] = true, parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterEnum'] = 'Success', parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterModel'] = { + prop: 'Hello World!' + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString, + parameterNumber, + parameterBoolean, + parameterEnum, + parameterModel + } + }); + } + + /** + * @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 callToTestOrderOfParams(parameterStringWithNoDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithNoDefault'], parameterOptionalStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithDefault'] = 'Hello World!', parameterOptionalStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithEmptyDefault'] = '', parameterOptionalStringWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithNoDefault'], parameterStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithDefault'] = 'Hello World!', parameterStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithEmptyDefault'] = '', parameterStringNullableWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithNoDefault'], parameterStringNullableWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithDefault'] = null): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault, + parameterStringWithDefault, + parameterStringWithEmptyDefault, + parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap index d5452b2bb..896303a61 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap @@ -4,107 +4,107 @@ * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; export type $OpenApiTs = { - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber: number | null; - /** - * This is a simple string with default value - */ - parameterString: string | null; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber: number | null; + /** + * This is a simple string with default value + */ + parameterString: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber: number; + /** + * This is a simple string that is optional with default value + */ + parameterString: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber: number; - /** - * This is a simple string that is optional with default value - */ - parameterString: string; - }; - }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; - }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap index 0339b6e31..56bade120 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap index a7cd5a412..adff38410 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap @@ -69,7 +69,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob | File; +export type SimpleFile = (Blob | File); /** * This is a simple reference @@ -84,40 +84,14 @@ export type SimpleStringWithPattern = string | null; /** * This is a simple enum with strings */ -export type EnumWithStrings = - | 'Success' - | 'Warning' - | 'Error' - | "'Single Quote'" - | '"Double Quotes"' - | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | "'Single Quote'" | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; -export type EnumWithReplacedCharacters = - | "'Single Quote'" - | '"Double Quotes"' - | 'øæåôöØÆÅÔÖ字符串' - | 3.1 - | ''; +export type EnumWithReplacedCharacters = "'Single Quote'" | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; /** * This is a simple enum with numbers */ -export type EnumWithNumbers = - | 1 - | 2 - | 3 - | 1.1 - | 1.2 - | 1.3 - | 100 - | 200 - | 300 - | -100 - | -200 - | -300 - | -1.1 - | -1.2 - | -1.3; +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; /** * Success=1,Warning=2,Error=3 @@ -134,17 +108,17 @@ export type EnumWithXEnumNames = 0 | 1 | 2; /** * This is a simple array with numbers */ -export type ArrayWithNumbers = Array; +export type ArrayWithNumbers = Array<(number)>; /** * This is a simple array with booleans */ -export type ArrayWithBooleans = Array; +export type ArrayWithBooleans = Array<(boolean)>; /** * This is a simple array with strings */ -export type ArrayWithStrings = Array; +export type ArrayWithStrings = Array<(string)>; /** * This is a simple array with references @@ -160,123 +134,117 @@ export type ArrayWithArray = Array>; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: camelCaseCommentWithBreaks; - bar?: string; + foo?: camelCaseCommentWithBreaks; + bar?: string; }>; /** * This is a simple array with any of properties */ -export type ArrayWithAnyOfProperties = Array< - | { - foo?: string; - } - | { - bar?: string; - } ->; +export type ArrayWithAnyOfProperties = Array<({ + foo?: string; +} | { + bar?: string; +})>; export type AnyOfAnyAndNull = { - data?: unknown | null; + data?: unknown | null; }; /** * This is a simple array with any of properties */ export type AnyOfArrays = { - results?: Array< - | { - foo?: string; - } - | { - bar?: string; - } - >; + results?: Array<({ + foo?: string; +} | { + bar?: string; +})>; }; /** * This is a string dictionary */ export type DictionaryWithString = { - [key: string]: string; + [key: string]: (string); }; export type DictionaryWithPropertiesAndAdditionalProperties = { - foo?: string; - [key: string]: string | undefined; + foo?: string; + [key: string]: (string) | undefined; }; /** * This is a string reference */ export type DictionaryWithReference = { - [key: string]: ModelWithString; + [key: string]: ModelWithString; }; /** * This is a complex dictionary */ export type DictionaryWithArray = { - [key: string]: Array; + [key: string]: Array; }; /** * This is a string dictionary */ export type DictionaryWithDictionary = { - [key: string]: { - [key: string]: string; - }; + [key: string]: { + [key: string]: (string); + }; }; /** * This is a complex dictionary */ export type DictionaryWithProperties = { - [key: string]: { - foo?: string; - bar?: string; - }; + [key: string]: { + foo?: string; + bar?: string; + }; }; /** * This is a model with one number property */ export type ModelWithInteger = { - /** - * This is a simple number property - */ - prop?: number; + /** + * This is a simple number property + */ + prop?: number; }; /** * This is a model with one boolean property */ export type ModelWithBoolean = { - /** - * This is a simple boolean property - */ - prop?: boolean; + /** + * This is a simple boolean property + */ + prop?: boolean; }; /** * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** @@ -288,119 +256,113 @@ export type Model_From_Zendesk = string; * This is a model with one string property */ export type ModelWithNullableString = { - /** - * This is a simple string property - */ - nullableProp1?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp1: string | null; - /** - * This is a simple string property - */ - nullableProp2?: string | null; - /** - * This is a simple string property - */ - nullableRequiredProp2: string | null; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one enum */ export type ModelWithEnum = { - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; - /** - * These are the HTTP error code enums - */ - statusCode?: - | '100' - | '200 FOO' - | '300 FOO_BAR' - | '400 foo-bar' - | '500 foo.bar' - | '600 foo&bar'; - /** - * Simple boolean enum - */ - bool?: boolean; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: boolean; }; /** * This is a model with one enum with escaped name */ export type ModelWithEnumWithHyphen = { - 'foo-bar-baz-qux'?: '3.0'; + 'foo-bar-baz-qux'?: '3.0'; }; /** * This is a model with one enum */ export type ModelWithEnumFromDescription = { - /** - * Success=1,Warning=2,Error=3 - */ - test?: number; + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; }; /** * This is a model with nested enums */ export type ModelWithNestedEnums = { - dictionaryWithEnum?: { - [key: string]: 'Success' | 'Warning' | 'Error'; - }; - dictionaryWithEnumFromDescription?: { - [key: string]: number; - }; - arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; - arrayWithDescription?: Array; - /** - * This is a simple enum with strings - */ - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + dictionaryWithEnum?: { + [key: string]: ('Success' | 'Warning' | 'Error'); + }; + dictionaryWithEnumFromDescription?: { + [key: string]: (number); + }; + arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; + arrayWithDescription?: Array<(number)>; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; }; /** * This is a model with one property containing a reference */ export type ModelWithReference = { - prop?: ModelWithProperties; + prop?: ModelWithProperties; }; /** * This is a model with one property containing an array */ export type ModelWithArrayReadOnlyAndWriteOnly = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing an array */ export type ModelWithArray = { - prop?: Array; - propWithFile?: Array; - propWithNumber?: Array; + prop?: Array; + propWithFile?: Array<((Blob | File))>; + propWithNumber?: Array<(number)>; }; /** * This is a model with one property containing a dictionary */ export type ModelWithDictionary = { - prop?: { - [key: string]: string; - }; + prop?: { + [key: string]: (string); + }; }; /** @@ -408,57 +370,50 @@ export type ModelWithDictionary = { * @deprecated */ export type DeprecatedModel = { - /** - * This is a deprecated property - * @deprecated - */ - prop?: string; + /** + * This is a deprecated property + * @deprecated + */ + prop?: string; }; /** * This is a model with one property containing a circular reference */ export type ModelWithCircularReference = { - prop?: ModelWithCircularReference; + prop?: ModelWithCircularReference; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * Circle */ export type ModelCircle = { - kind: 'circle'; - radius?: number; + kind: 'circle'; + radius?: number; }; /** * Square */ export type ModelSquare = { - kind: 'square'; - sideLength?: number; + kind: 'square'; + sideLength?: number; }; /** @@ -470,298 +425,268 @@ export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOf = { - propA?: - | ModelWithString - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary; + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; }; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithAnyOfAnonymous = { - propA?: - | { - propA?: string; - } - | string - | number; + propA?: { + propA?: string; +} | string | number; }; /** * This is a model with nested 'any of' property with a type null */ export type CompositionWithNestedAnyAndTypeNull = { - propA?: Array | Array; + propA?: Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>; }; export type Enum1 = 'Bird' | 'Dog'; -export type ConstValue = 'ConstValue'; +export type ConstValue = "ConstValue"; /** * This is a model with one property with a 'any of' relationship where the options are not $ref */ export type CompositionWithNestedAnyOfAndNull = { - propA?: Array | null; + propA?: Array<(Enum1 | ConstValue)> | null; }; /** * This is a model with one property with a 'one of' relationship */ export type CompositionWithOneOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a model that contains a simple dictionary within composition */ export type CompositionWithOneOfAndSimpleDictionary = { - propA?: - | boolean - | { - [key: string]: number; - }; + propA?: boolean | { + [key: string]: (number); +}; }; /** * This is a model that contains a dictionary of simple arrays within composition */ export type CompositionWithOneOfAndSimpleArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(boolean)>; +}; }; /** * This is a model that contains a dictionary of complex arrays (composited) within composition */ export type CompositionWithOneOfAndComplexArrayDictionary = { - propA?: - | boolean - | { - [key: string]: Array; - }; + propA?: boolean | { + [key: string]: Array<(number | string)>; +}; }; /** * This is a model with one property with a 'all of' relationship */ export type CompositionWithAllOfAndNullable = { - propA?: - | ({ - boolean?: boolean; - } & ModelWithEnum & - ModelWithArray & - ModelWithDictionary) - | null; + propA?: ({ + boolean?: boolean; +} & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; }; /** * This is a model with one property with a 'any of' relationship */ export type CompositionWithAnyOfAndNullable = { - propA?: - | { - boolean?: boolean; - } - | ModelWithEnum - | ModelWithArray - | ModelWithDictionary - | null; + propA?: { + boolean?: boolean; +} | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; }; /** * This is a base model with two simple optional properties */ export type CompositionBaseModel = { - firstName?: string; - lastname?: string; + firstName?: string; + lastname?: string; }; /** * This is a model that extends the base model */ export type CompositionExtendedModel = CompositionBaseModel & { - firstName: string; - lastname: string; - age: number; + firstName: string; + lastname: string; + age: number; }; /** * This is a model with one nested property */ export type ModelWithProperties = { - required: string; - readonly requiredAndReadOnly: string; - requiredAndNullable: string | null; - string?: string; - number?: number; - boolean?: boolean; - reference?: ModelWithString; - 'property with space'?: string; - default?: string; - try?: string; - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; }; /** * This is a model with one nested property */ export type ModelWithNestedProperties = { - readonly first: { - readonly second: { - readonly third: string | null; + readonly first: { + readonly second: { + readonly third: string | null; + } | null; } | null; - } | null; }; /** * This is a model with duplicated properties */ export type ModelWithDuplicateProperties = { - prop?: ModelWithString; + prop?: ModelWithString; }; /** * This is a model with ordered properties */ export type ModelWithOrderedProperties = { - zebra?: string; - apple?: string; - hawaii?: string; + zebra?: string; + apple?: string; + hawaii?: string; }; /** * This is a model with duplicated imports */ export type ModelWithDuplicateImports = { - propA?: ModelWithString; - propB?: ModelWithString; - propC?: ModelWithString; + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; }; /** * This is a model that extends another model */ export type ModelThatExtends = ModelWithString & { - propExtendsA?: string; - propExtendsB?: ModelWithString; + propExtendsA?: string; + propExtendsB?: ModelWithString; }; /** * This is a model that extends another model */ -export type ModelThatExtendsExtends = ModelWithString & - ModelThatExtends & { +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { propExtendsC?: string; propExtendsD?: ModelWithString; - }; +}; /** * This is a model that contains a some patterns */ export type ModelWithPattern = { - key: string; - name: string; - readonly enabled?: boolean; - readonly modified?: string; - id?: string; - text?: string; - patternWithSingleQuotes?: string; - patternWithNewline?: string; - patternWithBacktick?: string; + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; }; export type File = { - readonly id?: string; - readonly updated_at?: string; - readonly created_at?: string; - mime: string; - readonly file?: string; + readonly id?: string; + readonly updated_at?: string; + readonly created_at?: string; + mime: string; + readonly file?: string; }; export type _default = { - name?: string; + name?: string; }; export type Pageable = { - page?: number; - size?: number; - sort?: Array; + page?: number; + size?: number; + sort?: Array<(string)>; }; /** * This is a free-form object without additionalProperties. */ export type FreeFormObjectWithoutAdditionalProperties = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: true. */ export type FreeFormObjectWithAdditionalPropertiesEqTrue = { - [key: string]: unknown; + [key: string]: unknown; }; /** * This is a free-form object with additionalProperties: {}. */ export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - [key: string]: unknown; + [key: string]: unknown; }; export type ModelWithConst = { - String?: 'String'; - number?: 0; - null?: null; - withType?: 'Some string'; + String?: "String"; + number?: 0; + null?: null; + withType?: "Some string"; }; /** * This is a model with one property and additionalProperties: true */ export type ModelWithAdditionalPropertiesEqTrue = { - /** - * This is a simple string property - */ - prop?: string; - [key: string]: unknown; + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; }; export type NestedAnyOfArraysNullable = { - nullableArray?: Array | null; -}; - -export type CompositionWithOneOfAndProperties = - | { - foo: SimpleParameter; - baz: number | null; - qux: number; - } - | { - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; - baz: number | null; - qux: number; - }; + nullableArray?: Array<(string | boolean)> | null; +}; + +export type CompositionWithOneOfAndProperties = { + foo: SimpleParameter; + baz: number | null; + qux: number; +} | { + bar: NonAsciiStringæøåÆØÅöôêÊ字符串; + baz: number | null; + qux: number; +}; /** * An object that can be null */ export type NullableObject = { - foo?: string; + foo?: string; } | null; /** @@ -770,117 +695,118 @@ export type NullableObject = { export type CharactersInDescription = string; export type ModelWithNullableObject = { - data?: NullableObject; -}; - -export type ModelWithOneOfEnum = - | { - foo: 'Bar'; - } - | { - foo: 'Baz'; - } - | { - foo: 'Qux'; - } - | { - content: string; - foo: 'Quux'; - } - | { - content: [string, string]; - foo: 'Corge'; - }; + data?: NullableObject; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; export type ModelWithNestedArrayEnumsData = { - foo?: Array; - bar?: Array; + foo?: Array; + bar?: Array; }; export type ModelWithNestedArrayEnums = { - array_strings?: Array; - data?: ModelWithNestedArrayEnumsData; + array_strings?: Array<(string)>; + data?: ModelWithNestedArrayEnumsData; }; export type ModelWithNestedCompositionEnums = { - foo?: ModelWithNestedArrayEnumsDataFoo; + foo?: ModelWithNestedArrayEnumsDataFoo; }; export type ModelWithReadOnlyAndWriteOnly = { - foo: string; - readonly bar: string; - baz: string; + foo: string; + readonly bar: string; + baz: string; }; -export type ModelWithConstantSizeArray = [number, number]; +export type ModelWithConstantSizeArray = [ + number, + number +]; export type ModelWithAnyOfConstantSizeArray = [ - number | string, - number | string, - number | string, + number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayNullable = [ - number | null | string, - number | null | string, - number | null | string, + number | null | string, + number | null | string, + number | null | string ]; export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ - number | string, - number | string, + number | string, + number | string ]; export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ - number & string, - number & string, + number & string, + number & string ]; export type ModelWithNumericEnumUnion = { - /** - * Период - */ - value?: 1 | 3 | 6 | 12; + /** + * Период + */ + value?: 1 | 3 | 6 | 12; }; /** * Some description with `back ticks` */ export type ModelWithBackticksInDescription = { - /** - * The template `that` should be used for parsing and importing the contents of the CSV file. - * - *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

- *
-   * [
-   * {
-   * "resourceType": "Asset",
-   * "identifier": {
-   * "name": "${1}",
-   * "domain": {
-   * "name": "${2}",
-   * "community": {
-   * "name": "Some Community"
-   * }
-   * }
-   * },
-   * "attributes" : {
-   * "00000000-0000-0000-0000-000000003115" : [ {
-   * "value" : "${3}"
-   * } ],
-   * "00000000-0000-0000-0000-000000000222" : [ {
-   * "value" : "${4}"
-   * } ]
-   * }
-   * }
-   * ]
-   * 
- */ - template?: string; + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; }; /** @@ -891,4 +817,4 @@ export type SimpleParameter = string; /** * Parameter with illegal characters */ -export type x_Foo_Bar = string; +export type x_Foo_Bar = string; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/OpenAPI.ts.snap index 2f6bde646..091d25a4e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/OpenAPI.ts.snap @@ -25,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap index f0feb0e20..842edb3bd 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap @@ -9,327 +9,292 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } - onCancel(() => controller.abort()); + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - return await fetch(url, request); + onCancel(() => controller.abort()); + + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -339,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/index.ts.snap index f073fa9c4..d22d07cd0 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/index.ts.snap @@ -1,5 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; -export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; +export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/OpenAPI.ts.snap index 5c1459c6b..f9eab42e2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap index 4c6d3e6d3..79d04d01e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap @@ -6,331 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - const controller = new AbortController(); + const controller = new AbortController(); - let request: RequestInit = { - headers, - body: body ?? formData, - method: options.method, - signal: controller.signal, - }; + let request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; - if (config.WITH_CREDENTIALS) { - request.credentials = config.CREDENTIALS; - } + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } - for (const fn of config.interceptors.request._fns) { - request = await fn(request); - } + for (const fn of config.interceptors.request._fns) { + request = await fn(request); + } - onCancel(() => controller.abort()); + onCancel(() => controller.abort()); - return await fetch(url, request); + return await fetch(url, request); }; -export const getResponseHeader = ( - response: Response, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = response.headers.get(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = async (response: Response): Promise => { - if (response.status !== 204) { - try { - const contentType = response.headers.get('Content-Type'); - if (contentType) { - const binaryTypes = [ - 'application/octet-stream', - 'application/pdf', - 'application/zip', - 'audio/', - 'image/', - 'video/', - ]; - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return await response.json(); - } else if (binaryTypes.some((type) => contentType.includes(type))) { - return await response.blob(); - } else if (contentType.includes('multipart/form-data')) { - return await response.formData(); - } else if (contentType.includes('text/')) { - return await response.text(); - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; + if (contentType.includes('application/json') || contentType.includes('+json')) { + return await response.json(); + } else if (binaryTypes.some(type => contentType.includes(type))) { + return await response.blob(); + } else if (contentType.includes('multipart/form-data')) { + return await response.formData(); + } else if (contentType.includes('text/')) { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -340,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = await getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: response.ok, - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/index.ts.snap index 832d67208..3e1f0b35c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/index.ts.snap @@ -1,7 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; export * from './services.gen'; -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap index 88dce6fe2..06e7adb74 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap @@ -6,89 +6,79 @@ import { request as __request } from './core/request'; import type { $OpenApiTs } from './types.gen'; export class DefaultsService { - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string with default value - * @param data.parameterNumber This is a simple number with default value - * @param data.parameterBoolean This is a simple boolean with default value - * @param data.parameterEnum This is a simple enum with default value - * @param data.parameterModel This is a simple model with default value - * @throws ApiError - */ - public static callWithDefaultParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterString This is a simple string that is optional with default value - * @param data.parameterNumber This is a simple number that is optional with default value - * @param data.parameterBoolean This is a simple boolean that is optional with default value - * @param data.parameterEnum This is a simple enum that is optional with default value - * @param data.parameterModel This is a simple model that is optional with default value - * @throws ApiError - */ - public static callWithDefaultOptionalParameters( - data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/defaults', - query: { - parameterString: data.parameterString, - parameterNumber: data.parameterNumber, - parameterBoolean: data.parameterBoolean, - parameterEnum: data.parameterEnum, - parameterModel: data.parameterModel, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterStringWithNoDefault This is a string with no default - * @param data.parameterOptionalStringWithDefault This is a optional string with default - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default - * @param data.parameterStringWithDefault This is a string with default - * @param data.parameterStringWithEmptyDefault This is a string with empty default - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default - * @param data.parameterStringNullableWithDefault This is a string that can be null with default - * @throws ApiError - */ - public static callToTestOrderOfParams( - data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/defaults', - query: { - parameterOptionalStringWithDefault: - data.parameterOptionalStringWithDefault, - parameterOptionalStringWithEmptyDefault: - data.parameterOptionalStringWithEmptyDefault, - parameterOptionalStringWithNoDefault: - data.parameterOptionalStringWithNoDefault, - parameterStringWithDefault: data.parameterStringWithDefault, - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, - parameterStringWithNoDefault: data.parameterStringWithNoDefault, - parameterStringNullableWithNoDefault: - data.parameterStringNullableWithNoDefault, - parameterStringNullableWithDefault: - data.parameterStringNullableWithDefault, - }, - }); - } -} + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string with default value + * @param data.parameterNumber This is a simple number with default value + * @param data.parameterBoolean This is a simple boolean with default value + * @param data.parameterEnum This is a simple enum with default value + * @param data.parameterModel This is a simple model with default value + * @throws ApiError + */ + public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterString This is a simple string that is optional with default value + * @param data.parameterNumber This is a simple number that is optional with default value + * @param data.parameterBoolean This is a simple boolean that is optional with default value + * @param data.parameterEnum This is a simple enum that is optional with default value + * @param data.parameterModel This is a simple model that is optional with default value + * @throws ApiError + */ + public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/defaults', + query: { + parameterString: data.parameterString, + parameterNumber: data.parameterNumber, + parameterBoolean: data.parameterBoolean, + parameterEnum: data.parameterEnum, + parameterModel: data.parameterModel + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterStringWithNoDefault This is a string with no default + * @param data.parameterOptionalStringWithDefault This is a optional string with default + * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default + * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default + * @param data.parameterStringWithDefault This is a string with default + * @param data.parameterStringWithEmptyDefault This is a string with empty default + * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param data.parameterStringNullableWithDefault This is a string that can be null with default + * @throws ApiError + */ + public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/defaults', + query: { + parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, + parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, + parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, + parameterStringWithDefault: data.parameterStringWithDefault, + parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, + parameterStringWithNoDefault: data.parameterStringWithNoDefault, + parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault: data.parameterStringNullableWithDefault + } + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap index 7b2ea2ed2..fade8236c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap @@ -4,107 +4,107 @@ * This is a model with one string property */ export type ModelWithString = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; /** * This is a model with one string property */ export type ModelWithStringError = { - /** - * This is a simple string property - */ - prop?: string; + /** + * This is a simple string property + */ + prop?: string; }; export type $OpenApiTs = { - '/api/v{api-version}/defaults': { - get: { - req: { - /** - * This is a simple boolean with default value - */ - parameterBoolean?: boolean | null; - /** - * This is a simple enum with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model with default value - */ - parameterModel?: ModelWithString | null; - /** - * This is a simple number with default value - */ - parameterNumber?: number | null; - /** - * This is a simple string with default value - */ - parameterString?: string | null; - }; + '/api/v{api-version}/defaults': { + get: { + req: { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; + }; + }; + post: { + req: { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + }; + }; + put: { + req: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + }; + }; }; - post: { - req: { - /** - * This is a simple boolean that is optional with default value - */ - parameterBoolean?: boolean; - /** - * This is a simple enum that is optional with default value - */ - parameterEnum?: 'Success' | 'Warning' | 'Error'; - /** - * This is a simple model that is optional with default value - */ - parameterModel?: ModelWithString; - /** - * This is a simple number that is optional with default value - */ - parameterNumber?: number; - /** - * This is a simple string that is optional with default value - */ - parameterString?: string; - }; - }; - put: { - req: { - /** - * This is a optional string with default - */ - parameterOptionalStringWithDefault?: string; - /** - * This is a optional string with empty default - */ - parameterOptionalStringWithEmptyDefault?: string; - /** - * This is a optional string with no default - */ - parameterOptionalStringWithNoDefault?: string; - /** - * This is a string that can be null with default - */ - parameterStringNullableWithDefault?: string | null; - /** - * This is a string that can be null with no default - */ - parameterStringNullableWithNoDefault?: string | null; - /** - * This is a string with default - */ - parameterStringWithDefault: string; - /** - * This is a string with empty default - */ - parameterStringWithEmptyDefault: string; - /** - * This is a string with no default - */ - parameterStringWithNoDefault: string; - }; - }; - }; -}; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/index.ts.snap index 0339b6e31..56bade120 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './types.gen'; +export * from './types.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap index 9bc427229..43534df06 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_pascalcase/types.gen.ts.snap @@ -12,6 +12,6 @@ export type CamelCaseCommentWithBreaks = number; * This is a simple array with properties */ export type ArrayWithProperties = Array<{ - foo?: CamelCaseCommentWithBreaks; - bar?: string; -}>; + foo?: CamelCaseCommentWithBreaks; + bar?: string; +}>; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/index.ts.snap index 11f389291..bb994a669 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './schemas.gen'; +export * from './schemas.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap index 2bad92d27..01262c4ef 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap @@ -1,1561 +1,1545 @@ // This file is auto-generated by @hey-api/openapi-ts export const $camelCaseCommentWithBreaks = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithBreaks = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithBackticks = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithBackticksAndQuotes = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithSlashes = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithExpressionPlaceholders = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithQuotes = { - type: 'integer', + type: 'integer' } as const; export const $CommentWithReservedCharacters = { - type: 'integer', + type: 'integer' } as const; export const $SimpleInteger = { - type: 'integer', + type: 'integer' } as const; export const $SimpleBoolean = { - type: 'boolean', + type: 'boolean' } as const; export const $SimpleString = { - type: 'string', + type: 'string' } as const; export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { - type: 'string', + type: 'string' } as const; export const $SimpleFile = { - type: 'file', + type: 'file' } as const; export const $SimpleReference = { - $ref: '#/components/schemas/ModelWithString', + '$ref': '#/components/schemas/ModelWithString' } as const; export const $SimpleStringWithPattern = { - type: 'string', - nullable: true, - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', + type: 'string', + nullable: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$' } as const; export const $EnumWithStrings = { - enum: [ - 'Success', - 'Warning', - 'Error', - "'Single Quote'", - '"Double Quotes"', - 'Non-ascii: øæåôöØÆÅÔÖ字符串', - ], + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'] } as const; export const $EnumWithReplacedCharacters = { - enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], - type: 'string', + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], + type: 'string' } as const; export const $EnumWithNumbers = { - enum: [ - 1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3, - ], - default: 200, + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], + default: 200 } as const; export const $EnumFromDescription = { - type: 'number', + type: 'number' } as const; export const $EnumWithExtensions = { - enum: [200, 400, 500], + enum: [200, 400, 500] } as const; export const $EnumWithXEnumNames = { - enum: [0, 1, 2], + enum: [0, 1, 2] } as const; export const $ArrayWithNumbers = { - type: 'array', - items: { - type: 'integer', - }, + type: 'array', + items: { + type: 'integer' + } } as const; export const $ArrayWithBooleans = { - type: 'array', - items: { - type: 'boolean', - }, + type: 'array', + items: { + type: 'boolean' + } } as const; export const $ArrayWithStrings = { - type: 'array', - items: { - type: 'string', - }, - default: ['test'], + type: 'array', + items: { + type: 'string' + }, + default: ['test'] } as const; export const $ArrayWithReferences = { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $ArrayWithArray = { - type: 'array', - items: { type: 'array', items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ArrayWithProperties = { - type: 'array', - items: { - type: 'object', - properties: { - foo: { - $ref: '#/components/schemas/camelCaseCommentWithBreaks', - }, - bar: { - type: 'string', - }, - }, - }, + type: 'array', + items: { + type: 'object', + properties: { + foo: { + '$ref': '#/components/schemas/camelCaseCommentWithBreaks' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ArrayWithAnyOfProperties = { - type: 'array', - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - default: 'test', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, - }, - }, - ], - }, + type: 'array', + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string', + default: 'test' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] + } } as const; export const $AnyOfAnyAndNull = { - type: 'object', - properties: { - data: { - anyOf: [ - {}, - { - type: 'null', - }, - ], - }, - }, + type: 'object', + properties: { + data: { + anyOf: [ + {}, + { + type: 'null' + } + ] + } + } } as const; export const $AnyOfArrays = { - type: 'object', - properties: { - results: { - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, + type: 'object', + properties: { + results: { + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] }, - }, - ], - }, - type: 'array', - }, - }, + type: 'array' + } + } } as const; export const $DictionaryWithString = { - type: 'object', - additionalProperties: { - type: 'string', - }, + type: 'object', + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithPropertiesAndAdditionalProperties = { - type: 'object', - properties: { - foo: { - type: 'string', + type: 'object', + properties: { + foo: { + type: 'string' + } }, - }, - additionalProperties: { - type: 'string', - }, + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithReference = { - type: 'object', - additionalProperties: { - $ref: '#/components/schemas/ModelWithString', - }, + type: 'object', + additionalProperties: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $DictionaryWithArray = { - type: 'object', - additionalProperties: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'object', + additionalProperties: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $DictionaryWithDictionary = { - type: 'object', - additionalProperties: { type: 'object', additionalProperties: { - type: 'string', - }, - }, + type: 'object', + additionalProperties: { + type: 'string' + } + } } as const; export const $DictionaryWithProperties = { - type: 'object', - additionalProperties: { type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, + additionalProperties: { + type: 'object', + properties: { + foo: { + type: 'string' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ModelWithInteger = { - type: 'object', - properties: { - prop: { - type: 'integer', - }, - }, + type: 'object', + properties: { + prop: { + type: 'integer' + } + } } as const; export const $ModelWithBoolean = { - type: 'object', - properties: { - prop: { - type: 'boolean', - }, - }, + type: 'object', + properties: { + prop: { + type: 'boolean' + } + } } as const; export const $ModelWithString = { - type: 'object', - properties: { - prop: { - type: 'string', - }, - }, + type: 'object', + properties: { + prop: { + type: 'string' + } + } } as const; export const $ModelWithStringError = { - type: 'object', - properties: { - prop: { - type: 'string', - }, - }, + type: 'object', + properties: { + prop: { + type: 'string' + } + } } as const; export const $Model_From_Zendesk = { - type: 'string', + type: 'string' } as const; export const $ModelWithNullableString = { - type: 'object', - required: ['nullableRequiredProp1', 'nullableRequiredProp2'], - properties: { - nullableProp1: { - type: 'string', - nullable: true, - }, - nullableRequiredProp1: { - type: 'string', - nullable: true, - }, - nullableProp2: { - type: ['string', 'null'], - }, - nullableRequiredProp2: { - type: ['string', 'null'], - }, - 'foo_bar-enum': { - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + type: 'object', + required: ['nullableRequiredProp1', 'nullableRequiredProp2'], + properties: { + nullableProp1: { + type: 'string', + nullable: true + }, + nullableRequiredProp1: { + type: 'string', + nullable: true + }, + nullableProp2: { + type: ['string', 'null'] + }, + nullableRequiredProp2: { + type: ['string', 'null'] + }, + 'foo_bar-enum': { + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithEnum = { - type: 'object', - properties: { - 'foo_bar-enum': { - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - statusCode: { - enum: [ - '100', - '200 FOO', - '300 FOO_BAR', - '400 foo-bar', - '500 foo.bar', - '600 foo&bar', - ], - }, - bool: { - type: 'boolean', - enum: [true], - }, - }, + type: 'object', + properties: { + 'foo_bar-enum': { + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + }, + statusCode: { + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'] + }, + bool: { + type: 'boolean', + enum: [true] + } + } } as const; export const $ModelWithEnumWithHyphen = { - type: 'object', - properties: { - 'foo-bar-baz-qux': { - type: 'string', - enum: ['3.0'], - title: 'Foo-Bar-Baz-Qux', - default: '3.0', - }, - }, + type: 'object', + properties: { + 'foo-bar-baz-qux': { + type: 'string', + enum: ['3.0'], + title: 'Foo-Bar-Baz-Qux', + default: '3.0' + } + } } as const; export const $ModelWithEnumFromDescription = { - type: 'object', - properties: { - test: { - type: 'integer', - }, - }, + type: 'object', + properties: { + test: { + type: 'integer' + } + } } as const; export const $ModelWithNestedEnums = { - type: 'object', - properties: { - dictionaryWithEnum: { - type: 'object', - additionalProperties: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - dictionaryWithEnumFromDescription: { - type: 'object', - additionalProperties: { - type: 'integer', - }, - }, - arrayWithEnum: { - type: 'array', - items: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - arrayWithDescription: { - type: 'array', - items: { - type: 'integer', - }, - }, - 'foo_bar-enum': { - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + type: 'object', + properties: { + dictionaryWithEnum: { + type: 'object', + additionalProperties: { + enum: ['Success', 'Warning', 'Error'] + } + }, + dictionaryWithEnumFromDescription: { + type: 'object', + additionalProperties: { + type: 'integer' + } + }, + arrayWithEnum: { + type: 'array', + items: { + enum: ['Success', 'Warning', 'Error'] + } + }, + arrayWithDescription: { + type: 'array', + items: { + type: 'integer' + } + }, + 'foo_bar-enum': { + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithReference = { - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithProperties', - }, - }, + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithProperties' + } + } } as const; export const $ModelWithArrayReadOnlyAndWriteOnly = { - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithReadOnlyAndWriteOnly', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithReadOnlyAndWriteOnly' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithArray = { - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithDictionary = { - type: 'object', - properties: { - prop: { - type: 'object', - additionalProperties: { - type: 'string', - }, - }, - }, + type: 'object', + properties: { + prop: { + type: 'object', + additionalProperties: { + type: 'string' + } + } + } } as const; export const $DeprecatedModel = { - deprecated: true, - type: 'object', - properties: { - prop: { - deprecated: true, - type: 'string', - }, - }, + deprecated: true, + type: 'object', + properties: { + prop: { + deprecated: true, + type: 'string' + } + } } as const; export const $ModelWithCircularReference = { - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithCircularReference', - }, - }, + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithCircularReference' + } + } } as const; export const $CompositionWithOneOf = { - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAnonymous = { - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - type: 'string', - }, - { - type: 'integer', - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + type: 'string' + }, + { + type: 'integer' + } + ] + } + } } as const; export const $ModelCircle = { - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - radius: { - type: 'number', - }, - }, + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + radius: { + type: 'number' + } + } } as const; export const $ModelSquare = { - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - sideLength: { - type: 'number', - }, - }, + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + sideLength: { + type: 'number' + } + } } as const; export const $CompositionWithOneOfDiscriminator = { - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelCircle', - }, - { - $ref: '#/components/schemas/ModelSquare', - }, - ], - discriminator: { - propertyName: 'kind', - mapping: { - circle: '#/components/schemas/ModelCircle', - square: '#/components/schemas/ModelSquare', - }, - }, -} as const; - -export const $CompositionWithAnyOf = { - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, + type: 'object', + oneOf: [ { - $ref: '#/components/schemas/ModelWithArray', + '$ref': '#/components/schemas/ModelCircle' }, { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + '$ref': '#/components/schemas/ModelSquare' + } + ], + discriminator: { + propertyName: 'kind', + mapping: { + circle: '#/components/schemas/ModelCircle', + square: '#/components/schemas/ModelSquare' + } + } } as const; -export const $CompositionWithAnyOfAnonymous = { - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - type: 'string', - }, - { - type: 'integer', - }, - ], - }, - }, +export const $CompositionWithAnyOf = { + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; -export const $CompositionWithNestedAnyAndTypeNull = { - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - items: { - anyOf: [ - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - { - items: { +export const $CompositionWithAnyOfAnonymous = { + type: 'object', + properties: { + propA: { + type: 'object', anyOf: [ - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - ], - }, - }, + { + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + type: 'string' + }, + { + type: 'integer' + } + ] + } + } +} as const; + +export const $CompositionWithNestedAnyAndTypeNull = { + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithDictionary' + }, + { + type: 'null' + } + ] + }, + type: 'array' + }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + type: 'null' + } + ] + }, + type: 'array' + } + ] + } + } } as const; export const $Enum1 = { - enum: ['Bird', 'Dog'], - type: 'string', + enum: ['Bird', 'Dog'], + type: 'string' } as const; export const $ConstValue = { - type: 'string', - const: 'ConstValue', + type: 'string', + const: 'ConstValue' } as const; export const $CompositionWithNestedAnyOfAndNull = { - type: 'object', - properties: { - propA: { - anyOf: [ - { - items: { + type: 'object', + properties: { + propA: { anyOf: [ - { - $ref: '#/components/schemas/Enum1', - }, - { - $ref: '#/components/schemas/ConstValue', - }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/Enum1' + }, + { + '$ref': '#/components/schemas/ConstValue' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], - title: 'Scopes', - }, - }, + title: 'Scopes' + } + } } as const; export const $CompositionWithOneOfAndNullable = { - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - oneOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + oneOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleDictionary = { - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'number', - }, - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'number' + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleArrayDictionary = { - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - type: 'boolean', - }, - }, - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'array', + items: { + type: 'boolean' + } + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndComplexArrayDictionary = { - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - oneOf: [ + type: 'object', + properties: { + propA: { + oneOf: [ { - type: 'number', + type: 'boolean' }, { - type: 'string', - }, - ], - }, - }, - }, - ], - }, - }, + type: 'object', + additionalProperties: { + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + } + } + } + ] + } + } } as const; export const $CompositionWithAllOfAndNullable = { - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - allOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + allOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithAnyOfAndNullable = { - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - anyOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + anyOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionBaseModel = { - type: 'object', - properties: { - firstName: { - type: 'string', - }, - lastname: { - type: 'string', - }, - }, + type: 'object', + properties: { + firstName: { + type: 'string' + }, + lastname: { + type: 'string' + } + } } as const; export const $CompositionExtendedModel = { - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/CompositionBaseModel', - }, - ], - properties: { - age: { - type: 'number', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/CompositionBaseModel' + } + ], + properties: { + age: { + type: 'number' + } }, - }, - required: ['firstName', 'lastname', 'age'], + required: ['firstName', 'lastname', 'age'] } as const; export const $ModelWithProperties = { - type: 'object', - required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], - properties: { - required: { - type: 'string', - }, - requiredAndReadOnly: { - type: 'string', - readOnly: true, - }, - requiredAndNullable: { - type: 'string', - nullable: true, - }, - string: { - type: 'string', - }, - number: { - type: 'number', - }, - boolean: { - type: 'boolean', - }, - reference: { - $ref: '#/components/schemas/ModelWithString', - }, - 'property with space': { - type: 'string', - }, - default: { - type: 'string', - }, - try: { - type: 'string', - }, - '@namespace.string': { - type: 'string', - readOnly: true, - }, - '@namespace.integer': { - type: 'integer', - readOnly: true, - }, - }, + type: 'object', + required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], + properties: { + required: { + type: 'string' + }, + requiredAndReadOnly: { + type: 'string', + readOnly: true + }, + requiredAndNullable: { + type: 'string', + nullable: true + }, + string: { + type: 'string' + }, + number: { + type: 'number' + }, + boolean: { + type: 'boolean' + }, + reference: { + '$ref': '#/components/schemas/ModelWithString' + }, + 'property with space': { + type: 'string' + }, + default: { + type: 'string' + }, + try: { + type: 'string' + }, + '@namespace.string': { + type: 'string', + readOnly: true + }, + '@namespace.integer': { + type: 'integer', + readOnly: true + } + } } as const; export const $ModelWithNestedProperties = { - type: 'object', - required: ['first'], - properties: { - first: { - type: 'object', - required: ['second'], - readOnly: true, - nullable: true, - properties: { - second: { - type: 'object', - required: ['third'], - readOnly: true, - nullable: true, - properties: { - third: { - type: 'string', - required: true, - readOnly: true, - nullable: true, - }, - }, - }, - }, - }, - }, + type: 'object', + required: ['first'], + properties: { + first: { + type: 'object', + required: ['second'], + readOnly: true, + nullable: true, + properties: { + second: { + type: 'object', + required: ['third'], + readOnly: true, + nullable: true, + properties: { + third: { + type: 'string', + required: true, + readOnly: true, + nullable: true + } + } + } + } + } + } } as const; export const $ModelWithDuplicateProperties = { - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ModelWithOrderedProperties = { - type: 'object', - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, + type: 'object', + properties: { + zebra: { + type: 'string' + }, + apple: { + type: 'string' + }, + hawaii: { + type: 'string' + } + } } as const; export const $ModelWithDuplicateImports = { - type: 'object', - properties: { - propA: { - $ref: '#/components/schemas/ModelWithString', - }, - propB: { - $ref: '#/components/schemas/ModelWithString', - }, - propC: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'object', + properties: { + propA: { + '$ref': '#/components/schemas/ModelWithString' + }, + propB: { + '$ref': '#/components/schemas/ModelWithString' + }, + propC: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ModelThatExtends = { - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - type: 'object', - properties: { - propExtendsA: { - type: 'string', - }, - propExtendsB: { - $ref: '#/components/schemas/ModelWithString', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' }, - }, - }, - ], + { + type: 'object', + properties: { + propExtendsA: { + type: 'string' + }, + propExtendsB: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] } as const; export const $ModelThatExtendsExtends = { - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelThatExtends', - }, - { - type: 'object', - properties: { - propExtendsC: { - type: 'string', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' }, - propExtendsD: { - $ref: '#/components/schemas/ModelWithString', + { + '$ref': '#/components/schemas/ModelThatExtends' }, - }, - }, - ], + { + type: 'object', + properties: { + propExtendsC: { + type: 'string' + }, + propExtendsD: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] } as const; export const $ModelWithPattern = { - type: 'object', - required: ['key', 'name'], - properties: { - key: { - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', - type: 'string', - }, - name: { - maxLength: 255, - type: 'string', - }, - enabled: { - type: 'boolean', - readOnly: true, - }, - modified: { - type: 'string', - format: 'date-time', - readOnly: true, - }, - id: { - type: 'string', - pattern: '^d{2}-d{3}-d{4}$', - }, - text: { - type: 'string', - pattern: '^w+$', - }, - patternWithSingleQuotes: { - type: 'string', - pattern: "^[a-zA-Z0-9']*$", - }, - patternWithNewline: { - type: 'string', - pattern: `aaa -bbb`, - }, - patternWithBacktick: { - type: 'string', - pattern: 'aaa`bbb', - }, - }, + type: 'object', + required: ['key', 'name'], + properties: { + key: { + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', + type: 'string' + }, + name: { + maxLength: 255, + type: 'string' + }, + enabled: { + type: 'boolean', + readOnly: true + }, + modified: { + type: 'string', + format: 'date-time', + readOnly: true + }, + id: { + type: 'string', + pattern: '^\d{2}-\d{3}-\d{4}$' + }, + text: { + type: 'string', + pattern: '^\w+$' + }, + patternWithSingleQuotes: { + type: 'string', + pattern: "^[a-zA-Z0-9']*$" + }, + patternWithNewline: { + type: 'string', + pattern: `aaa +bbb` + }, + patternWithBacktick: { + type: 'string', + pattern: 'aaa`bbb' + } + } } as const; export const $File = { - required: ['mime'], - type: 'object', - properties: { - id: { - title: 'Id', - type: 'string', - readOnly: true, - minLength: 1, - }, - updated_at: { - title: 'Updated at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - created_at: { - title: 'Created at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - mime: { - title: 'Mime', - type: 'string', - maxLength: 24, - minLength: 1, - }, - file: { - title: 'File', - type: 'string', - readOnly: true, - format: 'uri', - }, - }, + required: ['mime'], + type: 'object', + properties: { + id: { + title: 'Id', + type: 'string', + readOnly: true, + minLength: 1 + }, + updated_at: { + title: 'Updated at', + type: 'string', + format: 'date-time', + readOnly: true + }, + created_at: { + title: 'Created at', + type: 'string', + format: 'date-time', + readOnly: true + }, + mime: { + title: 'Mime', + type: 'string', + maxLength: 24, + minLength: 1 + }, + file: { + title: 'File', + type: 'string', + readOnly: true, + format: 'uri' + } + } } as const; export const $default = { - type: 'object', - properties: { - name: { - type: 'string', - }, - }, + type: 'object', + properties: { + name: { + type: 'string' + } + } } as const; export const $Pageable = { - type: 'object', - properties: { - page: { - minimum: 0, - type: 'integer', - format: 'int32', - default: 0, - }, - size: { - minimum: 1, - type: 'integer', - format: 'int32', - }, - sort: { - type: 'array', - items: { - type: 'string', - }, - }, - }, + type: 'object', + properties: { + page: { + minimum: 0, + type: 'integer', + format: 'int32', + default: 0 + }, + size: { + minimum: 1, + type: 'integer', + format: 'int32' + }, + sort: { + type: 'array', + items: { + type: 'string' + } + } + } } as const; export const $FreeFormObjectWithoutAdditionalProperties = { - type: 'object', + type: 'object' } as const; export const $FreeFormObjectWithAdditionalPropertiesEqTrue = { - type: 'object', - additionalProperties: true, + type: 'object', + additionalProperties: true } as const; export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - type: 'object', - additionalProperties: {}, + type: 'object', + additionalProperties: {} } as const; export const $ModelWithConst = { - type: 'object', - properties: { - String: { - const: 'String', - }, - number: { - const: 0, - }, - null: { - const: null, - }, - withType: { - type: 'string', - const: 'Some string', - }, - }, + type: 'object', + properties: { + String: { + const: 'String' + }, + number: { + const: 0 + }, + null: { + const: null + }, + withType: { + type: 'string', + const: 'Some string' + } + } } as const; export const $ModelWithAdditionalPropertiesEqTrue = { - type: 'object', - properties: { - prop: { - type: 'string', + type: 'object', + properties: { + prop: { + type: 'string' + } }, - }, - additionalProperties: true, + additionalProperties: true } as const; export const $NestedAnyOfArraysNullable = { - properties: { - nullableArray: { - anyOf: [ - { - items: { + properties: { + nullableArray: { anyOf: [ - { - type: 'string', - }, - { - type: 'boolean', - }, - ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], + { + items: { + anyOf: [ + { + type: 'string' + }, + { + type: 'boolean' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } + ] + } }, - }, - type: 'object', + type: 'object' } as const; export const $CompositionWithOneOfAndProperties = { - type: 'object', - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - $ref: '#/components/parameters/SimpleParameter', + type: 'object', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + '$ref': '#/components/parameters/SimpleParameter' + } + }, + additionalProperties: false }, - }, - additionalProperties: false, - }, - { - type: 'object', - required: ['bar'], - properties: { - bar: { - $ref: '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2', + { + type: 'object', + required: ['bar'], + properties: { + bar: { + '$ref': '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2' + } + }, + additionalProperties: false + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true }, - }, - additionalProperties: false, - }, - ], - required: ['baz', 'qux'], - properties: { - baz: { - type: 'integer', - format: 'uint16', - minimum: 0, - nullable: true, - }, - qux: { - type: 'integer', - format: 'uint8', - minimum: 0, - }, - }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } } as const; export const $NullableObject = { - type: 'object', - nullable: true, - properties: { - foo: { - type: 'string', + type: 'object', + nullable: true, + properties: { + foo: { + type: 'string' + } }, - }, - default: null, + default: null } as const; export const $CharactersInDescription = { - type: 'string', + type: 'string' } as const; export const $ModelWithNullableObject = { - type: 'object', - properties: { - data: { - $ref: '#/components/schemas/NullableObject', - }, - }, + type: 'object', + properties: { + data: { + '$ref': '#/components/schemas/NullableObject' + } + } } as const; export const $ModelWithOneOfEnum = { - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Bar'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Baz'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Qux'], - }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'string', - format: 'date-time', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Bar'] + } + } }, - foo: { - type: 'string', - enum: ['Quux'], + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Baz'] + } + } }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'array', - items: [ - { - type: 'string', - format: 'date-time', - }, - { - type: 'string', - }, - ], - maxItems: 2, - minItems: 2, + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Qux'] + } + } }, - foo: { - type: 'string', - enum: ['Corge'], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'string', + format: 'date-time' + }, + foo: { + type: 'string', + enum: ['Quux'] + } + } }, - }, - }, - ], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'array', + items: [ + { + type: 'string', + format: 'date-time' + }, + { + type: 'string' + } + ], + maxItems: 2, + minItems: 2 + }, + foo: { + type: 'string', + enum: ['Corge'] + } + } + } + ] } as const; export const $ModelWithNestedArrayEnumsDataFoo = { - enum: ['foo', 'bar'], - type: 'string', + enum: ['foo', 'bar'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsDataBar = { - enum: ['baz', 'qux'], - type: 'string', + enum: ['baz', 'qux'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsData = { - type: 'object', - properties: { - foo: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - }, - bar: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataBar', - }, - }, - }, + type: 'object', + properties: { + foo: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + }, + bar: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataBar' + } + } + } } as const; export const $ModelWithNestedArrayEnums = { - type: 'object', - properties: { - array_strings: { - type: 'array', - items: { - type: 'string', - }, - }, - data: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsData', + type: 'object', + properties: { + array_strings: { + type: 'array', + items: { + type: 'string' + } }, - ], - }, - }, + data: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsData' + } + ] + } + } } as const; export const $ModelWithNestedCompositionEnums = { - type: 'object', - properties: { - foo: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - ], - }, - }, + type: 'object', + properties: { + foo: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + ] + } + } } as const; export const $ModelWithReadOnlyAndWriteOnly = { - type: 'object', - required: ['foo', 'bar', 'baz'], - properties: { - foo: { - type: 'string', - }, - bar: { - readOnly: true, - type: 'string', - }, - baz: { - type: 'string', - writeOnly: true, - }, - }, + type: 'object', + required: ['foo', 'bar', 'baz'], + properties: { + foo: { + type: 'string' + }, + bar: { + readOnly: true, + type: 'string' + }, + baz: { + type: 'string', + writeOnly: true + } + } } as const; export const $ModelWithConstantSizeArray = { - type: 'array', - items: { - type: 'number', - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + type: 'number' + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArray = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayNullable = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - nullable: true, - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number', + nullable: true + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArrayAndIntersect = { - type: 'array', - items: { - allOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + allOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithNumericEnumUnion = { - type: 'object', - properties: { - value: { - type: 'number', - enum: [1, 3, 6, 12], - }, - }, + type: 'object', + properties: { + value: { + type: 'number', + enum: [1, 3, 6, 12] + } + } } as const; export const $ModelWithBackticksInDescription = { - type: 'object', - properties: { - template: { - type: 'string', - }, - }, -} as const; + type: 'object', + properties: { + template: { + type: 'string' + } + } +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/index.ts.snap index 11f389291..bb994a669 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './schemas.gen'; +export * from './schemas.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap index 6ada30768..4af40c30e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap @@ -1,1694 +1,1660 @@ // This file is auto-generated by @hey-api/openapi-ts export const $camelCaseCommentWithBreaks = { - description: `Testing multiline comments in string: First line + description: `Testing multiline comments in string: First line Second line Fourth line`, - type: 'integer', + type: 'integer' } as const; export const $CommentWithBreaks = { - description: `Testing multiline comments in string: First line + description: `Testing multiline comments in string: First line Second line Fourth line`, - type: 'integer', + type: 'integer' } as const; export const $CommentWithBackticks = { - description: - 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', - type: 'integer', + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', + type: 'integer' } as const; export const $CommentWithBackticksAndQuotes = { - description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, - type: 'integer', + description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`, + type: 'integer' } as const; export const $CommentWithSlashes = { - description: - 'Testing slashes in string: \backwards\\ and /forwards/// should work', - type: 'integer', + description: 'Testing slashes in string: \backwards\\\ and /forwards/// should work', + type: 'integer' } as const; export const $CommentWithExpressionPlaceholders = { - description: - 'Testing expression placeholders in string: ${expression} should work', - type: 'integer', + description: 'Testing expression placeholders in string: ${expression} should work', + type: 'integer' } as const; export const $CommentWithQuotes = { - description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, - type: 'integer', + description: `Testing quotes in string: 'single quote''' and "double quotes""" should work`, + type: 'integer' } as const; export const $CommentWithReservedCharacters = { - description: - 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', - type: 'integer', + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', + type: 'integer' } as const; export const $SimpleInteger = { - description: 'This is a simple number', - type: 'integer', + description: 'This is a simple number', + type: 'integer' } as const; export const $SimpleBoolean = { - description: 'This is a simple boolean', - type: 'boolean', + description: 'This is a simple boolean', + type: 'boolean' } as const; export const $SimpleString = { - description: 'This is a simple string', - type: 'string', + description: 'This is a simple string', + type: 'string' } as const; export const $NonAsciiStringæøåÆØÅöôêÊ字符串 = { - description: - 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', - type: 'string', + description: 'A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)', + type: 'string' } as const; export const $SimpleFile = { - description: 'This is a simple file', - type: 'file', + description: 'This is a simple file', + type: 'file' } as const; export const $SimpleReference = { - description: 'This is a simple reference', - $ref: '#/components/schemas/ModelWithString', + description: 'This is a simple reference', + '$ref': '#/components/schemas/ModelWithString' } as const; export const $SimpleStringWithPattern = { - description: 'This is a simple string', - type: 'string', - nullable: true, - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', + description: 'This is a simple string', + type: 'string', + nullable: true, + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$' } as const; export const $EnumWithStrings = { - description: 'This is a simple enum with strings', - enum: [ - 'Success', - 'Warning', - 'Error', - "'Single Quote'", - '"Double Quotes"', - 'Non-ascii: øæåôöØÆÅÔÖ字符串', - ], + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'] } as const; export const $EnumWithReplacedCharacters = { - enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], - type: 'string', + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], + type: 'string' } as const; export const $EnumWithNumbers = { - description: 'This is a simple enum with numbers', - enum: [ - 1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3, - ], - default: 200, + description: 'This is a simple enum with numbers', + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], + default: 200 } as const; export const $EnumFromDescription = { - description: 'Success=1,Warning=2,Error=3', - type: 'number', + description: 'Success=1,Warning=2,Error=3', + type: 'number' } as const; export const $EnumWithExtensions = { - description: 'This is a simple enum with numbers', - enum: [200, 400, 500], - 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], - 'x-enum-descriptions': [ - 'Used when the status of something is successful', - 'Used when the status of something has a warning', - 'Used when the status of something has an error', - ], + description: 'This is a simple enum with numbers', + enum: [200, 400, 500], + 'x-enum-varnames': ['CUSTOM_SUCCESS', 'CUSTOM_WARNING', 'CUSTOM_ERROR'], + 'x-enum-descriptions': ['Used when the status of something is successful', 'Used when the status of something has a warning', 'Used when the status of something has an error'] } as const; export const $EnumWithXEnumNames = { - enum: [0, 1, 2], - 'x-enumNames': ['zero', 'one', 'two'], + enum: [0, 1, 2], + 'x-enumNames': ['zero', 'one', 'two'] } as const; export const $ArrayWithNumbers = { - description: 'This is a simple array with numbers', - type: 'array', - items: { - type: 'integer', - }, + description: 'This is a simple array with numbers', + type: 'array', + items: { + type: 'integer' + } } as const; export const $ArrayWithBooleans = { - description: 'This is a simple array with booleans', - type: 'array', - items: { - type: 'boolean', - }, + description: 'This is a simple array with booleans', + type: 'array', + items: { + type: 'boolean' + } } as const; export const $ArrayWithStrings = { - description: 'This is a simple array with strings', - type: 'array', - items: { - type: 'string', - }, - default: ['test'], + description: 'This is a simple array with strings', + type: 'array', + items: { + type: 'string' + }, + default: ['test'] } as const; export const $ArrayWithReferences = { - description: 'This is a simple array with references', - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, + description: 'This is a simple array with references', + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $ArrayWithArray = { - description: 'This is a simple array containing an array', - type: 'array', - items: { + description: 'This is a simple array containing an array', type: 'array', items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ArrayWithProperties = { - description: 'This is a simple array with properties', - type: 'array', - items: { - type: 'object', - properties: { - foo: { - $ref: '#/components/schemas/camelCaseCommentWithBreaks', - }, - bar: { - type: 'string', - }, - }, - }, + description: 'This is a simple array with properties', + type: 'array', + items: { + type: 'object', + properties: { + foo: { + '$ref': '#/components/schemas/camelCaseCommentWithBreaks' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ArrayWithAnyOfProperties = { - description: 'This is a simple array with any of properties', - type: 'array', - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - default: 'test', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, - }, - }, - ], - }, + description: 'This is a simple array with any of properties', + type: 'array', + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string', + default: 'test' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] + } } as const; export const $AnyOfAnyAndNull = { - type: 'object', - properties: { - data: { - anyOf: [ - {}, - { - type: 'null', - }, - ], - }, - }, + type: 'object', + properties: { + data: { + anyOf: [ + {}, + { + type: 'null' + } + ] + } + } } as const; export const $AnyOfArrays = { - description: 'This is a simple array with any of properties', - type: 'object', - properties: { - results: { - items: { - anyOf: [ - { - type: 'object', - properties: { - foo: { - type: 'string', - }, - }, - }, - { - type: 'object', - properties: { - bar: { - type: 'string', - }, + description: 'This is a simple array with any of properties', + type: 'object', + properties: { + results: { + items: { + anyOf: [ + { + type: 'object', + properties: { + foo: { + type: 'string' + } + } + }, + { + type: 'object', + properties: { + bar: { + type: 'string' + } + } + } + ] }, - }, - ], - }, - type: 'array', - }, - }, + type: 'array' + } + } } as const; export const $DictionaryWithString = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { - type: 'string', - }, + description: 'This is a string dictionary', + type: 'object', + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithPropertiesAndAdditionalProperties = { - type: 'object', - properties: { - foo: { - type: 'string', + type: 'object', + properties: { + foo: { + type: 'string' + } }, - }, - additionalProperties: { - type: 'string', - }, + additionalProperties: { + type: 'string' + } } as const; export const $DictionaryWithReference = { - description: 'This is a string reference', - type: 'object', - additionalProperties: { - $ref: '#/components/schemas/ModelWithString', - }, + description: 'This is a string reference', + type: 'object', + additionalProperties: { + '$ref': '#/components/schemas/ModelWithString' + } } as const; export const $DictionaryWithArray = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a complex dictionary', + type: 'object', + additionalProperties: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $DictionaryWithDictionary = { - description: 'This is a string dictionary', - type: 'object', - additionalProperties: { + description: 'This is a string dictionary', type: 'object', additionalProperties: { - type: 'string', - }, - }, + type: 'object', + additionalProperties: { + type: 'string' + } + } } as const; export const $DictionaryWithProperties = { - description: 'This is a complex dictionary', - type: 'object', - additionalProperties: { + description: 'This is a complex dictionary', type: 'object', - properties: { - foo: { - type: 'string', - }, - bar: { - type: 'string', - }, - }, - }, + additionalProperties: { + type: 'object', + properties: { + foo: { + type: 'string' + }, + bar: { + type: 'string' + } + } + } } as const; export const $ModelWithInteger = { - description: 'This is a model with one number property', - type: 'object', - properties: { - prop: { - description: 'This is a simple number property', - type: 'integer', - }, - }, + description: 'This is a model with one number property', + type: 'object', + properties: { + prop: { + description: 'This is a simple number property', + type: 'integer' + } + } } as const; export const $ModelWithBoolean = { - description: 'This is a model with one boolean property', - type: 'object', - properties: { - prop: { - description: 'This is a simple boolean property', - type: 'boolean', - }, - }, + description: 'This is a model with one boolean property', + type: 'object', + properties: { + prop: { + description: 'This is a simple boolean property', + type: 'boolean' + } + } } as const; export const $ModelWithString = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $ModelWithStringError = { - description: 'This is a model with one string property', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', - }, - }, + description: 'This is a model with one string property', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } + } } as const; export const $Model_From_Zendesk = { - description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`, - type: 'string', + description: `\`Comment\` or \`VoiceComment\`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets)`, + type: 'string' } as const; export const $ModelWithNullableString = { - description: 'This is a model with one string property', - type: 'object', - required: ['nullableRequiredProp1', 'nullableRequiredProp2'], - properties: { - nullableProp1: { - description: 'This is a simple string property', - type: 'string', - nullable: true, - }, - nullableRequiredProp1: { - description: 'This is a simple string property', - type: 'string', - nullable: true, - }, - nullableProp2: { - description: 'This is a simple string property', - type: ['string', 'null'], - }, - nullableRequiredProp2: { - description: 'This is a simple string property', - type: ['string', 'null'], - }, - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + description: 'This is a model with one string property', + type: 'object', + required: ['nullableRequiredProp1', 'nullableRequiredProp2'], + properties: { + nullableProp1: { + description: 'This is a simple string property', + type: 'string', + nullable: true + }, + nullableRequiredProp1: { + description: 'This is a simple string property', + type: 'string', + nullable: true + }, + nullableProp2: { + description: 'This is a simple string property', + type: ['string', 'null'] + }, + nullableRequiredProp2: { + description: 'This is a simple string property', + type: ['string', 'null'] + }, + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithEnum = { - description: 'This is a model with one enum', - type: 'object', - properties: { - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - statusCode: { - description: 'These are the HTTP error code enums', - enum: [ - '100', - '200 FOO', - '300 FOO_BAR', - '400 foo-bar', - '500 foo.bar', - '600 foo&bar', - ], - }, - bool: { - description: 'Simple boolean enum', - type: 'boolean', - enum: [true], - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + }, + statusCode: { + description: 'These are the HTTP error code enums', + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'] + }, + bool: { + description: 'Simple boolean enum', + type: 'boolean', + enum: [true] + } + } } as const; export const $ModelWithEnumWithHyphen = { - description: 'This is a model with one enum with escaped name', - type: 'object', - properties: { - 'foo-bar-baz-qux': { - type: 'string', - enum: ['3.0'], - title: 'Foo-Bar-Baz-Qux', - default: '3.0', - }, - }, + description: 'This is a model with one enum with escaped name', + type: 'object', + properties: { + 'foo-bar-baz-qux': { + type: 'string', + enum: ['3.0'], + title: 'Foo-Bar-Baz-Qux', + default: '3.0' + } + } } as const; export const $ModelWithEnumFromDescription = { - description: 'This is a model with one enum', - type: 'object', - properties: { - test: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, + description: 'This is a model with one enum', + type: 'object', + properties: { + test: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + } } as const; export const $ModelWithNestedEnums = { - description: 'This is a model with nested enums', - type: 'object', - properties: { - dictionaryWithEnum: { - type: 'object', - additionalProperties: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - dictionaryWithEnumFromDescription: { - type: 'object', - additionalProperties: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - arrayWithEnum: { - type: 'array', - items: { - enum: ['Success', 'Warning', 'Error'], - }, - }, - arrayWithDescription: { - type: 'array', - items: { - type: 'integer', - description: 'Success=1,Warning=2,Error=3', - }, - }, - 'foo_bar-enum': { - description: 'This is a simple enum with strings', - enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], - }, - }, + description: 'This is a model with nested enums', + type: 'object', + properties: { + dictionaryWithEnum: { + type: 'object', + additionalProperties: { + enum: ['Success', 'Warning', 'Error'] + } + }, + dictionaryWithEnumFromDescription: { + type: 'object', + additionalProperties: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + }, + arrayWithEnum: { + type: 'array', + items: { + enum: ['Success', 'Warning', 'Error'] + } + }, + arrayWithDescription: { + type: 'array', + items: { + type: 'integer', + description: 'Success=1,Warning=2,Error=3' + } + }, + 'foo_bar-enum': { + description: 'This is a simple enum with strings', + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'] + } + } } as const; export const $ModelWithReference = { - description: 'This is a model with one property containing a reference', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithProperties', - }, - }, + description: 'This is a model with one property containing a reference', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithProperties' + } + } } as const; export const $ModelWithArrayReadOnlyAndWriteOnly = { - description: 'This is a model with one property containing an array', - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithReadOnlyAndWriteOnly', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + description: 'This is a model with one property containing an array', + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithReadOnlyAndWriteOnly' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithArray = { - description: 'This is a model with one property containing an array', - type: 'object', - properties: { - prop: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithString', - }, - }, - propWithFile: { - type: 'array', - items: { - type: 'file', - }, - }, - propWithNumber: { - type: 'array', - items: { - type: 'number', - }, - }, - }, + description: 'This is a model with one property containing an array', + type: 'object', + properties: { + prop: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithString' + } + }, + propWithFile: { + type: 'array', + items: { + type: 'file' + } + }, + propWithNumber: { + type: 'array', + items: { + type: 'number' + } + } + } } as const; export const $ModelWithDictionary = { - description: 'This is a model with one property containing a dictionary', - type: 'object', - properties: { - prop: { - type: 'object', - additionalProperties: { - type: 'string', - }, - }, - }, + description: 'This is a model with one property containing a dictionary', + type: 'object', + properties: { + prop: { + type: 'object', + additionalProperties: { + type: 'string' + } + } + } } as const; export const $DeprecatedModel = { - deprecated: true, - description: 'This is a deprecated model with a deprecated property', - type: 'object', - properties: { - prop: { - deprecated: true, - description: 'This is a deprecated property', - type: 'string', - }, - }, + deprecated: true, + description: 'This is a deprecated model with a deprecated property', + type: 'object', + properties: { + prop: { + deprecated: true, + description: 'This is a deprecated property', + type: 'string' + } + } } as const; export const $ModelWithCircularReference = { - description: - 'This is a model with one property containing a circular reference', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithCircularReference', - }, - }, + description: 'This is a model with one property containing a circular reference', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithCircularReference' + } + } } as const; export const $CompositionWithOneOf = { - description: "This is a model with one property with a 'one of' relationship", - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'one of' relationship", + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAnonymous = { - description: - "This is a model with one property with a 'one of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - type: 'object', - oneOf: [ - { - description: 'Anonymous object type', - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - description: 'Anonymous string type', - type: 'string', - }, - { - description: 'Anonymous integer type', - type: 'integer', - }, - ], - }, - }, -} as const; - -export const $ModelCircle = { - description: 'Circle', - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - radius: { - type: 'number', - }, - }, + description: "This is a model with one property with a 'one of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { + type: 'object', + oneOf: [ + { + description: 'Anonymous object type', + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + description: 'Anonymous string type', + type: 'string' + }, + { + description: 'Anonymous integer type', + type: 'integer' + } + ] + } + } } as const; -export const $ModelSquare = { - description: 'Square', - type: 'object', - required: ['kind'], - properties: { - kind: { - type: 'string', - }, - sideLength: { - type: 'number', - }, - }, +export const $ModelCircle = { + description: 'Circle', + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + radius: { + type: 'number' + } + } } as const; -export const $CompositionWithOneOfDiscriminator = { - description: - "This is a model with one property with a 'one of' relationship where the options are not $ref", - type: 'object', - oneOf: [ - { - $ref: '#/components/schemas/ModelCircle', - }, - { - $ref: '#/components/schemas/ModelSquare', - }, - ], - discriminator: { - propertyName: 'kind', - mapping: { - circle: '#/components/schemas/ModelCircle', - square: '#/components/schemas/ModelSquare', - }, - }, +export const $ModelSquare = { + description: 'Square', + type: 'object', + required: ['kind'], + properties: { + kind: { + type: 'string' + }, + sideLength: { + type: 'number' + } + } } as const; -export const $CompositionWithAnyOf = { - description: "This is a model with one property with a 'any of' relationship", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, +export const $CompositionWithOneOfDiscriminator = { + description: "This is a model with one property with a 'one of' relationship where the options are not $ref", + type: 'object', + oneOf: [ { - $ref: '#/components/schemas/ModelWithArray', + '$ref': '#/components/schemas/ModelCircle' }, { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + '$ref': '#/components/schemas/ModelSquare' + } + ], + discriminator: { + propertyName: 'kind', + mapping: { + circle: '#/components/schemas/ModelCircle', + square: '#/components/schemas/ModelSquare' + } + } +} as const; + +export const $CompositionWithAnyOf = { + description: "This is a model with one property with a 'any of' relationship", + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithAnyOfAnonymous = { - description: - "This is a model with one property with a 'any of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - description: 'Anonymous object type', - type: 'object', - properties: { - propA: { - type: 'string', - }, - }, - }, - { - description: 'Anonymous string type', - type: 'string', - }, - { - description: 'Anonymous integer type', - type: 'integer', - }, - ], - }, - }, + description: "This is a model with one property with a 'any of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { + type: 'object', + anyOf: [ + { + description: 'Anonymous object type', + type: 'object', + properties: { + propA: { + type: 'string' + } + } + }, + { + description: 'Anonymous string type', + type: 'string' + }, + { + description: 'Anonymous integer type', + type: 'integer' + } + ] + } + } } as const; export const $CompositionWithNestedAnyAndTypeNull = { - description: "This is a model with nested 'any of' property with a type null", - type: 'object', - properties: { - propA: { - type: 'object', - anyOf: [ - { - items: { - anyOf: [ - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - { - items: { + description: "This is a model with nested 'any of' property with a type null", + type: 'object', + properties: { + propA: { + type: 'object', anyOf: [ - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - type: 'null', - }, - ], - }, - type: 'array', - }, - ], - }, - }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithDictionary' + }, + { + type: 'null' + } + ] + }, + type: 'array' + }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + type: 'null' + } + ] + }, + type: 'array' + } + ] + } + } } as const; export const $Enum1 = { - enum: ['Bird', 'Dog'], - type: 'string', + enum: ['Bird', 'Dog'], + type: 'string' } as const; export const $ConstValue = { - type: 'string', - const: 'ConstValue', + type: 'string', + const: 'ConstValue' } as const; export const $CompositionWithNestedAnyOfAndNull = { - description: - "This is a model with one property with a 'any of' relationship where the options are not $ref", - type: 'object', - properties: { - propA: { - anyOf: [ - { - items: { + description: "This is a model with one property with a 'any of' relationship where the options are not $ref", + type: 'object', + properties: { + propA: { anyOf: [ - { - $ref: '#/components/schemas/Enum1', - }, - { - $ref: '#/components/schemas/ConstValue', - }, + { + items: { + anyOf: [ + { + '$ref': '#/components/schemas/Enum1' + }, + { + '$ref': '#/components/schemas/ConstValue' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], - title: 'Scopes', - }, - }, + title: 'Scopes' + } + } } as const; export const $CompositionWithOneOfAndNullable = { - description: "This is a model with one property with a 'one of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - oneOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'one of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + oneOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleDictionary = { - description: - 'This is a model that contains a simple dictionary within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'number', - }, - }, - ], - }, - }, + description: 'This is a model that contains a simple dictionary within composition', + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'number' + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndSimpleArrayDictionary = { - description: - 'This is a model that contains a dictionary of simple arrays within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - type: 'boolean', - }, - }, - }, - ], - }, - }, + description: 'This is a model that contains a dictionary of simple arrays within composition', + type: 'object', + properties: { + propA: { + oneOf: [ + { + type: 'boolean' + }, + { + type: 'object', + additionalProperties: { + type: 'array', + items: { + type: 'boolean' + } + } + } + ] + } + } } as const; export const $CompositionWithOneOfAndComplexArrayDictionary = { - description: - 'This is a model that contains a dictionary of complex arrays (composited) within composition', - type: 'object', - properties: { - propA: { - oneOf: [ - { - type: 'boolean', - }, - { - type: 'object', - additionalProperties: { - type: 'array', - items: { - oneOf: [ + description: 'This is a model that contains a dictionary of complex arrays (composited) within composition', + type: 'object', + properties: { + propA: { + oneOf: [ { - type: 'number', + type: 'boolean' }, { - type: 'string', - }, - ], - }, - }, - }, - ], - }, - }, + type: 'object', + additionalProperties: { + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + } + } + } + ] + } + } } as const; export const $CompositionWithAllOfAndNullable = { - description: "This is a model with one property with a 'all of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - allOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'all of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + allOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionWithAnyOfAndNullable = { - description: "This is a model with one property with a 'any of' relationship", - type: 'object', - properties: { - propA: { - nullable: true, - type: 'object', - anyOf: [ - { - type: 'object', - properties: { - boolean: { - type: 'boolean', - }, - }, - }, - { - $ref: '#/components/schemas/ModelWithEnum', - }, - { - $ref: '#/components/schemas/ModelWithArray', - }, - { - $ref: '#/components/schemas/ModelWithDictionary', - }, - ], - }, - }, + description: "This is a model with one property with a 'any of' relationship", + type: 'object', + properties: { + propA: { + nullable: true, + type: 'object', + anyOf: [ + { + type: 'object', + properties: { + boolean: { + type: 'boolean' + } + } + }, + { + '$ref': '#/components/schemas/ModelWithEnum' + }, + { + '$ref': '#/components/schemas/ModelWithArray' + }, + { + '$ref': '#/components/schemas/ModelWithDictionary' + } + ] + } + } } as const; export const $CompositionBaseModel = { - description: 'This is a base model with two simple optional properties', - type: 'object', - properties: { - firstName: { - type: 'string', - }, - lastname: { - type: 'string', - }, - }, + description: 'This is a base model with two simple optional properties', + type: 'object', + properties: { + firstName: { + type: 'string' + }, + lastname: { + type: 'string' + } + } } as const; export const $CompositionExtendedModel = { - description: 'This is a model that extends the base model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/CompositionBaseModel', - }, - ], - properties: { - age: { - type: 'number', + description: 'This is a model that extends the base model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/CompositionBaseModel' + } + ], + properties: { + age: { + type: 'number' + } }, - }, - required: ['firstName', 'lastname', 'age'], + required: ['firstName', 'lastname', 'age'] } as const; export const $ModelWithProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], - properties: { - required: { - type: 'string', - }, - requiredAndReadOnly: { - type: 'string', - readOnly: true, - }, - requiredAndNullable: { - type: 'string', - nullable: true, - }, - string: { - type: 'string', - }, - number: { - type: 'number', - }, - boolean: { - type: 'boolean', - }, - reference: { - $ref: '#/components/schemas/ModelWithString', - }, - 'property with space': { - type: 'string', - }, - default: { - type: 'string', - }, - try: { - type: 'string', - }, - '@namespace.string': { - type: 'string', - readOnly: true, - }, - '@namespace.integer': { - type: 'integer', - readOnly: true, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['required', 'requiredAndReadOnly', 'requiredAndNullable'], + properties: { + required: { + type: 'string' + }, + requiredAndReadOnly: { + type: 'string', + readOnly: true + }, + requiredAndNullable: { + type: 'string', + nullable: true + }, + string: { + type: 'string' + }, + number: { + type: 'number' + }, + boolean: { + type: 'boolean' + }, + reference: { + '$ref': '#/components/schemas/ModelWithString' + }, + 'property with space': { + type: 'string' + }, + default: { + type: 'string' + }, + try: { + type: 'string' + }, + '@namespace.string': { + type: 'string', + readOnly: true + }, + '@namespace.integer': { + type: 'integer', + readOnly: true + } + } } as const; export const $ModelWithNestedProperties = { - description: 'This is a model with one nested property', - type: 'object', - required: ['first'], - properties: { - first: { - type: 'object', - required: ['second'], - readOnly: true, - nullable: true, - properties: { - second: { - type: 'object', - required: ['third'], - readOnly: true, - nullable: true, - properties: { - third: { - type: 'string', - required: true, - readOnly: true, - nullable: true, - }, - }, - }, - }, - }, - }, + description: 'This is a model with one nested property', + type: 'object', + required: ['first'], + properties: { + first: { + type: 'object', + required: ['second'], + readOnly: true, + nullable: true, + properties: { + second: { + type: 'object', + required: ['third'], + readOnly: true, + nullable: true, + properties: { + third: { + type: 'string', + required: true, + readOnly: true, + nullable: true + } + } + } + } + } + } } as const; export const $ModelWithDuplicateProperties = { - description: 'This is a model with duplicated properties', - type: 'object', - properties: { - prop: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a model with duplicated properties', + type: 'object', + properties: { + prop: { + '$ref': '#/components/schemas/ModelWithString' + } + } } as const; export const $ModelWithOrderedProperties = { - description: 'This is a model with ordered properties', - type: 'object', - properties: { - zebra: { - type: 'string', - }, - apple: { - type: 'string', - }, - hawaii: { - type: 'string', - }, - }, + description: 'This is a model with ordered properties', + type: 'object', + properties: { + zebra: { + type: 'string' + }, + apple: { + type: 'string' + }, + hawaii: { + type: 'string' + } + } } as const; export const $ModelWithDuplicateImports = { - description: 'This is a model with duplicated imports', - type: 'object', - properties: { - propA: { - $ref: '#/components/schemas/ModelWithString', - }, - propB: { - $ref: '#/components/schemas/ModelWithString', - }, - propC: { - $ref: '#/components/schemas/ModelWithString', - }, - }, + description: 'This is a model with duplicated imports', + type: 'object', + properties: { + propA: { + '$ref': '#/components/schemas/ModelWithString' + }, + propB: { + '$ref': '#/components/schemas/ModelWithString' + }, + propC: { + '$ref': '#/components/schemas/ModelWithString' + } + } +} as const; + +export const $ModelThatExtends = { + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + type: 'object', + properties: { + propExtendsA: { + type: 'string' + }, + propExtendsB: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] +} as const; + +export const $ModelThatExtendsExtends = { + description: 'This is a model that extends another model', + type: 'object', + allOf: [ + { + '$ref': '#/components/schemas/ModelWithString' + }, + { + '$ref': '#/components/schemas/ModelThatExtends' + }, + { + type: 'object', + properties: { + propExtendsC: { + type: 'string' + }, + propExtendsD: { + '$ref': '#/components/schemas/ModelWithString' + } + } + } + ] } as const; -export const $ModelThatExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - type: 'object', - properties: { - propExtendsA: { - type: 'string', +export const $ModelWithPattern = { + description: 'This is a model that contains a some patterns', + type: 'object', + required: ['key', 'name'], + properties: { + key: { + maxLength: 64, + pattern: '^[a-zA-Z0-9_]*$', + type: 'string' }, - propExtendsB: { - $ref: '#/components/schemas/ModelWithString', + name: { + maxLength: 255, + type: 'string' }, - }, - }, - ], -} as const; - -export const $ModelThatExtendsExtends = { - description: 'This is a model that extends another model', - type: 'object', - allOf: [ - { - $ref: '#/components/schemas/ModelWithString', - }, - { - $ref: '#/components/schemas/ModelThatExtends', - }, - { - type: 'object', - properties: { - propExtendsC: { - type: 'string', + enabled: { + type: 'boolean', + readOnly: true }, - propExtendsD: { - $ref: '#/components/schemas/ModelWithString', + modified: { + type: 'string', + format: 'date-time', + readOnly: true }, - }, - }, - ], -} as const; - -export const $ModelWithPattern = { - description: 'This is a model that contains a some patterns', - type: 'object', - required: ['key', 'name'], - properties: { - key: { - maxLength: 64, - pattern: '^[a-zA-Z0-9_]*$', - type: 'string', - }, - name: { - maxLength: 255, - type: 'string', - }, - enabled: { - type: 'boolean', - readOnly: true, - }, - modified: { - type: 'string', - format: 'date-time', - readOnly: true, - }, - id: { - type: 'string', - pattern: '^d{2}-d{3}-d{4}$', - }, - text: { - type: 'string', - pattern: '^w+$', - }, - patternWithSingleQuotes: { - type: 'string', - pattern: "^[a-zA-Z0-9']*$", - }, - patternWithNewline: { - type: 'string', - pattern: `aaa -bbb`, - }, - patternWithBacktick: { - type: 'string', - pattern: 'aaa`bbb', - }, - }, + id: { + type: 'string', + pattern: '^\d{2}-\d{3}-\d{4}$' + }, + text: { + type: 'string', + pattern: '^\w+$' + }, + patternWithSingleQuotes: { + type: 'string', + pattern: "^[a-zA-Z0-9']*$" + }, + patternWithNewline: { + type: 'string', + pattern: `aaa +bbb` + }, + patternWithBacktick: { + type: 'string', + pattern: 'aaa`bbb' + } + } } as const; export const $File = { - required: ['mime'], - type: 'object', - properties: { - id: { - title: 'Id', - type: 'string', - readOnly: true, - minLength: 1, - }, - updated_at: { - title: 'Updated at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - created_at: { - title: 'Created at', - type: 'string', - format: 'date-time', - readOnly: true, - }, - mime: { - title: 'Mime', - type: 'string', - maxLength: 24, - minLength: 1, - }, - file: { - title: 'File', - type: 'string', - readOnly: true, - format: 'uri', - }, - }, + required: ['mime'], + type: 'object', + properties: { + id: { + title: 'Id', + type: 'string', + readOnly: true, + minLength: 1 + }, + updated_at: { + title: 'Updated at', + type: 'string', + format: 'date-time', + readOnly: true + }, + created_at: { + title: 'Created at', + type: 'string', + format: 'date-time', + readOnly: true + }, + mime: { + title: 'Mime', + type: 'string', + maxLength: 24, + minLength: 1 + }, + file: { + title: 'File', + type: 'string', + readOnly: true, + format: 'uri' + } + } } as const; export const $default = { - type: 'object', - properties: { - name: { - type: 'string', - }, - }, + type: 'object', + properties: { + name: { + type: 'string' + } + } } as const; export const $Pageable = { - type: 'object', - properties: { - page: { - minimum: 0, - type: 'integer', - format: 'int32', - default: 0, - }, - size: { - minimum: 1, - type: 'integer', - format: 'int32', - }, - sort: { - type: 'array', - items: { - type: 'string', - }, - }, - }, + type: 'object', + properties: { + page: { + minimum: 0, + type: 'integer', + format: 'int32', + default: 0 + }, + size: { + minimum: 1, + type: 'integer', + format: 'int32' + }, + sort: { + type: 'array', + items: { + type: 'string' + } + } + } } as const; export const $FreeFormObjectWithoutAdditionalProperties = { - description: 'This is a free-form object without additionalProperties.', - type: 'object', + description: 'This is a free-form object without additionalProperties.', + type: 'object' } as const; export const $FreeFormObjectWithAdditionalPropertiesEqTrue = { - description: 'This is a free-form object with additionalProperties: true.', - type: 'object', - additionalProperties: true, + description: 'This is a free-form object with additionalProperties: true.', + type: 'object', + additionalProperties: true } as const; export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { - description: 'This is a free-form object with additionalProperties: {}.', - type: 'object', - additionalProperties: {}, + description: 'This is a free-form object with additionalProperties: {}.', + type: 'object', + additionalProperties: {} } as const; export const $ModelWithConst = { - type: 'object', - properties: { - String: { - const: 'String', - }, - number: { - const: 0, - }, - null: { - const: null, - }, - withType: { - type: 'string', - const: 'Some string', - }, - }, + type: 'object', + properties: { + String: { + const: 'String' + }, + number: { + const: 0 + }, + null: { + const: null + }, + withType: { + type: 'string', + const: 'Some string' + } + } } as const; export const $ModelWithAdditionalPropertiesEqTrue = { - description: - 'This is a model with one property and additionalProperties: true', - type: 'object', - properties: { - prop: { - description: 'This is a simple string property', - type: 'string', + description: 'This is a model with one property and additionalProperties: true', + type: 'object', + properties: { + prop: { + description: 'This is a simple string property', + type: 'string' + } }, - }, - additionalProperties: true, + additionalProperties: true } as const; export const $NestedAnyOfArraysNullable = { - properties: { - nullableArray: { - anyOf: [ - { - items: { + properties: { + nullableArray: { anyOf: [ - { - type: 'string', - }, - { - type: 'boolean', - }, - ], - }, - type: 'array', - }, - { - type: 'null', - }, - ], + { + items: { + anyOf: [ + { + type: 'string' + }, + { + type: 'boolean' + } + ] + }, + type: 'array' + }, + { + type: 'null' + } + ] + } }, - }, - type: 'object', + type: 'object' } as const; export const $CompositionWithOneOfAndProperties = { - type: 'object', - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - $ref: '#/components/parameters/SimpleParameter', + type: 'object', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + '$ref': '#/components/parameters/SimpleParameter' + } + }, + additionalProperties: false }, - }, - additionalProperties: false, - }, - { - type: 'object', - required: ['bar'], - properties: { - bar: { - $ref: '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2', + { + type: 'object', + required: ['bar'], + properties: { + bar: { + '$ref': '#/components/schemas/NonAsciiString%C3%A6%C3%B8%C3%A5%C3%86%C3%98%C3%85%C3%B6%C3%B4%C3%AA%C3%8A%E5%AD%97%E7%AC%A6%E4%B8%B2' + } + }, + additionalProperties: false + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true }, - }, - additionalProperties: false, - }, - ], - required: ['baz', 'qux'], - properties: { - baz: { - type: 'integer', - format: 'uint16', - minimum: 0, - nullable: true, - }, - qux: { - type: 'integer', - format: 'uint8', - minimum: 0, - }, - }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } } as const; export const $NullableObject = { - type: 'object', - nullable: true, - description: 'An object that can be null', - properties: { - foo: { - type: 'string', + type: 'object', + nullable: true, + description: 'An object that can be null', + properties: { + foo: { + type: 'string' + } }, - }, - default: null, + default: null } as const; export const $CharactersInDescription = { - type: 'string', - description: 'Some % character', + type: 'string', + description: 'Some % character' } as const; export const $ModelWithNullableObject = { - type: 'object', - properties: { - data: { - $ref: '#/components/schemas/NullableObject', - }, - }, + type: 'object', + properties: { + data: { + '$ref': '#/components/schemas/NullableObject' + } + } } as const; export const $ModelWithOneOfEnum = { - oneOf: [ - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Bar'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Baz'], - }, - }, - }, - { - type: 'object', - required: ['foo'], - properties: { - foo: { - type: 'string', - enum: ['Qux'], - }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'string', - format: 'date-time', + oneOf: [ + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Bar'] + } + } }, - foo: { - type: 'string', - enum: ['Quux'], + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Baz'] + } + } }, - }, - }, - { - type: 'object', - required: ['content', 'foo'], - properties: { - content: { - type: 'array', - items: [ - { - type: 'string', - format: 'date-time', - }, - { - type: 'string', - }, - ], - maxItems: 2, - minItems: 2, + { + type: 'object', + required: ['foo'], + properties: { + foo: { + type: 'string', + enum: ['Qux'] + } + } }, - foo: { - type: 'string', - enum: ['Corge'], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'string', + format: 'date-time' + }, + foo: { + type: 'string', + enum: ['Quux'] + } + } }, - }, - }, - ], + { + type: 'object', + required: ['content', 'foo'], + properties: { + content: { + type: 'array', + items: [ + { + type: 'string', + format: 'date-time' + }, + { + type: 'string' + } + ], + maxItems: 2, + minItems: 2 + }, + foo: { + type: 'string', + enum: ['Corge'] + } + } + } + ] } as const; export const $ModelWithNestedArrayEnumsDataFoo = { - enum: ['foo', 'bar'], - type: 'string', + enum: ['foo', 'bar'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsDataBar = { - enum: ['baz', 'qux'], - type: 'string', + enum: ['baz', 'qux'], + type: 'string' } as const; export const $ModelWithNestedArrayEnumsData = { - type: 'object', - properties: { - foo: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - }, - bar: { - type: 'array', - items: { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataBar', - }, - }, - }, + type: 'object', + properties: { + foo: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + }, + bar: { + type: 'array', + items: { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataBar' + } + } + } } as const; export const $ModelWithNestedArrayEnums = { - type: 'object', - properties: { - array_strings: { - type: 'array', - items: { - type: 'string', - }, - }, - data: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsData', + type: 'object', + properties: { + array_strings: { + type: 'array', + items: { + type: 'string' + } }, - ], - }, - }, + data: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsData' + } + ] + } + } } as const; export const $ModelWithNestedCompositionEnums = { - type: 'object', - properties: { - foo: { - allOf: [ - { - $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo', - }, - ], - }, - }, + type: 'object', + properties: { + foo: { + allOf: [ + { + '$ref': '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + ] + } + } } as const; export const $ModelWithReadOnlyAndWriteOnly = { - type: 'object', - required: ['foo', 'bar', 'baz'], - properties: { - foo: { - type: 'string', - }, - bar: { - readOnly: true, - type: 'string', - }, - baz: { - type: 'string', - writeOnly: true, - }, - }, + type: 'object', + required: ['foo', 'bar', 'baz'], + properties: { + foo: { + type: 'string' + }, + bar: { + readOnly: true, + type: 'string' + }, + baz: { + type: 'string', + writeOnly: true + } + } } as const; export const $ModelWithConstantSizeArray = { - type: 'array', - items: { - type: 'number', - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + type: 'number' + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArray = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayNullable = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - nullable: true, - }, - { - type: 'string', - }, - ], - }, - minItems: 3, - maxItems: 3, + type: 'array', + items: { + oneOf: [ + { + type: 'number', + nullable: true + }, + { + type: 'string' + } + ] + }, + minItems: 3, + maxItems: 3 } as const; export const $ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = { - type: 'array', - items: { - oneOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + oneOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithAnyOfConstantSizeArrayAndIntersect = { - type: 'array', - items: { - allOf: [ - { - type: 'number', - }, - { - type: 'string', - }, - ], - }, - minItems: 2, - maxItems: 2, + type: 'array', + items: { + allOf: [ + { + type: 'number' + }, + { + type: 'string' + } + ] + }, + minItems: 2, + maxItems: 2 } as const; export const $ModelWithNumericEnumUnion = { - type: 'object', - properties: { - value: { - type: 'number', - description: 'Период', - enum: [1, 3, 6, 12], - }, - }, + type: 'object', + properties: { + value: { + type: 'number', + description: 'Период', + enum: [1, 3, 6, 12] + } + } } as const; export const $ModelWithBackticksInDescription = { - description: 'Some description with `back ticks`', - type: 'object', - properties: { - template: { - type: 'string', - description: `The template \`that\` should be used for parsing and importing the contents of the CSV file. + description: 'Some description with `back ticks`', + type: 'object', + properties: { + template: { + type: 'string', + description: `The template \`that\` should be used for parsing and importing the contents of the CSV file.

There is one placeholder currently supported:

  • \${x} - refers to the n-th column in the CSV file, e.g. \${1}, \${2}, ...)

Example of a correct JSON template:

@@ -1714,7 +1680,7 @@ export const $ModelWithBackticksInDescription = {
     }
   }
 ]
-
`, - }, - }, -} as const; +` + } + } +} as const; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/index.ts.snap index 844e0a651..c87f165ef 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/index.ts.snap @@ -1,3 +1,2 @@ // This file is auto-generated by @hey-api/openapi-ts - -export * from './services.gen'; +export * from './services.gen'; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap index 67ee5bb98..0b39bff85 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap @@ -5,229 +5,219 @@ import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; export class myAwesomeSimpleApi { - /** - * @returns Model_From_Zendesk Success - * @throws ApiError - */ - public static apiVVersionOdataControllerCount(): CancelablePromise< - $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] - > { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple/$count', - }); - } - - /** - * @throws ApiError - */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PUT', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'OPTIONS', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'HEAD', - url: '/api/v{api-version}/simple', - }); - } - - /** - * @throws ApiError - */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request(OpenAPI, { - method: 'PATCH', - url: '/api/v{api-version}/simple', - }); - } + /** + * @returns Model_From_Zendesk Success + * @throws ApiError + */ + public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple/$count' + }); + } + + /** + * @throws ApiError + */ + public static getCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static putCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PUT', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static postCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static deleteCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static optionsCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'OPTIONS', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static headCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'HEAD', + url: '/api/v{api-version}/simple' + }); + } + + /** + * @throws ApiError + */ + public static patchCallWithoutParametersAndResponse(): CancelablePromise { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/v{api-version}/simple' + }); + } + } export class myAwesomeParametersApi { - /** - * @param data The data for the request. - * @param data.foo foo in method - * @param data.bar bar in method - * @throws ApiError - */ - public static deleteFoo( - data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'DELETE', - url: '/api/v{api-version}/foo/{foo}/bar/{bar}', - path: { - foo: data.foo, - bar: data.bar, - }, - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the header - * @param data.fooAllOfEnum - * @param data.parameterQuery This is the parameter that goes into the query params - * @param data.parameterForm This is the parameter that goes into the form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.parameterPath This is the parameter that goes into the path - * @param data.requestBody This is the parameter that goes into the body - * @param data.fooRefEnum - * @throws ApiError - */ - public static callWithParameters( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameterPath}', - path: { - parameterPath: data.parameterPath, - }, - cookies: { - parameterCookie: data.parameterCookie, - }, - headers: { - parameterHeader: data.parameterHeader, - }, - query: { - foo_ref_enum: data.fooRefEnum, - foo_all_of_enum: data.fooAllOfEnum, - parameterQuery: data.parameterQuery, - }, - formData: { - parameterForm: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameterHeader This is the parameter that goes into the request header - * @param data.parameterQuery This is the parameter that goes into the request query params - * @param data.parameterForm This is the parameter that goes into the request form data - * @param data.parameterCookie This is the parameter that goes into the cookie - * @param data.requestBody This is the parameter that goes into the body - * @param data.parameterPath1 This is the parameter that goes into the path - * @param data.parameterPath2 This is the parameter that goes into the path - * @param data.parameterPath3 This is the parameter that goes into the path - * @param data._default This is the parameter with a reserved keyword - * @throws ApiError - */ - public static callWithWeirdParameterNames( - data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - path: { - 'parameter.path.1': data.parameterPath1, - 'parameter-path-2': data.parameterPath2, - 'PARAMETER-PATH-3': data.parameterPath3, - }, - cookies: { - 'PARAMETER-COOKIE': data.parameterCookie, - }, - headers: { - 'parameter.header': data.parameterHeader, - }, - query: { - default: data._default, - 'parameter-query': data.parameterQuery, - }, - formData: { - parameter_form: data.parameterForm, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.requestBody This is a required parameter - * @param data.parameter This is an optional parameter - * @throws ApiError - */ - public static getCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } - - /** - * @param data The data for the request. - * @param data.parameter This is a required parameter - * @param data.requestBody This is an optional parameter - * @throws ApiError - */ - public static postCallWithOptionalParam( - data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], - ): CancelablePromise { - return __request(OpenAPI, { - method: 'POST', - url: '/api/v{api-version}/parameters/', - query: { - parameter: data.parameter, - }, - body: requestBody, - mediaType: 'application/json', - }); - } -} + /** + * @param data The data for the request. + * @param data.foo foo in method + * @param data.bar bar in method + * @throws ApiError + */ + public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'DELETE', + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', + path: { + foo: data.foo, + bar: data.bar + } + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the header + * @param data.fooAllOfEnum + * @param data.parameterQuery This is the parameter that goes into the query params + * @param data.parameterForm This is the parameter that goes into the form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.parameterPath This is the parameter that goes into the path + * @param data.requestBody This is the parameter that goes into the body + * @param data.fooRefEnum + * @throws ApiError + */ + public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameterPath}', + path: { + parameterPath: data.parameterPath + }, + cookies: { + parameterCookie: data.parameterCookie + }, + headers: { + parameterHeader: data.parameterHeader + }, + query: { + foo_ref_enum: data.fooRefEnum, + foo_all_of_enum: data.fooAllOfEnum, + parameterQuery: data.parameterQuery + }, + formData: { + parameterForm: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameterHeader This is the parameter that goes into the request header + * @param data.parameterQuery This is the parameter that goes into the request query params + * @param data.parameterForm This is the parameter that goes into the request form data + * @param data.parameterCookie This is the parameter that goes into the cookie + * @param data.requestBody This is the parameter that goes into the body + * @param data.parameterPath1 This is the parameter that goes into the path + * @param data.parameterPath2 This is the parameter that goes into the path + * @param data.parameterPath3 This is the parameter that goes into the path + * @param data._default This is the parameter with a reserved keyword + * @throws ApiError + */ + public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + path: { + 'parameter.path.1': data.parameterPath1, + 'parameter-path-2': data.parameterPath2, + 'PARAMETER-PATH-3': data.parameterPath3 + }, + cookies: { + 'PARAMETER-COOKIE': data.parameterCookie + }, + headers: { + 'parameter.header': data.parameterHeader + }, + query: { + default: data._default, + 'parameter-query': data.parameterQuery + }, + formData: { + parameter_form: data.parameterForm + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.requestBody This is a required parameter + * @param data.parameter This is an optional parameter + * @throws ApiError + */ + public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + + /** + * @param data The data for the request. + * @param data.parameter This is a required parameter + * @param data.requestBody This is an optional parameter + * @throws ApiError + */ + public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/v{api-version}/parameters/', + query: { + parameter: data.parameter + }, + body: requestBody, + mediaType: 'application/json' + }); + } + +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiError.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiError.ts.snap index b821db3ef..36675d288 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiError.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiError.ts.snap @@ -2,24 +2,20 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; import type { ApiResult } from './ApiResult'; export class ApiError extends Error { - public readonly url: string; - public readonly status: number; - public readonly statusText: string; - public readonly body: unknown; - public readonly request: ApiRequestOptions; + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: unknown; + public readonly request: ApiRequestOptions; - constructor( - request: ApiRequestOptions, - response: ApiResult, - message: string, - ) { - super(message); + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); - this.name = 'ApiError'; - this.url = response.url; - this.status = response.status; - this.statusText = response.statusText; - this.body = response.body; - this.request = request; - } -} + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiRequestOptions.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiRequestOptions.ts.snap index cb2727aff..8f8d4d159 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiRequestOptions.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiRequestOptions.ts.snap @@ -1,20 +1,13 @@ export type ApiRequestOptions = { - readonly method: - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH'; - readonly url: string; - readonly path?: Record; - readonly cookies?: Record; - readonly headers?: Record; - readonly query?: Record; - readonly formData?: Record; - readonly body?: any; - readonly mediaType?: string; - readonly responseHeader?: string; - readonly errors?: Record; -}; + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiResult.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiResult.ts.snap index 05040ba81..4c58e3913 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiResult.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/ApiResult.ts.snap @@ -1,7 +1,7 @@ export type ApiResult = { - readonly body: TData; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly url: string; -}; + readonly body: TData; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly url: string; +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/CancelablePromise.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/CancelablePromise.ts.snap index f002b69e9..ccc082e8f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/CancelablePromise.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/CancelablePromise.ts.snap @@ -1,126 +1,126 @@ export class CancelError extends Error { - constructor(message: string) { - super(message); - this.name = 'CancelError'; - } - - public get isCancelled(): boolean { - return true; - } + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } } export interface OnCancel { - readonly isResolved: boolean; - readonly isRejected: boolean; - readonly isCancelled: boolean; + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; - (cancelHandler: () => void): void; + (cancelHandler: () => void): void; } export class CancelablePromise implements Promise { - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - readonly cancelHandlers: (() => void)[]; - readonly promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: unknown) => void; - - constructor( - executor: ( - resolve: (value: T | PromiseLike) => void, - reject: (reason?: unknown) => void, - onCancel: OnCancel, - ) => void, - ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this.cancelHandlers = []; - this.promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - - const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isResolved = true; - if (this._resolve) this._resolve(value); - }; - - const onReject = (reason?: unknown): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isRejected = true; - if (this._reject) this._reject(reason); - }; - - const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this.cancelHandlers.push(cancelHandler); - }; - - Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, - }); - - Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, - }); - - Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, - }); - - return executor(onResolve, onReject, onCancel as OnCancel); - }); - } - - get [Symbol.toStringTag]() { - return 'Cancellable Promise'; - } - - public then( - onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, - onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, - ): Promise { - return this.promise.then(onFulfilled, onRejected); - } - - public catch( - onRejected?: ((reason: unknown) => TResult | PromiseLike) | null, - ): Promise { - return this.promise.catch(onRejected); - } - - public finally(onFinally?: (() => void) | null): Promise { - return this.promise.finally(onFinally); - } - - public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { - return; - } - this._isCancelled = true; - if (this.cancelHandlers.length) { - try { - for (const cancelHandler of this.cancelHandlers) { - cancelHandler(); - } - } catch (error) { - console.warn('Cancellation threw an error', error); - return; - } - } - this.cancelHandlers.length = 0; - if (this._reject) this._reject(new CancelError('Request aborted')); - } - - public get isCancelled(): boolean { - return this._isCancelled; - } -} + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + readonly cancelHandlers: (() => void)[]; + readonly promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: unknown) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: unknown) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this.cancelHandlers = []; + this.promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + if (this._resolve) this._resolve(value); + }; + + const onReject = (reason?: unknown): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + if (this._reject) this._reject(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this.cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: unknown) => TResult2 | PromiseLike) | null + ): Promise { + return this.promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: unknown) => TResult | PromiseLike) | null + ): Promise { + return this.promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this.promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this.cancelHandlers.length) { + try { + for (const cancelHandler of this.cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this.cancelHandlers.length = 0; + if (this._reject) this._reject(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/OpenAPI.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/OpenAPI.ts.snap index 3b8ff6278..b6969225e 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/OpenAPI.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/OpenAPI.ts.snap @@ -1,3 +1,4 @@ + import type { ApiRequestOptions } from './ApiRequestOptions'; type Headers = Record; @@ -24,30 +25,33 @@ export class Interceptors { } export type OpenAPIConfig = { - BASE: string; - CREDENTIALS: 'include' | 'omit' | 'same-origin'; - ENCODE_PATH?: ((path: string) => string) | undefined; - HEADERS?: Headers | Resolver | undefined; - PASSWORD?: string | Resolver | undefined; - TOKEN?: string | Resolver | undefined; - USERNAME?: string | Resolver | undefined; - VERSION: string; - WITH_CREDENTIALS: boolean; - interceptors: { - request: Interceptors; - response: Interceptors; - }; + BASE: string; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + ENCODE_PATH?: ((path: string) => string) | undefined; + HEADERS?: Headers | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + VERSION: string; + WITH_CREDENTIALS: boolean; + interceptors: { + request: Interceptors; + response: Interceptors; + }; }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://localhost:3000/base', - CREDENTIALS: 'include', - ENCODE_PATH: undefined, - HEADERS: undefined, - PASSWORD: undefined, - TOKEN: undefined, - USERNAME: undefined, - VERSION: '1.0', - WITH_CREDENTIALS: false, - interceptors: { request: new Interceptors(), response: new Interceptors() }, -}; + BASE: 'http://localhost:3000/base', + CREDENTIALS: 'include', + ENCODE_PATH: undefined, + HEADERS: undefined, + PASSWORD: undefined, + TOKEN: undefined, + USERNAME: undefined, + VERSION: '1.0', + WITH_CREDENTIALS: false, + interceptors: { + request: new Interceptors(), + response: new Interceptors(), + }, +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap index 1562e87f4..ecc9c47e0 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap @@ -6,324 +6,295 @@ import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; export const isString = (value: unknown): value is string => { - return typeof value === 'string'; + return typeof value === 'string'; }; export const isStringWithValue = (value: unknown): value is string => { - return isString(value) && value !== ''; + return isString(value) && value !== ''; }; export const isBlob = (value: any): value is Blob => { - return value instanceof Blob; + return value instanceof Blob; }; export const isFormData = (value: unknown): value is FormData => { - return value instanceof FormData; + return value instanceof FormData; }; export const isSuccess = (status: number): boolean => { - return status >= 200 && status < 300; + return status >= 200 && status < 300; }; export const base64 = (str: string): string => { - try { - return btoa(str); - } catch (err) { - // @ts-ignore - return Buffer.from(str).toString('base64'); - } + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } }; export const getQueryString = (params: Record): string => { - const qs: string[] = []; - - const append = (key: string, value: unknown) => { - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); - }; - - const encodePair = (key: string, value: unknown) => { - if (value === undefined || value === null) { - return; - } - - if (value instanceof Date) { - append(key, value.toISOString()); - } else if (Array.isArray(value)) { - value.forEach((v) => encodePair(key, v)); - } else if (typeof value === 'object') { - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); - } else { - append(key, value); - } - }; - - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); - - return qs.length ? `?${qs.join('&')}` : ''; + const qs: string[] = []; + + const append = (key: string, value: unknown) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const encodePair = (key: string, value: unknown) => { + if (value === undefined || value === null) { + return; + } + + if (value instanceof Date) { + append(key, value.toISOString()); + } else if (Array.isArray(value)) { + value.forEach(v => encodePair(key, v)); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); + } else { + append(key, value); + } + }; + + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); + + return qs.length ? `?${qs.join('&')}` : ''; }; const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { - const encoder = config.ENCODE_PATH || encodeURI; - - const path = options.url - .replace('{api-version}', config.VERSION) - .replace(/{(.*?)}/g, (substring: string, group: string) => { - if (options.path?.hasOwnProperty(group)) { - return encoder(String(options.path[group])); - } - return substring; - }); - - const url = config.BASE + path; - return options.query ? url + getQueryString(options.query) : url; + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = config.BASE + path; + return options.query ? url + getQueryString(options.query) : url; }; -export const getFormData = ( - options: ApiRequestOptions, -): FormData | undefined => { - if (options.formData) { - const formData = new FormData(); - - const process = (key: string, value: unknown) => { - if (isString(value) || isBlob(value)) { - formData.append(key, value); - } else { - formData.append(key, JSON.stringify(value)); - } - }; - - Object.entries(options.formData) - .filter(([, value]) => value !== undefined && value !== null) - .forEach(([key, value]) => { - if (Array.isArray(value)) { - value.forEach((v) => process(key, v)); - } else { - process(key, value); - } - }); - - return formData; - } - return undefined; +export const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: unknown) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([, value]) => value !== undefined && value !== null) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; }; type Resolver = (options: ApiRequestOptions) => Promise; -export const resolve = async ( - options: ApiRequestOptions, - resolver?: T | Resolver, -): Promise => { - if (typeof resolver === 'function') { - return (resolver as Resolver)(options); - } - return resolver; +export const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; }; -export const getHeaders = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): Promise => { - const [token, username, password, additionalHeaders] = await Promise.all([ - resolve(options, config.TOKEN), - resolve(options, config.USERNAME), - resolve(options, config.PASSWORD), - resolve(options, config.HEADERS), - ]); - - const headers = Object.entries({ - Accept: 'application/json', - ...additionalHeaders, - ...options.headers, - }) - .filter(([, value]) => value !== undefined && value !== null) - .reduce( - (headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), - {} as Record, - ); - - if (isStringWithValue(token)) { - headers['Authorization'] = `Bearer ${token}`; - } - - if (isStringWithValue(username) && isStringWithValue(password)) { - const credentials = base64(`${username}:${password}`); - headers['Authorization'] = `Basic ${credentials}`; - } - - if (options.body !== undefined) { - if (options.mediaType) { - headers['Content-Type'] = options.mediaType; - } else if (isBlob(options.body)) { - headers['Content-Type'] = options.body.type || 'application/octet-stream'; - } else if (isString(options.body)) { - headers['Content-Type'] = 'text/plain'; - } else if (!isFormData(options.body)) { - headers['Content-Type'] = 'application/json'; - } - } - - return new Headers(headers); +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const [token, username, password, additionalHeaders] = await Promise.all([ + resolve(options, config.TOKEN), + resolve(options, config.USERNAME), + resolve(options, config.PASSWORD), + resolve(options, config.HEADERS), + ]); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([, value]) => value !== undefined && value !== null) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body !== undefined) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); }; export const getRequestBody = (options: ApiRequestOptions): unknown => { - if (options.body !== undefined) { - if ( - options.mediaType?.includes('application/json') || - options.mediaType?.includes('+json') - ) { - return JSON.stringify(options.body); - } else if ( - isString(options.body) || - isBlob(options.body) || - isFormData(options.body) - ) { - return options.body; - } else { - return JSON.stringify(options.body); - } - } - return undefined; + if (options.body !== undefined) { + if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { + return JSON.stringify(options.body); + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; }; export const sendRequest = async ( - config: OpenAPIConfig, - options: ApiRequestOptions, - url: string, - body: any, - formData: FormData | undefined, - headers: Headers, - onCancel: OnCancel, + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel ): Promise => { - let xhr = new XMLHttpRequest(); - xhr.open(options.method, url, true); - xhr.withCredentials = config.WITH_CREDENTIALS; + let xhr = new XMLHttpRequest(); + xhr.open(options.method, url, true); + xhr.withCredentials = config.WITH_CREDENTIALS; - headers.forEach((value, key) => { - xhr.setRequestHeader(key, value); - }); + headers.forEach((value, key) => { + xhr.setRequestHeader(key, value); + }); - return new Promise(async (resolve, reject) => { - xhr.onload = () => resolve(xhr); - xhr.onabort = () => reject(new Error('Request aborted')); - xhr.onerror = () => reject(new Error('Network error')); + return new Promise(async (resolve, reject) => { + xhr.onload = () => resolve(xhr); + xhr.onabort = () => reject(new Error('Request aborted')); + xhr.onerror = () => reject(new Error('Network error')); - for (const fn of config.interceptors.request._fns) { - xhr = await fn(xhr); - } + for (const fn of config.interceptors.request._fns) { + xhr = await fn(xhr); + } - xhr.send(body ?? formData); + xhr.send(body ?? formData); - onCancel(() => xhr.abort()); - }); + onCancel(() => xhr.abort()); + }); }; -export const getResponseHeader = ( - xhr: XMLHttpRequest, - responseHeader?: string, -): string | undefined => { - if (responseHeader) { - const content = xhr.getResponseHeader(responseHeader); - if (isString(content)) { - return content; - } - } - return undefined; +export const getResponseHeader = (xhr: XMLHttpRequest, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = xhr.getResponseHeader(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; }; export const getResponseBody = (xhr: XMLHttpRequest): unknown => { - if (xhr.status !== 204) { - try { - const contentType = xhr.getResponseHeader('Content-Type'); - if (contentType) { - if ( - contentType.includes('application/json') || - contentType.includes('+json') - ) { - return JSON.parse(xhr.responseText); - } else { - return xhr.responseText; - } - } - } catch (error) { - console.error(error); - } - } - return undefined; + if (xhr.status !== 204) { + try { + const contentType = xhr.getResponseHeader('Content-Type'); + if (contentType) { + if (contentType.includes('application/json') || contentType.includes('+json')) { + return JSON.parse(xhr.responseText); + } else { + return xhr.responseText; + } + } + } catch (error) { + console.error(error); + } + } + return undefined; }; -export const catchErrorCodes = ( - options: ApiRequestOptions, - result: ApiResult, -): void => { - const errors: Record = { - 400: 'Bad Request', - 401: 'Unauthorized', - 402: 'Payment Required', - 403: 'Forbidden', - 404: 'Not Found', - 405: 'Method Not Allowed', - 406: 'Not Acceptable', - 407: 'Proxy Authentication Required', - 408: 'Request Timeout', - 409: 'Conflict', - 410: 'Gone', - 411: 'Length Required', - 412: 'Precondition Failed', - 413: 'Payload Too Large', - 414: 'URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Range Not Satisfiable', - 417: 'Expectation Failed', - 418: 'Im a teapot', - 421: 'Misdirected Request', - 422: 'Unprocessable Content', - 423: 'Locked', - 424: 'Failed Dependency', - 425: 'Too Early', - 426: 'Upgrade Required', - 428: 'Precondition Required', - 429: 'Too Many Requests', - 431: 'Request Header Fields Too Large', - 451: 'Unavailable For Legal Reasons', - 500: 'Internal Server Error', - 501: 'Not Implemented', - 502: 'Bad Gateway', - 503: 'Service Unavailable', - 504: 'Gateway Timeout', - 505: 'HTTP Version Not Supported', - 506: 'Variant Also Negotiates', - 507: 'Insufficient Storage', - 508: 'Loop Detected', - 510: 'Not Extended', - 511: 'Network Authentication Required', - ...options.errors, - }; - - const error = errors[result.status]; - if (error) { - throw new ApiError(options, result, error); - } - - if (!result.ok) { - const errorStatus = result.status ?? 'unknown'; - const errorStatusText = result.statusText ?? 'unknown'; - const errorBody = (() => { - try { - return JSON.stringify(result.body, null, 2); - } catch (e) { - return undefined; - } - })(); - - throw new ApiError( - options, - result, - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`, - ); - } +export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Failed', + 413: 'Payload Too Large', + 414: 'URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'Im a teapot', + 421: 'Misdirected Request', + 422: 'Unprocessable Content', + 423: 'Locked', + 424: 'Failed Dependency', + 425: 'Too Early', + 426: 'Upgrade Required', + 428: 'Precondition Required', + 429: 'Too Many Requests', + 431: 'Request Header Fields Too Large', + 451: 'Unavailable For Legal Reasons', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', + 506: 'Variant Also Negotiates', + 507: 'Insufficient Storage', + 508: 'Loop Detected', + 510: 'Not Extended', + 511: 'Network Authentication Required', + ...options.errors, + } + + const error = errors[result.status]; + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + const errorStatus = result.status ?? 'unknown'; + const errorStatusText = result.statusText ?? 'unknown'; + const errorBody = (() => { + try { + return JSON.stringify(result.body, null, 2); + } catch (e) { + return undefined; + } + })(); + + throw new ApiError(options, result, + `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` + ); + } }; /** @@ -333,52 +304,38 @@ export const catchErrorCodes = ( * @returns CancelablePromise * @throws ApiError */ -export const request = ( - config: OpenAPIConfig, - options: ApiRequestOptions, -): CancelablePromise => { - return new CancelablePromise(async (resolve, reject, onCancel) => { - try { - const url = getUrl(config, options); - const formData = getFormData(options); - const body = getRequestBody(options); - const headers = await getHeaders(config, options); - - if (!onCancel.isCancelled) { - let response = await sendRequest( - config, - options, - url, - body, - formData, - headers, - onCancel, - ); - - for (const fn of config.interceptors.response._fns) { - response = await fn(response); - } - - const responseBody = getResponseBody(response); - const responseHeader = getResponseHeader( - response, - options.responseHeader, - ); - - const result: ApiResult = { - url, - ok: isSuccess(response.status), - status: response.status, - statusText: response.statusText, - body: responseHeader ?? responseBody, - }; - - catchErrorCodes(options, result); - - resolve(result.body); - } - } catch (error) { - reject(error); - } - }); -}; +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + let response = await sendRequest(config, options, url, body, formData, headers, onCancel); + + for (const fn of config.interceptors.response._fns) { + response = await fn(response); + } + + const responseBody = getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + const result: ApiResult = { + url, + ok: isSuccess(response.status), + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + reject(error); + } + }); +}; \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/index.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/index.ts.snap index f073fa9c4..d22d07cd0 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/index.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/index.ts.snap @@ -1,5 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts - export { ApiError } from './core/ApiError'; export { CancelablePromise, CancelError } from './core/CancelablePromise'; -export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; +export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; \ No newline at end of file diff --git a/packages/openapi-ts/test/bin.spec.ts b/packages/openapi-ts/test/bin.spec.ts index 95bc1d01a..6a4ef235a 100755 --- a/packages/openapi-ts/test/bin.spec.ts +++ b/packages/openapi-ts/test/bin.spec.ts @@ -12,7 +12,6 @@ describe('bin', () => { '--dry-run', 'true', ]); - expect(result.stdout.toString()).not.toContain('Prettier'); expect(result.stdout.toString()).toContain('Done!'); expect(result.stderr.toString()).toBe(''); }); @@ -147,6 +146,8 @@ describe('bin', () => { './test/spec/v3.json', '--output', './test/generated/bin', + '--format', + 'prettier', ]); expect(result.stdout.toString()).toContain('Prettier'); expect(result.stderr.toString()).toBe('');