Something went wrong. Try again.
fork of hey-api/openapi-ts because I need some additional things
Something went wrong. Try again.
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798import type { MaybeArray } from '@hey-api/types';
import { inputToApiRegistry } from '../../utils/input';import { heyApiRegistryBaseUrl } from '../../utils/input/heyApi';import type { Input, UserInput, UserWatch, Watch } from './types';
const defaultWatch: Watch = { enabled: false, interval: 1_000, timeout: 60_000,};
// watch only remote filesfunction getWatch(input: Pick<Input, 'path' | 'watch'>): Watch { let watch = { ...defaultWatch };
// we cannot watch spec passed as an object if (typeof input.path !== 'string') { return watch; }
if (typeof input.watch === 'boolean') { watch.enabled = input.watch; } else if (typeof input.watch === 'number') { watch.enabled = true; watch.interval = input.watch; } else if (input.watch) { watch = { ...watch, ...input.watch, }; }
return watch;}
export function getInput(userConfig: { input: MaybeArray<UserInput | Required<UserInput>['path']>; watch?: UserWatch;}): ReadonlyArray<Input> { const userInputs = userConfig.input instanceof Array ? userConfig.input : [userConfig.input];
const inputs: Array<Input> = [];
for (const userInput of userInputs) { let input: Input = { path: '', watch: defaultWatch, };
if (typeof userInput === 'string') { input.path = userInput; } else if ( userInput && (userInput.path !== undefined || userInput.organization !== undefined) ) { // @ts-expect-error input = { ...input, path: heyApiRegistryBaseUrl, ...userInput, };
if (input.watch !== undefined) { input.watch = getWatch(input); } } else { input = { ...input, path: userInput, }; }
if (typeof input.path === 'string') { inputToApiRegistry(input as Input & { path: string }); }
if ( userConfig.watch !== undefined && input.watch.enabled === defaultWatch.enabled && input.watch.interval === defaultWatch.interval && input.watch.timeout === defaultWatch.timeout ) { input.watch = getWatch({ path: input.path, // @ts-expect-error watch: userConfig.watch, }); }
if (input.path) { inputs.push(input); } }
return inputs;}