Merge pull request #201 from mirkogolze/bugfix/import-postman-header-check

#192 implement fallback to search body language by header 'content-type'
This commit is contained in:
Anoop M D 2023-09-20 13:04:25 +05:30 committed by GitHub
commit 4016a83626
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,7 +91,10 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
}
if (bodyMode === 'raw') {
const language = get(i, 'request.body.options.raw.language');
let language = get(i, 'request.body.options.raw.language');
if (!language) {
language = searchLanguageByHeader(i.request.header);
}
if (language === 'json') {
brunoRequestItem.request.body.mode = 'json';
brunoRequestItem.request.body.json = i.request.body.raw;
@ -131,6 +134,21 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
});
};
const searchLanguageByHeader = (headers) => {
let contentType;
each(headers, (header) => {
if (header.key.toLowerCase() === 'content-type' && !header.disabled) {
if (typeof header.value == 'string' && /^[\w\-]+\/([\w\-]+\+)?json/.test(header.value)) {
contentType = 'json';
} else if (typeof header.value == 'string' && /^[\w\-]+\/([\w\-]+\+)?xml/.test(header.value)) {
contentType = 'xml';
}
return false;
}
});
return contentType;
};
const importPostmanV2Collection = (collection) => {
const brunoCollection = {
name: collection.info.name,