-
Notifications
You must be signed in to change notification settings - Fork 8
/
openapi.config.ts
60 lines (48 loc) · 1.33 KB
/
openapi.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as process from 'process';
import type { GenerateApiParams } from 'swagger-typescript-api';
import { generateApi } from 'swagger-typescript-api';
const cwd = process.cwd();
const templatesDir = path.resolve(cwd, './templates');
const envPath = ['.env.local', '.env'];
const commonParams: Partial<GenerateApiParams> = {
modular: true,
cleanOutput: true,
httpClientType: 'axios',
codeGenConstructs: (struct) => {
return {
Keyword: {
...struct.Keyword,
Object: 'Record<string, any>',
},
};
},
};
const gen = async () => {
let API_HOST = '';
envPath.some((path) => {
dotenv.config({
path,
});
const VITE_API_HOST = process.env.VITE_API_HOST;
if (VITE_API_HOST) {
API_HOST = VITE_API_HOST;
}
return !!VITE_API_HOST;
});
await generateApi({
url: `${API_HOST}/v3/api-docs/%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E6%A8%A1%E5%9D%97`,
output: path.resolve(cwd, './src/services/gen'),
templates: templatesDir,
...commonParams,
});
await generateApi({
url: `${API_HOST}/v3/api-docs/%E7%B3%BB%E7%BB%9F%E6%A8%A1%E5%9D%97`,
output: path.resolve(cwd, './src/services/system'),
templates: templatesDir,
...commonParams,
});
process.exit();
};
gen().catch(console.error);