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

chore: remove fastify dependency on services

Lubos 8a15a35e 4a939d16

+198 -1033
+5
.changeset/honest-rings-obey.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: deprecate types.tree option
+2 -26
packages/openapi-ts/src/index.ts
··· 8 8 import { generateLegacyOutput, generateOutput } from './generate/output'; 9 9 import type { IRContext } from './ir/context'; 10 10 import { parseExperimental, parseLegacy } from './openApi'; 11 - import type { ParserConfig } from './openApi/config'; 12 - import { 13 - operationFilterFn, 14 - operationNameFn, 15 - operationParameterFilterFn, 16 - operationParameterNameFn, 17 - } from './openApi/config'; 18 11 import type { ClientPlugins } from './plugins'; 19 12 import { defaultPluginConfigs } from './plugins'; 20 13 import type { DefaultPluginConfigsMap, PluginNames } from './plugins/types'; ··· 413 406 let context: IRContext | undefined; 414 407 415 408 Performance.start('parser'); 416 - const parserConfig: ParserConfig = { 417 - filterFn: { 418 - operation: operationFilterFn, 419 - operationParameter: operationParameterFilterFn, 420 - }, 421 - nameFn: { 422 - operation: operationNameFn, 423 - operationParameter: operationParameterNameFn, 424 - }, 425 - }; 426 409 if ( 427 410 config.experimentalParser && 428 411 !isLegacyClient(config) && 429 412 !legacyNameFromConfig(config) 430 413 ) { 431 - context = parseExperimental({ 432 - config, 433 - parserConfig, 434 - spec, 435 - }); 414 + context = parseExperimental({ config, spec }); 436 415 } 437 416 438 417 // fallback to legacy parser 439 418 if (!context) { 440 - const parsed = parseLegacy({ 441 - openApi: spec, 442 - parserConfig, 443 - }); 419 + const parsed = parseLegacy({ openApi: spec }); 444 420 client = postProcessClient(parsed); 445 421 } 446 422 Performance.end('parser');
+1 -12
packages/openapi-ts/src/ir/context.ts
··· 1 1 import path from 'node:path'; 2 2 3 3 import { TypeScriptFile } from '../generate/files'; 4 - import type { ParserConfig } from '../openApi/config'; 5 4 import type { Config } from '../types/config'; 6 5 import type { Files } from '../types/utils'; 7 6 import { resolveRef } from '../utils/ref'; ··· 34 33 * Intermediate representation model obtained from `spec`. 35 34 */ 36 35 public ir: IR; 37 - public parserConfig: ParserConfig; 38 36 /** 39 37 * Resolved specification from `input`. 40 38 */ 41 39 public spec: Spec; 42 40 43 - constructor({ 44 - config, 45 - parserConfig, 46 - spec, 47 - }: { 48 - config: Config; 49 - parserConfig: ParserConfig; 50 - spec: Spec; 51 - }) { 41 + constructor({ config, spec }: { config: Config; spec: Spec }) { 52 42 this.config = config; 53 43 this.files = {}; 54 44 this.ir = {}; 55 - this.parserConfig = parserConfig; 56 45 this.spec = spec; 57 46 } 58 47
+4 -3
packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
··· 1 1 import type { IRContext } from '../../../ir/context'; 2 2 import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; 3 + import { operationToId } from '../../shared/utils/operation'; 3 4 import type { 4 5 OperationObject, 5 6 PathItemObject, ··· 205 206 context.ir.paths[path] = {}; 206 207 } 207 208 208 - operation.id = context.parserConfig.nameFn.operation({ 209 - config: context.config, 209 + operation.id = operationToId({ 210 + context, 211 + id: operation.operationId, 210 212 method, 211 - operationId: operation.operationId, 212 213 path, 213 214 }); 214 215
+4 -3
packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
··· 1 1 import type { IRContext } from '../../../ir/context'; 2 2 import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; 3 + import { operationToId } from '../../shared/utils/operation'; 3 4 import type { 4 5 OperationObject, 5 6 PathItemObject, ··· 193 194 context.ir.paths[path] = {}; 194 195 } 195 196 196 - operation.id = context.parserConfig.nameFn.operation({ 197 - config: context.config, 197 + operation.id = operationToId({ 198 + context, 199 + id: operation.operationId, 198 200 method, 199 - operationId: operation.operationId, 200 201 path, 201 202 }); 202 203
+6 -27
packages/openapi-ts/src/openApi/__tests__/index.spec.ts
··· 5 5 import { parseV3_0_X } from '../3.0.x'; 6 6 import type { OpenApiV3_1_X } from '../3.1.x'; 7 7 import { parseV3_1_X } from '../3.1.x'; 8 - import type { ParserConfig } from '../config'; 9 8 import * as parseV2 from '../v2'; 10 9 import * as parseV3 from '../v3'; 11 10 ··· 16 15 parseV3_1_X: vi.fn(), 17 16 })); 18 17 19 - const parserConfig: ParserConfig = { 20 - filterFn: { 21 - operation: () => true, 22 - operationParameter: () => true, 23 - }, 24 - nameFn: { 25 - operation: () => 'operation', 26 - operationParameter: () => 'operationParameter', 27 - }, 28 - }; 29 - 30 18 describe('parse', () => { 31 19 afterEach(() => { 32 20 vi.restoreAllMocks(); ··· 43 31 paths: {}, 44 32 swagger: '2', 45 33 }; 46 - parseLegacy({ openApi: spec, parserConfig }); 34 + parseLegacy({ openApi: spec }); 47 35 expect(spy).toHaveBeenCalledWith(spec); 48 36 49 37 const spec2: OpenApi = { ··· 54 42 paths: {}, 55 43 swagger: '2.0', 56 44 }; 57 - parseLegacy({ openApi: spec2, parserConfig }); 45 + parseLegacy({ openApi: spec2 }); 58 46 expect(spy).toHaveBeenCalledWith(spec2); 59 47 }); 60 48 ··· 69 57 openapi: '3', 70 58 paths: {}, 71 59 }; 72 - parseLegacy({ openApi: spec, parserConfig }); 60 + parseLegacy({ openApi: spec }); 73 61 expect(spy).toHaveBeenCalledWith(spec); 74 62 75 63 const spec2: OpenApi = { ··· 80 68 openapi: '3.0', 81 69 paths: {}, 82 70 }; 83 - parseLegacy({ openApi: spec2, parserConfig }); 71 + parseLegacy({ openApi: spec2 }); 84 72 expect(spy).toHaveBeenCalledWith(spec2); 85 73 86 74 const spec3: OpenApi = { ··· 91 79 openapi: '3.1.0', 92 80 paths: {}, 93 81 }; 94 - parseLegacy({ openApi: spec3, parserConfig }); 82 + parseLegacy({ openApi: spec3 }); 95 83 expect(spy).toHaveBeenCalledWith(spec3); 96 84 }); 97 85 98 86 it('throws on unknown version', () => { 99 - expect(() => 100 - parseLegacy({ openApi: { foo: 'bar' }, parserConfig }), 101 - ).toThrow( 87 + expect(() => parseLegacy({ openApi: { foo: 'bar' } })).toThrow( 102 88 `Unsupported OpenAPI specification: ${JSON.stringify({ foo: 'bar' }, null, 2)}`, 103 89 ); 104 90 }); ··· 121 107 parseExperimental({ 122 108 // @ts-ignore 123 109 config: {}, 124 - parserConfig, 125 110 spec, 126 111 }); 127 112 expect(parseV3_0_X).toHaveBeenCalled(); ··· 139 124 parseExperimental({ 140 125 // @ts-ignore 141 126 config: {}, 142 - parserConfig, 143 127 spec, 144 128 }); 145 129 expect(parseV3_0_X).toHaveBeenCalled(); ··· 157 141 parseExperimental({ 158 142 // @ts-ignore 159 143 config: {}, 160 - parserConfig, 161 144 spec, 162 145 }); 163 146 expect(parseV3_0_X).toHaveBeenCalled(); ··· 175 158 parseExperimental({ 176 159 // @ts-ignore 177 160 config: {}, 178 - parserConfig, 179 161 spec, 180 162 }); 181 163 expect(parseV3_0_X).toHaveBeenCalled(); ··· 193 175 parseExperimental({ 194 176 // @ts-ignore 195 177 config: {}, 196 - parserConfig, 197 178 spec, 198 179 }); 199 180 expect(parseV3_0_X).toHaveBeenCalled(); ··· 210 191 parseExperimental({ 211 192 // @ts-ignore 212 193 config: {}, 213 - parserConfig, 214 194 spec, 215 195 }); 216 196 expect(parseV3_1_X).toHaveBeenCalled(); ··· 227 207 parseExperimental({ 228 208 // @ts-ignore 229 209 config: {}, 230 - parserConfig, 231 210 spec, 232 211 }); 233 212 expect(parseV3_1_X).toHaveBeenCalled();
+81
packages/openapi-ts/src/openApi/common/parser/operation.ts
··· 1 + import type { Config } from '../../../types/config'; 2 + import { camelCase } from '../../../utils/camelCase'; 3 + import { getConfig, isLegacyClient } from '../../../utils/config'; 4 + import { transformTypeKeyName } from '../../../utils/type'; 1 5 import type { 2 6 OperationParameter, 3 7 OperationResponse, 4 8 } from '../interfaces/client'; 9 + import { sanitizeNamespaceIdentifier } from './sanitize'; 5 10 6 11 export const getOperationKey = (operation: { 7 12 method: string; ··· 151 156 } 152 157 153 158 return types; 159 + }; 160 + 161 + export const operationFilterFn = ({ 162 + config, 163 + operationKey, 164 + }: { 165 + config: Config; 166 + operationKey: string; 167 + }): boolean => { 168 + const regexp = config.plugins['@hey-api/services']?.filter 169 + ? new RegExp(config.plugins['@hey-api/services']?.filter) 170 + : undefined; 171 + return !regexp || regexp.test(operationKey); 172 + }; 173 + 174 + /** 175 + * Convert the input value to a correct operation (method) class name. 176 + * This will use the operation ID - if available - and otherwise fallback 177 + * on a generated name from the URL 178 + */ 179 + export const operationNameFn = ({ 180 + config, 181 + method, 182 + operationId, 183 + path, 184 + }: { 185 + config: Config; 186 + method: string; 187 + operationId: string | undefined; 188 + path: string; 189 + }): string => { 190 + if (config.plugins['@hey-api/services']?.operationId && operationId) { 191 + return camelCase({ 192 + input: sanitizeNamespaceIdentifier(operationId), 193 + }); 194 + } 195 + 196 + let urlWithoutPlaceholders = path; 197 + 198 + // legacy clients ignore the "api-version" param since we do not want to 199 + // add it as the first/default parameter for each of the service calls 200 + if (isLegacyClient(config)) { 201 + urlWithoutPlaceholders = urlWithoutPlaceholders.replace( 202 + /[^/]*?{api-version}.*?\//g, 203 + '', 204 + ); 205 + } 206 + 207 + urlWithoutPlaceholders = urlWithoutPlaceholders 208 + .replace(/{(.*?)}/g, 'by-$1') 209 + // replace slashes with hyphens for camelcase method at the end 210 + .replace(/[/:]/g, '-'); 211 + 212 + return camelCase({ 213 + input: `${method}-${urlWithoutPlaceholders}`, 214 + }); 215 + }; 216 + 217 + export const operationParameterFilterFn = ( 218 + parameter: OperationParameter, 219 + ): boolean => { 220 + const config = getConfig(); 221 + 222 + // legacy clients ignore the "api-version" param since we do not want to 223 + // add it as the first/default parameter for each of the service calls 224 + return !isLegacyClient(config) || parameter.prop !== 'api-version'; 225 + }; 226 + 227 + export const operationParameterNameFn = ( 228 + parameter: Omit<OperationParameter, 'name'>, 229 + ): string => { 230 + const config = getConfig(); 231 + 232 + return !isLegacyClient(config) 233 + ? parameter.prop 234 + : transformTypeKeyName(parameter.prop); 154 235 }; 155 236 156 237 export const tagResponseTypes = (responses: OperationResponse[]) =>
-103
packages/openapi-ts/src/openApi/config.ts
··· 1 - import type { Config } from '../types/config'; 2 - import { camelCase } from '../utils/camelCase'; 3 - import { getConfig, isLegacyClient } from '../utils/config'; 4 - import { transformTypeKeyName } from '../utils/type'; 5 - import type { OperationParameter } from './common/interfaces/client'; 6 - import { sanitizeNamespaceIdentifier } from './common/parser/sanitize'; 7 - 8 - export interface ParserConfig { 9 - debug?: boolean; 10 - filterFn: { 11 - operation: typeof operationFilterFn; 12 - operationParameter: typeof operationParameterFilterFn; 13 - }; 14 - nameFn: { 15 - operation: typeof operationNameFn; 16 - operationParameter: typeof operationParameterNameFn; 17 - }; 18 - } 19 - 20 - let _config: ParserConfig; 21 - 22 - export const getParserConfig = () => _config; 23 - 24 - export const setParserConfig = (config: ParserConfig) => { 25 - _config = config; 26 - return getParserConfig(); 27 - }; 28 - 29 - export const operationFilterFn = ({ 30 - config, 31 - operationKey, 32 - }: { 33 - config: Config; 34 - operationKey: string; 35 - }): boolean => { 36 - const regexp = config.plugins['@hey-api/services']?.filter 37 - ? new RegExp(config.plugins['@hey-api/services']?.filter) 38 - : undefined; 39 - return !regexp || regexp.test(operationKey); 40 - }; 41 - 42 - export const operationParameterFilterFn = ( 43 - parameter: OperationParameter, 44 - ): boolean => { 45 - const config = getConfig(); 46 - 47 - // legacy clients ignore the "api-version" param since we do not want to 48 - // add it as the first/default parameter for each of the service calls 49 - return !isLegacyClient(config) || parameter.prop !== 'api-version'; 50 - }; 51 - 52 - /** 53 - * Convert the input value to a correct operation (method) class name. 54 - * This will use the operation ID - if available - and otherwise fallback 55 - * on a generated name from the URL 56 - */ 57 - export const operationNameFn = ({ 58 - config, 59 - method, 60 - operationId, 61 - path, 62 - }: { 63 - config: Config; 64 - method: string; 65 - operationId: string | undefined; 66 - path: string; 67 - }): string => { 68 - if (config.plugins['@hey-api/services']?.operationId && operationId) { 69 - return camelCase({ 70 - input: sanitizeNamespaceIdentifier(operationId), 71 - }); 72 - } 73 - 74 - let urlWithoutPlaceholders = path; 75 - 76 - // legacy clients ignore the "api-version" param since we do not want to 77 - // add it as the first/default parameter for each of the service calls 78 - if (isLegacyClient(config)) { 79 - urlWithoutPlaceholders = urlWithoutPlaceholders.replace( 80 - /[^/]*?{api-version}.*?\//g, 81 - '', 82 - ); 83 - } 84 - 85 - urlWithoutPlaceholders = urlWithoutPlaceholders 86 - .replace(/{(.*?)}/g, 'by-$1') 87 - // replace slashes with hyphens for camelcase method at the end 88 - .replace(/[/:]/g, '-'); 89 - 90 - return camelCase({ 91 - input: `${method}-${urlWithoutPlaceholders}`, 92 - }); 93 - }; 94 - 95 - export const operationParameterNameFn = ( 96 - parameter: Omit<OperationParameter, 'name'>, 97 - ): string => { 98 - const config = getConfig(); 99 - 100 - return !isLegacyClient(config) 101 - ? parameter.prop 102 - : transformTypeKeyName(parameter.prop); 103 - };
+1 -14
packages/openapi-ts/src/openApi/index.ts
··· 4 4 import { type OpenApiV3_1_X, parseV3_1_X } from './3.1.x'; 5 5 import type { Client } from './common/interfaces/client'; 6 6 import type { OpenApi } from './common/interfaces/OpenApi'; 7 - import type { ParserConfig } from './config'; 8 - import { setParserConfig } from './config'; 9 7 import { parse as parseV2 } from './v2'; 10 8 import { parse as parseV3 } from './v3'; 11 9 ··· 35 33 * all the models, services and schema's we should output. 36 34 * @param openApi The OpenAPI spec that we have loaded from disk. 37 35 */ 38 - export function parseLegacy({ 39 - openApi, 40 - parserConfig, 41 - }: { 42 - openApi: unknown; 43 - parserConfig: ParserConfig; 44 - }): Client { 36 + export function parseLegacy({ openApi }: { openApi: unknown }): Client { 45 37 const spec = openApi as OpenApi; 46 - 47 - setParserConfig(parserConfig); 48 38 49 39 if ('openapi' in spec) { 50 40 return parseV3(spec); ··· 62 52 // TODO: parser - add JSDoc comment 63 53 export const parseExperimental = ({ 64 54 config, 65 - parserConfig, 66 55 spec, 67 56 }: { 68 57 config: Config; 69 - parserConfig: ParserConfig; 70 58 spec: unknown; 71 59 }): IRContext | undefined => { 72 60 const context = new IRContext({ 73 61 config, 74 - parserConfig, 75 62 spec: spec as Record<string, any>, 76 63 }); 77 64
+39
packages/openapi-ts/src/openApi/shared/utils/operation.ts
··· 1 + import type { IRContext } from '../../../ir/context'; 2 + import { camelCase } from '../../../utils/camelCase'; 3 + import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize'; 4 + 5 + /** 6 + * Returns an operation ID to use across the application. By default, we try 7 + * to use the provided ID. If it's not provided or the services are configured 8 + * to exclude it, we generate operation ID from its location. 9 + */ 10 + export const operationToId = ({ 11 + context, 12 + method, 13 + id, 14 + path, 15 + }: { 16 + context: IRContext; 17 + id: string | undefined; 18 + method: string; 19 + path: string; 20 + }): string => { 21 + if ( 22 + id && 23 + (!context.config.plugins['@hey-api/services'] || 24 + context.config.plugins['@hey-api/services'].operationId) 25 + ) { 26 + return camelCase({ 27 + input: sanitizeNamespaceIdentifier(id), 28 + }); 29 + } 30 + 31 + const urlWithoutPlaceholders = path 32 + .replace(/{(.*?)}/g, 'by-$1') 33 + // replace slashes with hyphens for camelcase method at the end 34 + .replace(/[/:]/g, '-'); 35 + 36 + return camelCase({ 37 + input: `${method}-${urlWithoutPlaceholders}`, 38 + }); 39 + };
+2 -4
packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts
··· 4 4 import { getEnums } from '../../common/parser/getEnums'; 5 5 import { getPattern } from '../../common/parser/getPattern'; 6 6 import { getRef } from '../../common/parser/getRef'; 7 + import { operationParameterNameFn } from '../../common/parser/operation'; 7 8 import { getType } from '../../common/parser/type'; 8 - import { getParserConfig } from '../../config'; 9 9 import type { OpenApi } from '../interfaces/OpenApi'; 10 10 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 11 11 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; ··· 20 20 parameter: OpenApiParameter; 21 21 types: Client['types']; 22 22 }): OperationParameter => { 23 - const config = getParserConfig(); 24 - 25 23 const operationParameterWithoutName: Omit<OperationParameter, 'name'> = { 26 24 $refs: [], 27 25 base: 'unknown', ··· 56 54 }; 57 55 let operationParameter = { 58 56 ...operationParameterWithoutName, 59 - name: config.nameFn.operationParameter(operationParameterWithoutName), 57 + name: operationParameterNameFn(operationParameterWithoutName), 60 58 }; 61 59 62 60 if (parameter.$ref) {
+2 -4
packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts
··· 1 1 import type { Client } from '../../../types/client'; 2 2 import type { OperationParameters } from '../../common/interfaces/client'; 3 3 import { getRef } from '../../common/parser/getRef'; 4 - import { getParserConfig } from '../../config'; 4 + import { operationParameterFilterFn } from '../../common/parser/operation'; 5 5 import type { OpenApi } from '../interfaces/OpenApi'; 6 6 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 7 7 import { getOperationParameter } from './getOperationParameter'; ··· 17 17 parameters: OpenApiParameter[]; 18 18 types: Client['types']; 19 19 }): OperationParameters => { 20 - const config = getParserConfig(); 21 - 22 20 const operationParameters: OperationParameters = { 23 21 $refs: [], 24 22 imports: [], ··· 42 40 types, 43 41 }); 44 42 45 - const skip = !config.filterFn.operationParameter(parameter); 43 + const skip = !operationParameterFilterFn(parameter); 46 44 if (!allowedIn.includes(parameterDef.in) || skip) { 47 45 return; 48 46 }
+5 -5
packages/openapi-ts/src/openApi/v2/parser/getOperations.ts
··· 1 1 import { getConfig } from '../../../utils/config'; 2 2 import type { Client, Operation } from '../../common/interfaces/client'; 3 - import { getOperationKey } from '../../common/parser/operation'; 3 + import { 4 + getOperationKey, 5 + operationFilterFn, 6 + } from '../../common/parser/operation'; 4 7 import { allowedServiceMethods } from '../../common/parser/service'; 5 - import { getParserConfig } from '../../config'; 6 8 import type { OpenApi } from '../interfaces/OpenApi'; 7 9 import { getOperationParameters } from './getOperationParameters'; 8 10 import { getOperation } from './operation'; ··· 14 16 openApi: OpenApi; 15 17 types: Client['types']; 16 18 }): Operation[] => { 17 - const config = getParserConfig(); 18 - 19 19 const operationIds = new Map<string, string>(); 20 20 const operations: Operation[] = []; 21 21 ··· 49 49 } 50 50 51 51 if ( 52 - config.filterFn.operation({ 52 + operationFilterFn({ 53 53 config: getConfig(), 54 54 operationKey, 55 55 })
+5 -5
packages/openapi-ts/src/openApi/v2/parser/operation.ts
··· 4 4 Operation, 5 5 OperationParameters, 6 6 } from '../../common/interfaces/client'; 7 - import { getOperationResponseHeader } from '../../common/parser/operation'; 7 + import { 8 + getOperationResponseHeader, 9 + operationNameFn, 10 + } from '../../common/parser/operation'; 8 11 import { toSortedByRequired } from '../../common/parser/sort'; 9 - import { getParserConfig } from '../../config'; 10 12 import type { OpenApi } from '../interfaces/OpenApi'; 11 13 import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; 12 14 import { getOperationParameters } from './getOperationParameters'; ··· 27 29 types: Client['types']; 28 30 url: string; 29 31 }): Operation => { 30 - const config = getParserConfig(); 31 - 32 32 const operationWithoutName: Omit<Operation, 'name'> = { 33 33 $refs: [], 34 34 deprecated: op.deprecated === true, ··· 51 51 }; 52 52 const operation = { 53 53 ...operationWithoutName, 54 - name: config.nameFn.operation({ 54 + name: operationNameFn({ 55 55 config: getConfig(), 56 56 method: operationWithoutName.method, 57 57 operationId: op.operationId,
-6
packages/openapi-ts/src/openApi/v3/parser/getModels.ts
··· 1 1 import type { Client } from '../../../types/client'; 2 2 import { getParametersMeta, getSchemasMeta } from '../../../utils/meta'; 3 - import { getParserConfig } from '../../config'; 4 3 import type { OpenApi } from '../interfaces/OpenApi'; 5 4 import { getModel } from './getModel'; 6 5 import { getParameterSchema } from './parameter'; ··· 8 7 export const getModels = ( 9 8 openApi: OpenApi, 10 9 ): Pick<Client, 'models' | 'types'> => { 11 - const config = getParserConfig(); 12 - 13 10 const types: Client['types'] = {}; 14 11 let models: Client['models'] = []; 15 12 ··· 39 36 ([definitionName, definition]) => { 40 37 const schema = getParameterSchema(definition); 41 38 if (!schema) { 42 - if (config.debug) { 43 - console.warn('Skipping generating parameter:', definitionName); 44 - } 45 39 return; 46 40 } 47 41
+2 -4
packages/openapi-ts/src/openApi/v3/parser/getOperationParameter.ts
··· 5 5 import { getDefault } from '../../common/parser/getDefault'; 6 6 import { getPattern } from '../../common/parser/getPattern'; 7 7 import { getRef } from '../../common/parser/getRef'; 8 + import { operationParameterNameFn } from '../../common/parser/operation'; 8 9 import { getType } from '../../common/parser/type'; 9 - import { getParserConfig } from '../../config'; 10 10 import type { OpenApi } from '../interfaces/OpenApi'; 11 11 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 12 12 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; ··· 23 23 parameter: OpenApiParameter; 24 24 types: Client['types']; 25 25 }): OperationParameter => { 26 - const config = getParserConfig(); 27 - 28 26 const operationParameterWithoutName: Omit<OperationParameter, 'name'> = { 29 27 $refs: [], 30 28 base: 'unknown', ··· 48 46 }; 49 47 let operationParameter = { 50 48 ...operationParameterWithoutName, 51 - name: config.nameFn.operationParameter(operationParameterWithoutName), 49 + name: operationParameterNameFn(operationParameterWithoutName), 52 50 }; 53 51 54 52 if (parameter.$ref) {
+2 -4
packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts
··· 1 1 import type { Client } from '../../../types/client'; 2 2 import type { OperationParameters } from '../../common/interfaces/client'; 3 3 import { getRef } from '../../common/parser/getRef'; 4 - import { getParserConfig } from '../../config'; 4 + import { operationParameterFilterFn } from '../../common/parser/operation'; 5 5 import type { OpenApi } from '../interfaces/OpenApi'; 6 6 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 7 7 import { getOperationParameter } from './getOperationParameter'; ··· 17 17 parameters: OpenApiParameter[]; 18 18 types: Client['types']; 19 19 }): OperationParameters => { 20 - const config = getParserConfig(); 21 - 22 20 const operationParameters: OperationParameters = { 23 21 $refs: [], 24 22 imports: [], ··· 42 40 types, 43 41 }); 44 42 45 - const skip = !config.filterFn.operationParameter(parameter); 43 + const skip = !operationParameterFilterFn(parameter); 46 44 if (!allowedIn.includes(parameterDef.in) || skip) { 47 45 return; 48 46 }
+5 -5
packages/openapi-ts/src/openApi/v3/parser/getOperations.ts
··· 1 1 import { getConfig } from '../../../utils/config'; 2 2 import type { Client, Operation } from '../../common/interfaces/client'; 3 - import { getOperationKey } from '../../common/parser/operation'; 3 + import { 4 + getOperationKey, 5 + operationFilterFn, 6 + } from '../../common/parser/operation'; 4 7 import { allowedServiceMethods } from '../../common/parser/service'; 5 - import { getParserConfig } from '../../config'; 6 8 import type { OpenApi } from '../interfaces/OpenApi'; 7 9 import { getOperationParameters } from './getOperationParameters'; 8 10 import { getOperation } from './operation'; ··· 14 16 openApi: OpenApi; 15 17 types: Client['types']; 16 18 }): Operation[] => { 17 - const config = getParserConfig(); 18 - 19 19 const operationIds = new Map<string, string>(); 20 20 const operations: Operation[] = []; 21 21 ··· 49 49 } 50 50 51 51 if ( 52 - config.filterFn.operation({ 52 + operationFilterFn({ 53 53 config: getConfig(), 54 54 operationKey, 55 55 })
+5 -5
packages/openapi-ts/src/openApi/v3/parser/operation.ts
··· 6 6 OperationParameters, 7 7 } from '../../common/interfaces/client'; 8 8 import { getRef } from '../../common/parser/getRef'; 9 - import { getOperationResponseHeader } from '../../common/parser/operation'; 9 + import { 10 + getOperationResponseHeader, 11 + operationNameFn, 12 + } from '../../common/parser/operation'; 10 13 import { toSortedByRequired } from '../../common/parser/sort'; 11 - import { getParserConfig } from '../../config'; 12 14 import type { OpenApi } from '../interfaces/OpenApi'; 13 15 import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; 14 16 import type { OpenApiRequestBody } from '../interfaces/OpenApiRequestBody'; ··· 54 56 types: Client['types']; 55 57 url: string; 56 58 }): Operation => { 57 - const config = getParserConfig(); 58 - 59 59 const operationWithoutName: Omit<Operation, 'name'> = { 60 60 $refs: [], 61 61 deprecated: Boolean(op.deprecated), ··· 78 78 }; 79 79 const operation = { 80 80 ...operationWithoutName, 81 - name: config.nameFn.operation({ 81 + name: operationNameFn({ 82 82 config: getConfig(), 83 83 method: operationWithoutName.method, 84 84 operationId: op.operationId,
+9 -19
packages/openapi-ts/src/plugins/@hey-api/types/plugin.ts
··· 990 990 } 991 991 } 992 992 993 - // TODO: parser - once types are a plugin, this logic can be simplified 994 - // provide config option on types to generate path types and services 995 - // will set it to true if needed 996 - if ( 997 - context.config.plugins['@hey-api/services'] || 998 - context.config.plugins['@hey-api/types']?.tree 999 - ) { 1000 - for (const path in context.ir.paths) { 1001 - const pathItem = context.ir.paths[path as keyof IRPathsObject]; 993 + for (const path in context.ir.paths) { 994 + const pathItem = context.ir.paths[path as keyof IRPathsObject]; 1002 995 1003 - for (const _method in pathItem) { 1004 - const method = _method as keyof IRPathItemObject; 1005 - const operation = pathItem[method]!; 996 + for (const _method in pathItem) { 997 + const method = _method as keyof IRPathItemObject; 998 + const operation = pathItem[method]!; 1006 999 1007 - operationToType({ 1008 - context, 1009 - operation, 1010 - }); 1011 - } 1000 + operationToType({ 1001 + context, 1002 + operation, 1003 + }); 1012 1004 } 1013 - 1014 - // TODO: parser - document removal of tree? migrate it? 1015 1005 } 1016 1006 };
+2
packages/openapi-ts/src/plugins/@hey-api/types/types.d.ts
··· 28 28 * Generate a tree of types containing all operations? It will be named 29 29 * $OpenApiTs. 30 30 * @default false 31 + * 32 + * @deprecated 31 33 */ 32 34 tree?: boolean; 33 35 }
+1 -1
packages/openapi-ts/src/plugins/fastify/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: PluginConfig<Config> = { 6 - _dependencies: ['@hey-api/types', '@hey-api/services'], 6 + _dependencies: ['@hey-api/types'], 7 7 _handler: handler, 8 8 _handlerLegacy: () => {}, 9 9 name: 'fastify',
+1 -1
packages/openapi-ts/src/utils/__tests__/parse.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import { operationNameFn } from '../../openApi/config'; 3 + import { operationNameFn } from '../../openApi/common/parser/operation'; 4 4 import { setConfig } from '../config'; 5 5 6 6 describe('operationNameFn', () => {
+11 -14
packages/openapi-ts/src/utils/__tests__/postprocess.spec.ts
··· 1 - import { describe, expect, it } from 'vitest'; 1 + import { describe, expect, it, vi } from 'vitest'; 2 2 3 3 import { parseLegacy } from '../../openApi'; 4 - import type { ParserConfig } from '../../openApi/config'; 4 + import type { Config } from '../../types/config'; 5 5 import { getServiceName, postProcessClient } from '../postprocess'; 6 6 7 - const parserConfig: ParserConfig = { 8 - filterFn: { 9 - operation: () => true, 10 - operationParameter: () => true, 11 - }, 12 - nameFn: { 13 - operation: () => 'operation', 14 - operationParameter: () => 'operationParameter', 15 - }, 16 - }; 7 + vi.mock('../config', () => { 8 + const config: Partial<Config> = { 9 + plugins: {}, 10 + }; 11 + return { 12 + getConfig: () => config, 13 + isLegacyClient: vi.fn().mockReturnValue(true), 14 + }; 15 + }); 17 16 18 17 describe('getServiceName', () => { 19 18 it.each([ ··· 58 57 }, 59 58 }, 60 59 }, 61 - parserConfig, 62 60 }); 63 61 const { services } = postProcessClient(parserClient); 64 62 ··· 92 90 }, 93 91 }, 94 92 }, 95 - parserConfig, 96 93 }); 97 94 const { services } = postProcessClient(parserClient); 98 95
+1 -2
packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/index.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 - export * from './types.gen'; 3 - export * from './services.gen'; 2 + export * from './types.gen';
-382
packages/openapi-ts/test/__snapshots__/3.0.x/plugins/fastify/default/services.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; 4 - import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; 5 - 6 - export const client = createClient(createConfig()); 7 - 8 - export const export_ = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 9 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 10 - ...options, 11 - url: '/api/v{api-version}/no-tag' 12 - }); 13 - }; 14 - 15 - export const import_ = <ThrowOnError extends boolean = false>(options: Options<ImportData, ThrowOnError>) => { 16 - return (options?.client ?? client).post<ImportResponse, unknown, ThrowOnError>({ 17 - ...options, 18 - headers: { 19 - 'Content-Type': 'application/json', 20 - ...options?.headers 21 - }, 22 - url: '/api/v{api-version}/no-tag' 23 - }); 24 - }; 25 - 26 - export const apiVVersionOdataControllerCount = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 27 - return (options?.client ?? client).get<ApiVversionOdataControllerCountResponse, unknown, ThrowOnError>({ 28 - ...options, 29 - url: '/api/v{api-version}/simple/$count' 30 - }); 31 - }; 32 - 33 - export const getApiVbyApiVersionSimpleOperation = <ThrowOnError extends boolean = false>(options: Options<GetApiVbyApiVersionSimpleOperationData, ThrowOnError>) => { 34 - return (options?.client ?? client).get<GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, ThrowOnError>({ 35 - ...options, 36 - url: '/api/v{api-version}/simple:operation' 37 - }); 38 - }; 39 - 40 - export const deleteCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 41 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 42 - ...options, 43 - url: '/api/v{api-version}/simple' 44 - }); 45 - }; 46 - 47 - export const getCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 48 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 49 - ...options, 50 - url: '/api/v{api-version}/simple' 51 - }); 52 - }; 53 - 54 - export const headCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 55 - return (options?.client ?? client).head<unknown, unknown, ThrowOnError>({ 56 - ...options, 57 - url: '/api/v{api-version}/simple' 58 - }); 59 - }; 60 - 61 - export const optionsCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 62 - return (options?.client ?? client).options<unknown, unknown, ThrowOnError>({ 63 - ...options, 64 - url: '/api/v{api-version}/simple' 65 - }); 66 - }; 67 - 68 - export const patchCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 69 - return (options?.client ?? client).patch<unknown, unknown, ThrowOnError>({ 70 - ...options, 71 - url: '/api/v{api-version}/simple' 72 - }); 73 - }; 74 - 75 - export const postCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 76 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 77 - ...options, 78 - url: '/api/v{api-version}/simple' 79 - }); 80 - }; 81 - 82 - export const putCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 83 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 84 - ...options, 85 - url: '/api/v{api-version}/simple' 86 - }); 87 - }; 88 - 89 - export const deleteFoo = <ThrowOnError extends boolean = false>(options: Options<DeleteFooData3, ThrowOnError>) => { 90 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 91 - ...options, 92 - url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' 93 - }); 94 - }; 95 - 96 - export const callWithDescriptions = <ThrowOnError extends boolean = false>(options?: Options<CallWithDescriptionsData, ThrowOnError>) => { 97 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 98 - ...options, 99 - url: '/api/v{api-version}/descriptions' 100 - }); 101 - }; 102 - 103 - /** 104 - * @deprecated 105 - */ 106 - export const deprecatedCall = <ThrowOnError extends boolean = false>(options: Options<DeprecatedCallData, ThrowOnError>) => { 107 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 108 - ...options, 109 - url: '/api/v{api-version}/parameters/deprecated' 110 - }); 111 - }; 112 - 113 - export const callWithParameters = <ThrowOnError extends boolean = false>(options: Options<CallWithParametersData, ThrowOnError>) => { 114 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 115 - ...options, 116 - headers: { 117 - 'Content-Type': 'application/json', 118 - ...options?.headers 119 - }, 120 - url: '/api/v{api-version}/parameters/{parameterPath}' 121 - }); 122 - }; 123 - 124 - export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 125 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 126 - ...options, 127 - headers: { 128 - 'Content-Type': 'application/json', 129 - ...options?.headers 130 - }, 131 - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' 132 - }); 133 - }; 134 - 135 - export const getCallWithOptionalParam = <ThrowOnError extends boolean = false>(options: Options<GetCallWithOptionalParamData, ThrowOnError>) => { 136 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 137 - ...options, 138 - headers: { 139 - 'Content-Type': 'application/json', 140 - ...options?.headers 141 - }, 142 - url: '/api/v{api-version}/parameters' 143 - }); 144 - }; 145 - 146 - export const postCallWithOptionalParam = <ThrowOnError extends boolean = false>(options: Options<PostCallWithOptionalParamData, ThrowOnError>) => { 147 - return (options?.client ?? client).post<PostCallWithOptionalParamResponse, unknown, ThrowOnError>({ 148 - ...options, 149 - headers: { 150 - 'Content-Type': 'application/json', 151 - ...options?.headers 152 - }, 153 - url: '/api/v{api-version}/parameters' 154 - }); 155 - }; 156 - 157 - export const postApiVbyApiVersionRequestBody = <ThrowOnError extends boolean = false>(options?: Options<PostApiVbyApiVersionRequestBodyData, ThrowOnError>) => { 158 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 159 - ...options, 160 - headers: { 161 - 'Content-Type': 'application/json', 162 - ...options?.headers 163 - }, 164 - url: '/api/v{api-version}/requestBody' 165 - }); 166 - }; 167 - 168 - export const postApiVbyApiVersionFormData = <ThrowOnError extends boolean = false>(options?: Options<PostApiVbyApiVersionFormDataData, ThrowOnError>) => { 169 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 170 - ...options, 171 - ...formDataBodySerializer, 172 - headers: { 173 - 'Content-Type': null, 174 - ...options?.headers 175 - }, 176 - url: '/api/v{api-version}/formData' 177 - }); 178 - }; 179 - 180 - export const callWithDefaultParameters = <ThrowOnError extends boolean = false>(options?: Options<CallWithDefaultParametersData, ThrowOnError>) => { 181 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 182 - ...options, 183 - url: '/api/v{api-version}/defaults' 184 - }); 185 - }; 186 - 187 - export const callWithDefaultOptionalParameters = <ThrowOnError extends boolean = false>(options?: Options<CallWithDefaultOptionalParametersData, ThrowOnError>) => { 188 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 189 - ...options, 190 - url: '/api/v{api-version}/defaults' 191 - }); 192 - }; 193 - 194 - export const callToTestOrderOfParams = <ThrowOnError extends boolean = false>(options: Options<CallToTestOrderOfParamsData, ThrowOnError>) => { 195 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 196 - ...options, 197 - url: '/api/v{api-version}/defaults' 198 - }); 199 - }; 200 - 201 - export const duplicateName = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 202 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 203 - ...options, 204 - url: '/api/v{api-version}/duplicate' 205 - }); 206 - }; 207 - 208 - export const duplicateName2 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 209 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 210 - ...options, 211 - url: '/api/v{api-version}/duplicate' 212 - }); 213 - }; 214 - 215 - export const duplicateName3 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 216 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 217 - ...options, 218 - url: '/api/v{api-version}/duplicate' 219 - }); 220 - }; 221 - 222 - export const duplicateName4 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 223 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 224 - ...options, 225 - url: '/api/v{api-version}/duplicate' 226 - }); 227 - }; 228 - 229 - export const callWithNoContentResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 230 - return (options?.client ?? client).get<CallWithNoContentResponseResponse, unknown, ThrowOnError>({ 231 - ...options, 232 - url: '/api/v{api-version}/no-content' 233 - }); 234 - }; 235 - 236 - export const callWithResponseAndNoContentResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 237 - return (options?.client ?? client).get<CallWithResponseAndNoContentResponseResponse, unknown, ThrowOnError>({ 238 - ...options, 239 - url: '/api/v{api-version}/multiple-tags/response-and-no-content' 240 - }); 241 - }; 242 - 243 - export const dummyA = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 244 - return (options?.client ?? client).get<DummyAResponse, unknown, ThrowOnError>({ 245 - ...options, 246 - url: '/api/v{api-version}/multiple-tags/a' 247 - }); 248 - }; 249 - 250 - export const dummyB = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 251 - return (options?.client ?? client).get<DummyBResponse, unknown, ThrowOnError>({ 252 - ...options, 253 - url: '/api/v{api-version}/multiple-tags/b' 254 - }); 255 - }; 256 - 257 - export const callWithResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 258 - return (options?.client ?? client).get<CallWithResponseResponse, unknown, ThrowOnError>({ 259 - ...options, 260 - url: '/api/v{api-version}/response' 261 - }); 262 - }; 263 - 264 - export const callWithDuplicateResponses = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 265 - return (options?.client ?? client).post<CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, ThrowOnError>({ 266 - ...options, 267 - url: '/api/v{api-version}/response' 268 - }); 269 - }; 270 - 271 - export const callWithResponses = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 272 - return (options?.client ?? client).put<CallWithResponsesResponse, CallWithResponsesError, ThrowOnError>({ 273 - ...options, 274 - url: '/api/v{api-version}/response' 275 - }); 276 - }; 277 - 278 - export const collectionFormat = <ThrowOnError extends boolean = false>(options: Options<CollectionFormatData, ThrowOnError>) => { 279 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 280 - ...options, 281 - url: '/api/v{api-version}/collectionFormat' 282 - }); 283 - }; 284 - 285 - export const types = <ThrowOnError extends boolean = false>(options: Options<TypesData, ThrowOnError>) => { 286 - return (options?.client ?? client).get<TypesResponse, unknown, ThrowOnError>({ 287 - ...options, 288 - url: '/api/v{api-version}/types' 289 - }); 290 - }; 291 - 292 - export const uploadFile = <ThrowOnError extends boolean = false>(options: Options<UploadFileData, ThrowOnError>) => { 293 - return (options?.client ?? client).post<UploadFileResponse, unknown, ThrowOnError>({ 294 - ...options, 295 - ...urlSearchParamsBodySerializer, 296 - headers: { 297 - 'Content-Type': 'application/x-www-form-urlencoded', 298 - ...options?.headers 299 - }, 300 - url: '/api/v{api-version}/upload' 301 - }); 302 - }; 303 - 304 - export const fileResponse = <ThrowOnError extends boolean = false>(options: Options<FileResponseData, ThrowOnError>) => { 305 - return (options?.client ?? client).get<FileResponseResponse, unknown, ThrowOnError>({ 306 - ...options, 307 - url: '/api/v{api-version}/file/{id}' 308 - }); 309 - }; 310 - 311 - export const complexTypes = <ThrowOnError extends boolean = false>(options: Options<ComplexTypesData, ThrowOnError>) => { 312 - return (options?.client ?? client).get<ComplexTypesResponse, unknown, ThrowOnError>({ 313 - ...options, 314 - url: '/api/v{api-version}/complex' 315 - }); 316 - }; 317 - 318 - export const multipartResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 319 - return (options?.client ?? client).get<MultipartResponseResponse, unknown, ThrowOnError>({ 320 - ...options, 321 - url: '/api/v{api-version}/multipart' 322 - }); 323 - }; 324 - 325 - export const multipartRequest = <ThrowOnError extends boolean = false>(options?: Options<MultipartRequestData, ThrowOnError>) => { 326 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 327 - ...options, 328 - ...formDataBodySerializer, 329 - headers: { 330 - 'Content-Type': null, 331 - ...options?.headers 332 - }, 333 - url: '/api/v{api-version}/multipart' 334 - }); 335 - }; 336 - 337 - export const complexParams = <ThrowOnError extends boolean = false>(options: Options<ComplexParamsData, ThrowOnError>) => { 338 - return (options?.client ?? client).put<ComplexParamsResponse, unknown, ThrowOnError>({ 339 - ...options, 340 - headers: { 341 - 'Content-Type': 'application/json-patch+json', 342 - ...options?.headers 343 - }, 344 - url: '/api/v{api-version}/complex/{id}' 345 - }); 346 - }; 347 - 348 - export const callWithResultFromHeader = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 349 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 350 - ...options, 351 - url: '/api/v{api-version}/header' 352 - }); 353 - }; 354 - 355 - export const testErrorCode = <ThrowOnError extends boolean = false>(options: Options<TestErrorCodeData, ThrowOnError>) => { 356 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 357 - ...options, 358 - url: '/api/v{api-version}/error' 359 - }); 360 - }; 361 - 362 - export const nonAsciiæøåÆøÅöôêÊ字符串 = <ThrowOnError extends boolean = false>(options: Options<NonAsciiæøåÆøÅöôêÊ字符串Data, ThrowOnError>) => { 363 - return (options?.client ?? client).post<NonAsciiæøåÆøÅöôêÊ字符串Response, unknown, ThrowOnError>({ 364 - ...options, 365 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' 366 - }); 367 - }; 368 - 369 - /** 370 - * Login User 371 - */ 372 - export const putWithFormUrlEncoded = <ThrowOnError extends boolean = false>(options: Options<PutWithFormUrlEncodedData, ThrowOnError>) => { 373 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 374 - ...options, 375 - ...urlSearchParamsBodySerializer, 376 - headers: { 377 - 'Content-Type': 'application/x-www-form-urlencoded', 378 - ...options?.headers 379 - }, 380 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' 381 - }); 382 - };
+1 -2
packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/index.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 - export * from './types.gen'; 3 - export * from './services.gen'; 2 + export * from './types.gen';
-382
packages/openapi-ts/test/__snapshots__/3.1.x/plugins/fastify/default/services.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; 4 - import type { ImportData, ImportResponse, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, DummyAResponse, DummyBResponse, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; 5 - 6 - export const client = createClient(createConfig()); 7 - 8 - export const export_ = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 9 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 10 - ...options, 11 - url: '/api/v{api-version}/no-tag' 12 - }); 13 - }; 14 - 15 - export const import_ = <ThrowOnError extends boolean = false>(options: Options<ImportData, ThrowOnError>) => { 16 - return (options?.client ?? client).post<ImportResponse, unknown, ThrowOnError>({ 17 - ...options, 18 - headers: { 19 - 'Content-Type': 'application/json', 20 - ...options?.headers 21 - }, 22 - url: '/api/v{api-version}/no-tag' 23 - }); 24 - }; 25 - 26 - export const apiVVersionOdataControllerCount = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 27 - return (options?.client ?? client).get<ApiVversionOdataControllerCountResponse, unknown, ThrowOnError>({ 28 - ...options, 29 - url: '/api/v{api-version}/simple/$count' 30 - }); 31 - }; 32 - 33 - export const getApiVbyApiVersionSimpleOperation = <ThrowOnError extends boolean = false>(options: Options<GetApiVbyApiVersionSimpleOperationData, ThrowOnError>) => { 34 - return (options?.client ?? client).get<GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, ThrowOnError>({ 35 - ...options, 36 - url: '/api/v{api-version}/simple:operation' 37 - }); 38 - }; 39 - 40 - export const deleteCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 41 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 42 - ...options, 43 - url: '/api/v{api-version}/simple' 44 - }); 45 - }; 46 - 47 - export const getCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 48 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 49 - ...options, 50 - url: '/api/v{api-version}/simple' 51 - }); 52 - }; 53 - 54 - export const headCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 55 - return (options?.client ?? client).head<unknown, unknown, ThrowOnError>({ 56 - ...options, 57 - url: '/api/v{api-version}/simple' 58 - }); 59 - }; 60 - 61 - export const optionsCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 62 - return (options?.client ?? client).options<unknown, unknown, ThrowOnError>({ 63 - ...options, 64 - url: '/api/v{api-version}/simple' 65 - }); 66 - }; 67 - 68 - export const patchCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 69 - return (options?.client ?? client).patch<unknown, unknown, ThrowOnError>({ 70 - ...options, 71 - url: '/api/v{api-version}/simple' 72 - }); 73 - }; 74 - 75 - export const postCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 76 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 77 - ...options, 78 - url: '/api/v{api-version}/simple' 79 - }); 80 - }; 81 - 82 - export const putCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 83 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 84 - ...options, 85 - url: '/api/v{api-version}/simple' 86 - }); 87 - }; 88 - 89 - export const deleteFoo = <ThrowOnError extends boolean = false>(options: Options<DeleteFooData3, ThrowOnError>) => { 90 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 91 - ...options, 92 - url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}' 93 - }); 94 - }; 95 - 96 - export const callWithDescriptions = <ThrowOnError extends boolean = false>(options?: Options<CallWithDescriptionsData, ThrowOnError>) => { 97 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 98 - ...options, 99 - url: '/api/v{api-version}/descriptions' 100 - }); 101 - }; 102 - 103 - /** 104 - * @deprecated 105 - */ 106 - export const deprecatedCall = <ThrowOnError extends boolean = false>(options: Options<DeprecatedCallData, ThrowOnError>) => { 107 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 108 - ...options, 109 - url: '/api/v{api-version}/parameters/deprecated' 110 - }); 111 - }; 112 - 113 - export const callWithParameters = <ThrowOnError extends boolean = false>(options: Options<CallWithParametersData, ThrowOnError>) => { 114 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 115 - ...options, 116 - headers: { 117 - 'Content-Type': 'application/json', 118 - ...options?.headers 119 - }, 120 - url: '/api/v{api-version}/parameters/{parameterPath}' 121 - }); 122 - }; 123 - 124 - export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 125 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 126 - ...options, 127 - headers: { 128 - 'Content-Type': 'application/json', 129 - ...options?.headers 130 - }, 131 - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}' 132 - }); 133 - }; 134 - 135 - export const getCallWithOptionalParam = <ThrowOnError extends boolean = false>(options: Options<GetCallWithOptionalParamData, ThrowOnError>) => { 136 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 137 - ...options, 138 - headers: { 139 - 'Content-Type': 'application/json', 140 - ...options?.headers 141 - }, 142 - url: '/api/v{api-version}/parameters' 143 - }); 144 - }; 145 - 146 - export const postCallWithOptionalParam = <ThrowOnError extends boolean = false>(options: Options<PostCallWithOptionalParamData, ThrowOnError>) => { 147 - return (options?.client ?? client).post<PostCallWithOptionalParamResponse, unknown, ThrowOnError>({ 148 - ...options, 149 - headers: { 150 - 'Content-Type': 'application/json', 151 - ...options?.headers 152 - }, 153 - url: '/api/v{api-version}/parameters' 154 - }); 155 - }; 156 - 157 - export const postApiVbyApiVersionRequestBody = <ThrowOnError extends boolean = false>(options?: Options<PostApiVbyApiVersionRequestBodyData, ThrowOnError>) => { 158 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 159 - ...options, 160 - headers: { 161 - 'Content-Type': 'application/json', 162 - ...options?.headers 163 - }, 164 - url: '/api/v{api-version}/requestBody' 165 - }); 166 - }; 167 - 168 - export const postApiVbyApiVersionFormData = <ThrowOnError extends boolean = false>(options?: Options<PostApiVbyApiVersionFormDataData, ThrowOnError>) => { 169 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 170 - ...options, 171 - ...formDataBodySerializer, 172 - headers: { 173 - 'Content-Type': null, 174 - ...options?.headers 175 - }, 176 - url: '/api/v{api-version}/formData' 177 - }); 178 - }; 179 - 180 - export const callWithDefaultParameters = <ThrowOnError extends boolean = false>(options?: Options<CallWithDefaultParametersData, ThrowOnError>) => { 181 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 182 - ...options, 183 - url: '/api/v{api-version}/defaults' 184 - }); 185 - }; 186 - 187 - export const callWithDefaultOptionalParameters = <ThrowOnError extends boolean = false>(options?: Options<CallWithDefaultOptionalParametersData, ThrowOnError>) => { 188 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 189 - ...options, 190 - url: '/api/v{api-version}/defaults' 191 - }); 192 - }; 193 - 194 - export const callToTestOrderOfParams = <ThrowOnError extends boolean = false>(options: Options<CallToTestOrderOfParamsData, ThrowOnError>) => { 195 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 196 - ...options, 197 - url: '/api/v{api-version}/defaults' 198 - }); 199 - }; 200 - 201 - export const duplicateName = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 202 - return (options?.client ?? client).delete<unknown, unknown, ThrowOnError>({ 203 - ...options, 204 - url: '/api/v{api-version}/duplicate' 205 - }); 206 - }; 207 - 208 - export const duplicateName2 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 209 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 210 - ...options, 211 - url: '/api/v{api-version}/duplicate' 212 - }); 213 - }; 214 - 215 - export const duplicateName3 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 216 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 217 - ...options, 218 - url: '/api/v{api-version}/duplicate' 219 - }); 220 - }; 221 - 222 - export const duplicateName4 = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 223 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 224 - ...options, 225 - url: '/api/v{api-version}/duplicate' 226 - }); 227 - }; 228 - 229 - export const callWithNoContentResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 230 - return (options?.client ?? client).get<CallWithNoContentResponseResponse, unknown, ThrowOnError>({ 231 - ...options, 232 - url: '/api/v{api-version}/no-content' 233 - }); 234 - }; 235 - 236 - export const callWithResponseAndNoContentResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 237 - return (options?.client ?? client).get<CallWithResponseAndNoContentResponseResponse, unknown, ThrowOnError>({ 238 - ...options, 239 - url: '/api/v{api-version}/multiple-tags/response-and-no-content' 240 - }); 241 - }; 242 - 243 - export const dummyA = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 244 - return (options?.client ?? client).get<DummyAResponse, unknown, ThrowOnError>({ 245 - ...options, 246 - url: '/api/v{api-version}/multiple-tags/a' 247 - }); 248 - }; 249 - 250 - export const dummyB = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 251 - return (options?.client ?? client).get<DummyBResponse, unknown, ThrowOnError>({ 252 - ...options, 253 - url: '/api/v{api-version}/multiple-tags/b' 254 - }); 255 - }; 256 - 257 - export const callWithResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 258 - return (options?.client ?? client).get<CallWithResponseResponse, unknown, ThrowOnError>({ 259 - ...options, 260 - url: '/api/v{api-version}/response' 261 - }); 262 - }; 263 - 264 - export const callWithDuplicateResponses = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 265 - return (options?.client ?? client).post<CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, ThrowOnError>({ 266 - ...options, 267 - url: '/api/v{api-version}/response' 268 - }); 269 - }; 270 - 271 - export const callWithResponses = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 272 - return (options?.client ?? client).put<CallWithResponsesResponse, CallWithResponsesError, ThrowOnError>({ 273 - ...options, 274 - url: '/api/v{api-version}/response' 275 - }); 276 - }; 277 - 278 - export const collectionFormat = <ThrowOnError extends boolean = false>(options: Options<CollectionFormatData, ThrowOnError>) => { 279 - return (options?.client ?? client).get<unknown, unknown, ThrowOnError>({ 280 - ...options, 281 - url: '/api/v{api-version}/collectionFormat' 282 - }); 283 - }; 284 - 285 - export const types = <ThrowOnError extends boolean = false>(options: Options<TypesData, ThrowOnError>) => { 286 - return (options?.client ?? client).get<TypesResponse, unknown, ThrowOnError>({ 287 - ...options, 288 - url: '/api/v{api-version}/types' 289 - }); 290 - }; 291 - 292 - export const uploadFile = <ThrowOnError extends boolean = false>(options: Options<UploadFileData, ThrowOnError>) => { 293 - return (options?.client ?? client).post<UploadFileResponse, unknown, ThrowOnError>({ 294 - ...options, 295 - ...urlSearchParamsBodySerializer, 296 - headers: { 297 - 'Content-Type': 'application/x-www-form-urlencoded', 298 - ...options?.headers 299 - }, 300 - url: '/api/v{api-version}/upload' 301 - }); 302 - }; 303 - 304 - export const fileResponse = <ThrowOnError extends boolean = false>(options: Options<FileResponseData, ThrowOnError>) => { 305 - return (options?.client ?? client).get<FileResponseResponse, unknown, ThrowOnError>({ 306 - ...options, 307 - url: '/api/v{api-version}/file/{id}' 308 - }); 309 - }; 310 - 311 - export const complexTypes = <ThrowOnError extends boolean = false>(options: Options<ComplexTypesData, ThrowOnError>) => { 312 - return (options?.client ?? client).get<ComplexTypesResponse, unknown, ThrowOnError>({ 313 - ...options, 314 - url: '/api/v{api-version}/complex' 315 - }); 316 - }; 317 - 318 - export const multipartResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 319 - return (options?.client ?? client).get<MultipartResponseResponse, unknown, ThrowOnError>({ 320 - ...options, 321 - url: '/api/v{api-version}/multipart' 322 - }); 323 - }; 324 - 325 - export const multipartRequest = <ThrowOnError extends boolean = false>(options?: Options<MultipartRequestData, ThrowOnError>) => { 326 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 327 - ...options, 328 - ...formDataBodySerializer, 329 - headers: { 330 - 'Content-Type': null, 331 - ...options?.headers 332 - }, 333 - url: '/api/v{api-version}/multipart' 334 - }); 335 - }; 336 - 337 - export const complexParams = <ThrowOnError extends boolean = false>(options: Options<ComplexParamsData, ThrowOnError>) => { 338 - return (options?.client ?? client).put<ComplexParamsResponse, unknown, ThrowOnError>({ 339 - ...options, 340 - headers: { 341 - 'Content-Type': 'application/json-patch+json', 342 - ...options?.headers 343 - }, 344 - url: '/api/v{api-version}/complex/{id}' 345 - }); 346 - }; 347 - 348 - export const callWithResultFromHeader = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { 349 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 350 - ...options, 351 - url: '/api/v{api-version}/header' 352 - }); 353 - }; 354 - 355 - export const testErrorCode = <ThrowOnError extends boolean = false>(options: Options<TestErrorCodeData, ThrowOnError>) => { 356 - return (options?.client ?? client).post<unknown, unknown, ThrowOnError>({ 357 - ...options, 358 - url: '/api/v{api-version}/error' 359 - }); 360 - }; 361 - 362 - export const nonAsciiæøåÆøÅöôêÊ字符串 = <ThrowOnError extends boolean = false>(options: Options<NonAsciiæøåÆøÅöôêÊ字符串Data, ThrowOnError>) => { 363 - return (options?.client ?? client).post<NonAsciiæøåÆøÅöôêÊ字符串Response, unknown, ThrowOnError>({ 364 - ...options, 365 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' 366 - }); 367 - }; 368 - 369 - /** 370 - * Login User 371 - */ 372 - export const putWithFormUrlEncoded = <ThrowOnError extends boolean = false>(options: Options<PutWithFormUrlEncodedData, ThrowOnError>) => { 373 - return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({ 374 - ...options, 375 - ...urlSearchParamsBodySerializer, 376 - headers: { 377 - 'Content-Type': 'application/x-www-form-urlencoded', 378 - ...options?.headers 379 - }, 380 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串' 381 - }); 382 - };
+1
packages/openapi-ts/test/sample.cjs
··· 32 32 // asClass: true, 33 33 // include... 34 34 // name: '@hey-api/services', 35 + // operationId: false, 35 36 // serviceNameBuilder: '^Parameters', 36 37 }, 37 38 {