From 8b20032cad9b9686b84c9a15d1b64a3d32c7b028 Mon Sep 17 00:00:00 2001 From: Johanna Szepanski <johanna.szepanski@softhouse.se> Date: Mon, 26 Aug 2024 14:02:02 +0200 Subject: [PATCH] setup config and scripts for generation of api endpoints --- openapi-config.ts | 12 ++++++++++++ package.json | 3 ++- src/store/emptyApi.ts | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 openapi-config.ts create mode 100644 src/store/emptyApi.ts diff --git a/openapi-config.ts b/openapi-config.ts new file mode 100644 index 00000000..2d13d1b0 --- /dev/null +++ b/openapi-config.ts @@ -0,0 +1,12 @@ +import type { ConfigFile } from "@rtk-query/codegen-openapi"; + +const config: ConfigFile = { + schemaFile: "http://localhost:8080/api/spec", + apiFile: "./src/store/emptyApi.ts", + apiImport: "emptySplitApi", + outputFile: "./src/store/deployApi.ts", + exportName: "deployApi", + hooks: { queries: true, lazyQueries: true, mutations: true } +}; + +export default config; diff --git a/package.json b/package.json index 514445bb..9674925d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "lint:fix": "npm run lint -- --fix", "prettier": "npx prettier src --check", "prettier:fix": "npm run prettier -- --write", - "format": "npm run prettier:fix && npm run lint:fix" + "format": "npm run prettier:fix && npm run lint:fix", + "generate-api": "npx @rtk-query/codegen-openapi openapi-config.ts" }, "browserslist": { "production": [ diff --git a/src/store/emptyApi.ts b/src/store/emptyApi.ts new file mode 100644 index 00000000..f3b426cf --- /dev/null +++ b/src/store/emptyApi.ts @@ -0,0 +1,7 @@ +import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; + +// initialize an empty api service that we'll inject endpoints into later as needed +export const emptySplitApi = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: "/" }), + endpoints: () => ({}) +}); -- GitLab