Skip to content

Commit 1d0e368

Browse files
author
Vishal Shingala
committed
Added support for application/xml handling to include XML envelop body
1 parent b402d96 commit 1d0e368

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/schemaUtils.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
2828
APP_JSON = 'application/json',
2929
APP_JS = 'application/javascript',
3030
TEXT_XML = 'text/xml',
31+
APP_XML = 'application/xml',
3132
TEXT_PLAIN = 'text/plain',
3233
TEXT_HTML = 'text/html',
3334
FORM_DATA = 'multipart/form-data',
@@ -1910,6 +1911,7 @@ module.exports = {
19101911
else if (contentObj.hasOwnProperty(APP_JSON)) { bodyType = APP_JSON; }
19111912
else if (contentObj.hasOwnProperty(TEXT_HTML)) { bodyType = TEXT_HTML; }
19121913
else if (contentObj.hasOwnProperty(TEXT_PLAIN)) { bodyType = TEXT_PLAIN; }
1914+
else if (contentObj.hasOwnProperty(APP_XML)) { bodyType = APP_XML; }
19131915
else if (contentObj.hasOwnProperty(TEXT_XML)) { bodyType = TEXT_XML; }
19141916
else {
19151917
// take the first property it has
@@ -1930,20 +1932,24 @@ module.exports = {
19301932
};
19311933
}
19321934
else {
1933-
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
1934-
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
19351935
let getXmlVersionContent = (bodyContent) => {
19361936
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
19371937
let xmlBody = bodyContent;
1938+
19381939
if (!bodyContent.match(regExp)) {
1939-
const versionContent = '<?xml version="1.0" encoding="utf-8"?>';
1940+
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
19401941
xmlBody = versionContent + xmlBody;
19411942
}
19421943
return xmlBody;
19431944
};
1944-
bodyData = bodyType === TEXT_XML ?
1945+
1946+
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
1947+
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
1948+
1949+
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML) ?
19451950
getXmlVersionContent(bodyData) :
19461951
bodyData;
1952+
19471953
updateOptions = {
19481954
mode: rDataMode,
19491955
raw: bodyType !== APP_JSON ?

0 commit comments

Comments
 (0)