This repository was archived by the owner on Aug 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (34 loc) · 1.32 KB
/
index.ts
File metadata and controls
43 lines (34 loc) · 1.32 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
#!/usr/bin/env node
import "dotenv/config";
import axios from "axios";
import { OpenAPIV3 } from "openapi-types";
import { version } from "./package.json";
import SwaggerParser from "@apidevtools/swagger-parser";
import { ensureDir, remove, writeFile } from "fs-extra";
import { DIRECTORY, log, logError } from "./src/utils";
import { parseHookFiles } from "./src/hooks";
import openapiTS, { astToString } from "openapi-typescript";
const isPetstore = false;
const run = async () => {
log(`Starting code generation (v${version})`);
const url = isPetstore
? "https://petstore3.swagger.io/api/v3/openapi.json"
: `https://backengine-staging-cnsq.fly.dev`;
const ast = isPetstore
? await openapiTS(new URL(`${url}`))
: await openapiTS(new URL(`${url}/api/docs/json`));
const contents = astToString(ast);
const response = isPetstore
? await axios.get(`${url}`)
: await axios.get(`${url}/api/docs/json`);
const openApiDoc = (await SwaggerParser.dereference(
response.data
)) as OpenAPIV3.Document;
await remove(DIRECTORY);
await ensureDir(DIRECTORY);
await writeFile(`${DIRECTORY}/schema.ts`, contents);
await ensureDir(`${DIRECTORY}/hooks`);
await parseHookFiles(url, openApiDoc);
log("Code generation completed 🚀");
};
run().catch((error) => logError("Code generation failed ❌", error));