mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Added support for application/xml handling to include XML envelop body
This commit is contained in:
@@ -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 ?
|
||||
|
||||
Reference in New Issue
Block a user