fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'master' of https://github.com/nicolas-chaulet/openapi-typescript-codegen

Lubos 94a13cf4 1ebcc7ff

+1531 -920
+1 -1
README.md
··· 66 66 `openapi-ts` supports loading configuration from a file inside your project root directory. You just need to create a `openapi-ts.config.js` file 67 67 68 68 ```js 69 - /** @type {import('@nicolas-chaulet/openapi-typescript-codegen').Config} */ 69 + /** @type {import('@nicolas-chaulet/openapi-typescript-codegen').UserConfig} */ 70 70 export default { 71 71 input: 'path/to/openapi.json', 72 72 output: 'src/client',
+1 -1
package.json
··· 53 53 "eslint:fix": "eslint . --fix", 54 54 "eslint": "eslint .", 55 55 "prepublishOnly": "npm run build", 56 - "run": "node ./test/index.js", 57 56 "test": "jest --selectProjects UNIT", 58 57 "test:coverage": "jest --selectProjects UNIT --coverage", 59 58 "test:e2e": "jest --selectProjects E2E --runInBand --verbose", 59 + "test:sample": "node test/sample.cjs", 60 60 "test:update": "jest --selectProjects UNIT --updateSnapshot", 61 61 "test:watch": "jest --selectProjects UNIT --watch", 62 62 "typecheck": "tsc --noEmit"
+1
rollup.config.ts
··· 50 50 modelUnionType: true, 51 51 nameOperationDataType: true, 52 52 notEquals: true, 53 + operationDataType: true, 53 54 useDateType: true, 54 55 }, 55 56 knownHelpersOnly: true,
+1 -1
src/client/interfaces/Operation.ts
··· 6 6 deprecated: boolean; 7 7 description: string | null; 8 8 errors: OperationError[]; 9 - method: string; 9 + method: 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT'; 10 10 /** 11 11 * Method name. Methods contain the request logic. 12 12 */
+25 -30
src/index.ts
··· 1 1 import { existsSync, readFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 + import { pathToFileURL } from 'node:url'; 3 4 4 5 import { sync } from 'cross-spawn'; 5 6 6 - import type { Config } from './node'; 7 7 import { parse as parseV2 } from './openApi/v2'; 8 8 import { parse as parseV3 } from './openApi/v3'; 9 + import type { Config, UserConfig } from './types/config'; 9 10 import { getOpenApiSpec } from './utils/getOpenApiSpec'; 11 + import { registerHandlebarTemplates } from './utils/handlebars'; 10 12 import { postProcessClient } from './utils/postProcessClient'; 11 - import { registerHandlebarTemplates } from './utils/registerHandlebarTemplates'; 12 13 import { writeClient } from './utils/write/client'; 13 14 14 - type DefaultOptions = Omit<Required<Config>, 'base' | 'clientName' | 'request'> & 15 - Pick<Config, 'base' | 'clientName' | 'request'>; 16 - 17 15 type Dependencies = Record<string, unknown>; 18 16 19 17 // const configFiles = ['openapi-ts.config.js', 'openapi-ts.config.ts']; 20 18 // add support for `openapi-ts.config.ts` 21 19 const configFiles = ['openapi-ts.config.js']; 22 20 23 - export const parseOpenApiSpecification = ( 24 - openApi: Awaited<ReturnType<typeof getOpenApiSpec>>, 25 - options: DefaultOptions 26 - ) => { 21 + export const parseOpenApiSpecification = (openApi: Awaited<ReturnType<typeof getOpenApiSpec>>, options: Config) => { 27 22 if ('swagger' in openApi) { 28 23 return parseV2(openApi, options); 29 24 } ··· 33 28 throw new Error(`Unsupported Open API specification: ${JSON.stringify(openApi, null, 2)}`); 34 29 }; 35 30 36 - const formatClient = (options: DefaultOptions, dependencies: Dependencies) => { 31 + const formatClient = (options: Config, dependencies: Dependencies) => { 37 32 if (!options.autoformat) { 38 33 return; 39 34 } ··· 44 39 } 45 40 }; 46 41 47 - const inferClient = (dependencies: Dependencies): DefaultOptions['client'] => { 42 + const inferClient = (dependencies: Dependencies): Config['client'] => { 48 43 if (dependencies['@angular/cli']) { 49 44 return 'angular'; 50 45 } ··· 54 49 return 'fetch'; 55 50 }; 56 51 57 - const logClientMessage = (client: DefaultOptions['client']) => { 52 + const logClientMessage = (client: Config['client']) => { 58 53 switch (client) { 59 54 case 'angular': 60 55 return console.log('✨ Creating Angular client'); ··· 69 64 } 70 65 }; 71 66 72 - const getOptionsFromConfig = async (): Promise<Config | undefined> => { 67 + const getConfigFromFile = async (): Promise<UserConfig | undefined> => { 73 68 const configPath = configFiles 74 - .map(file => path.resolve(process.cwd(), file)) 69 + .map(file => pathToFileURL(path.resolve(process.cwd(), file))) 75 70 .find(filePath => existsSync(filePath)); 76 71 if (!configPath) { 77 72 return; 78 73 } 74 + // @ts-ignore 79 75 const exported = await import(configPath); 80 - return exported.default as Config; 76 + return exported.default as UserConfig; 81 77 }; 82 78 83 - const getOptions = async (options: Config, dependencies: Dependencies) => { 84 - const configOptions = await getOptionsFromConfig(); 85 - if (configOptions) { 86 - options = { ...options, ...configOptions }; 79 + const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => { 80 + const userConfigFromFile = await getConfigFromFile(); 81 + if (userConfigFromFile) { 82 + userConfig = { ...userConfig, ...userConfigFromFile }; 87 83 } 88 84 89 85 const { ··· 105 101 useDateType = false, 106 102 useOptions = false, 107 103 write = true, 108 - } = options; 104 + } = userConfig; 109 105 110 - const client = options.client || inferClient(dependencies); 106 + const client = userConfig.client || inferClient(dependencies); 111 107 112 - const defaultOptions: DefaultOptions = { 108 + const config: Config = { 113 109 autoformat, 114 110 base, 115 111 client, ··· 139 135 throw new Error('🚫 output not provided - provide path where we should generate your client'); 140 136 } 141 137 142 - return defaultOptions; 138 + return config; 143 139 }; 144 140 145 141 /** 146 142 * Generate the OpenAPI client. This method will read the OpenAPI specification and based on the 147 143 * given language it will generate the client, including the typed models, validation schemas, 148 144 * service layer, etc. 149 - * @param options Options passed to the generate method 145 + * @param userConfig {@link UserConfig} passed to the generate method 150 146 */ 151 - export const generate = async (options: Config): Promise<void> => { 147 + export const generate = async (userConfig: UserConfig): Promise<void> => { 152 148 const pkg = JSON.parse(readFileSync(path.resolve(process.cwd(), 'package.json')).toString()); 153 149 154 150 const dependencies = [pkg.dependencies, pkg.devDependencies].reduce( ··· 159 155 {} 160 156 ); 161 157 162 - const config = await getOptions(options, dependencies); 158 + const config = await getConfig(userConfig, dependencies); 163 159 164 160 const openApi = 165 161 typeof config.input === 'string' 166 162 ? await getOpenApiSpec(config.input) 167 163 : (config.input as unknown as Awaited<ReturnType<typeof getOpenApiSpec>>); 168 - const templates = registerHandlebarTemplates(openApi, config); 169 164 170 - const parsedClient = parseOpenApiSpecification(openApi, config); 171 - const finalClient = postProcessClient(parsedClient); 165 + const client = postProcessClient(parseOpenApiSpecification(openApi, config)); 166 + const templates = registerHandlebarTemplates(config, client); 172 167 173 168 if (config.write) { 174 169 logClientMessage(config.client); 175 - await writeClient(finalClient, templates, config); 170 + await writeClient(client, templates, config); 176 171 formatClient(config, dependencies); 177 172 } 178 173
+5 -94
src/node/index.ts
··· 1 - export interface Config { 2 - /** 3 - * Process generated files with autoformatter 4 - * @default true 5 - */ 6 - autoformat?: boolean; 7 - /** 8 - * Manually set base in OpenAPI config instead of inferring from server value 9 - */ 10 - base?: string; 11 - /** 12 - * The selected HTTP client (fetch, xhr, node or axios) 13 - * @default 'fetch' 14 - */ 15 - client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr'; 16 - /** 17 - * Custom client class name 18 - */ 19 - clientName?: string; 20 - /** 21 - * Generate JavaScript objects from enum definitions 22 - * @default false 23 - */ 24 - enums?: boolean; 25 - /** 26 - * Generate core client classes 27 - * @default true 28 - */ 29 - exportCore?: boolean; 30 - /** 31 - * Generate models 32 - * @default true 33 - */ 34 - exportModels?: boolean | string; 35 - /** 36 - * Generate schemas 37 - * @default false 38 - */ 39 - exportSchemas?: boolean; 40 - /** 41 - * Generate services 42 - * @default true 43 - */ 44 - exportServices?: boolean | string; 45 - /** 46 - * The relative location of the OpenAPI spec 47 - */ 48 - input: string | Record<string, unknown>; 49 - /** 50 - * Use operation ID to generate operation names? 51 - * @default true 52 - */ 53 - operationId?: boolean; 54 - /** 55 - * The relative location of the output directory 56 - */ 57 - output: string; 58 - /** 59 - * Model name postfix 60 - * @default ''' 61 - */ 62 - postfixModels?: string; 63 - /** 64 - * Service name postfix 65 - * @default 'Service' 66 - */ 67 - postfixServices?: string; 68 - /** 69 - * Path to custom request file 70 - */ 71 - request?: string; 72 - /** 73 - * Define shape of returned value from service calls 74 - * @default 'body' 75 - */ 76 - serviceResponse?: 'body' | 'generics' | 'response'; 77 - /** 78 - * Output Date instead of string for the format "date-time" in the models 79 - * @default false 80 - */ 81 - useDateType?: boolean; 82 - /** 83 - * Use options or arguments functions 84 - * @default false 85 - */ 86 - useOptions?: boolean; 87 - /** 88 - * Write the files to disk (true or false) 89 - * @default true 90 - */ 91 - write?: boolean; 92 - } 1 + import type { UserConfig } from '../types/config'; 2 + 3 + export type { UserConfig } from '../types/config'; 93 4 94 5 /** 95 - * Type helper for openapi-ts.config.ts, returns {@link Config} object 6 + * Type helper for openapi-ts.config.ts, returns {@link UserConfig} object 96 7 */ 97 - export function defineConfig(config: Config): Config { 8 + export function defineConfig(config: UserConfig): UserConfig { 98 9 return config; 99 10 }
+2 -5
src/openApi/v2/index.ts
··· 1 1 import type { Client } from '../../client/interfaces/Client'; 2 - import type { Config } from '../../node'; 2 + import type { Config } from '../../types/config'; 3 3 import type { OpenApi } from './interfaces/OpenApi'; 4 4 import { getModels } from './parser/getModels'; 5 5 import { getServer } from './parser/getServer'; ··· 12 12 * @param openApi The OpenAPI spec that we have loaded from disk. 13 13 * @param options Options passed to the generate method 14 14 */ 15 - export const parse = ( 16 - openApi: OpenApi, 17 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'> 18 - ): Client => { 15 + export const parse = (openApi: OpenApi, options: Config): Client => { 19 16 const version = getServiceVersion(openApi.info.version); 20 17 const server = getServer(openApi); 21 18 const models = getModels(openApi);
+4 -4
src/openApi/v2/parser/getOperation.ts
··· 1 1 import type { Operation } from '../../../client/interfaces/Operation'; 2 2 import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 3 - import type { Config } from '../../../node'; 3 + import type { Config } from '../../../types/config'; 4 4 import { getOperationName } from '../../../utils/operation'; 5 5 import type { OpenApi } from '../interfaces/OpenApi'; 6 6 import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; ··· 15 15 export const getOperation = ( 16 16 openApi: OpenApi, 17 17 url: string, 18 - method: string, 18 + method: Lowercase<Operation['method']>, 19 19 tag: string, 20 20 op: OpenApiOperation, 21 21 pathParams: OperationParameters, 22 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'> 22 + options: Config 23 23 ): Operation => { 24 24 const serviceName = getServiceName(tag); 25 25 const name = getOperationName(url, method, options, op.operationId); ··· 32 32 summary: op.summary || null, 33 33 description: op.description || null, 34 34 deprecated: op.deprecated === true, 35 - method: method.toUpperCase(), 35 + method: method.toUpperCase() as Operation['method'], 36 36 path: url, 37 37 parameters: [...pathParams.parameters], 38 38 parametersPath: [...pathParams.parametersPath],
+13
src/openApi/v2/parser/getServices.spec.ts
··· 3 3 describe('getServices', () => { 4 4 it('should create a unnamed service if tags are empty', () => { 5 5 const options: Parameters<typeof getServices>[1] = { 6 + autoformat: false, 7 + client: 'fetch', 8 + enums: false, 9 + exportCore: true, 10 + exportModels: true, 11 + exportSchemas: true, 12 + exportServices: true, 6 13 input: '', 7 14 operationId: false, 8 15 output: '', 16 + postfixModels: '', 17 + postfixServices: 'Service', 18 + serviceResponse: 'body', 19 + useDateType: false, 20 + useOptions: true, 21 + write: false, 9 22 }; 10 23 const services = getServices( 11 24 {
+2 -5
src/openApi/v2/parser/getServices.ts
··· 1 1 import type { Service } from '../../../client/interfaces/Service'; 2 - import type { Config } from '../../../node'; 2 + import type { Config } from '../../../types/config'; 3 3 import { unique } from '../../../utils/unique'; 4 4 import type { OpenApi } from '../interfaces/OpenApi'; 5 5 import { getOperation } from './getOperation'; ··· 8 8 /** 9 9 * Get the OpenAPI services 10 10 */ 11 - export const getServices = ( 12 - openApi: OpenApi, 13 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'> 14 - ): Service[] => { 11 + export const getServices = (openApi: OpenApi, options: Config): Service[] => { 15 12 const services = new Map<string, Service>(); 16 13 for (const url in openApi.paths) { 17 14 if (openApi.paths.hasOwnProperty(url)) {
+2 -5
src/openApi/v3/index.ts
··· 1 1 import type { Client } from '../../client/interfaces/Client'; 2 - import type { Config } from '../../node'; 2 + import type { Config } from '../../types/config'; 3 3 import type { OpenApi } from './interfaces/OpenApi'; 4 4 import { getModels } from './parser/getModels'; 5 5 import { getServer } from './parser/getServer'; ··· 12 12 * @param openApi The OpenAPI spec that we have loaded from disk. 13 13 * @param options Options passed to the generate method 14 14 */ 15 - export const parse = ( 16 - openApi: OpenApi, 17 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'> 18 - ): Client => { 15 + export const parse = (openApi: OpenApi, options: Config): Client => { 19 16 const version = getServiceVersion(openApi.info.version); 20 17 const server = getServer(openApi); 21 18 const models = getModels(openApi);
+13
src/openApi/v3/parser/__tests__/getServices.spec.ts
··· 3 3 describe('getServices', () => { 4 4 it('should create a unnamed service if tags are empty', () => { 5 5 const options: Parameters<typeof getServices>[1] = { 6 + autoformat: false, 7 + client: 'fetch', 8 + enums: false, 9 + exportCore: true, 10 + exportModels: true, 11 + exportSchemas: true, 12 + exportServices: true, 6 13 input: '', 7 14 operationId: true, 8 15 output: '', 16 + postfixModels: '', 17 + postfixServices: 'Service', 18 + serviceResponse: 'body', 19 + useDateType: false, 20 + useOptions: true, 21 + write: false, 9 22 }; 10 23 const services = getServices( 11 24 {
+3 -6
src/openApi/v3/parser/getServices.ts
··· 1 1 import type { Operation } from '../../../client/interfaces/Operation'; 2 2 import type { Service } from '../../../client/interfaces/Service'; 3 - import type { Config } from '../../../node'; 3 + import type { Config } from '../../../types/config'; 4 4 import { unique } from '../../../utils/unique'; 5 5 import type { OpenApi } from '../interfaces/OpenApi'; 6 6 import { getOperationParameters } from './getOperationParameters'; ··· 14 14 operations: [], 15 15 }); 16 16 17 - export const getServices = ( 18 - openApi: OpenApi, 19 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'> 20 - ): Service[] => { 17 + export const getServices = (openApi: OpenApi, options: Config): Service[] => { 21 18 const services = new Map<string, Service>(); 22 19 23 20 for (const url in openApi.paths) { ··· 25 22 const pathParams = getOperationParameters(openApi, path.parameters ?? []); 26 23 27 24 for (const key in path) { 28 - const method = key as (typeof allowedServiceMethods)[number]; 25 + const method = key as Lowercase<Operation['method']>; 29 26 if (allowedServiceMethods.includes(method)) { 30 27 const op = path[method]!; 31 28 const tags = op.tags?.length ? op.tags.filter(unique) : ['Default'];
+5 -5
src/openApi/v3/parser/operation.ts
··· 1 1 import type { Operation } from '../../../client/interfaces/Operation'; 2 2 import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 3 3 import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 4 - import type { Config } from '../../../node'; 4 + import type { Config } from '../../../types/config'; 5 5 import { getOperationName } from '../../../utils/operation'; 6 6 import type { OpenApi } from '../interfaces/OpenApi'; 7 7 import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; ··· 13 13 import { getOperationResponses } from './getOperationResponses'; 14 14 import { getOperationResults } from './getOperationResults'; 15 15 import { getRef } from './getRef'; 16 - import { allowedServiceMethods, getServiceName } from './service'; 16 + import { getServiceName } from './service'; 17 17 18 18 // add global path parameters, skip duplicate names 19 19 const mergeParameters = (opParams: OperationParameter[], globalParams: OperationParameter[]): OperationParameter[] => { ··· 34 34 35 35 export const getOperation = ( 36 36 openApi: OpenApi, 37 - options: Pick<Required<Config>, 'operationId'> & Omit<Config, 'operationId'>, 37 + options: Config, 38 38 data: { 39 - method: (typeof allowedServiceMethods)[number]; 39 + method: Lowercase<Operation['method']>; 40 40 op: OpenApiOperation; 41 41 pathParams: OperationParameters; 42 42 tag: string; ··· 53 53 description: op.description || null, 54 54 errors: [], 55 55 imports: [], 56 - method: method.toUpperCase(), 56 + method: method.toUpperCase() as Operation['method'], 57 57 name, 58 58 parameters: [], 59 59 parametersBody: pathParams.parametersBody,
+1 -1
src/templates/core/angular/request.hbs
··· 69 69 70 70 return getHeaders(config, options).pipe( 71 71 switchMap(headers => { 72 - return sendRequest<T>(config, options, http, url, formData, body, headers); 72 + return sendRequest<T>(config, options, http, url, body, formData, headers); 73 73 }), 74 74 map(response => { 75 75 const responseBody = getResponseBody(response);
+1 -16
src/templates/exportService.hbs
··· 37 37 {{/if}} 38 38 {{/if}} 39 39 40 - {{#if @root.$config.useOptions}} 41 - {{#each operations}} 42 - {{#if parameters}} 43 - export type {{{nameOperationDataType name}}} = { 44 - {{#each parameters}} 45 - {{#if description}} 46 - /** 47 - * {{{escapeComment description}}} 48 - */ 49 - {{/if}} 50 - {{{name}}}{{>isRequired}}: {{>type}}, 51 - {{/each}} 52 - } 53 - {{/if}} 54 - {{/each}} 55 - {{/if}} 40 + {{{operationDataType this}}} 56 41 57 42 {{#equals @root.$config.client 'angular'}} 58 43 @Injectable({
+95
src/types/config.ts
··· 1 + export interface UserConfig { 2 + /** 3 + * Process generated files with autoformatter 4 + * @default true 5 + */ 6 + autoformat?: boolean; 7 + /** 8 + * Manually set base in OpenAPI config instead of inferring from server value 9 + */ 10 + base?: string; 11 + /** 12 + * The selected HTTP client (fetch, xhr, node or axios) 13 + * @default 'fetch' 14 + */ 15 + client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr'; 16 + /** 17 + * Custom client class name 18 + */ 19 + clientName?: string; 20 + /** 21 + * Generate JavaScript objects from enum definitions 22 + * @default false 23 + */ 24 + enums?: boolean; 25 + /** 26 + * Generate core client classes 27 + * @default true 28 + */ 29 + exportCore?: boolean; 30 + /** 31 + * Generate models 32 + * @default true 33 + */ 34 + exportModels?: boolean | string; 35 + /** 36 + * Generate schemas 37 + * @default false 38 + */ 39 + exportSchemas?: boolean; 40 + /** 41 + * Generate services 42 + * @default true 43 + */ 44 + exportServices?: boolean | string; 45 + /** 46 + * The relative location of the OpenAPI spec 47 + */ 48 + input: string | Record<string, unknown>; 49 + /** 50 + * Use operation ID to generate operation names? 51 + * @default true 52 + */ 53 + operationId?: boolean; 54 + /** 55 + * The relative location of the output directory 56 + */ 57 + output: string; 58 + /** 59 + * Model name postfix 60 + * @default ''' 61 + */ 62 + postfixModels?: string; 63 + /** 64 + * Service name postfix 65 + * @default 'Service' 66 + */ 67 + postfixServices?: string; 68 + /** 69 + * Path to custom request file 70 + */ 71 + request?: string; 72 + /** 73 + * Define shape of returned value from service calls 74 + * @default 'body' 75 + */ 76 + serviceResponse?: 'body' | 'generics' | 'response'; 77 + /** 78 + * Output Date instead of string for the format "date-time" in the models 79 + * @default false 80 + */ 81 + useDateType?: boolean; 82 + /** 83 + * Use options or arguments functions 84 + * @default false 85 + */ 86 + useOptions?: boolean; 87 + /** 88 + * Write the files to disk (true or false) 89 + * @default true 90 + */ 91 + write?: boolean; 92 + } 93 + 94 + export type Config = Omit<Required<UserConfig>, 'base' | 'clientName' | 'request'> & 95 + Pick<UserConfig, 'base' | 'clientName' | 'request'>;
src/typings/hbs.d.ts src/types/hbs.d.ts
+95
src/utils/__tests__/handlebars.spec.ts
··· 1 + import Handlebars from 'handlebars/runtime'; 2 + 3 + import { registerHandlebarHelpers, registerHandlebarTemplates } from '../handlebars'; 4 + 5 + describe('registerHandlebarHelpers', () => { 6 + it('should register the helpers', () => { 7 + registerHandlebarHelpers( 8 + { 9 + autoformat: true, 10 + client: 'fetch', 11 + enums: true, 12 + exportCore: true, 13 + exportModels: true, 14 + exportSchemas: true, 15 + exportServices: true, 16 + input: '', 17 + operationId: true, 18 + output: '', 19 + postfixModels: '', 20 + postfixServices: '', 21 + serviceResponse: 'body', 22 + useDateType: false, 23 + useOptions: false, 24 + write: true, 25 + }, 26 + { 27 + models: [], 28 + server: '', 29 + services: [], 30 + version: '', 31 + } 32 + ); 33 + const helpers = Object.keys(Handlebars.helpers); 34 + expect(helpers).toContain('camelCase'); 35 + expect(helpers).toContain('dataParameters'); 36 + expect(helpers).toContain('debugThis'); 37 + expect(helpers).toContain('enumKey'); 38 + expect(helpers).toContain('enumName'); 39 + expect(helpers).toContain('enumUnionType'); 40 + expect(helpers).toContain('enumValue'); 41 + expect(helpers).toContain('equals'); 42 + expect(helpers).toContain('escapeComment'); 43 + expect(helpers).toContain('escapeDescription'); 44 + expect(helpers).toContain('escapeNewline'); 45 + expect(helpers).toContain('exactArray'); 46 + expect(helpers).toContain('ifdef'); 47 + expect(helpers).toContain('ifOperationDataOptional'); 48 + expect(helpers).toContain('intersection'); 49 + expect(helpers).toContain('modelUnionType'); 50 + expect(helpers).toContain('nameOperationDataType'); 51 + expect(helpers).toContain('notEquals'); 52 + expect(helpers).toContain('operationDataType'); 53 + expect(helpers).toContain('useDateType'); 54 + }); 55 + }); 56 + 57 + describe('registerHandlebarTemplates', () => { 58 + it('should return correct templates', () => { 59 + const templates = registerHandlebarTemplates( 60 + { 61 + autoformat: true, 62 + client: 'fetch', 63 + enums: true, 64 + exportCore: true, 65 + exportModels: true, 66 + exportSchemas: true, 67 + exportServices: true, 68 + input: '', 69 + operationId: true, 70 + output: '', 71 + postfixModels: '', 72 + postfixServices: '', 73 + serviceResponse: 'body', 74 + useDateType: false, 75 + useOptions: false, 76 + write: true, 77 + }, 78 + { 79 + models: [], 80 + server: '', 81 + services: [], 82 + version: '', 83 + } 84 + ); 85 + expect(templates.index).toBeDefined(); 86 + expect(templates.exports.model).toBeDefined(); 87 + expect(templates.exports.schema).toBeDefined(); 88 + expect(templates.exports.service).toBeDefined(); 89 + expect(templates.core.settings).toBeDefined(); 90 + expect(templates.core.apiError).toBeDefined(); 91 + expect(templates.core.apiRequestOptions).toBeDefined(); 92 + expect(templates.core.apiResult).toBeDefined(); 93 + expect(templates.core.request).toBeDefined(); 94 + }); 95 + });
-56
src/utils/__tests__/registerHandlebarHelpers.spec.ts
··· 1 - import Handlebars from 'handlebars/runtime'; 2 - 3 - import { registerHandlebarHelpers } from '../registerHandlebarHelpers'; 4 - 5 - describe('registerHandlebarHelpers', () => { 6 - it('should register the helpers', () => { 7 - registerHandlebarHelpers( 8 - { 9 - info: { 10 - title: '', 11 - version: '', 12 - }, 13 - openapi: '', 14 - paths: {}, 15 - }, 16 - { 17 - autoformat: true, 18 - client: 'fetch', 19 - enums: true, 20 - exportCore: true, 21 - exportModels: true, 22 - exportSchemas: true, 23 - exportServices: true, 24 - input: '', 25 - operationId: true, 26 - output: '', 27 - postfixModels: '', 28 - postfixServices: '', 29 - serviceResponse: 'body', 30 - useDateType: false, 31 - useOptions: false, 32 - write: true, 33 - } 34 - ); 35 - const helpers = Object.keys(Handlebars.helpers); 36 - expect(helpers).toContain('camelCase'); 37 - expect(helpers).toContain('dataParameters'); 38 - expect(helpers).toContain('debugThis'); 39 - expect(helpers).toContain('enumKey'); 40 - expect(helpers).toContain('enumName'); 41 - expect(helpers).toContain('enumUnionType'); 42 - expect(helpers).toContain('enumValue'); 43 - expect(helpers).toContain('equals'); 44 - expect(helpers).toContain('escapeComment'); 45 - expect(helpers).toContain('escapeDescription'); 46 - expect(helpers).toContain('escapeNewline'); 47 - expect(helpers).toContain('exactArray'); 48 - expect(helpers).toContain('ifdef'); 49 - expect(helpers).toContain('ifOperationDataOptional'); 50 - expect(helpers).toContain('intersection'); 51 - expect(helpers).toContain('modelUnionType'); 52 - expect(helpers).toContain('nameOperationDataType'); 53 - expect(helpers).toContain('notEquals'); 54 - expect(helpers).toContain('useDateType'); 55 - }); 56 - });
+2 -2
src/utils/getHttpRequestName.ts
··· 1 - import type { Config } from '../node'; 1 + import type { UserConfig } from '../node'; 2 2 3 3 /** 4 4 * Generate the HttpRequest filename based on the selected client 5 5 * @param client The selected HTTP client (fetch, xhr, node or axios) 6 6 */ 7 - export const getHttpRequestName = (client: Config['client']): string => { 7 + export const getHttpRequestName = (client: UserConfig['client']): string => { 8 8 switch (client) { 9 9 case 'angular': 10 10 return 'AngularHttpRequest';
+2 -2
src/utils/operation.ts
··· 1 1 import camelCase from 'camelcase'; 2 2 3 - import type { Config } from '../node'; 3 + import type { UserConfig } from '../node'; 4 4 import sanitizeOperationName from './sanitizeOperationName'; 5 5 6 6 /** ··· 11 11 export const getOperationName = ( 12 12 url: string, 13 13 method: string, 14 - options: Pick<Required<Config>, 'operationId'>, 14 + options: Pick<Required<UserConfig>, 'operationId'>, 15 15 operationId?: string 16 16 ): string => { 17 17 if (options.operationId && operationId) {
-162
src/utils/registerHandlebarHelpers.ts
··· 1 - import camelCase from 'camelcase'; 2 - import Handlebars from 'handlebars/runtime'; 3 - import { EOL } from 'os'; 4 - 5 - import type { Model } from '../client/interfaces/Model'; 6 - import type { OperationParameter } from '../client/interfaces/OperationParameter'; 7 - import type { Service } from '../client/interfaces/Service'; 8 - import type { Config } from '../node'; 9 - import type { OpenApi as OpenApiV2 } from '../openApi/v2/interfaces/OpenApi'; 10 - import type { OpenApi as OpenApiV3 } from '../openApi/v3/interfaces/OpenApi'; 11 - import { enumKey, enumName, enumUnionType, enumValue } from './enum'; 12 - import { escapeName } from './escapeName'; 13 - import { unique } from './unique'; 14 - 15 - const modelsExports = (config: Config, models: Model[], path: string) => { 16 - const output = models.map(model => { 17 - const importedModel = config.postfixModels 18 - ? `${model.name} as ${model.name + config.postfixModels}` 19 - : model.name; 20 - let result = [`export type { ${importedModel} } from '${path + model.name}';`]; 21 - if (config.enums && (model.enum.length || model.enums.length)) { 22 - const names = model.enums.map(enumerator => enumerator.name).filter(Boolean); 23 - const enumExports = names.length ? names : [model.name]; 24 - const enumExportsString = enumExports.map(name => enumName(name)).join(', '); 25 - result = [...result, `export { ${enumExportsString} } from '${path + model.name}';`]; 26 - } 27 - return result.join('\n'); 28 - }); 29 - return output.join('\n'); 30 - }; 31 - 32 - const modelImports = (model: Model | Service, path: string) => { 33 - if (!model.imports.length) { 34 - return ''; 35 - } 36 - const output = model.imports.map(item => `import type { ${item} } from '${path + item}';`); 37 - return output.join('\n'); 38 - }; 39 - 40 - const dataParameters = (parameters: OperationParameter[]) => { 41 - const output = parameters.map(parameter => { 42 - const key = parameter.prop; 43 - const value = parameter.name; 44 - if (key === value) { 45 - return key; 46 - } 47 - if (escapeName(key) === key) { 48 - return `${key}: ${value}`; 49 - } 50 - return `'${key}': ${value}`; 51 - }); 52 - return output.join(', '); 53 - }; 54 - 55 - const debugThis = (value: unknown) => { 56 - console.log(value); 57 - return ''; 58 - }; 59 - 60 - export const registerHandlebarHelpers = ( 61 - openApi: OpenApiV3 | OpenApiV2, 62 - config: Omit<Required<Config>, 'base' | 'clientName' | 'request'> 63 - ): void => { 64 - Handlebars.registerHelper('camelCase', camelCase); 65 - Handlebars.registerHelper('dataParameters', dataParameters); 66 - Handlebars.registerHelper('debugThis', debugThis); 67 - Handlebars.registerHelper('enumKey', enumKey); 68 - Handlebars.registerHelper('enumName', enumName); 69 - Handlebars.registerHelper('enumUnionType', enumUnionType); 70 - Handlebars.registerHelper('enumValue', enumValue); 71 - 72 - Handlebars.registerHelper( 73 - 'equals', 74 - function (this: unknown, a: string, b: string, options: Handlebars.HelperOptions) { 75 - return a === b ? options.fn(this) : options.inverse(this); 76 - } 77 - ); 78 - 79 - Handlebars.registerHelper('escapeComment', function (value: string) { 80 - return value 81 - .replace(/\*\//g, '*') 82 - .replace(/\/\*/g, '*') 83 - .replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); 84 - }); 85 - 86 - Handlebars.registerHelper('escapeDescription', function (value: string) { 87 - return value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${'); 88 - }); 89 - 90 - Handlebars.registerHelper('escapeNewline', function (value: string) { 91 - return value.replace(/\n/g, '\\n'); 92 - }); 93 - 94 - Handlebars.registerHelper('exactArray', function (this: unknown, model: Model, options: Handlebars.HelperOptions) { 95 - if (model.export === 'array' && model.maxItems && model.minItems && model.maxItems === model.minItems) { 96 - return options.fn(this); 97 - } 98 - return options.inverse(this); 99 - }); 100 - 101 - Handlebars.registerHelper('ifdef', function (this: unknown, ...args): string { 102 - const options = args.pop(); 103 - if (!args.every(value => !value)) { 104 - return options.fn(this); 105 - } 106 - return options.inverse(this); 107 - }); 108 - 109 - Handlebars.registerHelper( 110 - 'ifOperationDataOptional', 111 - function (this: unknown, parameters: OperationParameter[], options: Handlebars.HelperOptions) { 112 - return parameters.every(parameter => !parameter.isRequired) ? options.fn(this) : options.inverse(this); 113 - } 114 - ); 115 - 116 - Handlebars.registerHelper( 117 - 'intersection', 118 - function (this: unknown, models: Model[], parent: string | undefined, options: Handlebars.HelperOptions) { 119 - const partialType = Handlebars.partials['type']; 120 - const types = models.map(model => partialType({ $config: config, ...model, parent })); 121 - const uniqueTypes = types.filter(unique); 122 - let uniqueTypesString = uniqueTypes.join(' & '); 123 - if (uniqueTypes.length > 1) { 124 - uniqueTypesString = `(${uniqueTypesString})`; 125 - } 126 - return options.fn(uniqueTypesString); 127 - } 128 - ); 129 - 130 - Handlebars.registerHelper('modelImports', modelImports); 131 - Handlebars.registerHelper('modelsExports', modelsExports); 132 - 133 - Handlebars.registerHelper( 134 - 'modelUnionType', 135 - function (models: Model[], parent: string | undefined, filterProperties: 'exact' | undefined) { 136 - const partialType = Handlebars.partials['type']; 137 - const types = models 138 - .map(model => partialType({ $config: config, ...model, parent })) 139 - .filter((...args) => filterProperties === 'exact' || unique(...args)); 140 - const union = types.join(filterProperties === 'exact' ? ', ' : ' | '); 141 - return types.length > 1 && types.length !== models.length ? `(${union})` : union; 142 - } 143 - ); 144 - 145 - Handlebars.registerHelper('nameOperationDataType', function (value: string) { 146 - return camelCase(['TData', value].join('-'), { pascalCase: true }); 147 - }); 148 - 149 - Handlebars.registerHelper( 150 - 'notEquals', 151 - function (this: unknown, a: string, b: string, options: Handlebars.HelperOptions) { 152 - return a !== b ? options.fn(this) : options.inverse(this); 153 - } 154 - ); 155 - 156 - Handlebars.registerHelper( 157 - 'useDateType', 158 - function (this: unknown, config: Config, format: string | undefined, options: Handlebars.HelperOptions) { 159 - return config.useDateType && format === 'date-time' ? options.fn(this) : options.inverse(this); 160 - } 161 - ); 162 - };
-43
src/utils/registerHandlebarTemplates.spec.ts
··· 1 - import { registerHandlebarTemplates } from './registerHandlebarTemplates'; 2 - 3 - describe('registerHandlebarTemplates', () => { 4 - it('should return correct templates', () => { 5 - const templates = registerHandlebarTemplates( 6 - { 7 - info: { 8 - title: '', 9 - version: '', 10 - }, 11 - openapi: '', 12 - paths: {}, 13 - }, 14 - { 15 - autoformat: true, 16 - client: 'fetch', 17 - enums: true, 18 - exportCore: true, 19 - exportModels: true, 20 - exportSchemas: true, 21 - exportServices: true, 22 - input: '', 23 - operationId: true, 24 - output: '', 25 - postfixModels: '', 26 - postfixServices: '', 27 - serviceResponse: 'body', 28 - useDateType: false, 29 - useOptions: false, 30 - write: true, 31 - } 32 - ); 33 - expect(templates.index).toBeDefined(); 34 - expect(templates.exports.model).toBeDefined(); 35 - expect(templates.exports.schema).toBeDefined(); 36 - expect(templates.exports.service).toBeDefined(); 37 - expect(templates.core.settings).toBeDefined(); 38 - expect(templates.core.apiError).toBeDefined(); 39 - expect(templates.core.apiRequestOptions).toBeDefined(); 40 - expect(templates.core.apiResult).toBeDefined(); 41 - expect(templates.core.request).toBeDefined(); 42 - }); 43 - });
+195 -9
src/utils/registerHandlebarTemplates.ts src/utils/handlebars.ts
··· 1 + import camelCase from 'camelcase'; 1 2 import Handlebars from 'handlebars/runtime'; 3 + import { EOL } from 'os'; 2 4 3 - import type { Config } from '../node'; 4 - import type { OpenApi as OpenApiV2 } from '../openApi/v2/interfaces/OpenApi'; 5 - import type { OpenApi as OpenApiV3 } from '../openApi/v3/interfaces/OpenApi'; 5 + import type { Client } from '../client/interfaces/Client'; 6 + import type { Model } from '../client/interfaces/Model'; 7 + import type { OperationParameter } from '../client/interfaces/OperationParameter'; 8 + import type { Service } from '../client/interfaces/Service'; 6 9 import templateClient from '../templates/client.hbs'; 7 10 import angularGetHeaders from '../templates/core/angular/getHeaders.hbs'; 8 11 import angularGetRequestBody from '../templates/core/angular/getRequestBody.hbs'; ··· 87 90 import partialTypeIntersection from '../templates/partials/typeIntersection.hbs'; 88 91 import partialTypeReference from '../templates/partials/typeReference.hbs'; 89 92 import partialTypeUnion from '../templates/partials/typeUnion.hbs'; 90 - import { registerHandlebarHelpers } from './registerHandlebarHelpers'; 93 + import type { Config, UserConfig } from '../types/config'; 94 + import { enumKey, enumName, enumUnionType, enumValue } from './enum'; 95 + import { escapeName } from './escapeName'; 96 + import { sortByName } from './sortByName'; 97 + import { unique } from './unique'; 98 + 99 + const escapeComment = (value: string) => 100 + value 101 + .replace(/\*\//g, '*') 102 + .replace(/\/\*/g, '*') 103 + .replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); 104 + 105 + const modelsExports = (config: UserConfig, models: Model[], path: string) => { 106 + const output = models.map(model => { 107 + const importedModel = config.postfixModels 108 + ? `${model.name} as ${model.name + config.postfixModels}` 109 + : model.name; 110 + let result = [`export type { ${importedModel} } from '${path + model.name}';`]; 111 + if (config.enums && (model.enum.length || model.enums.length)) { 112 + const names = model.enums.map(enumerator => enumerator.name).filter(Boolean); 113 + const enumExports = names.length ? names : [model.name]; 114 + const enumExportsString = enumExports.map(name => enumName(name)).join(', '); 115 + result = [...result, `export { ${enumExportsString} } from '${path + model.name}';`]; 116 + } 117 + return result.join('\n'); 118 + }); 119 + return output.join('\n'); 120 + }; 121 + 122 + const modelImports = (model: Model | Service, path: string) => { 123 + if (!model.imports.length) { 124 + return ''; 125 + } 126 + const output = model.imports.map(item => `import type { ${item} } from '${path + item}';`); 127 + return output.join('\n'); 128 + }; 129 + 130 + const dataParameters = (parameters: OperationParameter[]) => { 131 + const output = parameters.map(parameter => { 132 + const key = parameter.prop; 133 + const value = parameter.name; 134 + if (key === value) { 135 + return key; 136 + } 137 + if (escapeName(key) === key) { 138 + return `${key}: ${value}`; 139 + } 140 + return `'${key}': ${value}`; 141 + }); 142 + return output.join(', '); 143 + }; 144 + 145 + const debugThis = (value: unknown) => { 146 + console.log(value); 147 + return ''; 148 + }; 149 + 150 + // same as `>isRequired` partial 151 + const isRequired = (model: Pick<Model, 'default' | 'isRequired'>) => (model.isRequired && !model.default ? '' : '?'); 152 + 153 + const nameOperationDataType = (value: string) => camelCase(['TData', value].join('-'), { pascalCase: true }); 154 + 155 + const operationDataType = (config: Config, service: Service) => { 156 + if (!config.useOptions) { 157 + return ''; 158 + } 159 + const partialType = Handlebars.partials['type']; 160 + const output = service.operations 161 + .filter(operation => operation.parameters.length) 162 + .map(operation => { 163 + const name = nameOperationDataType(operation.name); 164 + return `export type ${name} = { 165 + ${sortByName(operation.parameters) 166 + .map(parameter => { 167 + let comment: string[] = []; 168 + if (parameter.description) { 169 + comment = ['/**', ` * ${escapeComment(parameter.description)}`, ' */']; 170 + } 171 + return [ 172 + ...comment, 173 + `${parameter.name + isRequired(parameter)}: ${partialType({ $config: config, ...parameter })}`, 174 + ].join('\n'); 175 + }) 176 + .join('\n')} 177 + }`; 178 + }); 179 + return output.join('\n'); 180 + }; 181 + 182 + // eslint-disable-next-line @typescript-eslint/no-unused-vars 183 + export const registerHandlebarHelpers = (config: Config, client: Client): void => { 184 + Handlebars.registerHelper('camelCase', camelCase); 185 + Handlebars.registerHelper('dataParameters', dataParameters); 186 + Handlebars.registerHelper('debugThis', debugThis); 187 + Handlebars.registerHelper('enumKey', enumKey); 188 + Handlebars.registerHelper('enumName', enumName); 189 + Handlebars.registerHelper('enumUnionType', enumUnionType); 190 + Handlebars.registerHelper('enumValue', enumValue); 191 + 192 + Handlebars.registerHelper( 193 + 'equals', 194 + function (this: unknown, a: string, b: string, options: Handlebars.HelperOptions) { 195 + return a === b ? options.fn(this) : options.inverse(this); 196 + } 197 + ); 198 + 199 + Handlebars.registerHelper('escapeComment', escapeComment); 200 + 201 + Handlebars.registerHelper('escapeDescription', function (value: string) { 202 + return value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${'); 203 + }); 204 + 205 + Handlebars.registerHelper('escapeNewline', function (value: string) { 206 + return value.replace(/\n/g, '\\n'); 207 + }); 208 + 209 + Handlebars.registerHelper('exactArray', function (this: unknown, model: Model, options: Handlebars.HelperOptions) { 210 + if (model.export === 'array' && model.maxItems && model.minItems && model.maxItems === model.minItems) { 211 + return options.fn(this); 212 + } 213 + return options.inverse(this); 214 + }); 215 + 216 + Handlebars.registerHelper('ifdef', function (this: unknown, ...args): string { 217 + const options = args.pop(); 218 + if (!args.every(value => !value)) { 219 + return options.fn(this); 220 + } 221 + return options.inverse(this); 222 + }); 223 + 224 + Handlebars.registerHelper( 225 + 'ifOperationDataOptional', 226 + function (this: unknown, parameters: OperationParameter[], options: Handlebars.HelperOptions) { 227 + return parameters.every(parameter => !parameter.isRequired) ? options.fn(this) : options.inverse(this); 228 + } 229 + ); 230 + 231 + Handlebars.registerHelper( 232 + 'intersection', 233 + function (this: unknown, models: Model[], parent: string | undefined, options: Handlebars.HelperOptions) { 234 + const partialType = Handlebars.partials['type']; 235 + const types = models.map(model => partialType({ $config: config, ...model, parent })); 236 + const uniqueTypes = types.filter(unique); 237 + let uniqueTypesString = uniqueTypes.join(' & '); 238 + if (uniqueTypes.length > 1) { 239 + uniqueTypesString = `(${uniqueTypesString})`; 240 + } 241 + return options.fn(uniqueTypesString); 242 + } 243 + ); 244 + 245 + Handlebars.registerHelper('modelImports', modelImports); 246 + Handlebars.registerHelper('modelsExports', modelsExports); 247 + 248 + Handlebars.registerHelper( 249 + 'modelUnionType', 250 + function (models: Model[], parent: string | undefined, filterProperties: 'exact' | undefined) { 251 + const partialType = Handlebars.partials['type']; 252 + const types = models 253 + .map(model => partialType({ $config: config, ...model, parent })) 254 + .filter((...args) => filterProperties === 'exact' || unique(...args)); 255 + const union = types.join(filterProperties === 'exact' ? ', ' : ' | '); 256 + return types.length > 1 && types.length !== models.length ? `(${union})` : union; 257 + } 258 + ); 259 + 260 + Handlebars.registerHelper('nameOperationDataType', nameOperationDataType); 261 + 262 + Handlebars.registerHelper( 263 + 'notEquals', 264 + function (this: unknown, a: string, b: string, options: Handlebars.HelperOptions) { 265 + return a !== b ? options.fn(this) : options.inverse(this); 266 + } 267 + ); 268 + 269 + Handlebars.registerHelper('operationDataType', function (service: Service) { 270 + return operationDataType(config, service); 271 + }); 272 + 273 + Handlebars.registerHelper( 274 + 'useDateType', 275 + function (this: unknown, config: UserConfig, format: string | undefined, options: Handlebars.HelperOptions) { 276 + return config.useDateType && format === 'date-time' ? options.fn(this) : options.inverse(this); 277 + } 278 + ); 279 + }; 91 280 92 281 export interface Templates { 93 282 client: Handlebars.TemplateDelegate; ··· 114 303 * Read all the Handlebar templates that we need and return a wrapper object 115 304 * so we can easily access the templates in our generator/write functions. 116 305 */ 117 - export const registerHandlebarTemplates = ( 118 - openApi: OpenApiV3 | OpenApiV2, 119 - options: Omit<Required<Config>, 'base' | 'clientName' | 'request'> 120 - ): Templates => { 121 - registerHandlebarHelpers(openApi, options); 306 + export const registerHandlebarTemplates = (config: Config, client: Client): Templates => { 307 + registerHandlebarHelpers(config, client); 122 308 123 309 // Main templates (entry points for the files we write to disk) 124 310 const templates: Templates = {
+3 -3
src/utils/sortByName.spec.ts src/utils/__tests__/sortByName.spec.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 2 - import type { Service } from '../client/interfaces/Service'; 3 - import { sortByName } from './sortByName'; 1 + import type { Model } from '../../client/interfaces/Model'; 2 + import type { Service } from '../../client/interfaces/Service'; 3 + import { sortByName } from '../sortByName'; 4 4 5 5 describe('sortByName', () => { 6 6 it('should handle empty lists', () => {
+10
src/utils/write/__tests__/services.spec.ts
··· 43 43 }; 44 44 45 45 await writeClientServices(client, templates, '/', { 46 + autoformat: false, 46 47 client: 'fetch', 48 + enums: false, 49 + exportCore: true, 50 + exportModels: true, 51 + exportSchemas: true, 52 + exportServices: true, 47 53 input: '', 54 + operationId: true, 48 55 output: '', 56 + postfixModels: '', 49 57 postfixServices: 'Service', 50 58 serviceResponse: 'body', 59 + useDateType: false, 51 60 useOptions: false, 61 + write: true, 52 62 }); 53 63 54 64 expect(writeFileSync).toHaveBeenCalledWith(path.resolve('/', '/UserService.ts'), 'service');
+3 -3
src/utils/write/class.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 5 + import type { UserConfig } from '../../node'; 6 6 import { getHttpRequestName } from '../getHttpRequestName'; 7 - import type { Templates } from '../registerHandlebarTemplates'; 7 + import type { Templates } from '../handlebars'; 8 8 import { sortByName } from '../sortByName'; 9 9 10 10 /** ··· 20 20 client: Client, 21 21 templates: Templates, 22 22 outputPath: string, 23 - options: Pick<Required<Config>, 'client' | 'clientName' | 'enums' | 'postfixServices'> 23 + options: Pick<Required<UserConfig>, 'client' | 'clientName' | 'enums' | 'postfixServices'> 24 24 ): Promise<void> => { 25 25 const templateResult = templates.client({ 26 26 $config: options,
+16 -20
src/utils/write/client.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 5 + import type { Config } from '../../types/config'; 6 + import type { Templates } from '../handlebars'; 6 7 import { isSubDirectory } from '../isSubdirectory'; 7 - import type { Templates } from '../registerHandlebarTemplates'; 8 8 import { writeClientClass } from './class'; 9 9 import { writeClientCore } from './core'; 10 10 import { writeClientIndex } from './index'; ··· 16 16 * Write our OpenAPI client, using the given templates at the given output 17 17 * @param client Client containing models, schemas, and services 18 18 * @param templates Templates wrapper with all loaded Handlebars templates 19 - * @param options Options passed to the `generate()` function 19 + * @param options {@link Config} passed to the `generate()` function 20 20 */ 21 - export const writeClient = async ( 22 - client: Client, 23 - templates: Templates, 24 - options: Omit<Required<Config>, 'base' | 'clientName' | 'request'> & Pick<Config, 'base' | 'clientName' | 'request'> 25 - ): Promise<void> => { 21 + export const writeClient = async (client: Client, templates: Templates, options: Config): Promise<void> => { 26 22 const outputPath = path.resolve(process.cwd(), options.output); 27 23 28 24 if (!isSubDirectory(process.cwd(), options.output)) { ··· 51 47 await writeClientCore(client, templates, outputPathCore, options); 52 48 } 53 49 54 - if (options.exportServices) { 55 - const outputPathServices = path.resolve(outputPath, 'services'); 56 - await rmSync(outputPathServices, { 57 - force: true, 58 - recursive: true, 59 - }); 60 - await mkdirSync(outputPathServices, { 61 - recursive: true, 62 - }); 63 - await writeClientServices(client, templates, outputPathServices, options); 64 - } 65 - 66 50 if (options.exportSchemas) { 67 51 const outputPathSchemas = path.resolve(outputPath, 'schemas'); 68 52 await rmSync(outputPathSchemas, { ··· 85 69 recursive: true, 86 70 }); 87 71 await writeClientModels(client, templates, outputPathModels, options); 72 + } 73 + 74 + if (options.exportServices) { 75 + const outputPathServices = path.resolve(outputPath, 'services'); 76 + await rmSync(outputPathServices, { 77 + force: true, 78 + recursive: true, 79 + }); 80 + await mkdirSync(outputPathServices, { 81 + recursive: true, 82 + }); 83 + await writeClientServices(client, templates, outputPathServices, options); 88 84 } 89 85 90 86 if (options.clientName) {
+3 -3
src/utils/write/core.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 5 + import type { UserConfig } from '../../node'; 6 6 import { getHttpRequestName } from '../getHttpRequestName'; 7 - import type { Templates } from '../registerHandlebarTemplates'; 7 + import type { Templates } from '../handlebars'; 8 8 9 9 /** 10 10 * Generate OpenAPI core files, this includes the basic boilerplate code to handle requests. ··· 17 17 client: Client, 18 18 templates: Templates, 19 19 outputPath: string, 20 - options: Pick<Required<Config>, 'client' | 'serviceResponse'> & Omit<Config, 'client' | 'serviceResponse'> 20 + options: Pick<Required<UserConfig>, 'client' | 'serviceResponse'> & Omit<UserConfig, 'client' | 'serviceResponse'> 21 21 ): Promise<void> => { 22 22 const context = { 23 23 httpRequest: getHttpRequestName(options.client),
+4 -4
src/utils/write/index.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 6 - import { Templates } from '../registerHandlebarTemplates'; 5 + import type { UserConfig } from '../../node'; 6 + import { Templates } from '../handlebars'; 7 7 import { sortByName } from '../sortByName'; 8 8 9 9 /** ··· 20 20 templates: Templates, 21 21 outputPath: string, 22 22 options: Pick< 23 - Required<Config>, 23 + Required<UserConfig>, 24 24 | 'enums' 25 25 | 'exportCore' 26 26 | 'exportServices' ··· 29 29 | 'postfixServices' 30 30 | 'postfixModels' 31 31 > & 32 - Pick<Config, 'clientName'> 32 + Pick<UserConfig, 'clientName'> 33 33 ): Promise<void> => { 34 34 const templateResult = templates.index({ 35 35 $config: options,
+3 -3
src/utils/write/models.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 6 - import type { Templates } from '../registerHandlebarTemplates'; 5 + import type { UserConfig } from '../../node'; 6 + import type { Templates } from '../handlebars'; 7 7 8 8 /** 9 9 * Generate Models using the Handlebar template and write to disk. ··· 16 16 client: Client, 17 17 templates: Templates, 18 18 outputPath: string, 19 - options: Pick<Required<Config>, 'client' | 'enums' | 'useDateType'> 19 + options: Pick<Required<UserConfig>, 'client' | 'enums' | 'useDateType'> 20 20 ): Promise<void> => { 21 21 for (const model of client.models) { 22 22 const file = path.resolve(outputPath, `${model.name}.ts`);
+3 -3
src/utils/write/schemas.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 6 - import type { Templates } from '../registerHandlebarTemplates'; 5 + import type { UserConfig } from '../../node'; 6 + import type { Templates } from '../handlebars'; 7 7 8 8 /** 9 9 * Generate Schemas using the Handlebar template and write to disk. ··· 16 16 client: Client, 17 17 templates: Templates, 18 18 outputPath: string, 19 - options: Pick<Required<Config>, 'client' | 'enums'> 19 + options: Pick<Required<UserConfig>, 'client' | 'enums'> 20 20 ): Promise<void> => { 21 21 for (const model of client.models) { 22 22 const file = path.resolve(outputPath, `$${model.name}.ts`);
+4 -5
src/utils/write/services.ts
··· 2 2 import path from 'node:path'; 3 3 4 4 import type { Client } from '../../client/interfaces/Client'; 5 - import type { Config } from '../../node'; 6 - import type { Templates } from '../registerHandlebarTemplates'; 5 + import type { Config } from '../../types/config'; 6 + import type { Templates } from '../handlebars'; 7 7 8 8 /** 9 9 * Generate Services using the Handlebar template and write to disk. 10 10 * @param client Client containing models, schemas, and services 11 11 * @param templates The loaded handlebar templates 12 12 * @param outputPath Directory to write the generated files to 13 - * @param options Options passed to the `generate()` function 13 + * @param options {@link Config} passed to the `generate()` function 14 14 */ 15 15 export const writeClientServices = async ( 16 16 client: Client, 17 17 templates: Templates, 18 18 outputPath: string, 19 - options: Pick<Required<Config>, 'client' | 'postfixServices' | 'serviceResponse' | 'useOptions'> & 20 - Omit<Config, 'client' | 'postfixServices' | 'serviceResponse' | 'useOptions'> 19 + options: Config 21 20 ): Promise<void> => { 22 21 for (const service of client.services) { 23 22 const file = path.resolve(outputPath, `${service.name}${options.postfixServices}.ts`);
+914 -360
test/__snapshots__/index.spec.ts.snap
··· 2005 2005 import { OpenAPI } from '../core/OpenAPI'; 2006 2006 import { request as __request } from '../core/request'; 2007 2007 2008 + export type TDataCollectionFormat = { 2009 + /** 2010 + * This is an array parameter that is sent as csv format (comma-separated values) 2011 + */ 2012 + parameterArrayCsv: Array<string>; 2013 + /** 2014 + * This is an array parameter that is sent as multi format (multiple parameter instances) 2015 + */ 2016 + parameterArrayMulti: Array<string>; 2017 + /** 2018 + * This is an array parameter that is sent as pipes format (pipe-separated values) 2019 + */ 2020 + parameterArrayPipes: Array<string>; 2021 + /** 2022 + * This is an array parameter that is sent as ssv format (space-separated values) 2023 + */ 2024 + parameterArraySsv: Array<string>; 2025 + /** 2026 + * This is an array parameter that is sent as tsv format (tab-separated values) 2027 + */ 2028 + parameterArrayTsv: Array<string>; 2029 + }; 2030 + 2008 2031 export class CollectionFormatService { 2009 2032 /** 2010 - * @param parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) 2011 - * @param parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) 2012 - * @param parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) 2013 - * @param parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) 2014 - * @param parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) 2015 2033 * @throws ApiError 2016 2034 */ 2017 - public static collectionFormat( 2018 - parameterArrayCsv: Array<string>, 2019 - parameterArraySsv: Array<string>, 2020 - parameterArrayTsv: Array<string>, 2021 - parameterArrayPipes: Array<string>, 2022 - parameterArrayMulti: Array<string> 2023 - ): CancelablePromise<void> { 2035 + public static collectionFormat(data: TDataCollectionFormat): CancelablePromise<void> { 2036 + const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = 2037 + data; 2024 2038 return __request(OpenAPI, { 2025 2039 method: 'GET', 2026 2040 url: '/api/v{api-version}/collectionFormat', ··· 2043 2057 import { OpenAPI } from '../core/OpenAPI'; 2044 2058 import { request as __request } from '../core/request'; 2045 2059 2060 + export type TDataComplexTypes = { 2061 + /** 2062 + * Parameter containing object 2063 + */ 2064 + parameterObject: { 2065 + first?: { 2066 + second?: { 2067 + third?: string; 2068 + }; 2069 + }; 2070 + }; 2071 + /** 2072 + * Parameter containing reference 2073 + */ 2074 + parameterReference: ModelWithString; 2075 + }; 2076 + 2046 2077 export class ComplexService { 2047 2078 /** 2048 - * @param parameterObject Parameter containing object 2049 - * @param parameterReference Parameter containing reference 2050 2079 * @returns ModelWithString Successful response 2051 2080 * @throws ApiError 2052 2081 */ 2053 - public static complexTypes( 2054 - parameterObject: { 2055 - first?: { 2056 - second?: { 2057 - third?: string; 2058 - }; 2059 - }; 2060 - }, 2061 - parameterReference: ModelWithString 2062 - ): CancelablePromise<Array<ModelWithString>> { 2082 + public static complexTypes(data: TDataComplexTypes): CancelablePromise<Array<ModelWithString>> { 2083 + const { parameterObject, parameterReference } = data; 2063 2084 return __request(OpenAPI, { 2064 2085 method: 'GET', 2065 2086 url: '/api/v{api-version}/complex', ··· 2102 2123 import { OpenAPI } from '../core/OpenAPI'; 2103 2124 import { request as __request } from '../core/request'; 2104 2125 2126 + export type TDataCallWithDefaultParameters = { 2127 + /** 2128 + * This is a simple boolean with default value 2129 + */ 2130 + parameterBoolean?: boolean; 2131 + /** 2132 + * This is a simple enum with default value 2133 + */ 2134 + parameterEnum?: 'Success' | 'Warning' | 'Error'; 2135 + /** 2136 + * This is a simple model with default value 2137 + */ 2138 + parameterModel?: ModelWithString; 2139 + /** 2140 + * This is a simple number with default value 2141 + */ 2142 + parameterNumber?: number; 2143 + /** 2144 + * This is a simple string with default value 2145 + */ 2146 + parameterString?: string; 2147 + }; 2148 + export type TDataCallWithDefaultOptionalParameters = { 2149 + /** 2150 + * This is a simple boolean that is optional with default value 2151 + */ 2152 + parameterBoolean?: boolean; 2153 + /** 2154 + * This is a simple enum that is optional with default value 2155 + */ 2156 + parameterEnum?: 'Success' | 'Warning' | 'Error'; 2157 + /** 2158 + * This is a simple model that is optional with default value 2159 + */ 2160 + parameterModel?: ModelWithString; 2161 + /** 2162 + * This is a simple number that is optional with default value 2163 + */ 2164 + parameterNumber?: number; 2165 + /** 2166 + * This is a simple string that is optional with default value 2167 + */ 2168 + parameterString?: string; 2169 + }; 2170 + export type TDataCallToTestOrderOfParams = { 2171 + /** 2172 + * This is a optional string with default 2173 + */ 2174 + parameterOptionalStringWithDefault?: string; 2175 + /** 2176 + * This is a optional string with empty default 2177 + */ 2178 + parameterOptionalStringWithEmptyDefault?: string; 2179 + /** 2180 + * This is a optional string with no default 2181 + */ 2182 + parameterOptionalStringWithNoDefault?: string; 2183 + /** 2184 + * This is a string that can be null with default 2185 + */ 2186 + parameterStringNullableWithDefault?: string | null; 2187 + /** 2188 + * This is a string that can be null with no default 2189 + */ 2190 + parameterStringNullableWithNoDefault?: string | null; 2191 + /** 2192 + * This is a string with default 2193 + */ 2194 + parameterStringWithDefault?: string; 2195 + /** 2196 + * This is a string with empty default 2197 + */ 2198 + parameterStringWithEmptyDefault?: string; 2199 + /** 2200 + * This is a string with no default 2201 + */ 2202 + parameterStringWithNoDefault: string; 2203 + }; 2204 + 2105 2205 export class DefaultsService { 2106 2206 /** 2107 - * @param parameterString This is a simple string with default value 2108 - * @param parameterNumber This is a simple number with default value 2109 - * @param parameterBoolean This is a simple boolean with default value 2110 - * @param parameterEnum This is a simple enum with default value 2111 - * @param parameterModel This is a simple model with default value 2112 2207 * @throws ApiError 2113 2208 */ 2114 - public static callWithDefaultParameters( 2115 - parameterString: string = 'Hello World!', 2116 - parameterNumber: number = 123, 2117 - parameterBoolean: boolean = true, 2118 - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', 2119 - parameterModel: ModelWithString = { 2120 - prop: 'Hello World!', 2121 - } 2122 - ): CancelablePromise<void> { 2209 + public static callWithDefaultParameters(data: TDataCallWithDefaultParameters): CancelablePromise<void> { 2210 + const { 2211 + parameterBoolean = true, 2212 + parameterEnum = 'Success', 2213 + parameterModel = { 2214 + prop: 'Hello World!', 2215 + }, 2216 + parameterNumber = 123, 2217 + parameterString = 'Hello World!', 2218 + } = data; 2123 2219 return __request(OpenAPI, { 2124 2220 method: 'GET', 2125 2221 url: '/api/v{api-version}/defaults', ··· 2134 2230 } 2135 2231 2136 2232 /** 2137 - * @param parameterString This is a simple string that is optional with default value 2138 - * @param parameterNumber This is a simple number that is optional with default value 2139 - * @param parameterBoolean This is a simple boolean that is optional with default value 2140 - * @param parameterEnum This is a simple enum that is optional with default value 2141 - * @param parameterModel This is a simple model that is optional with default value 2142 2233 * @throws ApiError 2143 2234 */ 2144 2235 public static callWithDefaultOptionalParameters( 2145 - parameterString: string = 'Hello World!', 2146 - parameterNumber: number = 123, 2147 - parameterBoolean: boolean = true, 2148 - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', 2149 - parameterModel: ModelWithString = { 2150 - prop: 'Hello World!', 2151 - } 2236 + data: TDataCallWithDefaultOptionalParameters = {} 2152 2237 ): CancelablePromise<void> { 2238 + const { 2239 + parameterBoolean = true, 2240 + parameterEnum = 'Success', 2241 + parameterModel = { 2242 + prop: 'Hello World!', 2243 + }, 2244 + parameterNumber = 123, 2245 + parameterString = 'Hello World!', 2246 + } = data; 2153 2247 return __request(OpenAPI, { 2154 2248 method: 'POST', 2155 2249 url: '/api/v{api-version}/defaults', ··· 2164 2258 } 2165 2259 2166 2260 /** 2167 - * @param parameterStringWithNoDefault This is a string with no default 2168 - * @param parameterOptionalStringWithDefault This is a optional string with default 2169 - * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default 2170 - * @param parameterOptionalStringWithNoDefault This is a optional string with no default 2171 - * @param parameterStringWithDefault This is a string with default 2172 - * @param parameterStringWithEmptyDefault This is a string with empty default 2173 - * @param parameterStringNullableWithNoDefault This is a string that can be null with no default 2174 - * @param parameterStringNullableWithDefault This is a string that can be null with default 2175 2261 * @throws ApiError 2176 2262 */ 2177 - public static callToTestOrderOfParams( 2178 - parameterStringWithNoDefault: string, 2179 - parameterOptionalStringWithDefault: string = 'Hello World!', 2180 - parameterOptionalStringWithEmptyDefault: string = '', 2181 - parameterOptionalStringWithNoDefault?: string, 2182 - parameterStringWithDefault: string = 'Hello World!', 2183 - parameterStringWithEmptyDefault: string = '', 2184 - parameterStringNullableWithNoDefault?: string | null, 2185 - parameterStringNullableWithDefault: string | null = null 2186 - ): CancelablePromise<void> { 2263 + public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise<void> { 2264 + const { 2265 + parameterOptionalStringWithDefault = 'Hello World!', 2266 + parameterOptionalStringWithEmptyDefault = '', 2267 + parameterOptionalStringWithNoDefault, 2268 + parameterStringNullableWithDefault = null, 2269 + parameterStringNullableWithNoDefault, 2270 + parameterStringWithDefault = 'Hello World!', 2271 + parameterStringWithEmptyDefault = '', 2272 + parameterStringWithNoDefault, 2273 + } = data; 2187 2274 return __request(OpenAPI, { 2188 2275 method: 'PUT', 2189 2276 url: '/api/v{api-version}/defaults', ··· 2208 2295 import { OpenAPI } from '../core/OpenAPI'; 2209 2296 import { request as __request } from '../core/request'; 2210 2297 2211 - export class DescriptionsService { 2298 + export type TDataCallWithDescriptions = { 2299 + /** 2300 + * Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work 2301 + */ 2302 + parameterWithBackticks?: string; 2212 2303 /** 2213 - * @param parameterWithBreaks Testing multiline comments in string: First line 2304 + * Testing multiline comments in string: First line 2214 2305 * Second line 2215 2306 * 2216 2307 * Fourth line 2217 - * @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work 2218 - * @param parameterWithSlashes Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work 2219 - * @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work 2220 - * @param parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work 2221 - * @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work 2308 + */ 2309 + parameterWithBreaks?: string; 2310 + /** 2311 + * Testing expression placeholders in string: \${expression} should work 2312 + */ 2313 + parameterWithExpressionPlaceholders?: string; 2314 + /** 2315 + * Testing quotes in string: 'single quote''' and "double quotes""" should work 2316 + */ 2317 + parameterWithQuotes?: string; 2318 + /** 2319 + * Testing reserved characters in string: * inline * and ** inline ** should work 2320 + */ 2321 + parameterWithReservedCharacters?: string; 2322 + /** 2323 + * Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work 2324 + */ 2325 + parameterWithSlashes?: string; 2326 + }; 2327 + 2328 + export class DescriptionsService { 2329 + /** 2222 2330 * @throws ApiError 2223 2331 */ 2224 - public static callWithDescriptions( 2225 - parameterWithBreaks?: string, 2226 - parameterWithBackticks?: string, 2227 - parameterWithSlashes?: string, 2228 - parameterWithExpressionPlaceholders?: string, 2229 - parameterWithQuotes?: string, 2230 - parameterWithReservedCharacters?: string 2231 - ): CancelablePromise<void> { 2332 + public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise<void> { 2333 + const { 2334 + parameterWithBackticks, 2335 + parameterWithBreaks, 2336 + parameterWithExpressionPlaceholders, 2337 + parameterWithQuotes, 2338 + parameterWithReservedCharacters, 2339 + parameterWithSlashes, 2340 + } = data; 2232 2341 return __request(OpenAPI, { 2233 2342 method: 'POST', 2234 2343 url: '/api/v{api-version}/descriptions/', ··· 2300 2409 import { OpenAPI } from '../core/OpenAPI'; 2301 2410 import { request as __request } from '../core/request'; 2302 2411 2412 + export type TDataTestErrorCode = { 2413 + /** 2414 + * Status code to return 2415 + */ 2416 + status: string; 2417 + }; 2418 + 2303 2419 export class ErrorService { 2304 2420 /** 2305 - * @param status Status code to return 2306 2421 * @returns any Custom message: Successful response 2307 2422 * @throws ApiError 2308 2423 */ 2309 - public static testErrorCode(status: string): CancelablePromise<any> { 2424 + public static testErrorCode(data: TDataTestErrorCode): CancelablePromise<any> { 2425 + const { status } = data; 2310 2426 return __request(OpenAPI, { 2311 2427 method: 'POST', 2312 2428 url: '/api/v{api-version}/error', ··· 2470 2586 import { OpenAPI } from '../core/OpenAPI'; 2471 2587 import { request as __request } from '../core/request'; 2472 2588 2589 + export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { 2590 + /** 2591 + * Dummy input param 2592 + */ 2593 + nonAsciiParamæøåÆøÅöôêÊ: number; 2594 + }; 2595 + 2473 2596 export class NonAsciiÆøåÆøÅöôêÊService { 2474 2597 /** 2475 - * @param nonAsciiParamæøåÆøÅöôêÊ Dummy input param 2476 2598 * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response 2477 2599 * @throws ApiError 2478 2600 */ 2479 2601 public static nonAsciiæøåÆøÅöôêÊ字符串( 2480 - nonAsciiParamæøåÆøÅöôêÊ: number 2602 + data: TDataNonAsciiæøåÆøÅöôêÊ字符串 2481 2603 ): CancelablePromise<NonAsciiStringæøåÆØÅöôêÊ字符串> { 2604 + const { nonAsciiParamæøåÆøÅöôêÊ } = data; 2482 2605 return __request(OpenAPI, { 2483 2606 method: 'POST', 2484 2607 url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ··· 2496 2619 import { OpenAPI } from '../core/OpenAPI'; 2497 2620 import { request as __request } from '../core/request'; 2498 2621 2622 + export type TDataCallWithParameters = { 2623 + /** 2624 + * This is the parameter that is sent as request body 2625 + */ 2626 + parameterBody: string; 2627 + /** 2628 + * This is the parameter that goes into the form data 2629 + */ 2630 + parameterForm: string; 2631 + /** 2632 + * This is the parameter that goes into the header 2633 + */ 2634 + parameterHeader: string; 2635 + /** 2636 + * This is the parameter that goes into the path 2637 + */ 2638 + parameterPath: string; 2639 + /** 2640 + * This is the parameter that goes into the query params 2641 + */ 2642 + parameterQuery: string; 2643 + }; 2644 + export type TDataCallWithWeirdParameterNames = { 2645 + /** 2646 + * This is the parameter with a reserved keyword 2647 + */ 2648 + _default?: string; 2649 + /** 2650 + * This is the parameter that is sent as request body 2651 + */ 2652 + parameterBody: string; 2653 + /** 2654 + * This is the parameter that goes into the request form data 2655 + */ 2656 + parameterForm: string; 2657 + /** 2658 + * This is the parameter that goes into the request header 2659 + */ 2660 + parameterHeader: string; 2661 + /** 2662 + * This is the parameter that goes into the path 2663 + */ 2664 + parameterPath1?: string; 2665 + /** 2666 + * This is the parameter that goes into the path 2667 + */ 2668 + parameterPath2?: string; 2669 + /** 2670 + * This is the parameter that goes into the path 2671 + */ 2672 + parameterPath3?: string; 2673 + /** 2674 + * This is the parameter that goes into the request query params 2675 + */ 2676 + parameterQuery: string; 2677 + }; 2678 + 2499 2679 export class ParametersService { 2500 2680 /** 2501 - * @param parameterHeader This is the parameter that goes into the header 2502 - * @param parameterQuery This is the parameter that goes into the query params 2503 - * @param parameterForm This is the parameter that goes into the form data 2504 - * @param parameterBody This is the parameter that is sent as request body 2505 - * @param parameterPath This is the parameter that goes into the path 2506 2681 * @throws ApiError 2507 2682 */ 2508 - public static callWithParameters( 2509 - parameterHeader: string, 2510 - parameterQuery: string, 2511 - parameterForm: string, 2512 - parameterBody: string, 2513 - parameterPath: string 2514 - ): CancelablePromise<void> { 2683 + public static callWithParameters(data: TDataCallWithParameters): CancelablePromise<void> { 2684 + const { parameterBody, parameterForm, parameterHeader, parameterPath, parameterQuery } = data; 2515 2685 return __request(OpenAPI, { 2516 2686 method: 'POST', 2517 2687 url: '/api/v{api-version}/parameters/{parameterPath}', ··· 2532 2702 } 2533 2703 2534 2704 /** 2535 - * @param parameterHeader This is the parameter that goes into the request header 2536 - * @param parameterQuery This is the parameter that goes into the request query params 2537 - * @param parameterForm This is the parameter that goes into the request form data 2538 - * @param parameterBody This is the parameter that is sent as request body 2539 - * @param parameterPath1 This is the parameter that goes into the path 2540 - * @param parameterPath2 This is the parameter that goes into the path 2541 - * @param parameterPath3 This is the parameter that goes into the path 2542 - * @param _default This is the parameter with a reserved keyword 2543 2705 * @throws ApiError 2544 2706 */ 2545 - public static callWithWeirdParameterNames( 2546 - parameterHeader: string, 2547 - parameterQuery: string, 2548 - parameterForm: string, 2549 - parameterBody: string, 2550 - parameterPath1?: string, 2551 - parameterPath2?: string, 2552 - parameterPath3?: string, 2553 - _default?: string 2554 - ): CancelablePromise<void> { 2707 + public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise<void> { 2708 + const { 2709 + _default, 2710 + parameterBody, 2711 + parameterForm, 2712 + parameterHeader, 2713 + parameterPath1, 2714 + parameterPath2, 2715 + parameterPath3, 2716 + parameterQuery, 2717 + } = data; 2555 2718 return __request(OpenAPI, { 2556 2719 method: 'POST', 2557 2720 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', ··· 2740 2903 import { OpenAPI } from '../core/OpenAPI'; 2741 2904 import { request as __request } from '../core/request'; 2742 2905 2906 + export type TDataTypes = { 2907 + /** 2908 + * This is a number parameter 2909 + */ 2910 + id?: number; 2911 + /** 2912 + * This is an array parameter 2913 + */ 2914 + parameterArray: Array<string>; 2915 + /** 2916 + * This is a boolean parameter 2917 + */ 2918 + parameterBoolean?: boolean; 2919 + /** 2920 + * This is a dictionary parameter 2921 + */ 2922 + parameterDictionary: Record<string, string>; 2923 + /** 2924 + * This is an enum parameter 2925 + */ 2926 + parameterEnum: 'Success' | 'Warning' | 'Error'; 2927 + /** 2928 + * This is a number parameter 2929 + */ 2930 + parameterNumber?: number; 2931 + /** 2932 + * This is an object parameter 2933 + */ 2934 + parameterObject?: unknown; 2935 + /** 2936 + * This is a string parameter 2937 + */ 2938 + parameterString?: string; 2939 + }; 2940 + 2743 2941 export class TypesService { 2744 2942 /** 2745 - * @param parameterArray This is an array parameter 2746 - * @param parameterDictionary This is a dictionary parameter 2747 - * @param parameterEnum This is an enum parameter 2748 - * @param parameterNumber This is a number parameter 2749 - * @param parameterString This is a string parameter 2750 - * @param parameterBoolean This is a boolean parameter 2751 - * @param parameterObject This is an object parameter 2752 - * @param id This is a number parameter 2753 2943 * @returns number Response is a simple number 2754 2944 * @returns string Response is a simple string 2755 2945 * @returns boolean Response is a simple boolean 2756 2946 * @returns any Response is a simple object 2757 2947 * @throws ApiError 2758 2948 */ 2759 - public static types( 2760 - parameterArray: Array<string>, 2761 - parameterDictionary: Record<string, string>, 2762 - parameterEnum: 'Success' | 'Warning' | 'Error', 2763 - parameterNumber: number = 123, 2764 - parameterString: string = 'default', 2765 - parameterBoolean: boolean = true, 2766 - parameterObject: unknown = null, 2767 - id?: number 2768 - ): CancelablePromise<number | string | boolean | unknown> { 2949 + public static types(data: TDataTypes): CancelablePromise<number | string | boolean | unknown> { 2950 + const { 2951 + id, 2952 + parameterArray, 2953 + parameterBoolean = true, 2954 + parameterDictionary, 2955 + parameterEnum, 2956 + parameterNumber = 123, 2957 + parameterObject = null, 2958 + parameterString = 'default', 2959 + } = data; 2769 2960 return __request(OpenAPI, { 2770 2961 method: 'GET', 2771 2962 url: '/api/v{api-version}/types', ··· 3469 3660 3470 3661 export type TDataCallWithDefaultParameters = { 3471 3662 /** 3472 - * This is a simple string with default value 3473 - */ 3474 - parameterString?: string | null; 3475 - /** 3476 - * This is a simple number with default value 3477 - */ 3478 - parameterNumber?: number | null; 3479 - /** 3480 3663 * This is a simple boolean with default value 3481 3664 */ 3482 3665 parameterBoolean?: boolean | null; ··· 3488 3671 * This is a simple model with default value 3489 3672 */ 3490 3673 parameterModel?: ModelWithString | null; 3491 - }; 3492 - export type TDataCallWithDefaultOptionalParameters = { 3493 3674 /** 3494 - * This is a simple string that is optional with default value 3675 + * This is a simple number with default value 3495 3676 */ 3496 - parameterString?: string; 3677 + parameterNumber?: number | null; 3497 3678 /** 3498 - * This is a simple number that is optional with default value 3679 + * This is a simple string with default value 3499 3680 */ 3500 - parameterNumber?: number; 3681 + parameterString?: string | null; 3682 + }; 3683 + export type TDataCallWithDefaultOptionalParameters = { 3501 3684 /** 3502 3685 * This is a simple boolean that is optional with default value 3503 3686 */ ··· 3510 3693 * This is a simple model that is optional with default value 3511 3694 */ 3512 3695 parameterModel?: ModelWithString; 3513 - }; 3514 - export type TDataCallToTestOrderOfParams = { 3515 3696 /** 3516 - * This is a string with no default 3697 + * This is a simple number that is optional with default value 3517 3698 */ 3518 - parameterStringWithNoDefault: string; 3699 + parameterNumber?: number; 3700 + /** 3701 + * This is a simple string that is optional with default value 3702 + */ 3703 + parameterString?: string; 3704 + }; 3705 + export type TDataCallToTestOrderOfParams = { 3519 3706 /** 3520 3707 * This is a optional string with default 3521 3708 */ ··· 3529 3716 */ 3530 3717 parameterOptionalStringWithNoDefault?: string; 3531 3718 /** 3719 + * This is a string that can be null with default 3720 + */ 3721 + parameterStringNullableWithDefault?: string | null; 3722 + /** 3723 + * This is a string that can be null with no default 3724 + */ 3725 + parameterStringNullableWithNoDefault?: string | null; 3726 + /** 3532 3727 * This is a string with default 3533 3728 */ 3534 3729 parameterStringWithDefault?: string; ··· 3537 3732 */ 3538 3733 parameterStringWithEmptyDefault?: string; 3539 3734 /** 3540 - * This is a string that can be null with no default 3735 + * This is a string with no default 3541 3736 */ 3542 - parameterStringNullableWithNoDefault?: string | null; 3543 - /** 3544 - * This is a string that can be null with default 3545 - */ 3546 - parameterStringNullableWithDefault?: string | null; 3737 + parameterStringWithNoDefault: string; 3547 3738 }; 3548 3739 3549 3740 export class DefaultsService { ··· 3552 3743 */ 3553 3744 public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise<void> { 3554 3745 const { 3555 - parameterString = 'Hello World!', 3556 - parameterNumber = 123, 3557 3746 parameterBoolean = true, 3558 3747 parameterEnum = 'Success', 3559 3748 parameterModel = { 3560 3749 prop: 'Hello World!', 3561 3750 }, 3751 + parameterNumber = 123, 3752 + parameterString = 'Hello World!', 3562 3753 } = data; 3563 3754 return __request(OpenAPI, { 3564 3755 method: 'GET', ··· 3580 3771 data: TDataCallWithDefaultOptionalParameters = {} 3581 3772 ): CancelablePromise<void> { 3582 3773 const { 3583 - parameterString = 'Hello World!', 3584 - parameterNumber = 123, 3585 3774 parameterBoolean = true, 3586 3775 parameterEnum = 'Success', 3587 3776 parameterModel = { 3588 3777 prop: 'Hello World!', 3589 3778 }, 3779 + parameterNumber = 123, 3780 + parameterString = 'Hello World!', 3590 3781 } = data; 3591 3782 return __request(OpenAPI, { 3592 3783 method: 'POST', ··· 3606 3797 */ 3607 3798 public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise<void> { 3608 3799 const { 3609 - parameterStringWithNoDefault, 3610 3800 parameterOptionalStringWithDefault = 'Hello World!', 3611 3801 parameterOptionalStringWithEmptyDefault = '', 3612 3802 parameterOptionalStringWithNoDefault, 3803 + parameterStringNullableWithDefault = null, 3804 + parameterStringNullableWithNoDefault, 3613 3805 parameterStringWithDefault = 'Hello World!', 3614 3806 parameterStringWithEmptyDefault = '', 3615 - parameterStringNullableWithNoDefault, 3616 - parameterStringNullableWithDefault = null, 3807 + parameterStringWithNoDefault, 3617 3808 } = data; 3618 3809 return __request(OpenAPI, { 3619 3810 method: 'PUT', ··· 4275 4466 export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends'; 4276 4467 export type { ModelWithAdditionalPropertiesEqTrue } from './models/ModelWithAdditionalPropertiesEqTrue'; 4277 4468 export type { ModelWithArray } from './models/ModelWithArray'; 4469 + export type { ModelWithArrayReadOnlyAndWriteOnly } from './models/ModelWithArrayReadOnlyAndWriteOnly'; 4278 4470 export type { ModelWithBoolean } from './models/ModelWithBoolean'; 4279 4471 export type { ModelWithCircularReference } from './models/ModelWithCircularReference'; 4280 4472 export type { ModelWithConst } from './models/ModelWithConst'; ··· 4303 4495 export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties'; 4304 4496 export type { ModelWithPattern } from './models/ModelWithPattern'; 4305 4497 export type { ModelWithProperties } from './models/ModelWithProperties'; 4498 + export type { ModelWithReadOnlyAndWriteOnly } from './models/ModelWithReadOnlyAndWriteOnly'; 4306 4499 export type { ModelWithReference } from './models/ModelWithReference'; 4307 4500 export type { ModelWithString } from './models/ModelWithString'; 4308 4501 export type { NestedAnyOfArraysNullable } from './models/NestedAnyOfArraysNullable'; ··· 4372 4565 export { $ModelThatExtendsExtends } from './schemas/$ModelThatExtendsExtends'; 4373 4566 export { $ModelWithAdditionalPropertiesEqTrue } from './schemas/$ModelWithAdditionalPropertiesEqTrue'; 4374 4567 export { $ModelWithArray } from './schemas/$ModelWithArray'; 4568 + export { $ModelWithArrayReadOnlyAndWriteOnly } from './schemas/$ModelWithArrayReadOnlyAndWriteOnly'; 4375 4569 export { $ModelWithBoolean } from './schemas/$ModelWithBoolean'; 4376 4570 export { $ModelWithCircularReference } from './schemas/$ModelWithCircularReference'; 4377 4571 export { $ModelWithConst } from './schemas/$ModelWithConst'; ··· 4395 4589 export { $ModelWithOrderedProperties } from './schemas/$ModelWithOrderedProperties'; 4396 4590 export { $ModelWithPattern } from './schemas/$ModelWithPattern'; 4397 4591 export { $ModelWithProperties } from './schemas/$ModelWithProperties'; 4592 + export { $ModelWithReadOnlyAndWriteOnly } from './schemas/$ModelWithReadOnlyAndWriteOnly'; 4398 4593 export { $ModelWithReference } from './schemas/$ModelWithReference'; 4399 4594 export { $ModelWithString } from './schemas/$ModelWithString'; 4400 4595 export { $NestedAnyOfArraysNullable } from './schemas/$NestedAnyOfArraysNullable'; ··· 5105 5300 " 5106 5301 `; 5107 5302 5303 + exports[`v3 should generate: test/generated/v3/models/ModelWithArrayReadOnlyAndWriteOnly.ts 1`] = ` 5304 + "import type { ModelWithReadOnlyAndWriteOnly } from './ModelWithReadOnlyAndWriteOnly'; 5305 + 5306 + /** 5307 + * This is a model with one property containing an array 5308 + */ 5309 + export type ModelWithArrayReadOnlyAndWriteOnly = { 5310 + prop?: Array<ModelWithReadOnlyAndWriteOnly>; 5311 + propWithFile?: Array<Blob>; 5312 + propWithNumber?: Array<number>; 5313 + }; 5314 + " 5315 + `; 5316 + 5108 5317 exports[`v3 should generate: test/generated/v3/models/ModelWithBoolean.ts 1`] = ` 5109 5318 "/** 5110 5319 * This is a model with one boolean property ··· 5437 5646 try?: string; 5438 5647 readonly '@namespace.string'?: string; 5439 5648 readonly '@namespace.integer'?: number; 5649 + }; 5650 + " 5651 + `; 5652 + 5653 + exports[`v3 should generate: test/generated/v3/models/ModelWithReadOnlyAndWriteOnly.ts 1`] = ` 5654 + "export type ModelWithReadOnlyAndWriteOnly = { 5655 + foo: string; 5656 + readonly bar: string; 5657 + baz: string; 5440 5658 }; 5441 5659 " 5442 5660 `; ··· 6545 6763 " 6546 6764 `; 6547 6765 6766 + exports[`v3 should generate: test/generated/v3/schemas/$ModelWithArrayReadOnlyAndWriteOnly.ts 1`] = ` 6767 + "export const $ModelWithArrayReadOnlyAndWriteOnly = { 6768 + description: \`This is a model with one property containing an array\`, 6769 + properties: { 6770 + prop: { 6771 + type: 'array', 6772 + contains: { 6773 + type: 'ModelWithReadOnlyAndWriteOnly', 6774 + }, 6775 + }, 6776 + propWithFile: { 6777 + type: 'array', 6778 + contains: { 6779 + type: 'binary', 6780 + }, 6781 + }, 6782 + propWithNumber: { 6783 + type: 'array', 6784 + contains: { 6785 + type: 'number', 6786 + }, 6787 + }, 6788 + }, 6789 + } as const; 6790 + " 6791 + `; 6792 + 6548 6793 exports[`v3 should generate: test/generated/v3/schemas/$ModelWithBoolean.ts 1`] = ` 6549 6794 "export const $ModelWithBoolean = { 6550 6795 description: \`This is a model with one boolean property\`, ··· 7059 7304 " 7060 7305 `; 7061 7306 7307 + exports[`v3 should generate: test/generated/v3/schemas/$ModelWithReadOnlyAndWriteOnly.ts 1`] = ` 7308 + "export const $ModelWithReadOnlyAndWriteOnly = { 7309 + properties: { 7310 + foo: { 7311 + type: 'string', 7312 + isRequired: true, 7313 + }, 7314 + bar: { 7315 + type: 'string', 7316 + isReadOnly: true, 7317 + isRequired: true, 7318 + }, 7319 + baz: { 7320 + type: 'string', 7321 + isRequired: true, 7322 + }, 7323 + }, 7324 + } as const; 7325 + " 7326 + `; 7327 + 7062 7328 exports[`v3 should generate: test/generated/v3/schemas/$ModelWithReference.ts 1`] = ` 7063 7329 "export const $ModelWithReference = { 7064 7330 description: \`This is a model with one property containing a reference\`, ··· 7222 7488 import { OpenAPI } from '../core/OpenAPI'; 7223 7489 import { request as __request } from '../core/request'; 7224 7490 7491 + export type TDataCollectionFormat = { 7492 + /** 7493 + * This is an array parameter that is sent as csv format (comma-separated values) 7494 + */ 7495 + parameterArrayCsv: Array<string> | null; 7496 + /** 7497 + * This is an array parameter that is sent as multi format (multiple parameter instances) 7498 + */ 7499 + parameterArrayMulti: Array<string> | null; 7500 + /** 7501 + * This is an array parameter that is sent as pipes format (pipe-separated values) 7502 + */ 7503 + parameterArrayPipes: Array<string> | null; 7504 + /** 7505 + * This is an array parameter that is sent as ssv format (space-separated values) 7506 + */ 7507 + parameterArraySsv: Array<string> | null; 7508 + /** 7509 + * This is an array parameter that is sent as tsv format (tab-separated values) 7510 + */ 7511 + parameterArrayTsv: Array<string> | null; 7512 + }; 7513 + 7225 7514 export class CollectionFormatService { 7226 7515 /** 7227 - * @param parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) 7228 - * @param parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) 7229 - * @param parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) 7230 - * @param parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) 7231 - * @param parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) 7232 7516 * @throws ApiError 7233 7517 */ 7234 - public static collectionFormat( 7235 - parameterArrayCsv: Array<string> | null, 7236 - parameterArraySsv: Array<string> | null, 7237 - parameterArrayTsv: Array<string> | null, 7238 - parameterArrayPipes: Array<string> | null, 7239 - parameterArrayMulti: Array<string> | null 7240 - ): CancelablePromise<void> { 7518 + public static collectionFormat(data: TDataCollectionFormat): CancelablePromise<void> { 7519 + const { parameterArrayCsv, parameterArrayMulti, parameterArrayPipes, parameterArraySsv, parameterArrayTsv } = 7520 + data; 7241 7521 return __request(OpenAPI, { 7242 7522 method: 'GET', 7243 7523 url: '/api/v{api-version}/collectionFormat', ··· 7263 7543 import { OpenAPI } from '../core/OpenAPI'; 7264 7544 import { request as __request } from '../core/request'; 7265 7545 7546 + export type TDataComplexTypes = { 7547 + /** 7548 + * Parameter containing object 7549 + */ 7550 + parameterObject: { 7551 + first?: { 7552 + second?: { 7553 + third?: string; 7554 + }; 7555 + }; 7556 + }; 7557 + /** 7558 + * Parameter containing reference 7559 + */ 7560 + parameterReference: ModelWithString; 7561 + }; 7562 + export type TDataComplexParams = { 7563 + id: number; 7564 + requestBody?: { 7565 + readonly key: string | null; 7566 + name: string | null; 7567 + enabled?: boolean; 7568 + readonly type: 'Monkey' | 'Horse' | 'Bird'; 7569 + listOfModels?: Array<ModelWithString> | null; 7570 + listOfStrings?: Array<string> | null; 7571 + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 7572 + readonly user?: { 7573 + readonly id?: number; 7574 + readonly name?: string | null; 7575 + }; 7576 + }; 7577 + }; 7578 + 7266 7579 export class ComplexService { 7267 7580 /** 7268 - * @param parameterObject Parameter containing object 7269 - * @param parameterReference Parameter containing reference 7270 7581 * @returns ModelWithString Successful response 7271 7582 * @throws ApiError 7272 7583 */ 7273 - public static complexTypes( 7274 - parameterObject: { 7275 - first?: { 7276 - second?: { 7277 - third?: string; 7278 - }; 7279 - }; 7280 - }, 7281 - parameterReference: ModelWithString 7282 - ): CancelablePromise<Array<ModelWithString>> { 7584 + public static complexTypes(data: TDataComplexTypes): CancelablePromise<Array<ModelWithString>> { 7585 + const { parameterObject, parameterReference } = data; 7283 7586 return __request(OpenAPI, { 7284 7587 method: 'GET', 7285 7588 url: '/api/v{api-version}/complex', ··· 7295 7598 } 7296 7599 7297 7600 /** 7298 - * @param id 7299 - * @param requestBody 7300 7601 * @returns ModelWithString Success 7301 7602 * @throws ApiError 7302 7603 */ 7303 - public static complexParams( 7304 - id: number, 7305 - requestBody?: { 7306 - readonly key: string | null; 7307 - name: string | null; 7308 - enabled?: boolean; 7309 - readonly type: 'Monkey' | 'Horse' | 'Bird'; 7310 - listOfModels?: Array<ModelWithString> | null; 7311 - listOfStrings?: Array<string> | null; 7312 - parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; 7313 - readonly user?: { 7314 - readonly id?: number; 7315 - readonly name?: string | null; 7316 - }; 7317 - } 7318 - ): CancelablePromise<ModelWithString> { 7604 + public static complexParams(data: TDataComplexParams): CancelablePromise<ModelWithString> { 7605 + const { id, requestBody } = data; 7319 7606 return __request(OpenAPI, { 7320 7607 method: 'PUT', 7321 7608 url: '/api/v{api-version}/complex/{id}', ··· 7331 7618 `; 7332 7619 7333 7620 exports[`v3 should generate: test/generated/v3/services/DefaultService.ts 1`] = ` 7334 - "import type { CancelablePromise } from '../core/CancelablePromise'; 7621 + "import type { ModelWithArrayReadOnlyAndWriteOnly } from '../models/ModelWithArrayReadOnlyAndWriteOnly'; 7622 + import type { ModelWithReadOnlyAndWriteOnly } from '../models/ModelWithReadOnlyAndWriteOnly'; 7623 + import type { CancelablePromise } from '../core/CancelablePromise'; 7335 7624 import { OpenAPI } from '../core/OpenAPI'; 7336 7625 import { request as __request } from '../core/request'; 7337 7626 7627 + export type TDataPostServiceWithEmptyTag = { 7628 + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; 7629 + }; 7630 + 7338 7631 export class DefaultService { 7339 7632 /** 7340 7633 * @throws ApiError ··· 7345 7638 url: '/api/v{api-version}/no-tag', 7346 7639 }); 7347 7640 } 7641 + 7642 + /** 7643 + * @returns ModelWithReadOnlyAndWriteOnly 7644 + * @throws ApiError 7645 + */ 7646 + public static postServiceWithEmptyTag( 7647 + data: TDataPostServiceWithEmptyTag 7648 + ): CancelablePromise<ModelWithReadOnlyAndWriteOnly> { 7649 + const { requestBody } = data; 7650 + return __request(OpenAPI, { 7651 + method: 'POST', 7652 + url: '/api/v{api-version}/no-tag', 7653 + body: requestBody, 7654 + mediaType: 'application/json', 7655 + }); 7656 + } 7348 7657 } 7349 7658 " 7350 7659 `; ··· 7355 7664 import { OpenAPI } from '../core/OpenAPI'; 7356 7665 import { request as __request } from '../core/request'; 7357 7666 7667 + export type TDataCallWithDefaultParameters = { 7668 + /** 7669 + * This is a simple boolean with default value 7670 + */ 7671 + parameterBoolean?: boolean | null; 7672 + /** 7673 + * This is a simple enum with default value 7674 + */ 7675 + parameterEnum?: 'Success' | 'Warning' | 'Error'; 7676 + /** 7677 + * This is a simple model with default value 7678 + */ 7679 + parameterModel?: ModelWithString | null; 7680 + /** 7681 + * This is a simple number with default value 7682 + */ 7683 + parameterNumber?: number | null; 7684 + /** 7685 + * This is a simple string with default value 7686 + */ 7687 + parameterString?: string | null; 7688 + }; 7689 + export type TDataCallWithDefaultOptionalParameters = { 7690 + /** 7691 + * This is a simple boolean that is optional with default value 7692 + */ 7693 + parameterBoolean?: boolean; 7694 + /** 7695 + * This is a simple enum that is optional with default value 7696 + */ 7697 + parameterEnum?: 'Success' | 'Warning' | 'Error'; 7698 + /** 7699 + * This is a simple model that is optional with default value 7700 + */ 7701 + parameterModel?: ModelWithString; 7702 + /** 7703 + * This is a simple number that is optional with default value 7704 + */ 7705 + parameterNumber?: number; 7706 + /** 7707 + * This is a simple string that is optional with default value 7708 + */ 7709 + parameterString?: string; 7710 + }; 7711 + export type TDataCallToTestOrderOfParams = { 7712 + /** 7713 + * This is a optional string with default 7714 + */ 7715 + parameterOptionalStringWithDefault?: string; 7716 + /** 7717 + * This is a optional string with empty default 7718 + */ 7719 + parameterOptionalStringWithEmptyDefault?: string; 7720 + /** 7721 + * This is a optional string with no default 7722 + */ 7723 + parameterOptionalStringWithNoDefault?: string; 7724 + /** 7725 + * This is a string that can be null with default 7726 + */ 7727 + parameterStringNullableWithDefault?: string | null; 7728 + /** 7729 + * This is a string that can be null with no default 7730 + */ 7731 + parameterStringNullableWithNoDefault?: string | null; 7732 + /** 7733 + * This is a string with default 7734 + */ 7735 + parameterStringWithDefault?: string; 7736 + /** 7737 + * This is a string with empty default 7738 + */ 7739 + parameterStringWithEmptyDefault?: string; 7740 + /** 7741 + * This is a string with no default 7742 + */ 7743 + parameterStringWithNoDefault: string; 7744 + }; 7745 + 7358 7746 export class DefaultsService { 7359 7747 /** 7360 - * @param parameterString This is a simple string with default value 7361 - * @param parameterNumber This is a simple number with default value 7362 - * @param parameterBoolean This is a simple boolean with default value 7363 - * @param parameterEnum This is a simple enum with default value 7364 - * @param parameterModel This is a simple model with default value 7365 7748 * @throws ApiError 7366 7749 */ 7367 - public static callWithDefaultParameters( 7368 - parameterString: string | null = 'Hello World!', 7369 - parameterNumber: number | null = 123, 7370 - parameterBoolean: boolean | null = true, 7371 - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', 7372 - parameterModel: ModelWithString | null = { 7373 - prop: 'Hello World!', 7374 - } 7375 - ): CancelablePromise<void> { 7750 + public static callWithDefaultParameters(data: TDataCallWithDefaultParameters = {}): CancelablePromise<void> { 7751 + const { 7752 + parameterBoolean = true, 7753 + parameterEnum = 'Success', 7754 + parameterModel = { 7755 + prop: 'Hello World!', 7756 + }, 7757 + parameterNumber = 123, 7758 + parameterString = 'Hello World!', 7759 + } = data; 7376 7760 return __request(OpenAPI, { 7377 7761 method: 'GET', 7378 7762 url: '/api/v{api-version}/defaults', ··· 7387 7771 } 7388 7772 7389 7773 /** 7390 - * @param parameterString This is a simple string that is optional with default value 7391 - * @param parameterNumber This is a simple number that is optional with default value 7392 - * @param parameterBoolean This is a simple boolean that is optional with default value 7393 - * @param parameterEnum This is a simple enum that is optional with default value 7394 - * @param parameterModel This is a simple model that is optional with default value 7395 7774 * @throws ApiError 7396 7775 */ 7397 7776 public static callWithDefaultOptionalParameters( 7398 - parameterString: string = 'Hello World!', 7399 - parameterNumber: number = 123, 7400 - parameterBoolean: boolean = true, 7401 - parameterEnum: 'Success' | 'Warning' | 'Error' = 'Success', 7402 - parameterModel: ModelWithString = { 7403 - prop: 'Hello World!', 7404 - } 7777 + data: TDataCallWithDefaultOptionalParameters = {} 7405 7778 ): CancelablePromise<void> { 7779 + const { 7780 + parameterBoolean = true, 7781 + parameterEnum = 'Success', 7782 + parameterModel = { 7783 + prop: 'Hello World!', 7784 + }, 7785 + parameterNumber = 123, 7786 + parameterString = 'Hello World!', 7787 + } = data; 7406 7788 return __request(OpenAPI, { 7407 7789 method: 'POST', 7408 7790 url: '/api/v{api-version}/defaults', ··· 7417 7799 } 7418 7800 7419 7801 /** 7420 - * @param parameterStringWithNoDefault This is a string with no default 7421 - * @param parameterOptionalStringWithDefault This is a optional string with default 7422 - * @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default 7423 - * @param parameterOptionalStringWithNoDefault This is a optional string with no default 7424 - * @param parameterStringWithDefault This is a string with default 7425 - * @param parameterStringWithEmptyDefault This is a string with empty default 7426 - * @param parameterStringNullableWithNoDefault This is a string that can be null with no default 7427 - * @param parameterStringNullableWithDefault This is a string that can be null with default 7428 7802 * @throws ApiError 7429 7803 */ 7430 - public static callToTestOrderOfParams( 7431 - parameterStringWithNoDefault: string, 7432 - parameterOptionalStringWithDefault: string = 'Hello World!', 7433 - parameterOptionalStringWithEmptyDefault: string = '', 7434 - parameterOptionalStringWithNoDefault?: string, 7435 - parameterStringWithDefault: string = 'Hello World!', 7436 - parameterStringWithEmptyDefault: string = '', 7437 - parameterStringNullableWithNoDefault?: string | null, 7438 - parameterStringNullableWithDefault: string | null = null 7439 - ): CancelablePromise<void> { 7804 + public static callToTestOrderOfParams(data: TDataCallToTestOrderOfParams): CancelablePromise<void> { 7805 + const { 7806 + parameterOptionalStringWithDefault = 'Hello World!', 7807 + parameterOptionalStringWithEmptyDefault = '', 7808 + parameterOptionalStringWithNoDefault, 7809 + parameterStringNullableWithDefault = null, 7810 + parameterStringNullableWithNoDefault, 7811 + parameterStringWithDefault = 'Hello World!', 7812 + parameterStringWithEmptyDefault = '', 7813 + parameterStringWithNoDefault, 7814 + } = data; 7440 7815 return __request(OpenAPI, { 7441 7816 method: 'PUT', 7442 7817 url: '/api/v{api-version}/defaults', ··· 7462 7837 import { OpenAPI } from '../core/OpenAPI'; 7463 7838 import { request as __request } from '../core/request'; 7464 7839 7840 + export type TDataDeprecatedCall = { 7841 + /** 7842 + * This parameter is deprecated 7843 + */ 7844 + parameter: DeprecatedModel | null; 7845 + }; 7846 + 7465 7847 export class DeprecatedService { 7466 7848 /** 7467 7849 * @deprecated 7468 - * @param parameter This parameter is deprecated 7469 7850 * @throws ApiError 7470 7851 */ 7471 - public static deprecatedCall(parameter: DeprecatedModel | null): CancelablePromise<void> { 7852 + public static deprecatedCall(data: TDataDeprecatedCall): CancelablePromise<void> { 7853 + const { parameter } = data; 7472 7854 return __request(OpenAPI, { 7473 7855 method: 'POST', 7474 7856 url: '/api/v{api-version}/parameters/deprecated', ··· 7486 7868 import { OpenAPI } from '../core/OpenAPI'; 7487 7869 import { request as __request } from '../core/request'; 7488 7870 7489 - export class DescriptionsService { 7871 + export type TDataCallWithDescriptions = { 7490 7872 /** 7491 - * @param parameterWithBreaks Testing multiline comments in string: First line 7873 + * Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work 7874 + */ 7875 + parameterWithBackticks?: unknown; 7876 + /** 7877 + * Testing multiline comments in string: First line 7492 7878 * Second line 7493 7879 * 7494 7880 * Fourth line 7495 - * @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work 7496 - * @param parameterWithSlashes Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work 7497 - * @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work 7498 - * @param parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work 7499 - * @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work 7881 + */ 7882 + parameterWithBreaks?: unknown; 7883 + /** 7884 + * Testing expression placeholders in string: \${expression} should work 7885 + */ 7886 + parameterWithExpressionPlaceholders?: unknown; 7887 + /** 7888 + * Testing quotes in string: 'single quote''' and "double quotes""" should work 7889 + */ 7890 + parameterWithQuotes?: unknown; 7891 + /** 7892 + * Testing reserved characters in string: * inline * and ** inline ** should work 7893 + */ 7894 + parameterWithReservedCharacters?: unknown; 7895 + /** 7896 + * Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work 7897 + */ 7898 + parameterWithSlashes?: unknown; 7899 + }; 7900 + 7901 + export class DescriptionsService { 7902 + /** 7500 7903 * @throws ApiError 7501 7904 */ 7502 - public static callWithDescriptions( 7503 - parameterWithBreaks?: unknown, 7504 - parameterWithBackticks?: unknown, 7505 - parameterWithSlashes?: unknown, 7506 - parameterWithExpressionPlaceholders?: unknown, 7507 - parameterWithQuotes?: unknown, 7508 - parameterWithReservedCharacters?: unknown 7509 - ): CancelablePromise<void> { 7905 + public static callWithDescriptions(data: TDataCallWithDescriptions = {}): CancelablePromise<void> { 7906 + const { 7907 + parameterWithBackticks, 7908 + parameterWithBreaks, 7909 + parameterWithExpressionPlaceholders, 7910 + parameterWithQuotes, 7911 + parameterWithReservedCharacters, 7912 + parameterWithSlashes, 7913 + } = data; 7510 7914 return __request(OpenAPI, { 7511 7915 method: 'POST', 7512 7916 url: '/api/v{api-version}/descriptions/', ··· 7578 7982 import { OpenAPI } from '../core/OpenAPI'; 7579 7983 import { request as __request } from '../core/request'; 7580 7984 7985 + export type TDataTestErrorCode = { 7986 + /** 7987 + * Status code to return 7988 + */ 7989 + status: number; 7990 + }; 7991 + 7581 7992 export class ErrorService { 7582 7993 /** 7583 - * @param status Status code to return 7584 7994 * @returns any Custom message: Successful response 7585 7995 * @throws ApiError 7586 7996 */ 7587 - public static testErrorCode(status: number): CancelablePromise<any> { 7997 + public static testErrorCode(data: TDataTestErrorCode): CancelablePromise<any> { 7998 + const { status } = data; 7588 7999 return __request(OpenAPI, { 7589 8000 method: 'POST', 7590 8001 url: '/api/v{api-version}/error', ··· 7608 8019 import { OpenAPI } from '../core/OpenAPI'; 7609 8020 import { request as __request } from '../core/request'; 7610 8021 8022 + export type TDataFileResponse = { 8023 + id: string; 8024 + }; 8025 + 7611 8026 export class FileResponseService { 7612 8027 /** 7613 - * @param id 7614 8028 * @returns binary Success 7615 8029 * @throws ApiError 7616 8030 */ 7617 - public static fileResponse(id: string): CancelablePromise<Blob> { 8031 + public static fileResponse(data: TDataFileResponse): CancelablePromise<Blob> { 8032 + const { id } = data; 7618 8033 return __request(OpenAPI, { 7619 8034 method: 'GET', 7620 8035 url: '/api/v{api-version}/file/{id}', ··· 7633 8048 import { OpenAPI } from '../core/OpenAPI'; 7634 8049 import { request as __request } from '../core/request'; 7635 8050 8051 + export type TDataPostApiFormData = { 8052 + /** 8053 + * A reusable request body 8054 + */ 8055 + formData?: ModelWithString; 8056 + /** 8057 + * This is a reusable parameter 8058 + */ 8059 + parameter?: string; 8060 + }; 8061 + 7636 8062 export class FormDataService { 7637 8063 /** 7638 - * @param parameter This is a reusable parameter 7639 - * @param formData A reusable request body 7640 8064 * @throws ApiError 7641 8065 */ 7642 - public static postApiFormData(parameter?: string, formData?: ModelWithString): CancelablePromise<void> { 8066 + public static postApiFormData(data: TDataPostApiFormData = {}): CancelablePromise<void> { 8067 + const { formData, parameter } = data; 7643 8068 return __request(OpenAPI, { 7644 8069 method: 'POST', 7645 8070 url: '/api/v{api-version}/formData/', ··· 7685 8110 import { OpenAPI } from '../core/OpenAPI'; 7686 8111 import { request as __request } from '../core/request'; 7687 8112 8113 + export type TDataMultipartRequest = { 8114 + formData?: { 8115 + content?: Blob; 8116 + data?: ModelWithString | null; 8117 + }; 8118 + }; 8119 + 7688 8120 export class MultipartService { 7689 8121 /** 7690 - * @param formData 7691 8122 * @throws ApiError 7692 8123 */ 7693 - public static multipartRequest(formData?: { 7694 - content?: Blob; 7695 - data?: ModelWithString | null; 7696 - }): CancelablePromise<void> { 8124 + public static multipartRequest(data: TDataMultipartRequest = {}): CancelablePromise<void> { 8125 + const { formData } = data; 7697 8126 return __request(OpenAPI, { 7698 8127 method: 'POST', 7699 8128 url: '/api/v{api-version}/multipart', ··· 7842 8271 import { OpenAPI } from '../core/OpenAPI'; 7843 8272 import { request as __request } from '../core/request'; 7844 8273 8274 + export type TDataNonAsciiæøåÆøÅöôêÊ字符串 = { 8275 + /** 8276 + * Dummy input param 8277 + */ 8278 + nonAsciiParamæøåÆøÅöôêÊ: number; 8279 + }; 8280 + 7845 8281 export class NonAsciiÆøåÆøÅöôêÊService { 7846 8282 /** 7847 - * @param nonAsciiParamæøåÆøÅöôêÊ Dummy input param 7848 8283 * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response 7849 8284 * @throws ApiError 7850 8285 */ 7851 8286 public static nonAsciiæøåÆøÅöôêÊ字符串( 7852 - nonAsciiParamæøåÆøÅöôêÊ: number 8287 + data: TDataNonAsciiæøåÆøÅöôêÊ字符串 7853 8288 ): CancelablePromise<Array<NonAsciiStringæøåÆØÅöôêÊ字符串>> { 8289 + const { nonAsciiParamæøåÆøÅöôêÊ } = data; 7854 8290 return __request(OpenAPI, { 7855 8291 method: 'POST', 7856 8292 url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ··· 7872 8308 import { OpenAPI } from '../core/OpenAPI'; 7873 8309 import { request as __request } from '../core/request'; 7874 8310 8311 + export type TDataDeleteFoo = { 8312 + /** 8313 + * bar in method 8314 + */ 8315 + bar: string; 8316 + /** 8317 + * foo in method 8318 + */ 8319 + foo: string; 8320 + }; 8321 + export type TDataCallWithParameters = { 8322 + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; 8323 + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; 8324 + /** 8325 + * This is the parameter that goes into the cookie 8326 + */ 8327 + parameterCookie: string | null; 8328 + /** 8329 + * This is the parameter that goes into the form data 8330 + */ 8331 + parameterForm: string | null; 8332 + /** 8333 + * This is the parameter that goes into the header 8334 + */ 8335 + parameterHeader: string | null; 8336 + /** 8337 + * This is the parameter that goes into the path 8338 + */ 8339 + parameterPath: string | null; 8340 + /** 8341 + * This is the parameter that goes into the query params 8342 + */ 8343 + parameterQuery: string | null; 8344 + /** 8345 + * This is the parameter that goes into the body 8346 + */ 8347 + requestBody: ModelWithString | null; 8348 + }; 8349 + export type TDataCallWithWeirdParameterNames = { 8350 + /** 8351 + * This is the parameter with a reserved keyword 8352 + */ 8353 + _default?: string; 8354 + /** 8355 + * This is the parameter that goes into the cookie 8356 + */ 8357 + parameterCookie: string | null; 8358 + /** 8359 + * This is the parameter that goes into the request form data 8360 + */ 8361 + parameterForm: string | null; 8362 + /** 8363 + * This is the parameter that goes into the request header 8364 + */ 8365 + parameterHeader: string | null; 8366 + /** 8367 + * This is the parameter that goes into the path 8368 + */ 8369 + parameterPath1?: string; 8370 + /** 8371 + * This is the parameter that goes into the path 8372 + */ 8373 + parameterPath2?: string; 8374 + /** 8375 + * This is the parameter that goes into the path 8376 + */ 8377 + parameterPath3?: string; 8378 + /** 8379 + * This is the parameter that goes into the request query params 8380 + */ 8381 + parameterQuery: string | null; 8382 + /** 8383 + * This is the parameter that goes into the body 8384 + */ 8385 + requestBody: ModelWithString | null; 8386 + }; 8387 + export type TDataGetCallWithOptionalParam = { 8388 + /** 8389 + * This is an optional parameter 8390 + */ 8391 + parameter?: string; 8392 + /** 8393 + * This is a required parameter 8394 + */ 8395 + requestBody: ModelWithOneOfEnum; 8396 + }; 8397 + export type TDataPostCallWithOptionalParam = { 8398 + /** 8399 + * This is a required parameter 8400 + */ 8401 + parameter: Pageable; 8402 + /** 8403 + * This is an optional parameter 8404 + */ 8405 + requestBody?: ModelWithString; 8406 + }; 8407 + 7875 8408 export class ParametersService { 7876 8409 /** 7877 - * @param foo foo in method 7878 - * @param bar bar in method 7879 8410 * @throws ApiError 7880 8411 */ 7881 - public static deleteFoo(foo: string, bar: string): CancelablePromise<void> { 8412 + public static deleteFoo(data: TDataDeleteFoo): CancelablePromise<void> { 8413 + const { bar, foo } = data; 7882 8414 return __request(OpenAPI, { 7883 8415 method: 'DELETE', 7884 8416 url: '/api/v{api-version}/foo/{foo}/bar/{bar}', ··· 7890 8422 } 7891 8423 7892 8424 /** 7893 - * @param parameterHeader This is the parameter that goes into the header 7894 - * @param fooAllOfEnum 7895 - * @param parameterQuery This is the parameter that goes into the query params 7896 - * @param parameterForm This is the parameter that goes into the form data 7897 - * @param parameterCookie This is the parameter that goes into the cookie 7898 - * @param parameterPath This is the parameter that goes into the path 7899 - * @param requestBody This is the parameter that goes into the body 7900 - * @param fooRefEnum 7901 8425 * @throws ApiError 7902 8426 */ 7903 - public static callWithParameters( 7904 - parameterHeader: string | null, 7905 - fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo, 7906 - parameterQuery: string | null, 7907 - parameterForm: string | null, 7908 - parameterCookie: string | null, 7909 - parameterPath: string | null, 7910 - requestBody: ModelWithString | null, 7911 - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo 7912 - ): CancelablePromise<void> { 8427 + public static callWithParameters(data: TDataCallWithParameters): CancelablePromise<void> { 8428 + const { 8429 + fooAllOfEnum, 8430 + fooRefEnum, 8431 + parameterCookie, 8432 + parameterForm, 8433 + parameterHeader, 8434 + parameterPath, 8435 + parameterQuery, 8436 + requestBody, 8437 + } = data; 7913 8438 return __request(OpenAPI, { 7914 8439 method: 'POST', 7915 8440 url: '/api/v{api-version}/parameters/{parameterPath}', ··· 7936 8461 } 7937 8462 7938 8463 /** 7939 - * @param parameterHeader This is the parameter that goes into the request header 7940 - * @param parameterQuery This is the parameter that goes into the request query params 7941 - * @param parameterForm This is the parameter that goes into the request form data 7942 - * @param parameterCookie This is the parameter that goes into the cookie 7943 - * @param requestBody This is the parameter that goes into the body 7944 - * @param parameterPath1 This is the parameter that goes into the path 7945 - * @param parameterPath2 This is the parameter that goes into the path 7946 - * @param parameterPath3 This is the parameter that goes into the path 7947 - * @param _default This is the parameter with a reserved keyword 7948 8464 * @throws ApiError 7949 8465 */ 7950 - public static callWithWeirdParameterNames( 7951 - parameterHeader: string | null, 7952 - parameterQuery: string | null, 7953 - parameterForm: string | null, 7954 - parameterCookie: string | null, 7955 - requestBody: ModelWithString | null, 7956 - parameterPath1?: string, 7957 - parameterPath2?: string, 7958 - parameterPath3?: string, 7959 - _default?: string 7960 - ): CancelablePromise<void> { 8466 + public static callWithWeirdParameterNames(data: TDataCallWithWeirdParameterNames): CancelablePromise<void> { 8467 + const { 8468 + _default, 8469 + parameterCookie, 8470 + parameterForm, 8471 + parameterHeader, 8472 + parameterPath1, 8473 + parameterPath2, 8474 + parameterPath3, 8475 + parameterQuery, 8476 + requestBody, 8477 + } = data; 7961 8478 return __request(OpenAPI, { 7962 8479 method: 'POST', 7963 8480 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', ··· 7985 8502 } 7986 8503 7987 8504 /** 7988 - * @param requestBody This is a required parameter 7989 - * @param parameter This is an optional parameter 7990 8505 * @throws ApiError 7991 8506 */ 7992 - public static getCallWithOptionalParam( 7993 - requestBody: ModelWithOneOfEnum, 7994 - parameter?: string 7995 - ): CancelablePromise<void> { 8507 + public static getCallWithOptionalParam(data: TDataGetCallWithOptionalParam): CancelablePromise<void> { 8508 + const { parameter, requestBody } = data; 7996 8509 return __request(OpenAPI, { 7997 8510 method: 'GET', 7998 8511 url: '/api/v{api-version}/parameters/', ··· 8005 8518 } 8006 8519 8007 8520 /** 8008 - * @param parameter This is a required parameter 8009 - * @param requestBody This is an optional parameter 8010 8521 * @throws ApiError 8011 8522 */ 8012 - public static postCallWithOptionalParam( 8013 - parameter: Pageable, 8014 - requestBody?: ModelWithString 8015 - ): CancelablePromise<void> { 8523 + public static postCallWithOptionalParam(data: TDataPostCallWithOptionalParam): CancelablePromise<void> { 8524 + const { parameter, requestBody } = data; 8016 8525 return __request(OpenAPI, { 8017 8526 method: 'POST', 8018 8527 url: '/api/v{api-version}/parameters/', ··· 8033 8542 import { OpenAPI } from '../core/OpenAPI'; 8034 8543 import { request as __request } from '../core/request'; 8035 8544 8545 + export type TDataPostApiRequestBody = { 8546 + /** 8547 + * A reusable request body 8548 + */ 8549 + foo?: ModelWithString; 8550 + /** 8551 + * This is a reusable parameter 8552 + */ 8553 + parameter?: string; 8554 + }; 8555 + 8036 8556 export class RequestBodyService { 8037 8557 /** 8038 - * @param parameter This is a reusable parameter 8039 - * @param foo A reusable request body 8040 8558 * @throws ApiError 8041 8559 */ 8042 - public static postApiRequestBody(parameter?: string, foo?: ModelWithString): CancelablePromise<void> { 8560 + public static postApiRequestBody(data: TDataPostApiRequestBody = {}): CancelablePromise<void> { 8561 + const { foo, parameter } = data; 8043 8562 return __request(OpenAPI, { 8044 8563 method: 'POST', 8045 8564 url: '/api/v{api-version}/requestBody/', ··· 8217 8736 import { OpenAPI } from '../core/OpenAPI'; 8218 8737 import { request as __request } from '../core/request'; 8219 8738 8739 + export type TDataTypes = { 8740 + /** 8741 + * This is a number parameter 8742 + */ 8743 + id?: number; 8744 + /** 8745 + * This is an array parameter 8746 + */ 8747 + parameterArray: Array<string> | null; 8748 + /** 8749 + * This is a boolean parameter 8750 + */ 8751 + parameterBoolean?: boolean | null; 8752 + /** 8753 + * This is a dictionary parameter 8754 + */ 8755 + parameterDictionary: Record<string, unknown> | null; 8756 + /** 8757 + * This is an enum parameter 8758 + */ 8759 + parameterEnum: 'Success' | 'Warning' | 'Error' | null; 8760 + /** 8761 + * This is a number parameter 8762 + */ 8763 + parameterNumber?: number; 8764 + /** 8765 + * This is an object parameter 8766 + */ 8767 + parameterObject?: Record<string, unknown> | null; 8768 + /** 8769 + * This is a string parameter 8770 + */ 8771 + parameterString?: string | null; 8772 + }; 8773 + 8220 8774 export class TypesService { 8221 8775 /** 8222 - * @param parameterArray This is an array parameter 8223 - * @param parameterDictionary This is a dictionary parameter 8224 - * @param parameterEnum This is an enum parameter 8225 - * @param parameterNumber This is a number parameter 8226 - * @param parameterString This is a string parameter 8227 - * @param parameterBoolean This is a boolean parameter 8228 - * @param parameterObject This is an object parameter 8229 - * @param id This is a number parameter 8230 8776 * @returns number Response is a simple number 8231 8777 * @returns string Response is a simple string 8232 8778 * @returns boolean Response is a simple boolean 8233 8779 * @returns unknown Response is a simple object 8234 8780 * @throws ApiError 8235 8781 */ 8236 - public static types( 8237 - parameterArray: Array<string> | null, 8238 - parameterDictionary: Record<string, unknown> | null, 8239 - parameterEnum: 'Success' | 'Warning' | 'Error' | null, 8240 - parameterNumber: number = 123, 8241 - parameterString: string | null = 'default', 8242 - parameterBoolean: boolean | null = true, 8243 - parameterObject: Record<string, unknown> | null = null, 8244 - id?: number 8245 - ): CancelablePromise<number | string | boolean | Record<string, unknown>> { 8782 + public static types(data: TDataTypes): CancelablePromise<number | string | boolean | Record<string, unknown>> { 8783 + const { 8784 + id, 8785 + parameterArray, 8786 + parameterBoolean = true, 8787 + parameterDictionary, 8788 + parameterEnum, 8789 + parameterNumber = 123, 8790 + parameterObject = null, 8791 + parameterString = 'default', 8792 + } = data; 8246 8793 return __request(OpenAPI, { 8247 8794 method: 'GET', 8248 8795 url: '/api/v{api-version}/types', ··· 8269 8816 import { OpenAPI } from '../core/OpenAPI'; 8270 8817 import { request as __request } from '../core/request'; 8271 8818 8819 + export type TDataUploadFile = { 8820 + /** 8821 + * Supply a file reference for upload 8822 + */ 8823 + file: Blob; 8824 + }; 8825 + 8272 8826 export class UploadService { 8273 8827 /** 8274 - * @param file Supply a file reference for upload 8275 8828 * @returns boolean 8276 8829 * @throws ApiError 8277 8830 */ 8278 - public static uploadFile(file: Blob): CancelablePromise<boolean> { 8831 + public static uploadFile(data: TDataUploadFile): CancelablePromise<boolean> { 8832 + const { file } = data; 8279 8833 return __request(OpenAPI, { 8280 8834 method: 'POST', 8281 8835 url: '/api/v{api-version}/upload',
-64
test/index.js
··· 1 - 'use strict'; 2 - 3 - const OpenAPI = require('../'); 4 - 5 - const generate = async (input, output) => { 6 - await OpenAPI.generate({ 7 - client: 'fetch', 8 - // clientName: 'Demo', 9 - enums: true, 10 - exportCore: true, 11 - exportModels: true, 12 - exportSchemas: true, 13 - exportServices: true, 14 - input, 15 - output, 16 - postfixModels: '', 17 - serviceResponse: 'body', 18 - useDateType: false, 19 - useOptions: true, 20 - }); 21 - }; 22 - 23 - // eslint-disable-next-line @typescript-eslint/no-unused-vars 24 - const generateRealWorldSpecs = async () => { 25 - const response = await fetch('https://api.apis.guru/v2/list.json'); 26 - 27 - const list = await response.json(); 28 - delete list['api.video']; 29 - delete list['apideck.com:vault']; 30 - delete list['amazonaws.com:mediaconvert']; 31 - delete list['bungie.net']; 32 - delete list['docusign.net']; 33 - delete list['googleapis.com:adsense']; 34 - delete list['googleapis.com:servicebroker']; 35 - delete list['kubernetes.io']; 36 - delete list['microsoft.com:graph']; 37 - delete list['presalytics.io:ooxml']; 38 - delete list['stripe.com']; 39 - 40 - const specs = Object.entries(list).map(([name, api]) => { 41 - const latestVersion = api.versions[api.preferred]; 42 - return { 43 - name: name 44 - .replace(/^[^a-zA-Z]+/g, '') 45 - .replace(/[^\w\-]+/g, '-') 46 - .trim() 47 - .toLowerCase(), 48 - url: latestVersion.swaggerYamlUrl || latestVersion.swaggerUrl, 49 - }; 50 - }); 51 - 52 - for (let i = 0; i < specs.length; i++) { 53 - const spec = specs[i]; 54 - await generate(spec.url, `./test/generated/${spec.name}/`); 55 - } 56 - }; 57 - 58 - const main = async () => { 59 - await generate('./test/spec/v2.json', './test/generated/v2/'); 60 - await generate('./test/spec/v3.json', './test/generated/v3/'); 61 - // await generateRealWorldSpecs(); 62 - }; 63 - 64 - main();
+3 -3
test/index.spec.ts
··· 15 15 exportServices: true, 16 16 input: './test/spec/v2.json', 17 17 output: './test/generated/v2/', 18 - useOptions: false, 18 + useOptions: true, 19 19 }); 20 20 21 21 sync('./test/generated/v2/**/*.ts').forEach(file => { ··· 36 36 exportServices: true, 37 37 input: './test/spec/v3.json', 38 38 output: './test/generated/v3/', 39 - useOptions: false, 39 + useOptions: true, 40 40 }); 41 41 42 42 sync('./test/generated/v3/**/*.ts').forEach(file => { ··· 56 56 input: './test/spec/v3.json', 57 57 output: './test/generated/v3_date/', 58 58 useDateType: true, 59 - useOptions: false, 59 + useOptions: true, 60 60 }); 61 61 62 62 sync('./test/generated/v3_date/**/*.ts').forEach(file => {
+18
test/sample.cjs
··· 1 + const path = require('node:path'); 2 + 3 + const main = async () => { 4 + /** @type {import('../src/node/index').UserConfig} */ 5 + const config = { 6 + client: 'fetch', 7 + enums: true, 8 + exportSchemas: true, 9 + input: './test/spec/v3.json', 10 + output: './test/generated/v3/', 11 + useOptions: true, 12 + }; 13 + 14 + const { generate } = await import(path.resolve(process.cwd(), 'dist/index.js')); 15 + await generate(config); 16 + }; 17 + 18 + main();
+77
test/spec/v3.json
··· 14 14 "tags": [], 15 15 "get": { 16 16 "operationId": "ServiceWithEmptyTag" 17 + }, 18 + "post": { 19 + "operationId": "PostServiceWithEmptyTag", 20 + "requestBody": { 21 + "required": true, 22 + "content": { 23 + "application/json": { 24 + "schema": { 25 + "type": "object", 26 + "oneOf": [ 27 + { 28 + "$ref": "#/components/schemas/ModelWithReadOnlyAndWriteOnly" 29 + }, 30 + { 31 + "$ref": "#/components/schemas/ModelWithArrayReadOnlyAndWriteOnly" 32 + } 33 + ] 34 + } 35 + } 36 + } 37 + }, 38 + "responses": { 39 + "default": { 40 + "content": { 41 + "application/json": { 42 + "schema": { 43 + "$ref": "#/components/schemas/ModelWithReadOnlyAndWriteOnly" 44 + } 45 + } 46 + } 47 + } 48 + } 17 49 } 18 50 }, 19 51 "/api/v{api-version}/simple": { ··· 2129 2161 } 2130 2162 } 2131 2163 }, 2164 + "ModelWithArrayReadOnlyAndWriteOnly": { 2165 + "description": "This is a model with one property containing an array", 2166 + "type": "object", 2167 + "properties": { 2168 + "prop": { 2169 + "type": "array", 2170 + "items": { 2171 + "$ref": "#/components/schemas/ModelWithReadOnlyAndWriteOnly" 2172 + } 2173 + }, 2174 + "propWithFile": { 2175 + "type": "array", 2176 + "items": { 2177 + "type": "file" 2178 + } 2179 + }, 2180 + "propWithNumber": { 2181 + "type": "array", 2182 + "items": { 2183 + "type": "number" 2184 + } 2185 + } 2186 + } 2187 + }, 2132 2188 "ModelWithArray": { 2133 2189 "description": "This is a model with one property containing an array", 2134 2190 "type": "object", ··· 3173 3229 "$ref": "#/components/schemas/ModelWithNestedArrayEnumsDataFoo" 3174 3230 } 3175 3231 ] 3232 + } 3233 + } 3234 + }, 3235 + "ModelWithReadOnlyAndWriteOnly": { 3236 + "type": "object", 3237 + "required": [ 3238 + "foo", 3239 + "bar", 3240 + "baz" 3241 + ], 3242 + "properties": { 3243 + "foo": { 3244 + "type": "string" 3245 + }, 3246 + "bar": { 3247 + "readOnly": true, 3248 + "type": "string" 3249 + }, 3250 + "baz": { 3251 + "type": "string", 3252 + "writeOnly": true 3176 3253 } 3177 3254 } 3178 3255 }
+1 -1
tsconfig.json
··· 10 10 "**/__mocks__" 11 11 ], 12 12 "files": [ 13 - "./src/typings/hbs.d.ts" 13 + "./src/types/hbs.d.ts" 14 14 ], 15 15 "include": [ 16 16 "./src/**/*.ts",