From b8fd787d00c4abfdd2dde318e6aa060765ba84bd Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 2 Jun 2026 12:05:31 +0800 Subject: [PATCH] fix: preserve currentUser data envelope and tighten openapi hook types - Wrap /api/currentUser response in { data } in oneapi.json so the generated service matches the actual mock and worker response shape, restoring msg.data dereference in getInitialState (regression would have left currentUser as the response envelope, breaking access checks) - Narrow the customFunctionName cast from () => any to () => string Co-Authored-By: Claude Opus 4.8 (1M context) --- config/config.ts | 5 ++++- config/oneapi.json | 7 ++++++- src/app.tsx | 2 +- src/services/ant-design-pro/api.ts | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/config.ts b/config/config.ts index ec01b259..8285dcd6 100644 --- a/config/config.ts +++ b/config/config.ts @@ -210,6 +210,9 @@ export default defineConfig({ // types. isCamelCase (default true) normalizes function names back to // camelCase in service files. hook: { + // The plugin types this hook as `() => any` but invokes it with the + // operation data at runtime; cast to `() => string` to keep the real + // return type while satisfying the loose upstream signature. customFunctionName: ((data: { operationId?: string; method?: string; @@ -233,7 +236,7 @@ export default defineConfig({ .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(''); return name.charAt(0).toUpperCase() + name.slice(1); - }) as () => any, + }) as () => string, }, }, ], diff --git a/config/oneapi.json b/config/oneapi.json index c77d988b..b3aae19e 100644 --- a/config/oneapi.json +++ b/config/oneapi.json @@ -24,7 +24,12 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CurrentUser" + "type": "object", + "properties": { + "data": { + "$ref": "#/components/schemas/CurrentUser" + } + } } } } diff --git a/src/app.tsx b/src/app.tsx index 0650b348..d7dfbd30 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -41,7 +41,7 @@ export async function getInitialState(): Promise<{ const msg = await queryCurrentUser({ skipErrorHandler: true, }); - return msg; + return msg.data; } catch (_error) { const { pathname, search, hash } = history.location; history.replace( diff --git a/src/services/ant-design-pro/api.ts b/src/services/ant-design-pro/api.ts index fdd5afaf..39ccb44a 100644 --- a/src/services/ant-design-pro/api.ts +++ b/src/services/ant-design-pro/api.ts @@ -4,7 +4,7 @@ import { request } from "@umijs/max"; /** 获取当前的用户 GET /api/currentUser */ export async function currentUser(options?: { [key: string]: any }) { - return request("/api/currentUser", { + return request<{ data?: API.CurrentUser }>("/api/currentUser", { method: "GET", ...(options || {}), });