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 { createSdkConfig, 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 = createSdkConfig({
18 outputDir,
19 });
20
21 const scenarios = [
22 {
23 config: createConfig({
24 input: specPath,
25 output: {
26 path: 'export-all',
27 preferExportAll: true,
28 },
29 plugins: [
30 {
31 name: '@hey-api/sdk',
32 paramsStructure: 'flat',
33 },
34 ],
35 }),
36 description: 'export all',
37 },
38 {
39 config: createConfig({
40 input: specPath,
41 output: 'flat',
42 plugins: [
43 {
44 name: '@hey-api/sdk',
45 paramsStructure: 'flat',
46 },
47 ],
48 }),
49 description: 'flat',
50 },
51 {
52 config: createConfig({
53 input: specPath,
54 output: 'grouped',
55 plugins: [
56 {
57 name: '@hey-api/sdk',
58 paramsStructure: 'grouped',
59 },
60 ],
61 }),
62 description: 'grouped',
63 },
64 ];
65
66 it.each(scenarios)(
67 '$description',
68 async ({ config }) => {
69 await createClient(config);
70
71 const filePaths = getFilePaths(
72 typeof config.output === 'string' ? config.output : config.output.path,
73 );
74
75 await Promise.all(
76 filePaths.map(async (filePath) => {
77 const fileContent = fs.readFileSync(filePath, 'utf-8');
78 await expect(fileContent).toMatchFileSnapshot(
79 path.join(snapshotsDir, filePath.slice(outputDir.length + 1)),
80 );
81 }),
82 );
83 },
84 15_000,
85 );
86});