Skip to content

Commit

Permalink
refactor: adjust api generator
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Oct 9, 2024
1 parent 3fe1dbf commit a1a0143
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 65 deletions.
49 changes: 15 additions & 34 deletions generate-api.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
import fs from "fs";
import path from "path";
import { generateApi } from "swagger-typescript-api";

const PATH_TO_OUTPUT_DIR = path.resolve(process.cwd(), "./src/__generated__");

/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
generateApi({
name: "generated-sonarr-api.ts",
output: PATH_TO_OUTPUT_DIR,
url: "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/src/Sonarr.Api.V3/openapi.json",
httpClientType: "axios",
})
.then(({ files, configuration }) => {
files.forEach(({ content, name }) => {
fs.writeFile(path, content);
});
})
.catch((e) => console.error(e));
const main = async () => {
await generateApi({
name: "generated-sonarr-api.ts",
output: PATH_TO_OUTPUT_DIR,
url: "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/src/Sonarr.Api.V3/openapi.json",
httpClientType: "axios",
});

generateApi({
name: "generated-radarr-api.ts",
output: PATH_TO_OUTPUT_DIR,
url: "https://raw.githubusercontent.com/Radarr/Radarr/develop/src/Radarr.Api.V3/openapi.json",
httpClientType: "axios",
})
.then(({ files, configuration }) => {
files.forEach(({ content, name }) => {
fs.writeFile(path, content);
});
})
.catch((e) => console.error(e));
await generateApi({
name: "generated-radarr-api.ts",
output: PATH_TO_OUTPUT_DIR,
url: "https://raw.githubusercontent.com/Radarr/Radarr/develop/src/Radarr.Api.V3/openapi.json",
httpClientType: "axios",
});
};

// generateTemplates({
// cleanOutput: false,
// output: PATH_TO_OUTPUT_DIR,
// httpClientType: "fetch",
// modular: false,
// silent: false,
// rewrite: false,
// });
main();
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"type": "module",
"scripts": {
"coverage": "vitest run --coverage",
"generateApi": "tsx generate-api.js",
"generateApi": "tsx generate-api.js && prettier src/__generated__ --write",
"start": "tsx index.ts",
"test": "vitest",
"tsg": "swagger-to-ts -f input.json -o test.ts",
"type-check": "tsc --noEmit",
"build": "tsx esbuild.ts"
},
Expand All @@ -21,18 +20,17 @@
"pino": "9.4.0",
"pino-pretty": "11.2.2",
"simple-git": "3.27.0",
"swagger-typescript-api": "13.0.22",
"tsx": "4.19.1",
"yaml": "2.5.1"
},
"devDependencies": {
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
"@infinite-debugger/swagger-to-ts": "0.1.0-alpha.124",
"@playwright/test": "1.48.0",
"@types/node": "22.7.5",
"@vitest/coverage-v8": "2.1.2",
"esbuild": "^0.24.0",
"prettier": "3.3.3",
"swagger-typescript-api": "13.0.22",
"typescript": "5.6.3",
"vitest": "2.1.2"
}
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions src/__generated__/generated-radarr-api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions src/__generated__/generated-sonarr-api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1a0143

Please sign in to comment.