Browse Source

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) <noreply@anthropic.com>
pull/11839/head
afc163 4 months ago
parent
commit
b8fd787d00
  1. 5
      config/config.ts
  2. 7
      config/oneapi.json
  3. 2
      src/app.tsx
  4. 2
      src/services/ant-design-pro/api.ts

5
config/config.ts

@ -210,6 +210,9 @@ export default defineConfig({
// types. isCamelCase (default true) normalizes function names back to // types. isCamelCase (default true) normalizes function names back to
// camelCase in service files. // camelCase in service files.
hook: { 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: { customFunctionName: ((data: {
operationId?: string; operationId?: string;
method?: string; method?: string;
@ -233,7 +236,7 @@ export default defineConfig({
.map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(''); .join('');
return name.charAt(0).toUpperCase() + name.slice(1); return name.charAt(0).toUpperCase() + name.slice(1);
}) as () => any, }) as () => string,
}, },
}, },
], ],

7
config/oneapi.json

@ -24,7 +24,12 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/CurrentUser" "type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/CurrentUser"
}
}
} }
} }
} }

2
src/app.tsx

@ -41,7 +41,7 @@ export async function getInitialState(): Promise<{
const msg = await queryCurrentUser({ const msg = await queryCurrentUser({
skipErrorHandler: true, skipErrorHandler: true,
}); });
return msg; return msg.data;
} catch (_error) { } catch (_error) {
const { pathname, search, hash } = history.location; const { pathname, search, hash } = history.location;
history.replace( history.replace(

2
src/services/ant-design-pro/api.ts

@ -4,7 +4,7 @@ import { request } from "@umijs/max";
/** 获取当前的用户 GET /api/currentUser */ /** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }) { export async function currentUser(options?: { [key: string]: any }) {
return request<API.CurrentUser>("/api/currentUser", { return request<{ data?: API.CurrentUser }>("/api/currentUser", {
method: "GET", method: "GET",
...(options || {}), ...(options || {}),
}); });

Loading…
Cancel
Save