diff --git a/bin/index.js b/bin/index.js index 35c1c8033..e1abab12a 100755 --- a/bin/index.js +++ b/bin/index.js @@ -21,25 +21,32 @@ const params = program .option('--exportSchemas ', 'Write schemas to disk', false) .option('--postfix ', 'Service name postfix', 'Service') .option('--request ', 'Path to custom request file') + .option('-so, --serviceOptions , Service options path') .parse(process.argv) .opts(); const OpenAPI = require(path.resolve(__dirname, '../dist/index.js')); +const genereteParams = { + input: params.input, + output: params.output, + httpClient: params.client, + useOptions: params.useOptions, + useUnionTypes: params.useUnionTypes, + exportCore: JSON.parse(params.exportCore) === true, + exportServices: JSON.parse(params.exportServices) === true, + exportModels: JSON.parse(params.exportModels) === true, + exportSchemas: JSON.parse(params.exportSchemas) === true, + postfix: params.postfix, + request: params.request, +}; + +if (params.serviceOptions) { + genereteParams.serviceOptions = require(path.resolve(process.cwd(), params.serviceOptions)); +} + if (OpenAPI) { - OpenAPI.generate({ - input: params.input, - output: params.output, - httpClient: params.client, - useOptions: params.useOptions, - useUnionTypes: params.useUnionTypes, - exportCore: JSON.parse(params.exportCore) === true, - exportServices: JSON.parse(params.exportServices) === true, - exportModels: JSON.parse(params.exportModels) === true, - exportSchemas: JSON.parse(params.exportSchemas) === true, - postfix: params.postfix, - request: params.request, - }) + OpenAPI.generate(genereteParams) .then(() => { process.exit(0); }) diff --git a/src/index.ts b/src/index.ts index c27910c3c..42a59e643 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,9 +10,18 @@ import { writeClient } from './utils/writeClient'; export { HttpClient } from './HttpClient'; -export type Options = { +export interface ServiceOptions { + serviceImports?: string; + serviceConstructor?: string; + serviceDecorator?: string; + staticMethods?: boolean; + serviceRequestContext?: string; +} + +export interface Options { input: string | Record; output: string; + serviceOptions?: ServiceOptions; httpClient?: HttpClient; useOptions?: boolean; useUnionTypes?: boolean; @@ -23,7 +32,7 @@ export type Options = { postfix?: string; request?: string; write?: boolean; -}; +} /** * Generate the OpenAPI client. This method will read the OpenAPI specification and based on the @@ -55,6 +64,9 @@ export async function generate({ postfix = 'Service', request, write = true, + serviceOptions = { + staticMethods: true, + }, }: Options): Promise { const openApi = isString(input) ? await getOpenApiSpec(input) : input; const openApiVersion = getOpenApiVersion(openApi); @@ -81,6 +93,7 @@ export async function generate({ exportModels, exportSchemas, postfix, + serviceOptions, request ); break; @@ -102,6 +115,7 @@ export async function generate({ exportModels, exportSchemas, postfix, + serviceOptions, request ); break; diff --git a/src/templates/core/ApiRequestOptions.hbs b/src/templates/core/ApiRequestOptions.hbs index 76251eac4..b4035f510 100644 --- a/src/templates/core/ApiRequestOptions.hbs +++ b/src/templates/core/ApiRequestOptions.hbs @@ -11,4 +11,5 @@ export type ApiRequestOptions = { readonly mediaType?: string; readonly responseHeader?: string; readonly errors?: Record; + readonly context?: any; } diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index 1e13e19a9..a23e1ed29 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -10,8 +10,17 @@ import { request as __request } from '../core/request'; {{#if @root.useVersion}} import { OpenAPI } from '../core/OpenAPI'; {{/if}} +{{#if @root.serviceImports}} +{{@root.serviceImports}} +{{/if}} +{{#if @root.serviceDecorator}} +{{@root.serviceDecorator}} +{{/if}} export class {{{name}}}{{{@root.postfix}}} { + {{#if @root.serviceConstructor}} + {{@root.serviceConstructor}} + {{/if}} {{#each operations}} /** @@ -36,8 +45,8 @@ export class {{{name}}}{{{@root.postfix}}} { {{/each}} * @throws ApiError */ - public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> { - return __request({ + public{{#if @root.staticMethods}} static{{/if}} {{{name}}}({{>parameters}}) { + return __request<{{>result}}>({ method: '{{{method}}}', path: `{{{path}}}`, {{#if parametersCookie}} @@ -89,6 +98,9 @@ export class {{{name}}}{{{@root.postfix}}} { {{/each}} }, {{/if}} + {{#if @root.serviceRequestContext}} + context: {{@root.serviceRequestContext}}, + {{/if}} }); } diff --git a/src/utils/writeClient.spec.ts b/src/utils/writeClient.spec.ts index 268027573..a85b4e15b 100644 --- a/src/utils/writeClient.spec.ts +++ b/src/utils/writeClient.spec.ts @@ -32,7 +32,7 @@ describe('writeClient', () => { }, }; - await writeClient(client, templates, './dist', HttpClient.FETCH, false, false, true, true, true, true, ''); + await writeClient(client, templates, './dist', HttpClient.FETCH, false, false, true, true, true, true, '', {}); expect(rmdir).toBeCalled(); expect(mkdir).toBeCalled(); diff --git a/src/utils/writeClient.ts b/src/utils/writeClient.ts index f1858bee3..41b09aee7 100644 --- a/src/utils/writeClient.ts +++ b/src/utils/writeClient.ts @@ -2,6 +2,7 @@ import { resolve } from 'path'; import type { Client } from '../client/interfaces/Client'; import { HttpClient } from '../HttpClient'; +import { ServiceOptions } from '../index'; import { mkdir, rmdir } from './fileSystem'; import { isSubDirectory } from './isSubdirectory'; import { Templates } from './registerHandlebarTemplates'; @@ -39,6 +40,7 @@ export async function writeClient( exportModels: boolean, exportSchemas: boolean, postfix: string, + serviceOptions: ServiceOptions, request?: string ): Promise { const outputPath = resolve(process.cwd(), output); @@ -67,7 +69,8 @@ export async function writeClient( httpClient, useUnionTypes, useOptions, - postfix + postfix, + serviceOptions ); } diff --git a/src/utils/writeClientServices.spec.ts b/src/utils/writeClientServices.spec.ts index 1f6798ef5..d733579b3 100644 --- a/src/utils/writeClientServices.spec.ts +++ b/src/utils/writeClientServices.spec.ts @@ -33,7 +33,7 @@ describe('writeClientServices', () => { }, }; - await writeClientServices(services, templates, '/', HttpClient.FETCH, false, false, 'Service'); + await writeClientServices(services, templates, '/', HttpClient.FETCH, false, false, 'Service', {}); expect(writeFile).toBeCalledWith('/UserService.ts', 'service'); }); diff --git a/src/utils/writeClientServices.ts b/src/utils/writeClientServices.ts index 731ed5327..b9014d50e 100644 --- a/src/utils/writeClientServices.ts +++ b/src/utils/writeClientServices.ts @@ -1,5 +1,6 @@ import { resolve } from 'path'; +import { ServiceOptions } from '..'; import type { Service } from '../client/interfaces/Service'; import { HttpClient } from '../HttpClient'; import { writeFile } from './fileSystem'; @@ -25,7 +26,8 @@ export async function writeClientServices( httpClient: HttpClient, useUnionTypes: boolean, useOptions: boolean, - postfix: string + postfix: string, + serviceOptions: ServiceOptions ): Promise { for (const service of services) { const file = resolve(outputPath, `${service.name}${postfix}.ts`); @@ -37,6 +39,7 @@ export async function writeClientServices( useVersion, useOptions, postfix, + ...serviceOptions, }); await writeFile(file, format(templateResult)); } diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index c19166701..4153409d4 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -39,6 +39,7 @@ export type ApiRequestOptions = { readonly mediaType?: string; readonly responseHeader?: string; readonly errors?: Record; + readonly context?: any; }" `; @@ -2021,8 +2022,8 @@ export class CollectionFormatService { parameterArrayTsv: Array, parameterArrayPipes: Array, parameterArrayMulti: Array, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/collectionFormat\`, query: { @@ -2064,8 +2065,8 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): CancelablePromise> { - return __request({ + ) { + return __request>({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/complex\`, query: { @@ -2109,8 +2110,8 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -2139,8 +2140,8 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -2173,8 +2174,8 @@ export class DefaultsService { parameterStringWithEmptyDefault: string = '', parameterStringNullableWithNoDefault?: string | null, parameterStringNullableWithDefault: string | null = null, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -2206,8 +2207,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName(): CancelablePromise { - return __request({ + public static duplicateName() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -2216,8 +2217,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName1(): CancelablePromise { - return __request({ + public static duplicateName1() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -2226,8 +2227,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName2(): CancelablePromise { - return __request({ + public static duplicateName2() { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -2236,8 +2237,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName3(): CancelablePromise { - return __request({ + public static duplicateName3() { + return __request({ method: 'DELETE', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -2263,8 +2264,8 @@ export class ErrorService { */ public static testErrorCode( status: string, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/error\`, query: { @@ -2296,8 +2297,8 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static callWithResultFromHeader(): CancelablePromise { - return __request({ + public static callWithResultFromHeader() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/header\`, responseHeader: 'operation-location', @@ -2325,8 +2326,8 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static dummyA(): CancelablePromise { - return __request({ + public static dummyA() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/a\`, }); @@ -2336,8 +2337,8 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -2360,8 +2361,8 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static dummyA(): CancelablePromise { - return __request({ + public static dummyA() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/a\`, }); @@ -2371,8 +2372,8 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -2395,8 +2396,8 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -2419,8 +2420,8 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static callWithNoContentResponse(): CancelablePromise { - return __request({ + public static callWithNoContentResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/no-content\`, }); @@ -2453,8 +2454,8 @@ export class ParametersService { parameterForm: string, parameterBody: string, parameterPath: string, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath}\`, headers: { @@ -2490,8 +2491,8 @@ export class ParametersService { parameterPath2?: string, parameterPath3?: string, _default?: string, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, headers: { @@ -2528,8 +2529,8 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithResponse(): CancelablePromise { - return __request({ + public static callWithResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/response\`, }); @@ -2539,8 +2540,8 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithDuplicateResponses(): CancelablePromise { - return __request({ + public static callWithDuplicateResponses() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/response\`, errors: { @@ -2558,12 +2559,12 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static callWithResponses(): CancelablePromise<{ - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; - } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { - return __request({ + public static callWithResponses() { + return __request<{ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends>({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/response\`, errors: { @@ -2590,8 +2591,8 @@ export class SimpleService { /** * @throws ApiError */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static getCallWithoutParametersAndResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2600,8 +2601,8 @@ export class SimpleService { /** * @throws ApiError */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static putCallWithoutParametersAndResponse() { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2610,8 +2611,8 @@ export class SimpleService { /** * @throws ApiError */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static postCallWithoutParametersAndResponse() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2620,8 +2621,8 @@ export class SimpleService { /** * @throws ApiError */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static deleteCallWithoutParametersAndResponse() { + return __request({ method: 'DELETE', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2630,8 +2631,8 @@ export class SimpleService { /** * @throws ApiError */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static optionsCallWithoutParametersAndResponse() { + return __request({ method: 'OPTIONS', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2640,8 +2641,8 @@ export class SimpleService { /** * @throws ApiError */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static headCallWithoutParametersAndResponse() { + return __request({ method: 'HEAD', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2650,8 +2651,8 @@ export class SimpleService { /** * @throws ApiError */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static patchCallWithoutParametersAndResponse() { + return __request({ method: 'PATCH', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -2694,8 +2695,8 @@ export class TypesService { parameterBoolean: boolean = true, parameterObject: any = null, id?: number, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/types\`, query: { @@ -2752,6 +2753,7 @@ export type ApiRequestOptions = { readonly mediaType?: string; readonly responseHeader?: string; readonly errors?: Record; + readonly context?: any; }" `; @@ -5311,8 +5313,8 @@ export class CollectionFormatService { parameterArrayTsv: Array | null, parameterArrayPipes: Array | null, parameterArrayMulti: Array | null, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/collectionFormat\`, query: { @@ -5357,8 +5359,8 @@ export class ComplexService { }; }, parameterReference: ModelWithString, - ): CancelablePromise> { - return __request({ + ) { + return __request>({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/complex\`, query: { @@ -5393,8 +5395,8 @@ export class ComplexService { readonly name?: string | null; }; }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/complex/\${id}\`, body: requestBody, @@ -5432,8 +5434,8 @@ export class DefaultsService { parameterModel: ModelWithString | null = { \\"prop\\": \\"Hello World!\\" }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -5462,8 +5464,8 @@ export class DefaultsService { parameterModel: ModelWithString = { \\"prop\\": \\"Hello World!\\" }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -5496,8 +5498,8 @@ export class DefaultsService { parameterStringWithEmptyDefault: string = '', parameterStringNullableWithNoDefault?: string | null, parameterStringNullableWithDefault: string | null = null, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/defaults\`, query: { @@ -5529,8 +5531,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName(): CancelablePromise { - return __request({ + public static duplicateName() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -5539,8 +5541,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName1(): CancelablePromise { - return __request({ + public static duplicateName1() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -5549,8 +5551,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName2(): CancelablePromise { - return __request({ + public static duplicateName2() { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -5559,8 +5561,8 @@ export class DuplicateService { /** * @throws ApiError */ - public static duplicateName3(): CancelablePromise { - return __request({ + public static duplicateName3() { + return __request({ method: 'DELETE', path: \`/api/v\${OpenAPI.VERSION}/duplicate\`, }); @@ -5586,8 +5588,8 @@ export class ErrorService { */ public static testErrorCode( status: number, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/error\`, query: { @@ -5624,8 +5626,8 @@ export class FormDataService { public static postFormData( parameter?: string, formData?: ModelWithString, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/formData/\`, query: { @@ -5653,8 +5655,8 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static callWithResultFromHeader(): CancelablePromise { - return __request({ + public static callWithResultFromHeader() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/header\`, responseHeader: 'operation-location', @@ -5688,8 +5690,8 @@ export class MultipartService { content?: Blob; data?: ModelWithString | null; }, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/multipart\`, formData: formData, @@ -5701,14 +5703,14 @@ export class MultipartService { * @returns any OK * @throws ApiError */ - public static multipartResponse(): CancelablePromise<{ - file?: Blob; - metadata?: { - foo?: string; - bar?: string; - }; - }> { - return __request({ + public static multipartResponse() { + return __request<{ + file?: Blob; + metadata?: { + foo?: string; + bar?: string; + }; + }>({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multipart\`, }); @@ -5731,8 +5733,8 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static dummyA(): CancelablePromise { - return __request({ + public static dummyA() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/a\`, }); @@ -5742,8 +5744,8 @@ export class MultipleTags1Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -5766,8 +5768,8 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static dummyA(): CancelablePromise { - return __request({ + public static dummyA() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/a\`, }); @@ -5777,8 +5779,8 @@ export class MultipleTags2Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -5801,8 +5803,8 @@ export class MultipleTags3Service { * @returns void * @throws ApiError */ - public static dummyB(): CancelablePromise { - return __request({ + public static dummyB() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/multiple-tags/b\`, }); @@ -5825,8 +5827,8 @@ export class NoContentService { * @returns void * @throws ApiError */ - public static callWithNoContentResponse(): CancelablePromise { - return __request({ + public static callWithNoContentResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/no-content\`, }); @@ -5862,8 +5864,8 @@ export class ParametersService { parameterCookie: string | null, parameterPath: string | null, requestBody: ModelWithString | null, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath}\`, cookies: { @@ -5905,8 +5907,8 @@ export class ParametersService { parameterPath2?: string, parameterPath3?: string, _default?: string, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/parameters/\${parameterPath1}/\${parameterPath2}/\${parameterPath3}\`, cookies: { @@ -5935,8 +5937,8 @@ export class ParametersService { public static getCallWithOptionalParam( requestBody: ModelWithString, parameter?: string, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/parameters/\`, query: { @@ -5955,8 +5957,8 @@ export class ParametersService { public static postCallWithOptionalParam( parameter: string, requestBody?: ModelWithString, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/parameters/\`, query: { @@ -5989,8 +5991,8 @@ export class RequestBodyService { public static postRequestBody( parameter?: string, requestBody?: ModelWithString, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/requestBody/\`, query: { @@ -6021,8 +6023,8 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public static callWithResponse(): CancelablePromise { - return __request({ + public static callWithResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/response\`, }); @@ -6032,8 +6034,8 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithDuplicateResponses(): CancelablePromise { - return __request({ + public static callWithDuplicateResponses() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/response\`, errors: { @@ -6051,12 +6053,12 @@ export class ResponseService { * @returns ModelThatExtendsExtends Message for 202 response * @throws ApiError */ - public static callWithResponses(): CancelablePromise<{ - readonly '@namespace.string'?: string; - readonly '@namespace.integer'?: number; - readonly value?: Array; - } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends> { - return __request({ + public static callWithResponses() { + return __request<{ + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + } | ModelWithString | ModelThatExtends | ModelThatExtendsExtends>({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/response\`, errors: { @@ -6083,8 +6085,8 @@ export class SimpleService { /** * @throws ApiError */ - public static getCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static getCallWithoutParametersAndResponse() { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6093,8 +6095,8 @@ export class SimpleService { /** * @throws ApiError */ - public static putCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static putCallWithoutParametersAndResponse() { + return __request({ method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6103,8 +6105,8 @@ export class SimpleService { /** * @throws ApiError */ - public static postCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static postCallWithoutParametersAndResponse() { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6113,8 +6115,8 @@ export class SimpleService { /** * @throws ApiError */ - public static deleteCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static deleteCallWithoutParametersAndResponse() { + return __request({ method: 'DELETE', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6123,8 +6125,8 @@ export class SimpleService { /** * @throws ApiError */ - public static optionsCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static optionsCallWithoutParametersAndResponse() { + return __request({ method: 'OPTIONS', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6133,8 +6135,8 @@ export class SimpleService { /** * @throws ApiError */ - public static headCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static headCallWithoutParametersAndResponse() { + return __request({ method: 'HEAD', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6143,8 +6145,8 @@ export class SimpleService { /** * @throws ApiError */ - public static patchCallWithoutParametersAndResponse(): CancelablePromise { - return __request({ + public static patchCallWithoutParametersAndResponse() { + return __request({ method: 'PATCH', path: \`/api/v\${OpenAPI.VERSION}/simple\`, }); @@ -6187,8 +6189,8 @@ export class TypesService { parameterBoolean: boolean | null = true, parameterObject: any = null, id?: number, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'GET', path: \`/api/v\${OpenAPI.VERSION}/types\`, query: { @@ -6223,8 +6225,8 @@ export class UploadService { */ public static uploadFile( file: Blob, - ): CancelablePromise { - return __request({ + ) { + return __request({ method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/upload\`, formData: { diff --git a/test/index.js b/test/index.js index 7817170fd..337f73ba6 100644 --- a/test/index.js +++ b/test/index.js @@ -16,6 +16,15 @@ const generate = async (input, output) => { exportServices: true, // postfix: 'Api', // request: './test/custom/request.ts', + // serviceOptions: { + // staticMethods: false, + // serviceImports: ` + // import {Injectable} from '@angular/core'; + // import {HttpClient} from '@angular/common/http'; + // `, + // serviceDecorator: `@Injectable()`, + // serviceConstructor: `constructor(private http: HttpClient) {}`, + // }, }); };