Skip to content

Commit

Permalink
build: auto-override the OpenAPI file to include the BASE (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkier authored Sep 29, 2023
1 parent 157bdf2 commit 7b1375a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions frontend/OpenAPI_back.txt
Original file line number Diff line number Diff line change
@@ -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<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;

export type OpenAPIConfig = {
BASE: string;
VERSION: string;
WITH_CREDENTIALS: boolean;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
TOKEN?: string | Resolver<string> | undefined;
USERNAME?: string | Resolver<string> | undefined;
PASSWORD?: string | Resolver<string> | undefined;
HEADERS?: Headers | Resolver<Headers> | 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
};
75 changes: 75 additions & 0 deletions frontend/package-lock.json

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

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7b1375a

Please sign in to comment.