reading from openapi spec
This commit is contained in:
@@ -1,70 +1,14 @@
|
||||
import { AppConfig, ResourceConfig } from "./types/config";
|
||||
import { AppConfig } from "./types/config";
|
||||
import { loadConfigFromOpenApi } from "./utils/openapi_loader";
|
||||
|
||||
const AccountResource: ResourceConfig = {
|
||||
name: "accounts",
|
||||
label: "Account",
|
||||
pluralLabel: "Accounts",
|
||||
endpoint: "/accounts",
|
||||
primaryKey: "id",
|
||||
fields: {
|
||||
id: { type: "string", label: "ID", readOnly: true },
|
||||
name: { type: "string", label: "Name", required: true },
|
||||
type: {
|
||||
type: "enum",
|
||||
label: "Type",
|
||||
required: true,
|
||||
options: ["cash", "bank", "credit_card", "wallet", "other"],
|
||||
},
|
||||
currency: { type: "string", label: "Currency", required: true },
|
||||
is_active: { type: "boolean", label: "Active" },
|
||||
avatar: { type: "image", label: "Account Icon" },
|
||||
},
|
||||
};
|
||||
export async function getAppConfig(): Promise<AppConfig> {
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || "http://localhost:8000"
|
||||
const config = await loadConfigFromOpenApi(baseUrl);
|
||||
|
||||
const TagResource: ResourceConfig = {
|
||||
name: "tags",
|
||||
label: "Tag",
|
||||
pluralLabel: "Tags",
|
||||
endpoint: "/tags",
|
||||
primaryKey: "id",
|
||||
fields: {
|
||||
id: { type: "string", label: "ID", readOnly: true },
|
||||
name: { type: "string", label: "Name", required: true },
|
||||
parent_id: { type: "string", label: "Parent ID" },
|
||||
},
|
||||
};
|
||||
|
||||
const ExpenseResource: ResourceConfig = {
|
||||
name: "expenses",
|
||||
label: "Expense",
|
||||
pluralLabel: "Expenses",
|
||||
endpoint: "/expenses",
|
||||
primaryKey: "id",
|
||||
fields: {
|
||||
id: { type: "string", label: "ID", readOnly: true },
|
||||
amount: { type: "number", label: "Amount", required: true },
|
||||
occurred_at: { type: "datetime", label: "Occurred At", required: true },
|
||||
payee: {
|
||||
type: "object",
|
||||
label: "Payee",
|
||||
required: true,
|
||||
schema: {
|
||||
name: { type: "string", label: "Name", required: true },
|
||||
type: {
|
||||
type: "enum",
|
||||
label: "Type",
|
||||
options: ["merchant", "person", "transfer", "other"],
|
||||
},
|
||||
},
|
||||
},
|
||||
account: { type: "string", label: "Account ID", required: true },
|
||||
tags: { type: "array", label: "Tags" },
|
||||
created_at: { type: "datetime", label: "Created At", readOnly: true },
|
||||
},
|
||||
};
|
||||
|
||||
export const config: AppConfig = {
|
||||
baseUrl: import.meta.env.VITE_API_BASE_URL || "http://localhost:8000",
|
||||
authBaseUrl: import.meta.env.VITE_AUTH_BASE_URL || "http://localhost:8001",
|
||||
resources: [ExpenseResource, AccountResource, TagResource],
|
||||
};
|
||||
// You can still apply overrides here
|
||||
return {
|
||||
...config,
|
||||
authBaseUrl: import.meta.env.VITE_AUTH_BASE_URL || "http://localhost:8001",
|
||||
baseUrl: import.meta.env.VITE_API_BASE_URL || config.baseUrl,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user