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 pull request #430 from hey-api/fix/services-export

feat: replace postfixServices with configuration object

authored by

Lubos and committed by
GitHub
0e1776bd 9845cdd8

+380 -90
+5
.changeset/wild-bees-collect.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + feat: replace postfixServices with configuration object
+16 -4
docs/openapi-ts/migrating.md
··· 40 40 41 41 This config option is deprecated and will be removed. 42 42 43 - ### Deprecated `postfixServices` 44 - 45 - This config option is deprecated and will be removed. 46 - 47 43 ### Deprecated `request` 48 44 49 45 This config option is deprecated and will be removed. ··· 51 47 ### Deprecated `name` 52 48 53 49 This config option is deprecated and will be removed. 50 + 51 + ## v0.41.0 52 + 53 + ### Removed `postfixServices` 54 + 55 + This config option has been removed. You can now transform service names using the string pattern parameter. 56 + 57 + ```js{5} 58 + export default { 59 + input: 'path/to/openapi.json', 60 + output: 'src/client', 61 + services: { 62 + name: 'myAwesome{{name}}Api', 63 + }, 64 + } 65 + ``` 54 66 55 67 ## v0.40.0 56 68
+2 -3
packages/openapi-ts/bin/index.cjs
··· 29 29 .option('--dry-run [value]', 'Skip writing files to disk?') 30 30 .option('--enums <value>', 'Export enum definitions (javascript, typescript)') 31 31 .option('--exportCore [value]', 'Write core files to disk') 32 - .option('--exportServices [value]', 'Write services to disk') 33 32 .option('--format [value]', 'Process output folder with formatter?') 34 33 .option('--lint [value]', 'Process output folder with linter?') 35 34 .option('--name <value>', 'Custom client class name') 36 35 .option('--operationId [value]', 'Use operationd ID?') 37 - .option('--postfixServices <value>', 'Service name postfix') 38 36 .option('--request <value>', 'Path to custom request file') 39 37 .option('--schemas [value]', 'Write schemas to disk') 40 38 .option( 41 39 '--serviceResponse [value]', 42 40 'Define shape of returned value from service calls', 43 41 ) 42 + .option('--services [value]', 'Write services to disk') 44 43 .option('--types [value]', 'Write types to disk') 45 44 .option( 46 45 '--useDateType [value]', ··· 81 80 userConfig = processParams(params, [ 82 81 'dryRun', 83 82 'exportCore', 84 - 'exportServices', 85 83 'format', 86 84 'lint', 87 85 'operationId', 88 86 'schemas', 87 + 'services', 89 88 'types', 90 89 'useDateType', 91 90 'useOptions',
+1
packages/openapi-ts/rollup.config.ts
··· 27 27 equals: true, 28 28 ifdef: true, 29 29 notEquals: true, 30 + transformServiceName: true, 30 31 useDateType: true, 31 32 }, 32 33 knownHelpersOnly: true,
+20 -10
packages/openapi-ts/src/index.ts
··· 88 88 } 89 89 }; 90 90 91 + const getServices = (userConfig: UserConfig): Config['services'] => { 92 + let services: Config['services'] = { 93 + export: true, 94 + name: '{{name}}Service', 95 + }; 96 + if (typeof userConfig.services === 'boolean') { 97 + services.export = userConfig.services; 98 + } else if (typeof userConfig.services === 'string') { 99 + services.include = userConfig.services; 100 + } else { 101 + services = { 102 + ...services, 103 + ...userConfig.services, 104 + }; 105 + } 106 + return services; 107 + }; 108 + 91 109 const getTypes = (userConfig: UserConfig): Config['types'] => { 92 110 let types: Config['types'] = { 93 111 export: true, ··· 128 146 dryRun = false, 129 147 enums = false, 130 148 exportCore = true, 131 - exportServices = true, 132 149 format = true, 133 150 input, 134 151 lint = false, 135 152 name, 136 153 operationId = true, 137 - postfixServices = 'Service', 138 154 request, 139 155 schemas = true, 140 156 serviceResponse = 'body', ··· 158 174 ); 159 175 } 160 176 161 - if (postfixServices && postfixServices !== 'Service') { 162 - console.warn( 163 - '⚠️ Deprecation warning: postfixServices. This setting will be removed in future versions. Please create an issue wih your use case if you need this option https://github.com/hey-api/openapi-ts/issues', 164 - ); 165 - } 166 - 167 177 if (!useOptions) { 168 178 console.warn( 169 179 '⚠️ Deprecation warning: useOptions set to false. This setting will be removed in future versions. Please migrate useOptions to true https://heyapi.vercel.app/openapi-ts/migrating.html#v0-27-38', ··· 172 182 173 183 const client = userConfig.client || inferClient(dependencies); 174 184 const output = path.resolve(process.cwd(), userConfig.output); 185 + const services = getServices(userConfig); 175 186 const types = getTypes(userConfig); 176 187 177 188 return setConfig({ ··· 181 192 dryRun, 182 193 enums, 183 194 exportCore, 184 - exportServices, 185 195 format, 186 196 input, 187 197 lint, 188 198 name, 189 199 operationId, 190 200 output, 191 - postfixServices, 192 201 request, 193 202 schemas, 194 203 serviceResponse, 204 + services, 195 205 types, 196 206 useDateType, 197 207 useOptions,
+6 -4
packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts
··· 14 14 dryRun: true, 15 15 enums: false, 16 16 exportCore: false, 17 - exportServices: false, 18 17 format: false, 19 18 input: '', 20 19 lint: false, 21 20 operationId: true, 22 21 output: '', 23 - postfixServices: '', 24 22 schemas: false, 25 23 serviceResponse: 'body', 24 + services: { 25 + export: false, 26 + }, 26 27 types: { 27 28 export: false, 28 29 }, ··· 36 37 dryRun: true, 37 38 enums: false, 38 39 exportCore: false, 39 - exportServices: false, 40 40 format: false, 41 41 input: '', 42 42 lint: false, 43 43 operationId: false, 44 44 output: '', 45 - postfixServices: '', 46 45 schemas: false, 47 46 serviceResponse: 'body', 47 + services: { 48 + export: false, 49 + }, 48 50 types: { 49 51 export: false, 50 52 },
+1 -2
packages/openapi-ts/src/openApi/v2/parser/__tests__/getServices.spec.ts
··· 11 11 dryRun: true, 12 12 enums: false, 13 13 exportCore: true, 14 - exportServices: true, 15 14 format: false, 16 15 input: '', 17 16 lint: false, 18 17 operationId: false, 19 18 output: '', 20 - postfixServices: 'Service', 21 19 schemas: true, 22 20 serviceResponse: 'body', 21 + services: {}, 23 22 types: {}, 24 23 useDateType: false, 25 24 useOptions: true,
+1 -2
packages/openapi-ts/src/openApi/v3/parser/__tests__/getServices.spec.ts
··· 11 11 dryRun: true, 12 12 enums: false, 13 13 exportCore: true, 14 - exportServices: true, 15 14 format: false, 16 15 input: '', 17 16 lint: false, 18 17 operationId: true, 19 18 output: '', 20 - postfixServices: 'Service', 21 19 schemas: true, 22 20 serviceResponse: 'body', 21 + services: {}, 23 22 types: {}, 24 23 useDateType: false, 25 24 useOptions: true,
+4 -4
packages/openapi-ts/src/templates/client.hbs
··· 16 16 17 17 {{#if services}} 18 18 {{#each services}} 19 - import { {{{name}}}{{{@root.$config.postfixServices}}} } from './services.gen'; 19 + import { {{{transformServiceName name}}} } from './services.gen'; 20 20 {{/each}} 21 21 {{/if}} 22 22 ··· 46 46 useClass: AngularHttpRequest, 47 47 }, 48 48 {{#each services}} 49 - {{{name}}}{{{@root.$config.postfixServices}}}, 49 + {{{transformServiceName name}}}, 50 50 {{/each}} 51 51 ] 52 52 }) ··· 57 57 export class {{{@root.$config.name}}} { 58 58 59 59 {{#each services}} 60 - public readonly {{{camelCase name}}}: {{{name}}}{{{@root.$config.postfixServices}}}; 60 + public readonly {{{camelCase name}}}: {{{transformServiceName name}}}; 61 61 {{/each}} 62 62 63 63 public readonly request: BaseHttpRequest; ··· 80 80 }); 81 81 82 82 {{#each services}} 83 - this.{{{camelCase name}}} = new {{{name}}}{{{@root.$config.postfixServices}}}(this.request); 83 + this.{{{camelCase name}}} = new {{{transformServiceName name}}}(this.request); 84 84 {{/each}} 85 85 } 86 86 }
+25 -11
packages/openapi-ts/src/types/config.ts
··· 29 29 */ 30 30 exportCore?: boolean; 31 31 /** 32 - * Generate services? 33 - * @default true 34 - */ 35 - exportServices?: boolean | string; 36 - /** 37 32 * Process output folder with formatter? 38 33 * @default true 39 34 */ ··· 61 56 */ 62 57 output: string; 63 58 /** 64 - * Service name postfix 65 - * @default 'Service' 66 - */ 67 - postfixServices?: string; 68 - /** 69 59 * Path to custom request file 70 60 */ 71 61 request?: string; ··· 80 70 */ 81 71 serviceResponse?: 'body' | 'response'; 82 72 /** 73 + * Generate services? 74 + * @default true 75 + */ 76 + services?: 77 + | boolean 78 + | string 79 + | { 80 + /** 81 + * Generate services? 82 + * @default true 83 + */ 84 + export?: boolean; 85 + /** 86 + * Include only services matching regular expression 87 + */ 88 + include?: string; 89 + /** 90 + * Use your preferred naming pattern 91 + * @default '{{name}}Service' 92 + */ 93 + name?: string; 94 + }; 95 + /** 83 96 * Generate types? 84 97 * @default true 85 98 */ ··· 116 129 117 130 export type Config = Omit< 118 131 Required<UserConfig>, 119 - 'base' | 'name' | 'request' | 'types' 132 + 'base' | 'name' | 'request' | 'services' | 'types' 120 133 > & 121 134 Pick<UserConfig, 'base' | 'name' | 'request'> & { 135 + services: Extract<Required<UserConfig>['services'], object>; 122 136 types: Extract<Required<UserConfig>['types'], object>; 123 137 };
+3 -4
packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts
··· 15 15 dryRun: false, 16 16 enums: 'javascript', 17 17 exportCore: true, 18 - exportServices: true, 19 18 format: true, 20 19 input: '', 21 20 lint: false, 22 21 operationId: true, 23 22 output: '', 24 - postfixServices: '', 25 23 schemas: true, 26 24 serviceResponse: 'body', 25 + services: {}, 27 26 types: {}, 28 27 useDateType: false, 29 28 useOptions: false, ··· 34 33 expect(helpers).toContain('equals'); 35 34 expect(helpers).toContain('ifdef'); 36 35 expect(helpers).toContain('notEquals'); 36 + expect(helpers).toContain('transformServiceName'); 37 37 }); 38 38 }); 39 39 ··· 45 45 dryRun: false, 46 46 enums: 'javascript', 47 47 exportCore: true, 48 - exportServices: true, 49 48 format: true, 50 49 input: '', 51 50 lint: false, 52 51 operationId: true, 53 52 output: '', 54 - postfixServices: '', 55 53 schemas: true, 56 54 serviceResponse: 'body', 55 + services: {}, 57 56 types: {}, 58 57 useDateType: false, 59 58 useOptions: false,
+3
packages/openapi-ts/src/utils/handlebars.ts
··· 45 45 import xhrGetResponseHeader from '../templates/core/xhr/getResponseHeader.hbs'; 46 46 import xhrRequest from '../templates/core/xhr/request.hbs'; 47 47 import xhrSendRequest from '../templates/core/xhr/sendRequest.hbs'; 48 + import { transformServiceName } from './transform'; 48 49 49 50 export const registerHandlebarHelpers = (): void => { 50 51 Handlebars.registerHelper('camelCase', camelCase); ··· 80 81 return a !== b ? options.fn(this) : options.inverse(this); 81 82 }, 82 83 ); 84 + 85 + Handlebars.registerHelper('transformServiceName', transformServiceName); 83 86 }; 84 87 85 88 export interface Templates {
+9 -1
packages/openapi-ts/src/utils/transform.ts
··· 2 2 3 3 import { getConfig } from './config'; 4 4 5 - export const transformName = (name: string) => { 5 + export const transformServiceName = (name: string) => { 6 + const config = getConfig(); 7 + if (config.services.name) { 8 + return config.services.name.replace('{{name}}', name); 9 + } 10 + return name; 11 + }; 12 + 13 + export const transformTypeName = (name: string) => { 6 14 const config = getConfig(); 7 15 if (config.types.name === 'PascalCase') { 8 16 return camelcase(name, { pascalCase: true });
+1 -2
packages/openapi-ts/src/utils/write/__tests__/class.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportServices: true, 21 20 format: false, 22 21 input: '', 23 22 lint: false, 24 23 name: 'AppClient', 25 24 operationId: true, 26 25 output: '', 27 - postfixServices: '', 28 26 schemas: true, 29 27 serviceResponse: 'body', 28 + services: {}, 30 29 types: {}, 31 30 useDateType: false, 32 31 useOptions: true,
+1 -2
packages/openapi-ts/src/utils/write/__tests__/client.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportServices: true, 21 20 format: true, 22 21 input: '', 23 22 lint: false, 24 23 operationId: true, 25 24 output: './dist', 26 - postfixServices: 'Service', 27 25 schemas: true, 28 26 serviceResponse: 'body', 27 + services: {}, 29 28 types: {}, 30 29 useDateType: false, 31 30 useOptions: false,
+3 -6
packages/openapi-ts/src/utils/write/__tests__/core.spec.ts
··· 31 31 dryRun: false, 32 32 enums: 'javascript', 33 33 exportCore: true, 34 - exportServices: true, 35 34 format: false, 36 35 input: '', 37 36 lint: false, 38 37 name: 'AppClient', 39 38 operationId: true, 40 39 output: '', 41 - postfixServices: '', 42 40 schemas: true, 43 41 serviceResponse: 'body', 42 + services: {}, 44 43 types: {}, 45 44 useDateType: false, 46 45 useOptions: true, ··· 89 88 dryRun: false, 90 89 enums: 'javascript', 91 90 exportCore: true, 92 - exportServices: true, 93 91 format: false, 94 92 input: '', 95 93 lint: false, 96 94 name: 'AppClient', 97 95 operationId: true, 98 96 output: '', 99 - postfixServices: '', 100 97 schemas: true, 101 98 serviceResponse: 'body', 99 + services: {}, 102 100 types: {}, 103 101 useDateType: false, 104 102 useOptions: true, ··· 130 128 dryRun: false, 131 129 enums: 'javascript', 132 130 exportCore: true, 133 - exportServices: true, 134 131 format: false, 135 132 input: '', 136 133 lint: false, 137 134 name: 'AppClient', 138 135 operationId: true, 139 136 output: '', 140 - postfixServices: '', 141 137 schemas: true, 142 138 serviceResponse: 'body', 139 + services: {}, 143 140 types: {}, 144 141 useDateType: false, 145 142 useOptions: true,
+1 -2
packages/openapi-ts/src/utils/write/__tests__/index.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportServices: true, 21 20 format: false, 22 21 input: '', 23 22 lint: false, 24 23 operationId: true, 25 24 output: '', 26 - postfixServices: 'Service', 27 25 schemas: true, 28 26 serviceResponse: 'body', 27 + services: {}, 29 28 types: {}, 30 29 useDateType: false, 31 30 useOptions: true,
+1 -2
packages/openapi-ts/src/utils/write/__tests__/models.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - exportServices: true, 21 20 format: false, 22 21 input: '', 23 22 lint: false, 24 23 name: 'AppClient', 25 24 operationId: true, 26 25 output: '', 27 - postfixServices: '', 28 26 schemas: true, 29 27 serviceResponse: 'body', 28 + services: {}, 30 29 types: {}, 31 30 useDateType: false, 32 31 useOptions: true,
+1 -2
packages/openapi-ts/src/utils/write/__tests__/schemas.spec.ts
··· 18 18 dryRun: false, 19 19 enums: 'javascript', 20 20 exportCore: true, 21 - exportServices: true, 22 21 format: false, 23 22 input: '', 24 23 lint: false, 25 24 name: 'AppClient', 26 25 operationId: true, 27 26 output: '', 28 - postfixServices: '', 29 27 schemas: true, 30 28 serviceResponse: 'body', 29 + services: {}, 31 30 types: {}, 32 31 useDateType: false, 33 32 useOptions: true,
+1 -2
packages/openapi-ts/src/utils/write/__tests__/services.spec.ts
··· 17 17 dryRun: false, 18 18 enums: false, 19 19 exportCore: true, 20 - exportServices: true, 21 20 format: false, 22 21 input: '', 23 22 lint: false, 24 23 operationId: true, 25 24 output: '', 26 - postfixServices: 'Service', 27 25 schemas: true, 28 26 serviceResponse: 'body', 27 + services: {}, 29 28 types: {}, 30 29 useDateType: false, 31 30 useOptions: false,
+3 -3
packages/openapi-ts/src/utils/write/client.ts
··· 26 26 ): Promise<void> => { 27 27 const config = getConfig(); 28 28 29 - if (typeof config.exportServices === 'string') { 30 - const regexp = new RegExp(config.exportServices); 29 + if (config.services.include) { 30 + const regexp = new RegExp(config.services.include); 31 31 client.services = client.services.filter((service) => 32 32 regexp.test(service.name), 33 33 ); ··· 62 62 name: 'schemas.ts', 63 63 }); 64 64 } 65 - if (config.exportServices) { 65 + if (config.services.export) { 66 66 files.services = new TypeScriptFile({ 67 67 dir: config.output, 68 68 name: 'services.ts',
+2 -2
packages/openapi-ts/src/utils/write/models.ts
··· 12 12 import { enumKey, enumName, enumUnionType, enumValue } from '../enum'; 13 13 import { escapeComment } from '../escape'; 14 14 import { sortByName } from '../sort'; 15 - import { transformName } from '../transform'; 15 + import { transformTypeName } from '../transform'; 16 16 import { serviceExportedNamespace } from './services'; 17 17 import { toType } from './type'; 18 18 ··· 111 111 model.deprecated && '@deprecated', 112 112 ]; 113 113 const node = compiler.typedef.alias( 114 - transformName(model.name), 114 + transformTypeName(model.name), 115 115 toType(model), 116 116 comment, 117 117 );
+2 -1
packages/openapi-ts/src/utils/write/services.ts
··· 9 9 import { getConfig } from '../config'; 10 10 import { escapeComment, escapeDescription, escapeName } from '../escape'; 11 11 import { modelIsRequired } from '../required'; 12 + import { transformServiceName } from '../transform'; 12 13 import { unique } from '../unique'; 13 14 14 15 export const serviceExportedNamespace = () => '$OpenApiTs'; ··· 260 261 ? { args: [{ providedIn: 'root' }], name: 'Injectable' } 261 262 : undefined, 262 263 members, 263 - name: `${service.name}${config.postfixServices}`, 264 + name: transformServiceName(service.name), 264 265 }); 265 266 }; 266 267
+2 -2
packages/openapi-ts/src/utils/write/type.ts
··· 4 4 import { enumValue } from '../enum'; 5 5 import { escapeComment } from '../escape'; 6 6 import { modelIsRequired } from '../required'; 7 - import { transformName } from '../transform'; 7 + import { transformTypeName } from '../transform'; 8 8 import { unique } from '../unique'; 9 9 10 10 const base = (model: Model) => { ··· 18 18 // transform root level model names 19 19 if (model.base === model.type && model.$refs.length) { 20 20 if (model.$refs.some((ref) => ref.endsWith(model.base))) { 21 - return compiler.typedef.basic(transformName(model.base)); 21 + return compiler.typedef.basic(transformTypeName(model.base)); 22 22 } 23 23 } 24 24 return compiler.typedef.basic(model.base);
+3
packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/index.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export * from './services.gen';
+229
packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { CancelablePromise } from './core/CancelablePromise'; 4 + import { OpenAPI } from './core/OpenAPI'; 5 + import { request as __request } from './core/request'; 6 + 7 + export class myAwesomeSimpleApi { 8 + /** 9 + * @returns Model_From_Zendesk Success 10 + * @throws ApiError 11 + */ 12 + public static apiVVersionOdataControllerCount(): CancelablePromise< 13 + $OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200] 14 + > { 15 + return __request(OpenAPI, { 16 + method: 'GET', 17 + url: '/api/v{api-version}/simple/$count', 18 + }); 19 + } 20 + 21 + /** 22 + * @throws ApiError 23 + */ 24 + public static getCallWithoutParametersAndResponse(): CancelablePromise<void> { 25 + return __request(OpenAPI, { 26 + method: 'GET', 27 + url: '/api/v{api-version}/simple', 28 + }); 29 + } 30 + 31 + /** 32 + * @throws ApiError 33 + */ 34 + public static putCallWithoutParametersAndResponse(): CancelablePromise<void> { 35 + return __request(OpenAPI, { 36 + method: 'PUT', 37 + url: '/api/v{api-version}/simple', 38 + }); 39 + } 40 + 41 + /** 42 + * @throws ApiError 43 + */ 44 + public static postCallWithoutParametersAndResponse(): CancelablePromise<void> { 45 + return __request(OpenAPI, { 46 + method: 'POST', 47 + url: '/api/v{api-version}/simple', 48 + }); 49 + } 50 + 51 + /** 52 + * @throws ApiError 53 + */ 54 + public static deleteCallWithoutParametersAndResponse(): CancelablePromise<void> { 55 + return __request(OpenAPI, { 56 + method: 'DELETE', 57 + url: '/api/v{api-version}/simple', 58 + }); 59 + } 60 + 61 + /** 62 + * @throws ApiError 63 + */ 64 + public static optionsCallWithoutParametersAndResponse(): CancelablePromise<void> { 65 + return __request(OpenAPI, { 66 + method: 'OPTIONS', 67 + url: '/api/v{api-version}/simple', 68 + }); 69 + } 70 + 71 + /** 72 + * @throws ApiError 73 + */ 74 + public static headCallWithoutParametersAndResponse(): CancelablePromise<void> { 75 + return __request(OpenAPI, { 76 + method: 'HEAD', 77 + url: '/api/v{api-version}/simple', 78 + }); 79 + } 80 + 81 + /** 82 + * @throws ApiError 83 + */ 84 + public static patchCallWithoutParametersAndResponse(): CancelablePromise<void> { 85 + return __request(OpenAPI, { 86 + method: 'PATCH', 87 + url: '/api/v{api-version}/simple', 88 + }); 89 + } 90 + } 91 + 92 + export class myAwesomeParametersApi { 93 + /** 94 + * @throws ApiError 95 + */ 96 + public static deleteFoo( 97 + data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req'], 98 + ): CancelablePromise<void> { 99 + const { foo, bar } = data; 100 + return __request(OpenAPI, { 101 + method: 'DELETE', 102 + url: '/api/v{api-version}/foo/{foo}/bar/{bar}', 103 + path: { 104 + foo, 105 + bar, 106 + }, 107 + }); 108 + } 109 + 110 + /** 111 + * @throws ApiError 112 + */ 113 + public static callWithParameters( 114 + data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req'], 115 + ): CancelablePromise<void> { 116 + const { 117 + parameterHeader, 118 + fooAllOfEnum, 119 + parameterQuery, 120 + parameterForm, 121 + parameterCookie, 122 + parameterPath, 123 + requestBody, 124 + fooRefEnum, 125 + } = data; 126 + return __request(OpenAPI, { 127 + method: 'POST', 128 + url: '/api/v{api-version}/parameters/{parameterPath}', 129 + path: { 130 + parameterPath, 131 + }, 132 + cookies: { 133 + parameterCookie, 134 + }, 135 + headers: { 136 + parameterHeader, 137 + }, 138 + query: { 139 + foo_ref_enum: fooRefEnum, 140 + foo_all_of_enum: fooAllOfEnum, 141 + parameterQuery, 142 + }, 143 + formData: { 144 + parameterForm, 145 + }, 146 + body: requestBody, 147 + mediaType: 'application/json', 148 + }); 149 + } 150 + 151 + /** 152 + * @throws ApiError 153 + */ 154 + public static callWithWeirdParameterNames( 155 + data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req'], 156 + ): CancelablePromise<void> { 157 + const { 158 + parameterHeader, 159 + parameterQuery, 160 + parameterForm, 161 + parameterCookie, 162 + requestBody, 163 + parameterPath1, 164 + parameterPath2, 165 + parameterPath3, 166 + _default, 167 + } = data; 168 + return __request(OpenAPI, { 169 + method: 'POST', 170 + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 171 + path: { 172 + 'parameter.path.1': parameterPath1, 173 + 'parameter-path-2': parameterPath2, 174 + 'PARAMETER-PATH-3': parameterPath3, 175 + }, 176 + cookies: { 177 + 'PARAMETER-COOKIE': parameterCookie, 178 + }, 179 + headers: { 180 + 'parameter.header': parameterHeader, 181 + }, 182 + query: { 183 + default: _default, 184 + 'parameter-query': parameterQuery, 185 + }, 186 + formData: { 187 + parameter_form: parameterForm, 188 + }, 189 + body: requestBody, 190 + mediaType: 'application/json', 191 + }); 192 + } 193 + 194 + /** 195 + * @throws ApiError 196 + */ 197 + public static getCallWithOptionalParam( 198 + data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req'], 199 + ): CancelablePromise<void> { 200 + const { requestBody, parameter } = data; 201 + return __request(OpenAPI, { 202 + method: 'GET', 203 + url: '/api/v{api-version}/parameters/', 204 + query: { 205 + parameter, 206 + }, 207 + body: requestBody, 208 + mediaType: 'application/json', 209 + }); 210 + } 211 + 212 + /** 213 + * @throws ApiError 214 + */ 215 + public static postCallWithOptionalParam( 216 + data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req'], 217 + ): CancelablePromise<void> { 218 + const { parameter, requestBody } = data; 219 + return __request(OpenAPI, { 220 + method: 'POST', 221 + url: '/api/v{api-version}/parameters/', 222 + query: { 223 + parameter, 224 + }, 225 + body: requestBody, 226 + mediaType: 'application/json', 227 + }); 228 + } 229 + }
+8 -8
packages/openapi-ts/test/bin.spec.ts
··· 109 109 '--useOptions', 110 110 '--exportCore', 111 111 'true', 112 - '--exportServices', 112 + '--services', 113 113 'true', 114 114 '--types', 115 115 'true', ··· 129 129 './test/spec/v3.json', 130 130 '--output', 131 131 './test/generated/bin', 132 - '--exportServices', 132 + '--services', 133 133 '^(Simple|Types)', 134 134 '--types', 135 135 '^(Simple|Types)', ··· 217 217 'false', 218 218 '--schemas', 219 219 'false', 220 - '--exportServices', 220 + '--services', 221 221 'false', 222 222 '--format', 223 223 'false', ··· 236 236 expect(result.stderr.toString()).toContain('dryRun: true'); 237 237 expect(result.stderr.toString()).toContain('exportCore: false'); 238 238 expect(result.stderr.toString()).toContain('types: false'); 239 - expect(result.stderr.toString()).toContain('exportServices: false'); 239 + expect(result.stderr.toString()).toContain('services: false'); 240 240 expect(result.stderr.toString()).toContain('format: false'); 241 241 expect(result.stderr.toString()).toContain('lint: false'); 242 242 expect(result.stderr.toString()).toContain('operationId: false'); ··· 259 259 'true', 260 260 '--schemas', 261 261 'true', 262 - '--exportServices', 262 + '--services', 263 263 'true', 264 264 '--format', 265 265 'true', ··· 278 278 expect(result.stderr.toString()).toContain('dryRun: true'); 279 279 expect(result.stderr.toString()).toContain('exportCore: true'); 280 280 expect(result.stderr.toString()).toContain('types: true'); 281 - expect(result.stderr.toString()).toContain('exportServices: true'); 281 + expect(result.stderr.toString()).toContain('services: true'); 282 282 expect(result.stderr.toString()).toContain('format: true'); 283 283 expect(result.stderr.toString()).toContain('lint: true'); 284 284 expect(result.stderr.toString()).toContain('operationId: true'); ··· 299 299 '--types', 300 300 'foo', 301 301 '--schemas', 302 - '--exportServices', 302 + '--services', 303 303 'bar', 304 304 '--format', 305 305 '--lint', ··· 319 319 expect(result.stderr.toString()).toContain('useDateType: true'); 320 320 expect(result.stderr.toString()).toContain('useOptions: true'); 321 321 expect(result.stderr.toString()).toContain("types: 'foo"); 322 - expect(result.stderr.toString()).toContain("exportServices: 'bar'"); 322 + expect(result.stderr.toString()).toContain("services: 'bar'"); 323 323 }); 324 324 });
+26 -11
packages/openapi-ts/test/index.spec.ts
··· 22 22 client: 'fetch', 23 23 enums: 'javascript', 24 24 exportCore: true, 25 - exportServices: true, 26 25 input: '', 27 26 output: '', 28 27 schemas: true, 28 + services: true, 29 29 types: true, 30 30 useOptions: true, 31 31 } as UserConfig, ··· 51 51 client: 'fetch', 52 52 enums: 'javascript', 53 53 exportCore: true, 54 - exportServices: true, 55 54 input: '', 56 55 output: '', 57 56 schemas: true, 57 + services: true, 58 58 types: true, 59 59 useOptions: true, 60 60 }; ··· 82 82 ...config, 83 83 client: 'node', 84 84 enums: false, 85 - exportServices: false, 86 85 schemas: false, 86 + services: false, 87 87 types: false, 88 88 } as UserConfig, 89 89 description: 'generate node client', ··· 94 94 ...config, 95 95 client: 'axios', 96 96 enums: false, 97 - exportServices: false, 98 97 schemas: false, 98 + services: false, 99 99 types: false, 100 100 } as UserConfig, 101 101 description: 'generate axios client', ··· 106 106 ...config, 107 107 client: 'xhr', 108 108 enums: false, 109 - exportServices: false, 110 109 schemas: false, 110 + services: false, 111 111 types: false, 112 112 } as UserConfig, 113 113 description: 'generate xhr client', ··· 117 117 config: { 118 118 ...config, 119 119 exportCore: false, 120 - exportServices: false, 121 120 schemas: false, 121 + services: false, 122 122 types: '^ModelWithPattern', 123 123 useDateType: true, 124 124 } as UserConfig, ··· 128 128 { 129 129 config: { 130 130 ...config, 131 - exportServices: '^Defaults', 132 131 schemas: false, 132 + services: '^Defaults', 133 133 types: '^ModelWithString', 134 134 useDateType: true, 135 135 useOptions: false, ··· 140 140 { 141 141 config: { 142 142 ...config, 143 - exportServices: '^Defaults', 144 143 schemas: false, 144 + services: '^Defaults', 145 145 types: '^ModelWithString', 146 146 useDateType: true, 147 147 } as UserConfig, ··· 172 172 ...config, 173 173 enums: false, 174 174 exportCore: false, 175 - exportServices: false, 176 175 schemas: false, 176 + services: false, 177 177 } as UserConfig, 178 178 description: 'generate models', 179 179 name: 'v3_models', ··· 183 183 ...config, 184 184 enums: false, 185 185 exportCore: false, 186 - exportServices: false, 187 186 schemas: false, 187 + services: false, 188 188 types: { 189 189 include: '^(camelCaseCommentWithBreaks|ArrayWithProperties)', 190 190 name: 'PascalCase', ··· 198 198 ...config, 199 199 enums: false, 200 200 exportCore: false, 201 - exportServices: false, 201 + schemas: false, 202 + services: { 203 + include: '^(Simple|Parameters)', 204 + name: 'myAwesome{{name}}Api', 205 + }, 206 + types: false, 207 + } as UserConfig, 208 + description: 'generate services with custom name', 209 + name: 'v3_services_name', 210 + }, 211 + { 212 + config: { 213 + ...config, 214 + enums: false, 215 + exportCore: false, 202 216 schemas: true, 217 + services: false, 203 218 types: false, 204 219 } as UserConfig, 205 220 description: 'generate JSON Schemas',