-
Notifications
You must be signed in to change notification settings - Fork 0
/
openapi-codegen.config.ts
42 lines (33 loc) · 1007 Bytes
/
openapi-codegen.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
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { generateSchemaTypes } from '@openapi-codegen/typescript';
import { defineConfig } from '@openapi-codegen/cli';
const apiName = process.env.API_NAME || 'elorus';
if (!existsSync(`./${apiName}.json`)) {
throw new Error(`./${apiName}.json does not exist.`);
}
const openapiFolder = `./src/openapi/${apiName}`;
if (!existsSync(openapiFolder)) {
mkdirSync(openapiFolder);
}
function capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
writeFileSync(
`${openapiFolder}/index.ts`,
`export type * as ${capitalizeFirstLetter(apiName)} from './${apiName}Schemas';`,
);
const config = defineConfig({
[apiName]: {
from: {
source: 'file',
relativePath: `./${apiName}.json`,
},
outputDir: `src/openapi/${apiName}`,
to: async (context) => {
await generateSchemaTypes(context, {
filenamePrefix: apiName,
});
},
},
});
export default config;