mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
* Refactor URL construction in Postman collection processing * Updated the constructUrl function and made it more loose. Also now when there is a param with its key as undefined we discard it. * Handled the case when the url is an object and dosen't have a raw value. * Added missing return. * Removed the URL fragments * Removed unused destructures. * Minor changes.
This commit is contained in:
parent
858afdbf03
commit
eb33504f19
@ -54,6 +54,47 @@ const convertV21Auth = (array) => {
|
|||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const constructUrlFromParts = (url) => {
|
||||||
|
const { protocol = 'http', host, path, port, query, hash } = url || {};
|
||||||
|
const hostStr = Array.isArray(host) ? host.filter(Boolean).join('.') : host || '';
|
||||||
|
const pathStr = Array.isArray(path) ? path.filter(Boolean).join('/') : path || '';
|
||||||
|
const portStr = port ? `:${port}` : '';
|
||||||
|
const queryStr =
|
||||||
|
query && Array.isArray(query) && query.length > 0
|
||||||
|
? `?${query
|
||||||
|
.filter((q) => q.key)
|
||||||
|
.map((q) => `${q.key}=${q.value || ''}`)
|
||||||
|
.join('&')}`
|
||||||
|
: '';
|
||||||
|
const urlStr = `${protocol}://${hostStr}${portStr}${pathStr ? `/${pathStr}` : ''}${queryStr}`;
|
||||||
|
return urlStr;
|
||||||
|
};
|
||||||
|
|
||||||
|
const constructUrl = (url) => {
|
||||||
|
if (!url) return '';
|
||||||
|
|
||||||
|
if (typeof url === 'string') {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof url === 'object') {
|
||||||
|
const { raw } = url;
|
||||||
|
|
||||||
|
if (raw && typeof raw === 'string') {
|
||||||
|
// If the raw URL contains url-fragments remove it
|
||||||
|
if (raw.includes('#')) {
|
||||||
|
return raw.split('#')[0]; // Returns the part of raw URL without the url-fragment part.
|
||||||
|
}
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no raw value exists, construct the URL from parts
|
||||||
|
return constructUrlFromParts(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
let translationLog = {};
|
let translationLog = {};
|
||||||
|
|
||||||
const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) => {
|
const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) => {
|
||||||
@ -94,12 +135,7 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) =
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = '';
|
const url = constructUrl(i.request.url);
|
||||||
if (typeof i.request.url === 'string') {
|
|
||||||
url = i.request.url;
|
|
||||||
} else {
|
|
||||||
url = get(i, 'request.url.raw') || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const brunoRequestItem = {
|
const brunoRequestItem = {
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
@ -107,7 +143,7 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) =
|
|||||||
type: 'http-request',
|
type: 'http-request',
|
||||||
request: {
|
request: {
|
||||||
url: url,
|
url: url,
|
||||||
method: i.request.method,
|
method: i?.request?.method?.toUpperCase(),
|
||||||
auth: {
|
auth: {
|
||||||
mode: 'none',
|
mode: 'none',
|
||||||
basic: null,
|
basic: null,
|
||||||
@ -313,12 +349,17 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) =
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
each(get(i, 'request.url.variable'), (param) => {
|
each(get(i, 'request.url.variable', []), (param) => {
|
||||||
|
if (!param.key) {
|
||||||
|
// If no key, skip this iteration and discard the param
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
brunoRequestItem.request.params.push({
|
brunoRequestItem.request.params.push({
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
name: param.key,
|
name: param.key,
|
||||||
value: param.value,
|
value: param.value ?? '',
|
||||||
description: param.description,
|
description: param.description ?? '',
|
||||||
type: 'path',
|
type: 'path',
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user