forked from extern/bruno
fix(#257): Name collision during Insomnia collection import
This commit is contained in:
parent
e83c2da798
commit
26d99c7aee
@ -30,10 +30,23 @@ const parseGraphQL = (text) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const transformInsomniaRequestItem = (request) => {
|
const addSuffixToDuplicateName = (item, index, allItems) => {
|
||||||
|
// Check if the request name already exist and if so add a number suffix
|
||||||
|
const nameSuffix = allItems.reduce((nameSuffix, otherItem, otherIndex) => {
|
||||||
|
if (otherItem.name === item.name && otherIndex < index) {
|
||||||
|
nameSuffix++;
|
||||||
|
}
|
||||||
|
return nameSuffix;
|
||||||
|
}, 0);
|
||||||
|
return nameSuffix !== 0 ? `${item.name}_${nameSuffix}` : item.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformInsomniaRequestItem = (request, index, allRequests) => {
|
||||||
|
const name = addSuffixToDuplicateName(request, index, allRequests);
|
||||||
|
|
||||||
const brunoRequestItem = {
|
const brunoRequestItem = {
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
name: request.name,
|
name,
|
||||||
type: 'http-request',
|
type: 'http-request',
|
||||||
request: {
|
request: {
|
||||||
url: request.url,
|
url: request.url,
|
||||||
@ -143,14 +156,15 @@ const parseInsomniaCollection = (data) => {
|
|||||||
resources.filter((resource) => resource._type === 'request_group' && resource.parentId === parentId) || [];
|
resources.filter((resource) => resource._type === 'request_group' && resource.parentId === parentId) || [];
|
||||||
const requests = resources.filter((resource) => resource._type === 'request' && resource.parentId === parentId);
|
const requests = resources.filter((resource) => resource._type === 'request' && resource.parentId === parentId);
|
||||||
|
|
||||||
const folders = requestGroups.map((folder) => {
|
const folders = requestGroups.map((folder, index, allFolder) => {
|
||||||
|
const name = addSuffixToDuplicateName(folder, index, allFolder);
|
||||||
const requests = resources.filter(
|
const requests = resources.filter(
|
||||||
(resource) => resource._type === 'request' && resource.parentId === folder._id
|
(resource) => resource._type === 'request' && resource.parentId === folder._id
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
name: folder.name,
|
name,
|
||||||
type: 'folder',
|
type: 'folder',
|
||||||
items: createFolderStructure(resources, folder._id).concat(requests.map(transformInsomniaRequestItem))
|
items: createFolderStructure(resources, folder._id).concat(requests.map(transformInsomniaRequestItem))
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user