|
| 1 | +import type { PrinterConfigs, PrintResults } from '../src'; |
1 | 2 | import type { OpenAPILatest } from '../src/types/openapi'; |
2 | 3 | import * as crypto from 'node:crypto'; |
3 | 4 | import fs from 'node:fs'; |
@@ -29,13 +30,23 @@ export function createTempDirname() { |
29 | 30 | ] as const; |
30 | 31 | } |
31 | 32 |
|
32 | | -export function exampleTest(version: string, name: string, test: (document: OpenAPILatest.Document) => string) { |
| 33 | +export function exampleTest(version: string, name: string, test: (document: OpenAPILatest.Document, configs: PrinterConfigs) => PrintResults) { |
33 | 34 | const src = path.join(__dirname, 'example-json', version, `${name}.json`); |
34 | | - const dest = path.join(__dirname, 'example-dest', version, `${name}.ts`); |
| 35 | + const dir = path.join(__dirname, 'example-dest', version); |
35 | 36 | const document = fs.readFileSync(src, 'utf8'); |
36 | | - const output = test(JSON.parse(document)); |
37 | | - const dir = path.dirname(dest); |
| 37 | + |
| 38 | + const mainFile = path.join(dir, `${name}.ts`); |
| 39 | + const typeFile = path.join(dir, `${name}.type.ts`); |
| 40 | + const zodFile = path.join(dir, `${name}.zod.ts`); |
| 41 | + |
| 42 | + const { main, type, zod } = test(JSON.parse(document), { |
| 43 | + mainFile, |
| 44 | + typeFile, |
| 45 | + zodFile, |
| 46 | + }); |
38 | 47 |
|
39 | 48 | fs.mkdirSync(dir, { recursive: true }); |
40 | | - fs.writeFileSync(dest, output); |
| 49 | + fs.writeFileSync(mainFile, main.code); |
| 50 | + fs.writeFileSync(typeFile, type.code); |
| 51 | + fs.writeFileSync(zodFile, zod.code); |
41 | 52 | } |
0 commit comments