fork of hey-api/openapi-ts because I need some additional things
at feat/use-mutation-hooks 25 lines 706 B view raw
1import { ono } from '@jsdevtools/ono'; 2import fs from 'fs'; 3 4import type { FileInfo } from '../types'; 5import { ResolverError } from '../util/errors'; 6import * as url from '../util/url'; 7 8export const fileResolver = { 9 handler: async ({ file }: { file: FileInfo }): Promise<void> => { 10 let path: string | undefined; 11 12 try { 13 path = url.toFileSystemPath(file.url); 14 } catch (error: any) { 15 throw new ResolverError(ono.uri(error, `Malformed URI: ${file.url}`), file.url); 16 } 17 18 try { 19 const data = await fs.promises.readFile(path); 20 file.data = data; 21 } catch (error: any) { 22 throw new ResolverError(ono(error, `Error opening file "${path}"`), path); 23 } 24 }, 25};