From 34eb4009c66578ec74e81dbcbd7a3ff1867dfc96 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 4 Apr 2024 03:57:01 +0100 Subject: [PATCH] fix(openapi-ts): namespace service data types --- .changeset/neat-cars-scream.md | 5 + package.json | 3 +- packages/openapi-ts/rollup.config.ts | 1 - packages/openapi-ts/src/index.ts | 14 +- .../src/templates/exportService.hbs | 2 - .../partials/operationParameters.hbs | 6 +- .../src/utils/__tests__/handlebars.spec.ts | 1 - packages/openapi-ts/src/utils/handlebars.ts | 92 +- packages/openapi-ts/src/utils/write/models.ts | 4 +- .../openapi-ts/src/utils/write/schemas.ts | 4 +- .../openapi-ts/src/utils/write/services.ts | 71 +- .../test/generated/v2/services.ts.snap | 604 +++++------ .../test/generated/v3/services.ts.snap | 866 ++++++++-------- .../generated/v3_angular/services.ts.snap | 866 ++++++++-------- .../test/generated/v3_client/services.ts.snap | 862 ++++++++-------- .../v3_enums_typescript/services.ts.snap | 866 ++++++++-------- .../v3_experimental/services.ts.snap | 938 +++++++++--------- .../generated/v3_options/services.ts.snap | 178 ++-- packages/openapi-ts/test/bin.spec.ts | 4 - 19 files changed, 2847 insertions(+), 2540 deletions(-) create mode 100644 .changeset/neat-cars-scream.md diff --git a/.changeset/neat-cars-scream.md b/.changeset/neat-cars-scream.md new file mode 100644 index 000000000..a9ff31dec --- /dev/null +++ b/.changeset/neat-cars-scream.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix(openapi-ts): namespace service data types diff --git a/package.json b/package.json index b6de0704f..6f3756251 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,5 @@ "devDependencies": { "@changesets/cli": "2.27.1", "@svitejs/changesets-changelog-github-compact": "1.1.0" - }, - "packageManager": "pnpm@8.15.6+sha256.01c01eeb990e379b31ef19c03e9d06a14afa5250b82e81303f88721c99ff2e6f" + } } diff --git a/packages/openapi-ts/rollup.config.ts b/packages/openapi-ts/rollup.config.ts index 48d79fc08..ebb2a87d2 100644 --- a/packages/openapi-ts/rollup.config.ts +++ b/packages/openapi-ts/rollup.config.ts @@ -41,7 +41,6 @@ export function handlebarsPlugin(): Plugin { modelUnionType: true, nameOperationDataType: true, notEquals: true, - operationDataType: true, useDateType: true, }, knownHelpersOnly: true, diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index 848823738..aab4cd049 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -15,7 +15,7 @@ import { writeClient } from './utils/write/client'; type Dependencies = Record; -// Mapping of all dependencies used in each client. These should be installed in the generated client package +// Dependencies used in each client. User must have installed these to use the generated client const clientDependencies: Record = { angular: ['@angular/common', '@angular/core', 'rxjs'], axios: ['axios'], @@ -127,6 +127,18 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => throw new Error('🚫 output must be within the current working directory'); } + if (postfixModels) { + console.warn( + '⚠️ Deprecation warning: postfixModels. This setting will be removed in future versions. Please create an issue wih your use case if you need this option https://github.com/hey-api/openapi-ts/issues' + ); + } + + if (postfixServices && postfixServices !== 'Service') { + console.warn( + '⚠️ Deprecation warning: postfixServices. This setting will be removed in future versions. Please create an issue wih your use case if you need this option https://github.com/hey-api/openapi-ts/issues' + ); + } + if (!useOptions) { console.warn( '⚠️ Deprecation warning: useOptions set to false. This setting will be removed in future versions. Please migrate useOptions to true https://github.com/hey-api/openapi-ts#v0.27.38' diff --git a/packages/openapi-ts/src/templates/exportService.hbs b/packages/openapi-ts/src/templates/exportService.hbs index 0c6132dd9..eb0052caa 100644 --- a/packages/openapi-ts/src/templates/exportService.hbs +++ b/packages/openapi-ts/src/templates/exportService.hbs @@ -1,5 +1,3 @@ -{{{operationDataType this}}} - {{#equals @root.$config.client 'angular'}} @Injectable({ providedIn: 'root', diff --git a/packages/openapi-ts/src/templates/partials/operationParameters.hbs b/packages/openapi-ts/src/templates/partials/operationParameters.hbs index 2d466da83..b712304dc 100644 --- a/packages/openapi-ts/src/templates/partials/operationParameters.hbs +++ b/packages/openapi-ts/src/templates/partials/operationParameters.hbs @@ -1,11 +1,11 @@ {{#if @root.$config.useOptions~}} {{~#if @root.$config.name~}} -{{#if parameters}}data: {{{nameOperationDataType name}}}{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}}{{/if}} +{{#if parameters}}data: {{{nameOperationDataType @root this}}}{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}}{{/if}} {{~else~}} {{~#notEquals @root.$config.serviceResponse 'generics'~}} -{{#if parameters}}data: {{{nameOperationDataType name}}}{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}}{{/if}} +{{#if parameters}}data: {{{nameOperationDataType @root this}}}{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}}{{/if}} {{~else~}} -data: {{#if parameters}}{{{nameOperationDataType name}}} & {{/if}}TConfig{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}} +data: {{#if parameters}}{{{nameOperationDataType @root this}}} & {{/if}}TConfig{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}} {{~/notEquals~}} {{~/if~}} {{~else}} diff --git a/packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts b/packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts index afe749941..5ab67626c 100644 --- a/packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts +++ b/packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts @@ -53,7 +53,6 @@ describe('registerHandlebarHelpers', () => { expect(helpers).toContain('modelUnionType'); expect(helpers).toContain('nameOperationDataType'); expect(helpers).toContain('notEquals'); - expect(helpers).toContain('operationDataType'); expect(helpers).toContain('useDateType'); }); }); diff --git a/packages/openapi-ts/src/utils/handlebars.ts b/packages/openapi-ts/src/utils/handlebars.ts index 162595b4c..2f618ace0 100644 --- a/packages/openapi-ts/src/utils/handlebars.ts +++ b/packages/openapi-ts/src/utils/handlebars.ts @@ -129,41 +129,30 @@ const dataParameters = (config: Config, parameters: OperationParameter[]) => { // same as `>isRequired` partial const isRequired = (model: Pick) => (model.isRequired && !model.default ? '' : '?'); -const nameOperationDataType = (value: string) => camelCase(['T', 'Data', value].join('-'), { pascalCase: true }); +const nameOperationDataType = (service: Service, operation: Service['operations'][number]) => { + const namespace = `${camelCase(service.name, { pascalCase: true })}Data`; + const key = camelCase(operation.name, { pascalCase: true }); + return `${namespace}.${key}`; +}; -const operationDataType = (config: Config, service: Service) => { +export const operationDataType = (config: Config, service: Service) => { if (!config.useOptions) { return ''; } const partialType = Handlebars.partials['type']; - const output = service.operations - .filter(operation => operation.parameters.length) - .map(operation => { - const name = nameOperationDataType(operation.name); - return `export type ${name} = { - ${sortByName(operation.parameters) - .filter(parameter => { - if (!config.experimental) { - return true; - } - return parameter.in !== 'query'; - }) - .map(parameter => { - let comment: string[] = []; - if (parameter.description) { - comment = ['/**', ` * ${escapeComment(parameter.description)}`, ' */']; - } - return [ - ...comment, - `${parameter.name + isRequired(parameter)}: ${partialType({ $config: config, ...parameter })}`, - ].join('\n'); - }) - .join('\n')} - ${ - config.experimental - ? ` - query${operation.parametersQuery.every(parameter => !parameter.isRequired) ? '?' : ''}: { - ${sortByName(operation.parametersQuery) + const namespace = `${camelCase(service.name, { pascalCase: true })}Data`; + const output = `export type ${namespace} = { + ${service.operations + .filter(operation => operation.parameters.length) + .map( + operation => `${camelCase(operation.name, { pascalCase: true })}: { + ${sortByName(operation.parameters) + .filter(parameter => { + if (!config.experimental) { + return true; + } + return parameter.in !== 'query'; + }) .map(parameter => { let comment: string[] = []; if (parameter.description) { @@ -175,13 +164,31 @@ const operationDataType = (config: Config, service: Service) => { ].join('\n'); }) .join('\n')} - } - ` - : '' - } - }`; - }); - return output.join('\n'); + ${ + config.experimental + ? ` + query${operation.parametersQuery.every(parameter => !parameter.isRequired) ? '?' : ''}: { + ${sortByName(operation.parametersQuery) + .map(parameter => { + let comment: string[] = []; + if (parameter.description) { + comment = ['/**', ` * ${escapeComment(parameter.description)}`, ' */']; + } + return [ + ...comment, + `${parameter.name + isRequired(parameter)}: ${partialType({ $config: config, ...parameter })}`, + ].join('\n'); + }) + .join('\n')} + } + ` + : '' + } + };` + ) + .join('\n')} + }`; + return output; }; export const registerHandlebarHelpers = (config: Config, client: Client): void => { @@ -275,7 +282,12 @@ export const registerHandlebarHelpers = (config: Config, client: Client): void = } ); - Handlebars.registerHelper('nameOperationDataType', nameOperationDataType); + Handlebars.registerHelper( + 'nameOperationDataType', + function (service: Service, operation: Service['operations'][number]) { + return nameOperationDataType(service, operation); + } + ); Handlebars.registerHelper( 'notEquals', @@ -284,10 +296,6 @@ export const registerHandlebarHelpers = (config: Config, client: Client): void = } ); - Handlebars.registerHelper('operationDataType', function (service: Service) { - return operationDataType(config, service); - }); - Handlebars.registerHelper( 'useDateType', function (this: unknown, config: Config, format: string | undefined, options: Handlebars.HelperOptions) { diff --git a/packages/openapi-ts/src/utils/write/models.ts b/packages/openapi-ts/src/utils/write/models.ts index 11e6bd960..c2f37726a 100644 --- a/packages/openapi-ts/src/utils/write/models.ts +++ b/packages/openapi-ts/src/utils/write/models.ts @@ -18,10 +18,10 @@ export const writeClientModels = async ( outputPath: string, config: Config ): Promise => { - // Dont create empty file - if (client.models.length === 0) { + if (!client.models.length) { return; } + // Generate a file with all models const results: string[] = []; for (const model of client.models) { diff --git a/packages/openapi-ts/src/utils/write/schemas.ts b/packages/openapi-ts/src/utils/write/schemas.ts index a19b4be43..99d05adf1 100644 --- a/packages/openapi-ts/src/utils/write/schemas.ts +++ b/packages/openapi-ts/src/utils/write/schemas.ts @@ -18,10 +18,10 @@ export const writeClientSchemas = async ( outputPath: string, config: Config ): Promise => { - // Dont create empty file - if (client.models.length === 0) { + if (!client.models.length) { return; } + // Generate file with all schemas const results: string[] = []; for (const model of client.models) { diff --git a/packages/openapi-ts/src/utils/write/services.ts b/packages/openapi-ts/src/utils/write/services.ts index 64622421f..81a5d1cb4 100644 --- a/packages/openapi-ts/src/utils/write/services.ts +++ b/packages/openapi-ts/src/utils/write/services.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import type { Client } from '../../types/client'; import type { Config } from '../../types/config'; -import type { Templates } from '../handlebars'; +import { operationDataType, type Templates } from '../handlebars'; import { unique } from '../unique'; /** @@ -19,64 +19,69 @@ export const writeClientServices = async ( outputPath: string, config: Config ): Promise => { - // Dont create empty file - if (client.services.length === 0) { + if (!client.services.length) { return; } - // Generate a file with all services. - const results: string[] = []; - const imports: string[] = []; + + let imports: string[] = []; + let operationTypes: string[] = []; + let results: string[] = []; + for (const service of client.services) { const result = templates.exports.service({ $config: config, ...service, }); - imports.push(...service.imports); - results.push(result); - } - // Import all models required by the services. - const uniqueImports = imports.filter(unique); - if (uniqueImports.length > 0) { - const importString = `import type { ${uniqueImports.join(',')} } from './models';`; - results.unshift(importString); + const operationDataTypes = operationDataType(config, service); + imports = [...imports, ...service.imports]; + operationTypes = [...operationTypes, operationDataTypes]; + results = [...results, result]; } + // Import required packages and core files. - const imports2: string[] = []; + const coreImports: string[] = []; if (config.client === 'angular') { - imports2.push(`import { Injectable } from '@angular/core';`); + coreImports.push(`import { Injectable } from '@angular/core';`); if (config.name === undefined) { - imports2.push(`import { HttpClient } from '@angular/common/http';`); + coreImports.push(`import { HttpClient } from '@angular/common/http';`); } - imports2.push(`import type { Observable } from 'rxjs';`); + coreImports.push(`import type { Observable } from 'rxjs';`); } else { - imports2.push(`import type { CancelablePromise } from './core/CancelablePromise';`); + coreImports.push(`import type { CancelablePromise } from './core/CancelablePromise';`); } if (config.serviceResponse === 'response') { - imports2.push(`import type { ApiResult } from './core/ApiResult;`); + coreImports.push(`import type { ApiResult } from './core/ApiResult;`); } if (config.name) { if (config.client === 'angular') { - imports2.push(`import { BaseHttpRequest } from './core/BaseHttpRequest';`); + coreImports.push(`import { BaseHttpRequest } from './core/BaseHttpRequest';`); } else { - imports2.push(`import type { BaseHttpRequest } from './core/BaseHttpRequest';`); + coreImports.push(`import type { BaseHttpRequest } from './core/BaseHttpRequest';`); } } else { if (config.useOptions) { if (config.serviceResponse === 'generics') { - imports2.push(`import { mergeOpenApiConfig, OpenAPI } from './core/OpenAPI';`); - imports2.push(`import { request as __request } from './core/request';`); - imports2.push(`import type { TApiResponse, TConfig, TResult } from './core/types';`); + coreImports.push(`import { mergeOpenApiConfig, OpenAPI } from './core/OpenAPI';`); + coreImports.push(`import { request as __request } from './core/request';`); + coreImports.push(`import type { TApiResponse, TConfig, TResult } from './core/types';`); } else { - imports2.push(`import { OpenAPI } from './core/OpenAPI';`); - imports2.push(`import { request as __request } from './core/request';`); + coreImports.push(`import { OpenAPI } from './core/OpenAPI';`); + coreImports.push(`import { request as __request } from './core/request';`); } } else { - imports2.push(`import { OpenAPI } from './core/OpenAPI';`); - imports2.push(`import { request as __request } from './core/request';`); + coreImports.push(`import { OpenAPI } from './core/OpenAPI';`); + coreImports.push(`import { request as __request } from './core/request';`); } } - results.unshift(imports2.join('\n')); - // Generate index file exporting all generated service files. - const file = path.resolve(outputPath, 'services.ts'); - await writeFileSync(file, results.join('\n\n')); + + // Import all models required by the services. + let modelImportsString = ''; + const uniqueImports = imports.filter(unique); + if (uniqueImports.length) { + modelImportsString = `import type { ${uniqueImports.join(',')} } from './models';`; + } + + const data = [coreImports.join('\n'), modelImportsString, ...operationTypes, ...results].join('\n\n'); + + await writeFileSync(path.resolve(outputPath, 'services.ts'), data); }; diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.ts.snap index 1b9eb5589..2562ec051 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.ts.snap @@ -9,6 +9,295 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; +export type DefaultData = {}; + +export type SimpleData = {}; + +export type DescriptionsData = { + CallWithDescriptions: { + /** + * 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; + }; +}; + +export type ParametersData = { + CallWithParameters: { + /** + * 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; + }; + CallWithWeirdParameterNames: { + /** + * 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; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + /** + * 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; + }; +}; + +export type TypesData = { + Types: { + /** + * 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: Record; + /** + * 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; + }; +}; + +export type ComplexData = { + ComplexTypes: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + /** + * Status code to return + */ + status: string; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; +}; + export class DefaultService { /** * @throws ApiError @@ -93,48 +382,18 @@ export class SimpleService { } } -export type TDataCallWithDescriptions = { - /** - * 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; -}; - export class DescriptionsService { /** * @throws ApiError */ - public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): CancelablePromise { const { - parameterWithBackticks, parameterWithBreaks, + parameterWithBackticks, + parameterWithSlashes, parameterWithExpressionPlaceholders, parameterWithQuotes, parameterWithReservedCharacters, - parameterWithSlashes, } = data; return __request(OpenAPI, { method: 'POST', @@ -151,69 +410,12 @@ export class DescriptionsService { } } -export type TDataCallWithParameters = { - /** - * 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; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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; -}; - export class ParametersService { /** * @throws ApiError */ - public static callWithParameters(data: TDataCallWithParameters): CancelablePromise { - const { parameterBody, parameterForm, parameterHeader, parameterPath, parameterQuery } = data; + public static callWithParameters(data: ParametersData.CallWithParameters): CancelablePromise { + const { parameterHeader, parameterQuery, parameterForm, parameterBody, parameterPath } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -236,16 +438,18 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + public static callWithWeirdParameterNames( + data: ParametersData.CallWithWeirdParameterNames + ): CancelablePromise { const { - _default, - parameterBody, - parameterForm, parameterHeader, + parameterQuery, + parameterForm, + parameterBody, parameterPath1, parameterPath2, parameterPath3, - parameterQuery, + _default, } = data; return __request(OpenAPI, { method: 'POST', @@ -270,98 +474,19 @@ export class ParametersService { } } -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; -}; - export class DefaultsService { /** * @throws ApiError */ - public static callWithDefaultParameters(data: TDataCallWithDefaultParameters): CancelablePromise { + public static callWithDefaultParameters(data: DefaultsData.CallWithDefaultParameters): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'GET', @@ -380,16 +505,16 @@ export class DefaultsService { * @throws ApiError */ public static callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'POST', @@ -407,16 +532,16 @@ export class DefaultsService { /** * @throws ApiError */ - public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return __request(OpenAPI, { method: 'PUT', @@ -632,35 +757,12 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - /** - * 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; -}; - export class CollectionFormatService { /** * @throws ApiError */ - public static collectionFormat(data: TDataCollectionFormat): CancelablePromise { - const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = + public static collectionFormat(data: CollectionFormatData.CollectionFormat): CancelablePromise { + const { parameterArrayCsv, parameterArraySsv, parameterArrayTsv, parameterArrayPipes, parameterArrayMulti } = data; return __request(OpenAPI, { method: 'GET', @@ -676,41 +778,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * 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: Record; - /** - * 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; -}; - export class TypesService { /** * @returns number Response is a simple number @@ -719,16 +786,16 @@ export class TypesService { * @returns any Response is a simple object * @throws ApiError */ - public static types(data: TDataTypes): CancelablePromise { + public static types(data: TypesData.Types): CancelablePromise { const { - id, parameterArray, - parameterBoolean = true, parameterDictionary, parameterEnum, parameterNumber = 123, - parameterObject = null, parameterString = 'default', + parameterBoolean = true, + parameterObject = null, + id, } = data; return __request(OpenAPI, { method: 'GET', @@ -749,29 +816,12 @@ export class TypesService { } } -export type TDataComplexTypes = { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; -}; - export class ComplexService { /** * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: TDataComplexTypes): CancelablePromise> { + public static complexTypes(data: ComplexData.ComplexTypes): CancelablePromise> { const { parameterObject, parameterReference } = data; return __request(OpenAPI, { method: 'GET', @@ -806,19 +856,12 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - /** - * Status code to return - */ - status: string; -}; - export class ErrorService { /** * @returns any Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: TDataTestErrorCode): CancelablePromise { + public static testErrorCode(data: ErrorData.TestErrorCode): CancelablePromise { const { status } = data; return __request(OpenAPI, { method: 'POST', @@ -836,20 +879,13 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; -}; - export class NonAsciiÆøåÆøÅöôêÊService { /** * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ public static nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): CancelablePromise { const { nonAsciiParamæøåÆøÅöôêÊ } = data; return __request(OpenAPI, { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.ts.snap index 5ed220f66..a8a4e9555 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.ts.snap @@ -18,8 +18,412 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; -export type TDataPostServiceWithEmptyTag = { - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +export type DefaultData = { + PostServiceWithEmptyTag: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; +}; + +export type SimpleData = {}; + +export type ParametersData = { + DeleteFoo: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + CallWithParameters: { + 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; + }; + CallWithWeirdParameterNames: { + /** + * 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; + }; + GetCallWithOptionalParam: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + PostCallWithOptionalParam: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; +}; + +export type DescriptionsData = { + CallWithDescriptions: { + /** + * 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; + }; +}; + +export type DeprecatedData = { + DeprecatedCall: { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + }; +}; + +export type RequestBodyData = { + PostApiRequestBody: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type FormDataData = { + PostApiFormData: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + /** + * 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; + }; +}; + +export type TypesData = { + Types: { + /** + * 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: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; +}; + +export type UploadData = { + UploadFile: { + /** + * Supply a file reference for upload + */ + file: Blob | File; + }; +}; + +export type FileResponseData = { + FileResponse: { + id: string; + }; +}; + +export type ComplexData = { + ComplexTypes: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + ComplexParams: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; +}; + +export type MultipartData = { + MultipartRequest: { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; }; export class DefaultService { @@ -38,7 +442,7 @@ export class DefaultService { * @throws ApiError */ public static postServiceWithEmptyTag( - data: TDataPostServiceWithEmptyTag + data: DefaultData.PostServiceWithEmptyTag ): CancelablePromise { const { requestBody } = data; return __request(OpenAPI, { @@ -122,109 +526,12 @@ export class SimpleService { } } -export type TDataDeleteFoo = { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; -}; -export type TDataCallWithParameters = { - 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; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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; -}; -export type TDataGetCallWithOptionalParam = { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; -}; -export type TDataPostCallWithOptionalParam = { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; -}; - export class ParametersService { /** * @throws ApiError */ - public static deleteFoo(data: TDataDeleteFoo): CancelablePromise { - const { bar, foo } = data; + public static deleteFoo(data: ParametersData.DeleteFoo): CancelablePromise { + const { foo, bar } = data; return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -238,16 +545,16 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithParameters(data: TDataCallWithParameters): CancelablePromise { + public static callWithParameters(data: ParametersData.CallWithParameters): CancelablePromise { const { + parameterHeader, fooAllOfEnum, - fooRefEnum, - parameterCookie, + parameterQuery, parameterForm, - parameterHeader, + parameterCookie, parameterPath, - parameterQuery, requestBody, + fooRefEnum, } = data; return __request(OpenAPI, { method: 'POST', @@ -277,17 +584,19 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + public static callWithWeirdParameterNames( + data: ParametersData.CallWithWeirdParameterNames + ): CancelablePromise { const { - _default, - parameterCookie, - parameterForm, parameterHeader, + parameterQuery, + parameterForm, + parameterCookie, + requestBody, parameterPath1, parameterPath2, parameterPath3, - parameterQuery, - requestBody, + _default, } = data; return __request(OpenAPI, { method: 'POST', @@ -318,8 +627,8 @@ export class ParametersService { /** * @throws ApiError */ - public static getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise { - const { parameter, requestBody } = data; + public static getCallWithOptionalParam(data: ParametersData.GetCallWithOptionalParam): CancelablePromise { + const { requestBody, parameter } = data; return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -334,7 +643,7 @@ export class ParametersService { /** * @throws ApiError */ - public static postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersData.PostCallWithOptionalParam): CancelablePromise { const { parameter, requestBody } = data; return __request(OpenAPI, { method: 'POST', @@ -348,48 +657,18 @@ export class ParametersService { } } -export type TDataCallWithDescriptions = { - /** - * 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; -}; - export class DescriptionsService { /** * @throws ApiError */ - public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): CancelablePromise { const { - parameterWithBackticks, parameterWithBreaks, + parameterWithBackticks, + parameterWithSlashes, parameterWithExpressionPlaceholders, parameterWithQuotes, parameterWithReservedCharacters, - parameterWithSlashes, } = data; return __request(OpenAPI, { method: 'POST', @@ -406,19 +685,12 @@ export class DescriptionsService { } } -export type TDataDeprecatedCall = { - /** - * This parameter is deprecated - */ - parameter: DeprecatedModel | null; -}; - export class DeprecatedService { /** * @deprecated * @throws ApiError */ - public static deprecatedCall(data: TDataDeprecatedCall): CancelablePromise { + public static deprecatedCall(data: DeprecatedData.DeprecatedCall): CancelablePromise { const { parameter } = data; return __request(OpenAPI, { method: 'POST', @@ -430,23 +702,12 @@ export class DeprecatedService { } } -export type TDataPostApiRequestBody = { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class RequestBodyService { /** * @throws ApiError */ - public static postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise { - const { foo, parameter } = data; + public static postApiRequestBody(data: RequestBodyData.PostApiRequestBody = {}): CancelablePromise { + const { parameter, foo } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -459,23 +720,12 @@ export class RequestBodyService { } } -export type TDataPostApiFormData = { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class FormDataService { /** * @throws ApiError */ - public static postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise { - const { formData, parameter } = data; + public static postApiFormData(data: FormDataData.PostApiFormData = {}): CancelablePromise { + const { parameter, formData } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -488,98 +738,21 @@ export class FormDataService { } } -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; -}; - export class DefaultsService { /** * @throws ApiError */ - public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + public static callWithDefaultParameters( + data: DefaultsData.CallWithDefaultParameters = {} + ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'GET', @@ -598,16 +771,16 @@ export class DefaultsService { * @throws ApiError */ public static callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'POST', @@ -625,16 +798,16 @@ export class DefaultsService { /** * @throws ApiError */ - public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return __request(OpenAPI, { method: 'PUT', @@ -850,35 +1023,12 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - /** - * 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; -}; - export class CollectionFormatService { /** * @throws ApiError */ - public static collectionFormat(data: TDataCollectionFormat): CancelablePromise { - const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = + public static collectionFormat(data: CollectionFormatData.CollectionFormat): CancelablePromise { + const { parameterArrayCsv, parameterArraySsv, parameterArrayTsv, parameterArrayPipes, parameterArrayMulti } = data; return __request(OpenAPI, { method: 'GET', @@ -894,41 +1044,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * 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: Record | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber?: number; - /** - * This is an object parameter - */ - parameterObject?: Record | null; - /** - * This is a string parameter - */ - parameterString?: string | null; -}; - export class TypesService { /** * @returns number Response is a simple number @@ -937,16 +1052,16 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: TDataTypes): CancelablePromise> { + public static types(data: TypesData.Types): CancelablePromise> { const { - id, parameterArray, - parameterBoolean = true, parameterDictionary, parameterEnum, parameterNumber = 123, - parameterObject = null, parameterString = 'default', + parameterBoolean = true, + parameterObject = null, + id, } = data; return __request(OpenAPI, { method: 'GET', @@ -967,19 +1082,12 @@ export class TypesService { } } -export type TDataUploadFile = { - /** - * Supply a file reference for upload - */ - file: Blob | File; -}; - export class UploadService { /** * @returns boolean * @throws ApiError */ - public static uploadFile(data: TDataUploadFile): CancelablePromise { + public static uploadFile(data: UploadData.UploadFile): CancelablePromise { const { file } = data; return __request(OpenAPI, { method: 'POST', @@ -991,16 +1099,12 @@ export class UploadService { } } -export type TDataFileResponse = { - id: string; -}; - export class FileResponseService { /** * @returns binary Success * @throws ApiError */ - public static fileResponse(data: TDataFileResponse): CancelablePromise { + public static fileResponse(data: FileResponseData.FileResponse): CancelablePromise { const { id } = data; return __request(OpenAPI, { method: 'GET', @@ -1012,45 +1116,12 @@ export class FileResponseService { } } -export type TDataComplexTypes = { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; -}; -export type TDataComplexParams = { - 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; - }; - }; -}; - export class ComplexService { /** * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: TDataComplexTypes): CancelablePromise> { + public static complexTypes(data: ComplexData.ComplexTypes): CancelablePromise> { const { parameterObject, parameterReference } = data; return __request(OpenAPI, { method: 'GET', @@ -1070,7 +1141,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public static complexParams(data: TDataComplexParams): CancelablePromise { + public static complexParams(data: ComplexData.ComplexParams): CancelablePromise { const { id, requestBody } = data; return __request(OpenAPI, { method: 'PUT', @@ -1084,18 +1155,11 @@ export class ComplexService { } } -export type TDataMultipartRequest = { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; - }; -}; - export class MultipartService { /** * @throws ApiError */ - public static multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise { + public static multipartRequest(data: MultipartData.MultipartRequest = {}): CancelablePromise { const { formData } = data; return __request(OpenAPI, { method: 'POST', @@ -1141,19 +1205,12 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - /** - * Status code to return - */ - status: number; -}; - export class ErrorService { /** * @returns any Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: TDataTestErrorCode): CancelablePromise { + public static testErrorCode(data: ErrorData.TestErrorCode): CancelablePromise { const { status } = data; return __request(OpenAPI, { method: 'POST', @@ -1171,20 +1228,13 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; -}; - export class NonAsciiÆøåÆøÅöôêÊService { /** * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ public static nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): CancelablePromise> { const { nonAsciiParamæøåÆøÅöôêÊ } = data; return __request(OpenAPI, { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.ts.snap index cf66b6202..1927db249 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.ts.snap @@ -20,8 +20,412 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; -export type TDataPostServiceWithEmptyTag = { - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +export type DefaultData = { + PostServiceWithEmptyTag: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; +}; + +export type SimpleData = {}; + +export type ParametersData = { + DeleteFoo: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + CallWithParameters: { + 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; + }; + CallWithWeirdParameterNames: { + /** + * 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; + }; + GetCallWithOptionalParam: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + PostCallWithOptionalParam: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; +}; + +export type DescriptionsData = { + CallWithDescriptions: { + /** + * 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; + }; +}; + +export type DeprecatedData = { + DeprecatedCall: { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + }; +}; + +export type RequestBodyData = { + PostApiRequestBody: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type FormDataData = { + PostApiFormData: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + /** + * 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; + }; +}; + +export type TypesData = { + Types: { + /** + * 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: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; +}; + +export type UploadData = { + UploadFile: { + /** + * Supply a file reference for upload + */ + file: Blob | File; + }; +}; + +export type FileResponseData = { + FileResponse: { + id: string; + }; +}; + +export type ComplexData = { + ComplexTypes: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + ComplexParams: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; +}; + +export type MultipartData = { + MultipartRequest: { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; }; @Injectable({ @@ -44,7 +448,9 @@ export class DefaultService { * @returns ModelWithReadOnlyAndWriteOnly * @throws ApiError */ - public postServiceWithEmptyTag(data: TDataPostServiceWithEmptyTag): Observable { + public postServiceWithEmptyTag( + data: DefaultData.PostServiceWithEmptyTag + ): Observable { const { requestBody } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -132,103 +538,6 @@ export class SimpleService { } } -export type TDataDeleteFoo = { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; -}; -export type TDataCallWithParameters = { - 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; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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; -}; -export type TDataGetCallWithOptionalParam = { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; -}; -export type TDataPostCallWithOptionalParam = { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; -}; - @Injectable({ providedIn: 'root', }) @@ -238,8 +547,8 @@ export class ParametersService { /** * @throws ApiError */ - public deleteFoo(data: TDataDeleteFoo): Observable { - const { bar, foo } = data; + public deleteFoo(data: ParametersData.DeleteFoo): Observable { + const { foo, bar } = data; return __request(OpenAPI, this.http, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -253,16 +562,16 @@ export class ParametersService { /** * @throws ApiError */ - public callWithParameters(data: TDataCallWithParameters): Observable { + public callWithParameters(data: ParametersData.CallWithParameters): Observable { const { + parameterHeader, fooAllOfEnum, - fooRefEnum, - parameterCookie, + parameterQuery, parameterForm, - parameterHeader, + parameterCookie, parameterPath, - parameterQuery, requestBody, + fooRefEnum, } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -292,17 +601,17 @@ export class ParametersService { /** * @throws ApiError */ - public callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): Observable { + public callWithWeirdParameterNames(data: ParametersData.CallWithWeirdParameterNames): Observable { const { - _default, - parameterCookie, - parameterForm, parameterHeader, + parameterQuery, + parameterForm, + parameterCookie, + requestBody, parameterPath1, parameterPath2, parameterPath3, - parameterQuery, - requestBody, + _default, } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -333,8 +642,8 @@ export class ParametersService { /** * @throws ApiError */ - public getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): Observable { - const { parameter, requestBody } = data; + public getCallWithOptionalParam(data: ParametersData.GetCallWithOptionalParam): Observable { + const { requestBody, parameter } = data; return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -349,7 +658,7 @@ export class ParametersService { /** * @throws ApiError */ - public postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): Observable { + public postCallWithOptionalParam(data: ParametersData.PostCallWithOptionalParam): Observable { const { parameter, requestBody } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -363,36 +672,6 @@ export class ParametersService { } } -export type TDataCallWithDescriptions = { - /** - * 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; -}; - @Injectable({ providedIn: 'root', }) @@ -402,14 +681,14 @@ export class DescriptionsService { /** * @throws ApiError */ - public callWithDescriptions(data: TDataCallWithDescriptions = {}): Observable { + public callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): Observable { const { - parameterWithBackticks, parameterWithBreaks, + parameterWithBackticks, + parameterWithSlashes, parameterWithExpressionPlaceholders, parameterWithQuotes, parameterWithReservedCharacters, - parameterWithSlashes, } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -426,13 +705,6 @@ export class DescriptionsService { } } -export type TDataDeprecatedCall = { - /** - * This parameter is deprecated - */ - parameter: DeprecatedModel | null; -}; - @Injectable({ providedIn: 'root', }) @@ -443,7 +715,7 @@ export class DeprecatedService { * @deprecated * @throws ApiError */ - public deprecatedCall(data: TDataDeprecatedCall): Observable { + public deprecatedCall(data: DeprecatedData.DeprecatedCall): Observable { const { parameter } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -455,17 +727,6 @@ export class DeprecatedService { } } -export type TDataPostApiRequestBody = { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - @Injectable({ providedIn: 'root', }) @@ -475,8 +736,8 @@ export class RequestBodyService { /** * @throws ApiError */ - public postApiRequestBody(data: TDataPostApiRequestBody = {}): Observable { - const { foo, parameter } = data; + public postApiRequestBody(data: RequestBodyData.PostApiRequestBody = {}): Observable { + const { parameter, foo } = data; return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -489,17 +750,6 @@ export class RequestBodyService { } } -export type TDataPostApiFormData = { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - @Injectable({ providedIn: 'root', }) @@ -509,8 +759,8 @@ export class FormDataService { /** * @throws ApiError */ - public postApiFormData(data: TDataPostApiFormData = {}): Observable { - const { formData, parameter } = data; + public postApiFormData(data: FormDataData.PostApiFormData = {}): Observable { + const { parameter, formData } = data; return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -523,85 +773,6 @@ export class FormDataService { } } -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; -}; - @Injectable({ providedIn: 'root', }) @@ -611,15 +782,15 @@ export class DefaultsService { /** * @throws ApiError */ - public callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): Observable { + public callWithDefaultParameters(data: DefaultsData.CallWithDefaultParameters = {}): Observable { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, this.http, { method: 'GET', @@ -637,15 +808,17 @@ export class DefaultsService { /** * @throws ApiError */ - public callWithDefaultOptionalParameters(data: TDataCallWithDefaultOptionalParameters = {}): Observable { + public callWithDefaultOptionalParameters( + data: DefaultsData.CallWithDefaultOptionalParameters = {} + ): Observable { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -663,16 +836,16 @@ export class DefaultsService { /** * @throws ApiError */ - public callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): Observable { + public callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): Observable { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return __request(OpenAPI, this.http, { method: 'PUT', @@ -918,29 +1091,6 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - /** - * 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; -}; - @Injectable({ providedIn: 'root', }) @@ -950,8 +1100,8 @@ export class CollectionFormatService { /** * @throws ApiError */ - public collectionFormat(data: TDataCollectionFormat): Observable { - const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = + public collectionFormat(data: CollectionFormatData.CollectionFormat): Observable { + const { parameterArrayCsv, parameterArraySsv, parameterArrayTsv, parameterArrayPipes, parameterArrayMulti } = data; return __request(OpenAPI, this.http, { method: 'GET', @@ -967,41 +1117,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * 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: Record | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber?: number; - /** - * This is an object parameter - */ - parameterObject?: Record | null; - /** - * This is a string parameter - */ - parameterString?: string | null; -}; - @Injectable({ providedIn: 'root', }) @@ -1015,16 +1130,16 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public types(data: TDataTypes): Observable> { + public types(data: TypesData.Types): Observable> { const { - id, parameterArray, - parameterBoolean = true, parameterDictionary, parameterEnum, parameterNumber = 123, - parameterObject = null, parameterString = 'default', + parameterBoolean = true, + parameterObject = null, + id, } = data; return __request(OpenAPI, this.http, { method: 'GET', @@ -1045,13 +1160,6 @@ export class TypesService { } } -export type TDataUploadFile = { - /** - * Supply a file reference for upload - */ - file: Blob | File; -}; - @Injectable({ providedIn: 'root', }) @@ -1062,7 +1170,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public uploadFile(data: TDataUploadFile): Observable { + public uploadFile(data: UploadData.UploadFile): Observable { const { file } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -1074,10 +1182,6 @@ export class UploadService { } } -export type TDataFileResponse = { - id: string; -}; - @Injectable({ providedIn: 'root', }) @@ -1088,7 +1192,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: TDataFileResponse): Observable { + public fileResponse(data: FileResponseData.FileResponse): Observable { const { id } = data; return __request(OpenAPI, this.http, { method: 'GET', @@ -1100,39 +1204,6 @@ export class FileResponseService { } } -export type TDataComplexTypes = { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; -}; -export type TDataComplexParams = { - 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; - }; - }; -}; - @Injectable({ providedIn: 'root', }) @@ -1143,7 +1214,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public complexTypes(data: TDataComplexTypes): Observable> { + public complexTypes(data: ComplexData.ComplexTypes): Observable> { const { parameterObject, parameterReference } = data; return __request(OpenAPI, this.http, { method: 'GET', @@ -1163,7 +1234,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public complexParams(data: TDataComplexParams): Observable { + public complexParams(data: ComplexData.ComplexParams): Observable { const { id, requestBody } = data; return __request(OpenAPI, this.http, { method: 'PUT', @@ -1177,13 +1248,6 @@ export class ComplexService { } } -export type TDataMultipartRequest = { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; - }; -}; - @Injectable({ providedIn: 'root', }) @@ -1193,7 +1257,7 @@ export class MultipartService { /** * @throws ApiError */ - public multipartRequest(data: TDataMultipartRequest = {}): Observable { + public multipartRequest(data: MultipartData.MultipartRequest = {}): Observable { const { formData } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -1244,13 +1308,6 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - /** - * Status code to return - */ - status: number; -}; - @Injectable({ providedIn: 'root', }) @@ -1261,7 +1318,7 @@ export class ErrorService { * @returns any Custom message: Successful response * @throws ApiError */ - public testErrorCode(data: TDataTestErrorCode): Observable { + public testErrorCode(data: ErrorData.TestErrorCode): Observable { const { status } = data; return __request(OpenAPI, this.http, { method: 'POST', @@ -1279,13 +1336,6 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; -}; - @Injectable({ providedIn: 'root', }) @@ -1297,7 +1347,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @throws ApiError */ public nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): Observable> { const { nonAsciiParamæøåÆøÅöôêÊ } = data; return __request(OpenAPI, this.http, { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.ts.snap index b8873e09a..e46028ffe 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.ts.snap @@ -17,8 +17,412 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; -export type TDataPostServiceWithEmptyTag = { - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +export type DefaultData = { + PostServiceWithEmptyTag: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; +}; + +export type SimpleData = {}; + +export type ParametersData = { + DeleteFoo: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + CallWithParameters: { + 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; + }; + CallWithWeirdParameterNames: { + /** + * 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; + }; + GetCallWithOptionalParam: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + PostCallWithOptionalParam: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; +}; + +export type DescriptionsData = { + CallWithDescriptions: { + /** + * 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; + }; +}; + +export type DeprecatedData = { + DeprecatedCall: { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + }; +}; + +export type RequestBodyData = { + PostApiRequestBody: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type FormDataData = { + PostApiFormData: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + /** + * 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; + }; +}; + +export type TypesData = { + Types: { + /** + * 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: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; +}; + +export type UploadData = { + UploadFile: { + /** + * Supply a file reference for upload + */ + file: Blob | File; + }; +}; + +export type FileResponseData = { + FileResponse: { + id: string; + }; +}; + +export type ComplexData = { + ComplexTypes: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + ComplexParams: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; +}; + +export type MultipartData = { + MultipartRequest: { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; }; export class DefaultService { @@ -39,7 +443,7 @@ export class DefaultService { * @throws ApiError */ public postServiceWithEmptyTag( - data: TDataPostServiceWithEmptyTag + data: DefaultData.PostServiceWithEmptyTag ): CancelablePromise { const { requestBody } = data; return this.httpRequest.request({ @@ -125,111 +529,14 @@ export class SimpleService { } } -export type TDataDeleteFoo = { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; -}; -export type TDataCallWithParameters = { - 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; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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; -}; -export type TDataGetCallWithOptionalParam = { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; -}; -export type TDataPostCallWithOptionalParam = { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; -}; - export class ParametersService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public deleteFoo(data: TDataDeleteFoo): CancelablePromise { - const { bar, foo } = data; + public deleteFoo(data: ParametersData.DeleteFoo): CancelablePromise { + const { foo, bar } = data; return this.httpRequest.request({ method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -243,16 +550,16 @@ export class ParametersService { /** * @throws ApiError */ - public callWithParameters(data: TDataCallWithParameters): CancelablePromise { + public callWithParameters(data: ParametersData.CallWithParameters): CancelablePromise { const { + parameterHeader, fooAllOfEnum, - fooRefEnum, - parameterCookie, + parameterQuery, parameterForm, - parameterHeader, + parameterCookie, parameterPath, - parameterQuery, requestBody, + fooRefEnum, } = data; return this.httpRequest.request({ method: 'POST', @@ -282,17 +589,17 @@ export class ParametersService { /** * @throws ApiError */ - public callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + public callWithWeirdParameterNames(data: ParametersData.CallWithWeirdParameterNames): CancelablePromise { const { - _default, - parameterCookie, - parameterForm, parameterHeader, + parameterQuery, + parameterForm, + parameterCookie, + requestBody, parameterPath1, parameterPath2, parameterPath3, - parameterQuery, - requestBody, + _default, } = data; return this.httpRequest.request({ method: 'POST', @@ -323,8 +630,8 @@ export class ParametersService { /** * @throws ApiError */ - public getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise { - const { parameter, requestBody } = data; + public getCallWithOptionalParam(data: ParametersData.GetCallWithOptionalParam): CancelablePromise { + const { requestBody, parameter } = data; return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/parameters/', @@ -339,7 +646,7 @@ export class ParametersService { /** * @throws ApiError */ - public postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise { + public postCallWithOptionalParam(data: ParametersData.PostCallWithOptionalParam): CancelablePromise { const { parameter, requestBody } = data; return this.httpRequest.request({ method: 'POST', @@ -353,50 +660,20 @@ export class ParametersService { } } -export type TDataCallWithDescriptions = { - /** - * 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; -}; - export class DescriptionsService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + public callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): CancelablePromise { const { - parameterWithBackticks, parameterWithBreaks, + parameterWithBackticks, + parameterWithSlashes, parameterWithExpressionPlaceholders, parameterWithQuotes, parameterWithReservedCharacters, - parameterWithSlashes, } = data; return this.httpRequest.request({ method: 'POST', @@ -413,13 +690,6 @@ export class DescriptionsService { } } -export type TDataDeprecatedCall = { - /** - * This parameter is deprecated - */ - parameter: DeprecatedModel | null; -}; - export class DeprecatedService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -427,7 +697,7 @@ export class DeprecatedService { * @deprecated * @throws ApiError */ - public deprecatedCall(data: TDataDeprecatedCall): CancelablePromise { + public deprecatedCall(data: DeprecatedData.DeprecatedCall): CancelablePromise { const { parameter } = data; return this.httpRequest.request({ method: 'POST', @@ -439,25 +709,14 @@ export class DeprecatedService { } } -export type TDataPostApiRequestBody = { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class RequestBodyService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise { - const { foo, parameter } = data; + public postApiRequestBody(data: RequestBodyData.PostApiRequestBody = {}): CancelablePromise { + const { parameter, foo } = data; return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -470,25 +729,14 @@ export class RequestBodyService { } } -export type TDataPostApiFormData = { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class FormDataService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise { - const { formData, parameter } = data; + public postApiFormData(data: FormDataData.PostApiFormData = {}): CancelablePromise { + const { parameter, formData } = data; return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/formData/', @@ -501,100 +749,21 @@ export class FormDataService { } } -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; -}; - export class DefaultsService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + public callWithDefaultParameters(data: DefaultsData.CallWithDefaultParameters = {}): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return this.httpRequest.request({ method: 'GET', @@ -613,16 +782,16 @@ export class DefaultsService { * @throws ApiError */ public callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return this.httpRequest.request({ method: 'POST', @@ -640,16 +809,16 @@ export class DefaultsService { /** * @throws ApiError */ - public callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return this.httpRequest.request({ method: 'PUT', @@ -877,37 +1046,14 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - /** - * 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; -}; - export class CollectionFormatService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public collectionFormat(data: TDataCollectionFormat): CancelablePromise { - const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = + public collectionFormat(data: CollectionFormatData.CollectionFormat): CancelablePromise { + const { parameterArrayCsv, parameterArraySsv, parameterArrayTsv, parameterArrayPipes, parameterArrayMulti } = data; return this.httpRequest.request({ method: 'GET', @@ -923,41 +1069,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * 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: Record | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber?: number; - /** - * This is an object parameter - */ - parameterObject?: Record | null; - /** - * This is a string parameter - */ - parameterString?: string | null; -}; - export class TypesService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -968,16 +1079,16 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public types(data: TDataTypes): CancelablePromise> { + public types(data: TypesData.Types): CancelablePromise> { const { - id, parameterArray, - parameterBoolean = true, parameterDictionary, parameterEnum, parameterNumber = 123, - parameterObject = null, parameterString = 'default', + parameterBoolean = true, + parameterObject = null, + id, } = data; return this.httpRequest.request({ method: 'GET', @@ -998,13 +1109,6 @@ export class TypesService { } } -export type TDataUploadFile = { - /** - * Supply a file reference for upload - */ - file: Blob | File; -}; - export class UploadService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -1012,7 +1116,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public uploadFile(data: TDataUploadFile): CancelablePromise { + public uploadFile(data: UploadData.UploadFile): CancelablePromise { const { file } = data; return this.httpRequest.request({ method: 'POST', @@ -1024,10 +1128,6 @@ export class UploadService { } } -export type TDataFileResponse = { - id: string; -}; - export class FileResponseService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -1035,7 +1135,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: TDataFileResponse): CancelablePromise { + public fileResponse(data: FileResponseData.FileResponse): CancelablePromise { const { id } = data; return this.httpRequest.request({ method: 'GET', @@ -1047,39 +1147,6 @@ export class FileResponseService { } } -export type TDataComplexTypes = { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; -}; -export type TDataComplexParams = { - 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; - }; - }; -}; - export class ComplexService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -1087,7 +1154,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public complexTypes(data: TDataComplexTypes): CancelablePromise> { + public complexTypes(data: ComplexData.ComplexTypes): CancelablePromise> { const { parameterObject, parameterReference } = data; return this.httpRequest.request({ method: 'GET', @@ -1107,7 +1174,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public complexParams(data: TDataComplexParams): CancelablePromise { + public complexParams(data: ComplexData.ComplexParams): CancelablePromise { const { id, requestBody } = data; return this.httpRequest.request({ method: 'PUT', @@ -1121,20 +1188,13 @@ export class ComplexService { } } -export type TDataMultipartRequest = { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; - }; -}; - export class MultipartService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** * @throws ApiError */ - public multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise { + public multipartRequest(data: MultipartData.MultipartRequest = {}): CancelablePromise { const { formData } = data; return this.httpRequest.request({ method: 'POST', @@ -1182,13 +1242,6 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - /** - * Status code to return - */ - status: number; -}; - export class ErrorService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -1196,7 +1249,7 @@ export class ErrorService { * @returns any Custom message: Successful response * @throws ApiError */ - public testErrorCode(data: TDataTestErrorCode): CancelablePromise { + public testErrorCode(data: ErrorData.TestErrorCode): CancelablePromise { const { status } = data; return this.httpRequest.request({ method: 'POST', @@ -1214,13 +1267,6 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; -}; - export class NonAsciiÆøåÆøÅöôêÊService { constructor(public readonly httpRequest: BaseHttpRequest) {} @@ -1229,7 +1275,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @throws ApiError */ public nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): CancelablePromise> { const { nonAsciiParamæøåÆøÅöôêÊ } = data; return this.httpRequest.request({ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.ts.snap index 5ed220f66..a8a4e9555 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.ts.snap @@ -18,8 +18,412 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; -export type TDataPostServiceWithEmptyTag = { - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +export type DefaultData = { + PostServiceWithEmptyTag: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; + }; +}; + +export type SimpleData = {}; + +export type ParametersData = { + DeleteFoo: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + }; + CallWithParameters: { + 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; + }; + CallWithWeirdParameterNames: { + /** + * 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; + }; + GetCallWithOptionalParam: { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + }; + PostCallWithOptionalParam: { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + }; +}; + +export type DescriptionsData = { + CallWithDescriptions: { + /** + * 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; + }; +}; + +export type DeprecatedData = { + DeprecatedCall: { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + }; +}; + +export type RequestBodyData = { + PostApiRequestBody: { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type FormDataData = { + PostApiFormData: { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + /** + * 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; + }; +}; + +export type TypesData = { + Types: { + /** + * 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: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; +}; + +export type UploadData = { + UploadFile: { + /** + * Supply a file reference for upload + */ + file: Blob | File; + }; +}; + +export type FileResponseData = { + FileResponse: { + id: string; + }; +}; + +export type ComplexData = { + ComplexTypes: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + ComplexParams: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + }; +}; + +export type MultipartData = { + MultipartRequest: { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + /** + * Status code to return + */ + status: number; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; }; export class DefaultService { @@ -38,7 +442,7 @@ export class DefaultService { * @throws ApiError */ public static postServiceWithEmptyTag( - data: TDataPostServiceWithEmptyTag + data: DefaultData.PostServiceWithEmptyTag ): CancelablePromise { const { requestBody } = data; return __request(OpenAPI, { @@ -122,109 +526,12 @@ export class SimpleService { } } -export type TDataDeleteFoo = { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; -}; -export type TDataCallWithParameters = { - 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; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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; -}; -export type TDataGetCallWithOptionalParam = { - /** - * This is an optional parameter - */ - parameter?: string; - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; -}; -export type TDataPostCallWithOptionalParam = { - /** - * This is a required parameter - */ - parameter: Pageable; - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; -}; - export class ParametersService { /** * @throws ApiError */ - public static deleteFoo(data: TDataDeleteFoo): CancelablePromise { - const { bar, foo } = data; + public static deleteFoo(data: ParametersData.DeleteFoo): CancelablePromise { + const { foo, bar } = data; return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -238,16 +545,16 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithParameters(data: TDataCallWithParameters): CancelablePromise { + public static callWithParameters(data: ParametersData.CallWithParameters): CancelablePromise { const { + parameterHeader, fooAllOfEnum, - fooRefEnum, - parameterCookie, + parameterQuery, parameterForm, - parameterHeader, + parameterCookie, parameterPath, - parameterQuery, requestBody, + fooRefEnum, } = data; return __request(OpenAPI, { method: 'POST', @@ -277,17 +584,19 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + public static callWithWeirdParameterNames( + data: ParametersData.CallWithWeirdParameterNames + ): CancelablePromise { const { - _default, - parameterCookie, - parameterForm, parameterHeader, + parameterQuery, + parameterForm, + parameterCookie, + requestBody, parameterPath1, parameterPath2, parameterPath3, - parameterQuery, - requestBody, + _default, } = data; return __request(OpenAPI, { method: 'POST', @@ -318,8 +627,8 @@ export class ParametersService { /** * @throws ApiError */ - public static getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise { - const { parameter, requestBody } = data; + public static getCallWithOptionalParam(data: ParametersData.GetCallWithOptionalParam): CancelablePromise { + const { requestBody, parameter } = data; return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -334,7 +643,7 @@ export class ParametersService { /** * @throws ApiError */ - public static postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersData.PostCallWithOptionalParam): CancelablePromise { const { parameter, requestBody } = data; return __request(OpenAPI, { method: 'POST', @@ -348,48 +657,18 @@ export class ParametersService { } } -export type TDataCallWithDescriptions = { - /** - * 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; -}; - export class DescriptionsService { /** * @throws ApiError */ - public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): CancelablePromise { const { - parameterWithBackticks, parameterWithBreaks, + parameterWithBackticks, + parameterWithSlashes, parameterWithExpressionPlaceholders, parameterWithQuotes, parameterWithReservedCharacters, - parameterWithSlashes, } = data; return __request(OpenAPI, { method: 'POST', @@ -406,19 +685,12 @@ export class DescriptionsService { } } -export type TDataDeprecatedCall = { - /** - * This parameter is deprecated - */ - parameter: DeprecatedModel | null; -}; - export class DeprecatedService { /** * @deprecated * @throws ApiError */ - public static deprecatedCall(data: TDataDeprecatedCall): CancelablePromise { + public static deprecatedCall(data: DeprecatedData.DeprecatedCall): CancelablePromise { const { parameter } = data; return __request(OpenAPI, { method: 'POST', @@ -430,23 +702,12 @@ export class DeprecatedService { } } -export type TDataPostApiRequestBody = { - /** - * A reusable request body - */ - foo?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class RequestBodyService { /** * @throws ApiError */ - public static postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise { - const { foo, parameter } = data; + public static postApiRequestBody(data: RequestBodyData.PostApiRequestBody = {}): CancelablePromise { + const { parameter, foo } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -459,23 +720,12 @@ export class RequestBodyService { } } -export type TDataPostApiFormData = { - /** - * A reusable request body - */ - formData?: ModelWithString; - /** - * This is a reusable parameter - */ - parameter?: string; -}; - export class FormDataService { /** * @throws ApiError */ - public static postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise { - const { formData, parameter } = data; + public static postApiFormData(data: FormDataData.PostApiFormData = {}): CancelablePromise { + const { parameter, formData } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -488,98 +738,21 @@ export class FormDataService { } } -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; -}; - export class DefaultsService { /** * @throws ApiError */ - public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + public static callWithDefaultParameters( + data: DefaultsData.CallWithDefaultParameters = {} + ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'GET', @@ -598,16 +771,16 @@ export class DefaultsService { * @throws ApiError */ public static callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'POST', @@ -625,16 +798,16 @@ export class DefaultsService { /** * @throws ApiError */ - public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return __request(OpenAPI, { method: 'PUT', @@ -850,35 +1023,12 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - /** - * 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; -}; - export class CollectionFormatService { /** * @throws ApiError */ - public static collectionFormat(data: TDataCollectionFormat): CancelablePromise { - const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = + public static collectionFormat(data: CollectionFormatData.CollectionFormat): CancelablePromise { + const { parameterArrayCsv, parameterArraySsv, parameterArrayTsv, parameterArrayPipes, parameterArrayMulti } = data; return __request(OpenAPI, { method: 'GET', @@ -894,41 +1044,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * 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: Record | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber?: number; - /** - * This is an object parameter - */ - parameterObject?: Record | null; - /** - * This is a string parameter - */ - parameterString?: string | null; -}; - export class TypesService { /** * @returns number Response is a simple number @@ -937,16 +1052,16 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: TDataTypes): CancelablePromise> { + public static types(data: TypesData.Types): CancelablePromise> { const { - id, parameterArray, - parameterBoolean = true, parameterDictionary, parameterEnum, parameterNumber = 123, - parameterObject = null, parameterString = 'default', + parameterBoolean = true, + parameterObject = null, + id, } = data; return __request(OpenAPI, { method: 'GET', @@ -967,19 +1082,12 @@ export class TypesService { } } -export type TDataUploadFile = { - /** - * Supply a file reference for upload - */ - file: Blob | File; -}; - export class UploadService { /** * @returns boolean * @throws ApiError */ - public static uploadFile(data: TDataUploadFile): CancelablePromise { + public static uploadFile(data: UploadData.UploadFile): CancelablePromise { const { file } = data; return __request(OpenAPI, { method: 'POST', @@ -991,16 +1099,12 @@ export class UploadService { } } -export type TDataFileResponse = { - id: string; -}; - export class FileResponseService { /** * @returns binary Success * @throws ApiError */ - public static fileResponse(data: TDataFileResponse): CancelablePromise { + public static fileResponse(data: FileResponseData.FileResponse): CancelablePromise { const { id } = data; return __request(OpenAPI, { method: 'GET', @@ -1012,45 +1116,12 @@ export class FileResponseService { } } -export type TDataComplexTypes = { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; -}; -export type TDataComplexParams = { - 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; - }; - }; -}; - export class ComplexService { /** * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: TDataComplexTypes): CancelablePromise> { + public static complexTypes(data: ComplexData.ComplexTypes): CancelablePromise> { const { parameterObject, parameterReference } = data; return __request(OpenAPI, { method: 'GET', @@ -1070,7 +1141,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public static complexParams(data: TDataComplexParams): CancelablePromise { + public static complexParams(data: ComplexData.ComplexParams): CancelablePromise { const { id, requestBody } = data; return __request(OpenAPI, { method: 'PUT', @@ -1084,18 +1155,11 @@ export class ComplexService { } } -export type TDataMultipartRequest = { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; - }; -}; - export class MultipartService { /** * @throws ApiError */ - public static multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise { + public static multipartRequest(data: MultipartData.MultipartRequest = {}): CancelablePromise { const { formData } = data; return __request(OpenAPI, { method: 'POST', @@ -1141,19 +1205,12 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - /** - * Status code to return - */ - status: number; -}; - export class ErrorService { /** * @returns any Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: TDataTestErrorCode): CancelablePromise { + public static testErrorCode(data: ErrorData.TestErrorCode): CancelablePromise { const { status } = data; return __request(OpenAPI, { method: 'POST', @@ -1171,20 +1228,13 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; -}; - export class NonAsciiÆøåÆøÅöôêÊService { /** * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ public static nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): CancelablePromise> { const { nonAsciiParamæøåÆøÅöôêÊ } = data; return __request(OpenAPI, { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/services.ts.snap index 34c1e1eff..ff7336472 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_experimental/services.ts.snap @@ -18,10 +18,463 @@ import type { NonAsciiStringæøåÆØÅöôêÊ字符串, } from './models'; -export type TDataPostServiceWithEmptyTag = { - requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +export type DefaultData = { + PostServiceWithEmptyTag: { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; - query?: {}; + query?: {}; + }; +}; + +export type SimpleData = {}; + +export type ParametersData = { + DeleteFoo: { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; + + query?: {}; + }; + CallWithParameters: { + /** + * 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 body + */ + requestBody: ModelWithString | null; + + query: { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + }; + }; + CallWithWeirdParameterNames: { + /** + * 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 body + */ + requestBody: ModelWithString | null; + + query: { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + }; + }; + GetCallWithOptionalParam: { + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; + + query?: { + /** + * This is an optional parameter + */ + parameter?: string; + }; + }; + PostCallWithOptionalParam: { + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; + + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + }; +}; + +export type DescriptionsData = { + CallWithDescriptions: { + query?: { + /** + * 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; + }; + }; +}; + +export type DeprecatedData = { + DeprecatedCall: { + /** + * This parameter is deprecated + */ + parameter: DeprecatedModel | null; + + query?: {}; + }; +}; + +export type RequestBodyData = { + PostApiRequestBody: { + /** + * A reusable request body + */ + foo?: ModelWithString; + + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; +}; + +export type FormDataData = { + PostApiFormData: { + /** + * A reusable request body + */ + formData?: ModelWithString; + + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + }; +}; + +export type DefaultsData = { + CallWithDefaultParameters: { + query?: { + /** + * 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; + }; + }; + CallWithDefaultOptionalParameters: { + query?: { + /** + * 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; + }; + }; + CallToTestOrderOfParams: { + query: { + /** + * 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; + }; + }; +}; + +export type DuplicateData = {}; + +export type NoContentData = {}; + +export type ResponseData = {}; + +export type MultipleTags1Data = {}; + +export type MultipleTags2Data = {}; + +export type MultipleTags3Data = {}; + +export type CollectionFormatData = { + CollectionFormat: { + query: { + /** + * 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; + }; + }; +}; + +export type TypesData = { + Types: { + /** + * This is a number parameter + */ + id?: number; + + query: { + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a boolean parameter + */ + parameterBoolean?: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: Record | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber?: number; + /** + * This is an object parameter + */ + parameterObject?: Record | null; + /** + * This is a string parameter + */ + parameterString?: string | null; + }; + }; +}; + +export type UploadData = { + UploadFile: { + /** + * Supply a file reference for upload + */ + file: Blob | File; + + query?: {}; + }; +}; + +export type FileResponseData = { + FileResponse: { + id: string; + + query?: {}; + }; +}; + +export type ComplexData = { + ComplexTypes: { + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + }; + ComplexParams: { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + + query?: {}; + }; +}; + +export type MultipartData = { + MultipartRequest: { + formData?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + + query?: {}; + }; +}; + +export type HeaderData = {}; + +export type ErrorData = { + TestErrorCode: { + query: { + /** + * Status code to return + */ + status: number; + }; + }; +}; + +export type NonAsciiÆøåÆøÅöôêÊData = { + NonAsciiæøåÆøÅöôêÊ字符串: { + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; + }; + }; }; export class DefaultService { @@ -40,7 +493,7 @@ export class DefaultService { * @throws ApiError */ public static postServiceWithEmptyTag( - data: TDataPostServiceWithEmptyTag + data: DefaultData.PostServiceWithEmptyTag ): CancelablePromise { const { query, requestBody } = data; return __request(OpenAPI, { @@ -124,123 +577,12 @@ export class SimpleService { } } -export type TDataDeleteFoo = { - /** - * bar in method - */ - bar: string; - /** - * foo in method - */ - foo: string; - - query?: {}; -}; -export type TDataCallWithParameters = { - /** - * 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 body - */ - requestBody: ModelWithString | null; - - query: { - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; - /** - * This is the parameter that goes into the query params - */ - parameterQuery: string | null; - }; -}; -export type TDataCallWithWeirdParameterNames = { - /** - * 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 body - */ - requestBody: ModelWithString | null; - - query: { - /** - * This is the parameter with a reserved keyword - */ - _default?: string; - /** - * This is the parameter that goes into the request query params - */ - parameterQuery: string | null; - }; -}; -export type TDataGetCallWithOptionalParam = { - /** - * This is a required parameter - */ - requestBody: ModelWithOneOfEnum; - - query?: { - /** - * This is an optional parameter - */ - parameter?: string; - }; -}; -export type TDataPostCallWithOptionalParam = { - /** - * This is an optional parameter - */ - requestBody?: ModelWithString; - - query: { - /** - * This is a required parameter - */ - parameter: Pageable; - }; -}; - export class ParametersService { /** * @throws ApiError */ - public static deleteFoo(data: TDataDeleteFoo): CancelablePromise { - const { query, bar, foo } = data; + public static deleteFoo(data: ParametersData.DeleteFoo): CancelablePromise { + const { query, foo, bar } = data; return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -251,8 +593,8 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithParameters(data: TDataCallWithParameters): CancelablePromise { - const { query, parameterCookie, parameterForm, parameterHeader, parameterPath, requestBody } = data; + public static callWithParameters(data: ParametersData.CallWithParameters): CancelablePromise { + const { query, parameterHeader, parameterForm, parameterCookie, parameterPath, requestBody } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -271,16 +613,18 @@ export class ParametersService { /** * @throws ApiError */ - public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise { + public static callWithWeirdParameterNames( + data: ParametersData.CallWithWeirdParameterNames + ): CancelablePromise { const { query, - parameterCookie, - parameterForm, parameterHeader, + parameterForm, + parameterCookie, + requestBody, parameterPath1, parameterPath2, parameterPath3, - requestBody, } = data; return __request(OpenAPI, { method: 'POST', @@ -300,7 +644,7 @@ export class ParametersService { /** * @throws ApiError */ - public static getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise { + public static getCallWithOptionalParam(data: ParametersData.GetCallWithOptionalParam): CancelablePromise { const { query, requestBody } = data; return __request(OpenAPI, { method: 'GET', @@ -316,7 +660,7 @@ export class ParametersService { /** * @throws ApiError */ - public static postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersData.PostCallWithOptionalParam): CancelablePromise { const { query, requestBody } = data; return __request(OpenAPI, { method: 'POST', @@ -330,43 +674,11 @@ export class ParametersService { } } -export type TDataCallWithDescriptions = { - query?: { - /** - * 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; - }; -}; - export class DescriptionsService { /** * @throws ApiError */ - public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsData.CallWithDescriptions = {}): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'POST', @@ -378,21 +690,12 @@ export class DescriptionsService { } } -export type TDataDeprecatedCall = { - /** - * This parameter is deprecated - */ - parameter: DeprecatedModel | null; - - query?: {}; -}; - export class DeprecatedService { /** * @deprecated * @throws ApiError */ - public static deprecatedCall(data: TDataDeprecatedCall): CancelablePromise { + public static deprecatedCall(data: DeprecatedData.DeprecatedCall): CancelablePromise { const { query, parameter } = data; return __request(OpenAPI, { method: 'POST', @@ -402,25 +705,11 @@ export class DeprecatedService { } } -export type TDataPostApiRequestBody = { - /** - * A reusable request body - */ - foo?: ModelWithString; - - query?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; -}; - export class RequestBodyService { /** * @throws ApiError */ - public static postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise { + public static postApiRequestBody(data: RequestBodyData.PostApiRequestBody = {}): CancelablePromise { const { query, foo } = data; return __request(OpenAPI, { method: 'POST', @@ -434,25 +723,11 @@ export class RequestBodyService { } } -export type TDataPostApiFormData = { - /** - * A reusable request body - */ - formData?: ModelWithString; - - query?: { - /** - * This is a reusable parameter - */ - parameter?: string; - }; -}; - export class FormDataService { /** * @throws ApiError */ - public static postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise { + public static postApiFormData(data: FormDataData.PostApiFormData = {}): CancelablePromise { const { query, formData } = data; return __request(OpenAPI, { method: 'POST', @@ -466,108 +741,25 @@ export class FormDataService { } } -export type TDataCallWithDefaultParameters = { - query?: { - /** - * 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; - }; -}; -export type TDataCallWithDefaultOptionalParameters = { - query?: { - /** - * 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; - }; -}; -export type TDataCallToTestOrderOfParams = { - query: { - /** - * 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; - }; -}; - export class DefaultsService { /** * @throws ApiError */ - public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + public static callWithDefaultParameters( + data: DefaultsData.CallWithDefaultParameters = {} + ): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/defaults', query: { + parameterString: 'Hello World!', + parameterNumber: 123, parameterBoolean: true, parameterEnum: 'Success', parameterModel: { prop: 'Hello World!', }, - parameterNumber: 123, - parameterString: 'Hello World!', ...query, }, }); @@ -577,20 +769,20 @@ export class DefaultsService { * @throws ApiError */ public static callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/defaults', query: { + parameterString: 'Hello World!', + parameterNumber: 123, parameterBoolean: true, parameterEnum: 'Success', parameterModel: { prop: 'Hello World!', }, - parameterNumber: 123, - parameterString: 'Hello World!', ...query, }, }); @@ -599,7 +791,7 @@ export class DefaultsService { /** * @throws ApiError */ - public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'PUT', @@ -607,9 +799,9 @@ export class DefaultsService { query: { parameterOptionalStringWithDefault: 'Hello World!', parameterOptionalStringWithEmptyDefault: '', - parameterStringNullableWithDefault: null, parameterStringWithDefault: 'Hello World!', parameterStringWithEmptyDefault: '', + parameterStringNullableWithDefault: null, ...query, }, }); @@ -813,36 +1005,11 @@ export class MultipleTags3Service { } } -export type TDataCollectionFormat = { - query: { - /** - * 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; - }; -}; - export class CollectionFormatService { /** * @throws ApiError */ - public static collectionFormat(data: TDataCollectionFormat): CancelablePromise { + public static collectionFormat(data: CollectionFormatData.CollectionFormat): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'GET', @@ -854,44 +1021,6 @@ export class CollectionFormatService { } } -export type TDataTypes = { - /** - * This is a number parameter - */ - id?: number; - - query: { - /** - * This is an array parameter - */ - parameterArray: Array | null; - /** - * This is a boolean parameter - */ - parameterBoolean?: boolean | null; - /** - * This is a dictionary parameter - */ - parameterDictionary: Record | null; - /** - * This is an enum parameter - */ - parameterEnum: 'Success' | 'Warning' | 'Error' | null; - /** - * This is a number parameter - */ - parameterNumber?: number; - /** - * This is an object parameter - */ - parameterObject?: Record | null; - /** - * This is a string parameter - */ - parameterString?: string | null; - }; -}; - export class TypesService { /** * @returns number Response is a simple number @@ -900,38 +1029,29 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: TDataTypes): CancelablePromise> { + public static types(data: TypesData.Types): CancelablePromise> { const { query, id } = data; return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/types', path: {}, query: { - parameterBoolean: true, parameterNumber: 123, - parameterObject: null, parameterString: 'default', + parameterBoolean: true, + parameterObject: null, ...query, }, }); } } -export type TDataUploadFile = { - /** - * Supply a file reference for upload - */ - file: Blob | File; - - query?: {}; -}; - export class UploadService { /** * @returns boolean * @throws ApiError */ - public static uploadFile(data: TDataUploadFile): CancelablePromise { + public static uploadFile(data: UploadData.UploadFile): CancelablePromise { const { query, file } = data; return __request(OpenAPI, { method: 'POST', @@ -941,18 +1061,12 @@ export class UploadService { } } -export type TDataFileResponse = { - id: string; - - query?: {}; -}; - export class FileResponseService { /** * @returns binary Success * @throws ApiError */ - public static fileResponse(data: TDataFileResponse): CancelablePromise { + public static fileResponse(data: FileResponseData.FileResponse): CancelablePromise { const { query, id } = data; return __request(OpenAPI, { method: 'GET', @@ -962,49 +1076,12 @@ export class FileResponseService { } } -export type TDataComplexTypes = { - query: { - /** - * Parameter containing object - */ - parameterObject: { - first?: { - second?: { - third?: string; - }; - }; - }; - /** - * Parameter containing reference - */ - parameterReference: ModelWithString; - }; -}; -export type TDataComplexParams = { - 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; - }; - }; - - query?: {}; -}; - export class ComplexService { /** * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: TDataComplexTypes): CancelablePromise> { + public static complexTypes(data: ComplexData.ComplexTypes): CancelablePromise> { const { query } = data; return __request(OpenAPI, { method: 'GET', @@ -1023,7 +1100,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public static complexParams(data: TDataComplexParams): CancelablePromise { + public static complexParams(data: ComplexData.ComplexParams): CancelablePromise { const { query, id, requestBody } = data; return __request(OpenAPI, { method: 'PUT', @@ -1035,20 +1112,11 @@ export class ComplexService { } } -export type TDataMultipartRequest = { - formData?: { - content?: Blob | File; - data?: ModelWithString | null; - }; - - query?: {}; -}; - export class MultipartService { /** * @throws ApiError */ - public static multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise { + public static multipartRequest(data: MultipartData.MultipartRequest = {}): CancelablePromise { const { query, formData } = data; return __request(OpenAPI, { method: 'POST', @@ -1094,21 +1162,12 @@ export class HeaderService { } } -export type TDataTestErrorCode = { - query: { - /** - * Status code to return - */ - status: number; - }; -}; - export class ErrorService { /** * @returns any Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: TDataTestErrorCode): CancelablePromise { + public static testErrorCode(data: ErrorData.TestErrorCode): CancelablePromise { const { query } = data; return __request(OpenAPI, { method: 'POST', @@ -1126,22 +1185,13 @@ export class ErrorService { } } -export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { - query: { - /** - * Dummy input param - */ - nonAsciiParamæøåÆøÅöôêÊ: number; - }; -}; - export class NonAsciiÆøåÆøÅöôêÊService { /** * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ public static nonAsciiæøåÆøÅöôêÊ字符串( - data: TDataNonAsciiæøåÆøÅöôêÊ字符串 + data: NonAsciiÆøåÆøÅöôêÊData.NonAsciiæøåÆøÅöôêÊ字符串 ): CancelablePromise> { const { query } = data; return __request(OpenAPI, { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.ts.snap index 2b8bb2e35..1cd385dd5 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.ts.snap @@ -4,98 +4,102 @@ import { request as __request } from './core/request'; import type { ModelWithString } from './models'; -export type TDataCallWithDefaultParameters = { - /** - * 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; -}; -export type TDataCallWithDefaultOptionalParameters = { - /** - * 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; -}; -export type TDataCallToTestOrderOfParams = { - /** - * 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; +export type DefaultsData = { + CallWithDefaultParameters: { + /** + * 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; + }; + CallWithDefaultOptionalParameters: { + /** + * 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; + }; + CallToTestOrderOfParams: { + /** + * 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; + }; }; export class DefaultsService { /** * @throws ApiError */ - public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise { + public static callWithDefaultParameters( + data: DefaultsData.CallWithDefaultParameters = {} + ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'GET', @@ -114,16 +118,16 @@ export class DefaultsService { * @throws ApiError */ public static callWithDefaultOptionalParameters( - data: TDataCallWithDefaultOptionalParameters = {} + data: DefaultsData.CallWithDefaultOptionalParameters = {} ): CancelablePromise { const { + parameterString = 'Hello World!', + parameterNumber = 123, parameterBoolean = true, parameterEnum = 'Success', parameterModel = { prop: 'Hello World!', }, - parameterNumber = 123, - parameterString = 'Hello World!', } = data; return __request(OpenAPI, { method: 'POST', @@ -141,16 +145,16 @@ export class DefaultsService { /** * @throws ApiError */ - public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsData.CallToTestOrderOfParams): CancelablePromise { const { + parameterStringWithNoDefault, parameterOptionalStringWithDefault = 'Hello World!', parameterOptionalStringWithEmptyDefault = '', parameterOptionalStringWithNoDefault, - parameterStringNullableWithDefault = null, - parameterStringNullableWithNoDefault, parameterStringWithDefault = 'Hello World!', parameterStringWithEmptyDefault = '', - parameterStringWithNoDefault, + parameterStringNullableWithNoDefault, + parameterStringNullableWithDefault = null, } = data; return __request(OpenAPI, { method: 'PUT', diff --git a/packages/openapi-ts/test/bin.spec.ts b/packages/openapi-ts/test/bin.spec.ts index 42f6aa4e4..b6cad2745 100755 --- a/packages/openapi-ts/test/bin.spec.ts +++ b/packages/openapi-ts/test/bin.spec.ts @@ -115,10 +115,6 @@ describe('bin', () => { 'true', '--exportSchemas', 'true', - '--postfixServices', - 'Service', - '--postfixModels', - 'Dto', '--write', 'false', ]);