-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: uninstall default and import problem (#267)
* fix: uninstall default and import --------- Co-authored-by: sunzhouyang <[email protected]>
- Loading branch information
Showing
4 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const defaultExtensions = ['postcat-export-openapi', 'postcat-import-openapi']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { cloneDeep } from 'lodash-es'; | ||
export interface ParamAttr { | ||
example: string; | ||
} | ||
|
||
export interface ChildList { | ||
name: string; | ||
isRequired: number; | ||
description: string; | ||
paramAttr: ParamAttr; | ||
dataType: number; | ||
} | ||
|
||
export interface RootObject { | ||
name: string; | ||
isRequired: number; | ||
paramAttr: ParamAttr; | ||
dataType: number; | ||
description: string; | ||
childList: ChildList[]; | ||
} | ||
|
||
/** | ||
* @description Merge specified key | ||
* @param {RootObject[]} baseArr baseArr | ||
* @param {RootObject[]} newDataArr newDataArr | ||
* @param {string} mergerKey specified key | ||
* @param {string} childKey childList correspondence key | ||
* @param {boolean} childKey isChild | ||
* @return {RootObject[]} assginArr | ||
*/ | ||
|
||
export const pcMerge = ( | ||
baseArr: RootObject[], | ||
newDataArr: RootObject[], | ||
mergerKey: string, | ||
childKey: string, | ||
isChild: boolean | ||
): RootObject[] => { | ||
let handleData = !isChild ? cloneDeep(baseArr) : baseArr; | ||
for (let item of newDataArr) { | ||
//If you can't find this name, just push it | ||
if (handleData.findIndex(ele => ele.name === item.name) === -1) handleData.push(item); | ||
else { | ||
for (let ele of handleData) { | ||
if (item.name === ele.name) { | ||
//Assigns the specified key | ||
ele[mergerKey] = item[mergerKey]; | ||
if (item[childKey] && item[childKey].length !== 0) { | ||
if (ele[childKey]) { | ||
//Subtree recursion | ||
pcMerge(ele[childKey], item[childKey], mergerKey, childKey, true); | ||
} else { | ||
ele[childKey] = item[childKey]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return handleData; | ||
}; |