From 7b1375a25c6cc1a5a625b6666b064a59f7a66b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=A4uerle?= Date: Fri, 29 Sep 2023 13:44:34 +0200 Subject: [PATCH] build: auto-override the OpenAPI file to include the BASE (#242) --- frontend/DEVELOPMENT.md | 2 +- frontend/OpenAPI_back.txt | 33 +++++++++++++++++ frontend/package-lock.json | 75 ++++++++++++++++++++++++++++++++++++++ frontend/package.json | 4 +- 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 frontend/OpenAPI_back.txt diff --git a/frontend/DEVELOPMENT.md b/frontend/DEVELOPMENT.md index b38d0603..eae2e039 100644 --- a/frontend/DEVELOPMENT.md +++ b/frontend/DEVELOPMENT.md @@ -10,7 +10,7 @@ Before starting local development, you need a `.env` file. You can take inspiration for this from the `.env.example` file in this folder. Once you have this set up, you can run `yarn` or `npm install` to install required npm packages and then `yarn dev` or `npm run dev` to run the frontend in dev mode. -When you add a new route to the backend, run `npm run generate-api` to update the functions in the `ZenoService` object. **You must add back the BASE parameter in `zenapi/core/OpenAPI.ts` with the following: `BASE: getEndpoint() + '/api',`** +When you add a new route to the backend, run `npm run generate-api` to update the functions in the `ZenoService` object. ### Static Analysis Tools diff --git a/frontend/OpenAPI_back.txt b/frontend/OpenAPI_back.txt new file mode 100644 index 00000000..dcd07452 --- /dev/null +++ b/frontend/OpenAPI_back.txt @@ -0,0 +1,33 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { getEndpoint } from '$lib/api/util'; +import type { ApiRequestOptions } from './ApiRequestOptions'; + +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; + +export type OpenAPIConfig = { + BASE: string; + VERSION: string; + WITH_CREDENTIALS: boolean; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + TOKEN?: string | Resolver | undefined; + USERNAME?: string | Resolver | undefined; + PASSWORD?: string | Resolver | undefined; + HEADERS?: Headers | Resolver | undefined; + ENCODE_PATH?: ((path: string) => string) | undefined; +}; + +export const OpenAPI: OpenAPIConfig = { + BASE: getEndpoint() + '/api', + VERSION: '0.1.0', + WITH_CREDENTIALS: false, + CREDENTIALS: 'include', + TOKEN: undefined, + USERNAME: undefined, + PASSWORD: undefined, + HEADERS: undefined, + ENCODE_PATH: undefined +}; diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 011d1da6..8065987f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -67,6 +67,7 @@ "postcss": "^8.4.29", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.10.1", + "shx": "^0.3.4", "simple-svelte-autocomplete": "^2.5.2", "smui-theme": "^7.0.0-beta.8", "svelecte": "^3.16.4", @@ -4204,6 +4205,15 @@ "node": ">=12" } }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -5341,6 +5351,18 @@ "node": ">=8.10.0" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dev": true, + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/regl": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/regl/-/regl-2.1.0.tgz", @@ -5654,6 +5676,59 @@ "node": ">=8" } }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dev": true, + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/shelljs/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/shx": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", + "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "dev": true, + "dependencies": { + "minimist": "^1.2.3", + "shelljs": "^0.8.5" + }, + "bin": { + "shx": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/simple-svelte-autocomplete": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/simple-svelte-autocomplete/-/simple-svelte-autocomplete-2.5.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index b97d73d5..c1168a50 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,7 +13,8 @@ "lint": "prettier --plugin-search-dir . --check . && eslint .", "format": "prettier --plugin-search-dir . --write .", "smui-theme": "smui-theme compile static/smui.css -i src/theme", - "generate-api": "npx openapi-typescript-codegen --input http://127.0.0.1:8000/api/openapi.json --output ./src/lib/zenoapi --client fetch; npx prettier -w ./src/lib/zenoapi" + "generate-api": "npx openapi-typescript-codegen --input http://127.0.0.1:8000/api/openapi.json --output ./src/lib/zenoapi --client fetch; npx prettier -w ./src/lib/zenoapi && npm run copy-openapi", + "copy-openapi": "shx cp ./OpenAPI_back.txt ./src/lib/zenoapi/core/OpenAPI.ts" }, "devDependencies": { "@formkit/auto-animate": "^1.0.0-pre-alpha.3", @@ -52,6 +53,7 @@ "postcss": "^8.4.29", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.10.1", + "shx": "^0.3.4", "simple-svelte-autocomplete": "^2.5.2", "smui-theme": "^7.0.0-beta.8", "svelecte": "^3.16.4",