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 = 'method-class-conflict';
10
11const outputDir = path.join(getTempSnapshotsPath(), namespace);
12const snapshotsDir = path.join(getSnapshotsPath(), namespace);
13
14const specPath = path.join(getSpecsPath(), '3.0.x', 'sdk-method-class-conflict.yaml');
15
16describe(`SDK: ${namespace}`, () => {
17 const createConfig = createConfigFactory({ outputDir });
18
19 const scenarios = [
20 {
21 config: createConfig({
22 input: specPath,
23 output: {
24 entryFile: false,
25 path: 'class',
26 },
27 plugins: [
28 {
29 asClass: true,
30 instance: false,
31 name: '@hey-api/sdk',
32 },
33 ],
34 }),
35 description: 'class',
36 },
37 {
38 config: createConfig({
39 input: specPath,
40 output: {
41 entryFile: false,
42 path: 'flat',
43 },
44 plugins: [
45 {
46 asClass: false,
47 instance: false,
48 name: '@hey-api/sdk',
49 },
50 ],
51 }),
52 description: 'flat',
53 },
54 {
55 config: createConfig({
56 input: specPath,
57 output: {
58 entryFile: false,
59 path: 'instance',
60 },
61 plugins: [
62 {
63 instance: true,
64 name: '@hey-api/sdk',
65 },
66 ],
67 }),
68 description: 'instance',
69 },
70 ];
71
72 it.each(scenarios)(
73 '$description',
74 async ({ config }) => {
75 await createClient(config);
76
77 const filePaths = getFilePaths(
78 typeof config.output === 'string' ? config.output : config.output.path,
79 );
80
81 await Promise.all(
82 filePaths.map(async (filePath) => {
83 const fileContent = fs.readFileSync(filePath, 'utf-8');
84 await expect(fileContent).toMatchFileSnapshot(
85 path.join(snapshotsDir, filePath.slice(outputDir.length + 1)),
86 );
87 }),
88 );
89 },
90 15_000,
91 );
92});