fork of hey-api/openapi-ts because I need some additional things
at feat/use-query-options-param 67 lines 2.0 kB view raw
1import type { OperationsStrategy, PluginContext } from '@hey-api/shared'; 2 3import type { UserConfig } from '../types'; 4import type { OperationsConfig, UserOperationsConfig } from './types'; 5 6type Config = Omit<UserConfig, 'name'>; 7 8export function resolveOperations(config: Config, context: PluginContext): OperationsConfig { 9 return normalizeConfig(config.operations, context); 10} 11 12function normalizeConfig( 13 input: Exclude<OperationsStrategy, 'flat'> | UserOperationsConfig | undefined, 14 context: PluginContext, 15): OperationsConfig { 16 if (!input || typeof input === 'string' || typeof input === 'function') { 17 input = { strategy: input }; 18 } 19 20 const strategy = input.strategy ?? 'single'; 21 22 return context.valueToObject({ 23 defaultValue: { 24 container: 'class', 25 methods: 'instance', 26 nesting: 'operationId', 27 nestingDelimiters: /[./]/, 28 strategy, 29 strategyDefaultTag: 'default', 30 }, 31 mappers: { 32 object(value) { 33 value.containerName = context.valueToObject({ 34 defaultValue: 35 strategy === 'single' 36 ? { casing: 'PascalCase', name: 'Sdk' } 37 : { casing: 'PascalCase' }, 38 mappers: { 39 function: (name) => ({ name }), 40 string: (name) => ({ name }), 41 }, 42 value: value.containerName, 43 }); 44 value.methodName = context.valueToObject({ 45 defaultValue: { casing: 'snake_case' }, 46 mappers: { 47 function: (name) => ({ name }), 48 string: (name) => ({ name }), 49 }, 50 value: value.methodName, 51 }); 52 value.segmentName = context.valueToObject({ 53 defaultValue: { casing: 'PascalCase' }, 54 mappers: { 55 function: (name) => ({ name }), 56 string: (name) => ({ name }), 57 }, 58 value: value.segmentName, 59 }); 60 return value; 61 }, 62 }, 63 value: { 64 ...input, 65 } as UserOperationsConfig, 66 }) as OperationsConfig; 67}