Added support for application/xml handling to include XML envelop body

This commit is contained in:
Vishal Shingala
2022-07-19 14:39:48 +05:30
parent b402d96edf
commit 1d0e3681c2

View File

@@ -28,6 +28,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
APP_JSON = 'application/json',
APP_JS = 'application/javascript',
TEXT_XML = 'text/xml',
APP_XML = 'application/xml',
TEXT_PLAIN = 'text/plain',
TEXT_HTML = 'text/html',
FORM_DATA = 'multipart/form-data',
@@ -1910,6 +1911,7 @@ module.exports = {
else if (contentObj.hasOwnProperty(APP_JSON)) { bodyType = APP_JSON; }
else if (contentObj.hasOwnProperty(TEXT_HTML)) { bodyType = TEXT_HTML; }
else if (contentObj.hasOwnProperty(TEXT_PLAIN)) { bodyType = TEXT_PLAIN; }
else if (contentObj.hasOwnProperty(APP_XML)) { bodyType = APP_XML; }
else if (contentObj.hasOwnProperty(TEXT_XML)) { bodyType = TEXT_XML; }
else {
// take the first property it has
@@ -1930,20 +1932,24 @@ module.exports = {
};
}
else {
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
let getXmlVersionContent = (bodyContent) => {
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
let xmlBody = bodyContent;
if (!bodyContent.match(regExp)) {
const versionContent = '<?xml version="1.0" encoding="utf-8"?>';
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
xmlBody = versionContent + xmlBody;
}
return xmlBody;
};
bodyData = bodyType === TEXT_XML ?
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML) ?
getXmlVersionContent(bodyData) :
bodyData;
updateOptions = {
mode: rDataMode,
raw: bodyType !== APP_JSON ?