Skip to content

Commit

Permalink
fix: cannot validate existed service name successfully in the rename …
Browse files Browse the repository at this point in the history
…modal
  • Loading branch information
Orchardxyz committed Feb 28, 2024
1 parent e671b66 commit 2b12084
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to the "tswagger" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

### Fixed

- Cannot validate existed service name successfully in the rename modal.

## [2.0.2] - 2024-02-27

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const tsTypeRenameRule: Rule = {
message: '类型名称只能包含英文和数字, 且首字母必须大写',
};

type ValidateServiceNameInfo = {
groupName: string;
method: string;
path: string;
};

const convertNameMappingList = (nameMappingList: ApiGroupNameMapping[]) => {
const allGroupName = [...new Set(nameMappingList.map((name) => name.groupName))];
const newGroup: NameMappingByGroup[] = [];
Expand Down Expand Up @@ -98,13 +104,8 @@ const ResultRenameDrawer: React.FC<ResultRenameDrawerProps> = (props) => {
}
});

/**
* 验证同一分组下的接口方法名称是否重复
* @param groupNamePath - 分组路径
* @param serviceName - 接口方法名称
* @returns {Promise<void>} - 返回一个Promise对象,如果同一分组下的接口方法名称重复则抛出错误,否则解析为void
*/
const validateSameServiceName = (groupName: string, groupNamePath: NamePath, serviceName?: string) => {
const validateSameServiceName = (info: ValidateServiceNameInfo, groupNamePath: NamePath, serviceName?: string) => {
const { groupName, method, path } = info;
const currentGroup = (form.getFieldValue(groupNamePath) ?? []) as ApiGroupNameMapping[];
const hasSameServiceName = currentGroup.filter((item) => item.serviceName === serviceName).length > 1;

Expand All @@ -113,7 +114,7 @@ const ResultRenameDrawer: React.FC<ResultRenameDrawerProps> = (props) => {
}

const localGroup = localServiceInfo.find((item) => item.groupName === groupName);
if (localGroup && localGroup.nameMappingList.some((item) => item.serviceName === serviceName)) {
if (localGroup && localGroup.nameMappingList.some((item) => item.serviceName === serviceName && (item.method !== method || item.path !== path))) {
return Promise.reject(new Error(`本地<${groupName}>分组下存在相同名称的接口文件,请重新命名`));
}

Expand Down

0 comments on commit 2b12084

Please sign in to comment.