Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: auto-override the OpenAPI file to include the BASE #242

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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