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>
afc163 4 months ago
parent
commit
3859e807ff
  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
// 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,
},
},
],

7
config/oneapi.json

@ -24,7 +24,12 @@
"content": {
"application/json": {
"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({
skipErrorHandler: true,
});
return msg;
return msg.data;
} catch (_error) {
const { pathname, search, hash } = history.location;
history.replace(

2
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>("/api/currentUser", {
return request<{ data?: API.CurrentUser }>("/api/currentUser", {
method: "GET",
...(options || {}),
});

Loading…
Cancel
Save