From a1a0143269c03a3ffbe32adf431a67392114b8d7 Mon Sep 17 00:00:00 2001 From: Eduard Marbach Date: Wed, 9 Oct 2024 16:15:00 +0200 Subject: [PATCH] refactor: adjust api generator --- generate-api.js | 49 +++++++---------------- package.json | 6 +-- pnpm-lock.yaml | 6 +-- src/__generated__/generated-radarr-api.ts | 19 ++++----- src/__generated__/generated-sonarr-api.ts | 19 ++++----- 5 files changed, 34 insertions(+), 65 deletions(-) diff --git a/generate-api.js b/generate-api.js index d9364c8..b370fe1 100644 --- a/generate-api.js +++ b/generate-api.js @@ -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(); diff --git a/package.json b/package.json index 96099b6..30ace10 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f793129..d3da7c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: simple-git: specifier: 3.27.0 version: 3.27.0 - swagger-typescript-api: - specifier: 13.0.22 - version: 13.0.22 tsx: specifier: 4.19.1 version: 4.19.1 @@ -57,6 +54,9 @@ importers: prettier: specifier: 3.3.3 version: 3.3.3 + swagger-typescript-api: + specifier: 13.0.22 + version: 13.0.22 typescript: specifier: 5.6.3 version: 5.6.3 diff --git a/src/__generated__/generated-radarr-api.ts b/src/__generated__/generated-radarr-api.ts index e29f8ce..3297733 100644 --- a/src/__generated__/generated-radarr-api.ts +++ b/src/__generated__/generated-radarr-api.ts @@ -1724,9 +1724,7 @@ export interface FullRequestParams extends Omit; export interface ApiConfig extends Omit { - securityWorker?: ( - securityData: SecurityDataType | null, - ) => Promise | AxiosRequestConfig | void; + securityWorker?: (securityData: SecurityDataType | null) => Promise | AxiosRequestConfig | void; secure?: boolean; format?: ResponseType; } @@ -1806,10 +1804,7 @@ export class HttpClient { ...params }: FullRequestParams): Promise> => { const secureParams = - ((typeof secure === "boolean" ? secure : this.secure) && - this.securityWorker && - (await this.securityWorker(this.securityData))) || - {}; + ((typeof secure === "boolean" ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); const responseFormat = format || this.format || undefined; @@ -2853,7 +2848,7 @@ export class Api extends HttpClient extends HttpClient extends HttpClient extends HttpClient extends HttpClient; export interface ApiConfig extends Omit { - securityWorker?: ( - securityData: SecurityDataType | null, - ) => Promise | AxiosRequestConfig | void; + securityWorker?: (securityData: SecurityDataType | null) => Promise | AxiosRequestConfig | void; secure?: boolean; format?: ResponseType; } @@ -1861,10 +1859,7 @@ export class HttpClient { ...params }: FullRequestParams): Promise> => { const secureParams = - ((typeof secure === "boolean" ? secure : this.secure) && - this.securityWorker && - (await this.securityWorker(this.securityData))) || - {}; + ((typeof secure === "boolean" ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); const responseFormat = format || this.format || undefined; @@ -2764,7 +2759,7 @@ export class Api extends HttpClient extends HttpClient extends HttpClient extends HttpClient extends HttpClient