fork of hey-api/openapi-ts because I need some additional things
1import fs from 'node:fs';
2import path from 'node:path';
3
4import { createClient } from '@hey-api/openapi-ts';
5
6import { getFilePaths, getSpecsPath } from '../../utils';
7import { createConfigFactory, getSnapshotsPath, getTempSnapshotsPath } from './utils';
8
9const namespace = 'opencode';
10
11const outputDir = path.join(getTempSnapshotsPath(), namespace);
12const snapshotsDir = path.join(getSnapshotsPath(), namespace);
13
14const specPath = path.join(getSpecsPath(), '3.1.x', 'opencode.yaml');
15
16describe(`SDK: ${namespace}`, () => {
17 const createConfig = createConfigFactory({ outputDir });
18
19 const scenarios = [
20 {
21 config: createConfig({
22 input: specPath,
23 output: {
24 path: 'export-all',
25 preferExportAll: true,
26 },
27 plugins: [
28 {
29 name: '@hey-api/sdk',
30 paramsStructure: 'flat',
31 },
32 ],
33 }),
34 description: 'export all',
35 },
36 {
37 config: createConfig({
38 input: specPath,
39 output: 'flat',
40 plugins: [
41 {
42 name: '@hey-api/sdk',
43 paramsStructure: 'flat',
44 },
45 ],
46 }),
47 description: 'flat',
48 },
49 {
50 config: createConfig({
51 input: specPath,
52 output: 'grouped',
53 plugins: [
54 {
55 name: '@hey-api/sdk',
56 paramsStructure: 'grouped',
57 },
58 ],
59 }),
60 description: 'grouped',
61 },
62 ];
63
64 it.each(scenarios)(
65 '$description',
66 async ({ config }) => {
67 await createClient(config);
68
69 const filePaths = getFilePaths(
70 typeof config.output === 'string' ? config.output : config.output.path,
71 );
72
73 await Promise.all(
74 filePaths.map(async (filePath) => {
75 const fileContent = fs.readFileSync(filePath, 'utf-8');
76 await expect(fileContent).toMatchFileSnapshot(
77 path.join(snapshotsDir, filePath.slice(outputDir.length + 1)),
78 );
79 }),
80 );
81 },
82 15_000,
83 );
84});