fix: openapi collection import to not add protocol by default (#3011)

* Update package.json

* Update package.json

* Update package.json

* Update package.json

* revert jest command

* fix: openapi importwith server url

* fix: updates
This commit is contained in:
lohit 2024-09-03 17:32:29 +05:30 committed by GitHub
parent b102898709
commit 8a233fb489
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,9 +31,8 @@ const readFile = (files) => {
}; };
const ensureUrl = (url) => { const ensureUrl = (url) => {
let protUrl = url.startsWith('http') ? url : `http://${url}`; // emoving multiple slashes after the protocol if it exists, or after the beginning of the string otherwise
// replace any double or triple slashes return url.replace(/(^\w+:|^)\/{2,}/, '$1/');
return protUrl.replace(/([^:]\/)\/+/g, '$1');
}; };
const buildEmptyJsonBody = (bodySchema) => { const buildEmptyJsonBody = (bodySchema) => {
@ -67,7 +66,7 @@ const transformOpenapiRequestItem = (request) => {
name: operationName, name: operationName,
type: 'http-request', type: 'http-request',
request: { request: {
url: ensureUrl(request.global.server + '/' + path), url: ensureUrl(request.global.server + path),
method: request.method.toUpperCase(), method: request.method.toUpperCase(),
auth: { auth: {
mode: 'none', mode: 'none',
@ -306,7 +305,7 @@ const getDefaultUrl = (serverObject) => {
url = url.replace(`{${variableName}}`, sub); url = url.replace(`{${variableName}}`, sub);
}); });
} }
return url; return url.endsWith('/') ? url : `${url}/`;
}; };
const getSecurity = (apiSpec) => { const getSecurity = (apiSpec) => {