Browse Source

fix: normalize OpenAPI generated type name casing (#11575)

Add customFunctionName hook to capitalize operationId first letter,
ensuring generated parameter type names follow PascalCase convention
(e.g., GetFakeCaptchaParams, RuleParams) consistent with schema-derived
types (e.g., CurrentUser, LoginParams). Update service imports to
match regenerated file organization.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
pull/11839/head
afc163 4 months ago
parent
commit
523265d1e4
  1. 26
      config/config.ts
  2. 2
      src/components/RightContent/AvatarDropdown.tsx
  3. 2
      src/pages/table-list/components/CreateForm.tsx
  4. 2
      src/pages/table-list/components/UpdateForm.tsx
  5. 2
      src/pages/table-list/index.tsx
  6. 3
      src/pages/user/login/index.tsx
  7. 85
      src/services/ant-design-pro/api.ts
  8. 6
      src/services/ant-design-pro/index.ts
  9. 38
      src/services/ant-design-pro/login.ts
  10. 42
      src/services/ant-design-pro/rule.ts
  11. 107
      src/services/ant-design-pro/typings.d.ts

26
config/config.ts

@ -205,6 +205,32 @@ export default defineConfig({
// schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
schemaPath: join(__dirname, 'oneapi.json'),
mock: false,
// Capitalize the first letter of operationId so that generated type
// names follow PascalCase convention, consistent with schema-derived
// types. isCamelCase (default true) normalizes function names back to
// camelCase in service files.
hook: {
customFunctionName: ((data: {
operationId?: string;
method?: string;
path?: string;
}) => {
if (data.operationId) {
return (
data.operationId.charAt(0).toUpperCase() +
data.operationId.slice(1)
);
}
const method = data.method || 'get';
const segments = (data.path || '').split('/').filter(Boolean);
const name =
method +
segments
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join('');
return name.charAt(0).toUpperCase() + name.slice(1);
}) as () => any,
},
},
],

2
src/components/RightContent/AvatarDropdown.tsx

@ -7,7 +7,7 @@ import { history, useModel } from '@umijs/max';
import type { MenuProps } from 'antd';
import { Spin } from 'antd';
import React, { startTransition } from 'react';
import { outLogin } from '@/services/ant-design-pro/api';
import { outLogin } from '@/services/ant-design-pro/login';
import HeaderDropdown from '../HeaderDropdown';
type GlobalHeaderRightProps = {

2
src/pages/table-list/components/CreateForm.tsx

@ -9,7 +9,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { FormattedMessage, useIntl } from '@umijs/max';
import { Button, message } from 'antd';
import type { FC } from 'react';
import { addRule } from '@/services/ant-design-pro/api';
import { addRule } from '@/services/ant-design-pro/rule';
interface CreateFormProps {
reload?: ActionType['reload'];

2
src/pages/table-list/components/UpdateForm.tsx

@ -10,7 +10,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { FormattedMessage, useIntl } from '@umijs/max';
import { Modal, message } from 'antd';
import React, { cloneElement, useCallback, useState } from 'react';
import { updateRule } from '@/services/ant-design-pro/api';
import { updateRule } from '@/services/ant-design-pro/rule';
type UpdateFormProps = {
trigger?: React.ReactElement<any>;

2
src/pages/table-list/index.tsx

@ -13,7 +13,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { FormattedMessage, useIntl } from '@umijs/max';
import { Button, Drawer, type FormInstance, Input, message } from 'antd';
import React, { useCallback, useRef, useState } from 'react';
import { removeRule, rule } from '@/services/ant-design-pro/api';
import { removeRule, rule } from '@/services/ant-design-pro/rule';
import CreateForm from './components/CreateForm';
import UpdateForm from './components/UpdateForm';

3
src/pages/user/login/index.tsx

@ -23,8 +23,7 @@ import { Alert, App, Tabs } from 'antd';
import { createStyles } from 'antd-style';
import React, { startTransition, useState } from 'react';
import { Footer } from '@/components';
import { login } from '@/services/ant-design-pro/api';
import { getFakeCaptcha } from '@/services/ant-design-pro/login';
import { getFakeCaptcha, login } from '@/services/ant-design-pro/login';
import Settings from '../../../../config/defaultSettings';
const useStyles = createStyles(({ token }) => {

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

@ -1,94 +1,19 @@
// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
import { request } from "@umijs/max";
/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }) {
return request<{
data: API.CurrentUser;
}>('/api/currentUser', {
method: 'GET',
...(options || {}),
});
}
/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
return request<Record<string, any>>('/api/login/outLogin', {
method: 'POST',
...(options || {}),
});
}
/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
return request<API.LoginResult>('/api/login/account', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data: body,
return request<API.CurrentUser>("/api/currentUser", {
method: "GET",
...(options || {}),
});
}
/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
return request<API.NoticeIconList>('/api/notices', {
method: 'GET',
return request<API.NoticeIconList>("/api/notices", {
method: "GET",
...(options || {}),
});
}
/** 获取规则列表 GET /api/rule */
export async function rule(
params: {
// query
/** 当前的页码 */
current?: number;
/** 页面的容量 */
pageSize?: number;
},
options?: { [key: string]: any },
) {
return request<API.RuleList>('/api/rule', {
method: 'GET',
params: {
...params,
},
...(options || {}),
});
}
/** 更新规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
return request<API.RuleListItem>('/api/rule', {
method: 'POST',
data: {
method: 'update',
...(options || {}),
},
});
}
/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
return request<API.RuleListItem>('/api/rule', {
method: 'POST',
data: {
method: 'post',
...(options || {}),
},
});
}
/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
return request<Record<string, any>>('/api/rule', {
method: 'POST',
data: {
method: 'delete',
...(options || {}),
},
});
}

6
src/services/ant-design-pro/index.ts

@ -2,9 +2,11 @@
/* eslint-disable */
// API 更新时间:
// API 唯一标识:
import * as api from './api';
import * as login from './login';
import * as api from "./api";
import * as login from "./login";
import * as rule from "./rule";
export default {
api,
login,
rule,
};

38
src/services/ant-design-pro/login.ts

@ -1,21 +1,41 @@
// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
import { request } from "@umijs/max";
/** 登录接口 POST /api/login/account */
export async function login(
body: API.LoginParams,
options?: { [key: string]: any }
) {
return request<API.LoginResult>("/api/login/account", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
data: body,
...(options || {}),
});
}
/** 发送验证码 POST /api/login/captcha */
export async function getFakeCaptcha(
params: {
// query
/** 手机号 */
phone?: string;
},
options?: { [key: string]: any },
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params: API.GetFakeCaptchaParams,
options?: { [key: string]: any }
) {
return request<API.FakeCaptcha>('/api/login/captcha', {
method: 'GET',
return request<API.FakeCaptcha>("/api/login/captcha", {
method: "POST",
params: {
...params,
},
...(options || {}),
});
}
/** 登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
return request<Record<string, any>>("/api/login/outLogin", {
method: "POST",
...(options || {}),
});
}

42
src/services/ant-design-pro/rule.ts

@ -0,0 +1,42 @@
// @ts-ignore
/* eslint-disable */
import { request } from "@umijs/max";
/** 获取规则列表 GET /api/rule */
export async function rule(
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params: API.RuleParams,
options?: { [key: string]: any }
) {
return request<API.RuleList>("/api/rule", {
method: "GET",
params: {
...params,
},
...(options || {}),
});
}
/** 新建规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
return request<API.RuleListItem>("/api/rule", {
method: "PUT",
...(options || {}),
});
}
/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
return request<API.RuleListItem>("/api/rule", {
method: "POST",
...(options || {}),
});
}
/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
return request<Record<string, any>>("/api/rule", {
method: "DELETE",
...(options || {}),
});
}

107
src/services/ant-design-pro/typings.d.ts

@ -1,6 +1,3 @@
// @ts-ignore
/* eslint-disable */
declare namespace API {
type CurrentUser = {
name?: string;
@ -23,36 +20,12 @@ declare namespace API {
phone?: string;
};
type LoginResult = {
status?: string;
type?: string;
currentAuthority?: string;
};
type PageParams = {
current?: number;
pageSize?: number;
};
type RuleListItem = {
key?: number;
disabled?: boolean;
href?: string;
avatar?: string;
name?: string;
owner?: string;
desc?: string;
callNo?: number;
status?: number;
updatedAt?: string;
createdAt?: string;
progress?: number;
};
type RuleList = {
data?: RuleListItem[];
/** 列表的内容总数 */
total?: number;
type ErrorResponse = {
/** 业务约定的错误码 */
errorCode: string;
/** 业务上的错误信息 */
errorMessage?: string;
/** 业务上的请求是否成功 */
success?: boolean;
};
@ -61,6 +34,11 @@ declare namespace API {
status?: string;
};
type GetFakeCaptchaParams = {
/** 手机号 */
phone?: string;
};
type LoginParams = {
username?: string;
password?: string;
@ -68,24 +46,12 @@ declare namespace API {
type?: string;
};
type ErrorResponse = {
/** 业务约定的错误码 */
errorCode: string;
/** 业务上的错误信息 */
errorMessage?: string;
/** 业务上的请求是否成功 */
success?: boolean;
};
type NoticeIconList = {
data?: NoticeIconItem[];
/** 列表的内容总数 */
total?: number;
success?: boolean;
type LoginResult = {
status?: string;
type?: string;
currentAuthority?: string;
};
type NoticeIconItemType = 'notification' | 'message' | 'event';
type NoticeIconItem = {
id?: string;
extra?: string;
@ -98,4 +64,47 @@ declare namespace API {
description?: string;
type?: NoticeIconItemType;
};
type NoticeIconItemType = "notification" | "message" | "event";
type NoticeIconList = {
data?: NoticeIconItem[];
/** 列表的内容总数 */
total?: number;
success?: boolean;
};
type PageParams = {
current?: number;
pageSize?: number;
};
type RuleList = {
data?: RuleListItem[];
/** 列表的内容总数 */
total?: number;
success?: boolean;
};
type RuleListItem = {
key?: number;
disabled?: boolean;
href?: string;
avatar?: string;
name?: string;
owner?: string;
desc?: string;
callNo?: number;
status?: number;
updatedAt?: string;
createdAt?: string;
progress?: number;
};
type RuleParams = {
/** 当前的页码 */
current?: number;
/** 页面的容量 */
pageSize?: number;
};
}

Loading…
Cancel
Save