fork of hey-api/openapi-ts because I need some additional things
1import path from 'node:path';
2import { fileURLToPath } from 'node:url';
3
4import { type UserConfig } from '@hey-api/openapi-python';
5
6import { getSpecsPath } from '../../../utils';
7
8const __filename = fileURLToPath(import.meta.url);
9const __dirname = path.dirname(__filename);
10
11export const createPydanticConfig =
12 ({ openApiVersion, outputDir }: { openApiVersion: string; outputDir: string }) =>
13 (userConfig: UserConfig) => {
14 const input = userConfig.input instanceof Array ? userConfig.input[0]! : userConfig.input;
15 const inputPath = path.join(
16 getSpecsPath(),
17 openApiVersion,
18 typeof input === 'string' ? input : (input.path as string),
19 );
20 return {
21 plugins: ['pydantic'],
22 ...userConfig,
23 input:
24 typeof userConfig.input === 'string'
25 ? inputPath
26 : {
27 ...userConfig.input,
28 path: inputPath,
29 },
30 logs: {
31 level: 'silent',
32 path: './logs',
33 },
34 output: path.join(outputDir, typeof userConfig.output === 'string' ? userConfig.output : ''),
35 } as const satisfies UserConfig;
36 };
37
38export const getSnapshotsPath = (): string => path.join(__dirname, '..', '__snapshots__');
39
40export const getTempSnapshotsPath = (): string => path.join(__dirname, '..', '.gen', 'snapshots');