feat(httpapi): the API is described by an OpenAPI document generated with Huma (#2028)
Every /api operation is registered with Huma behind one admin-token middleware, served at /api/openapi.json with a docs page at /api/docs, and committed as api/openapi.yaml, which task check keeps current.
This commit is contained in:
32 files changed
+4467
-1105
No files matched your search
@@ -22,8 +22,8 @@ async function request(path: string, signal?: AbortSignal): Promise<Response> {
|
||||
const res = await fetch(path, { headers: { Authorization: `Bearer ${token()}` }, signal });
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new ApiError(body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string; detail?: string };
|
||||
throw new ApiError(body.detail ?? body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -276,8 +276,8 @@ async function send<T>(method: string, path: string, payload?: unknown): Promise
|
||||
});
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new ApiError(body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string; detail?: string };
|
||||
throw new ApiError(body.detail ?? body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
}
|
||||
return (await res.json().catch(() => undefined)) as T;
|
||||
}
|
||||
@@ -309,8 +309,8 @@ export async function answerApproval(id: string, approved: boolean): Promise<voi
|
||||
});
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new Error(body.error ?? `${res.status} ${res.statusText}`);
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string; detail?: string };
|
||||
throw new Error(body.detail ?? body.error ?? `${res.status} ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
export type Level = "act_quietly" | "act_and_tell" | "propose_and_wait" | "escalate" | "never";
|
||||
@@ -373,8 +373,8 @@ export async function resetClass(id: string): Promise<void> {
|
||||
});
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new Error(body.error ?? `${res.status} ${res.statusText}`);
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string; detail?: string };
|
||||
throw new Error(body.detail ?? body.error ?? `${res.status} ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user