-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswagger-config.mjs
More file actions
45 lines (40 loc) · 1006 Bytes
/
swagger-config.mjs
File metadata and controls
45 lines (40 loc) · 1006 Bytes
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
import { resolve } from 'path';
import { generateApi } from 'swagger-typescript-api';
const environments = {
dev: {
url: 'https://petstore.swagger.io/v2/swagger.json',
output: './apis',
},
};
const generateApiForEnv = async (env = 'dev') => {
const config = environments[env];
if (!config) {
throw new Error(`Unknown environment: ${env}`);
}
const baseConfig = {
name: 'Api.ts',
httpClientType: 'fetch',
generateClient: true,
generateRouteTypes: true,
prettier: {
printWidth: 120,
tabWidth: 2,
trailingComma: 'all',
parser: 'typescript',
},
};
try {
await generateApi({
...baseConfig,
url: config.url,
output: resolve(process.cwd(), config.output),
});
console.log(`API generated successfully for ${env} environment!`);
} catch (error) {
console.error(`Error generating API for ${env}:`, error);
process.exit(1);
}
};
(async function main() {
await generateApiForEnv('dev');
})();