-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.ts
More file actions
46 lines (41 loc) · 1.2 KB
/
generate.ts
File metadata and controls
46 lines (41 loc) · 1.2 KB
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
import { generateApi } from "swagger-typescript-api";
import * as path from "path";
import * as fs from "fs";
const typesInterfaces = new Set();
/* NOTE: all fields are optional expect one of `output`, `url` or `spec` */
generateApi({
name: "index.ts",
output: path.resolve(process.cwd(), "./src/main/"),
url: "http://localhost:5270/swagger/v1/swagger.json",
// url: "https://dev.api.lingopraxis.com/swagger/v1/swagger.json",
enumNamesAsValues: false,
generateClient: false,
hooks: {
onCreateComponent: (component) => {
//@ts-ignore
if (!component.rawTypeData?.enum) {
typesInterfaces.add(component.typeName);
component.typeName = `I${component.typeName}`;
}
return component;
},
onFormatTypeName: (typeName) => {
if (typesInterfaces.has(typeName)) {
return `I${typeName}`;
}
return typeName;
},
},
})
.then(({ files }) => {
files.forEach(({ content }) => {
fs.writeFile(
path.resolve(process.cwd(), "./src/main/", "index.ts"),
content,
(err: NodeJS.ErrnoException | null) => {
if (err) console.log("error", err);
}
);
});
})
.catch((e) => console.error(e));