Adding xml version data to body if not present

- When content is text/xml and the provided body or example does not contain the version data it will be added at the beginning.
This commit is contained in:
Erik Mendoza
2022-07-18 21:00:41 -05:00
parent 3cce44aca9
commit b402d96edf
3 changed files with 26 additions and 7 deletions

View File

@@ -1932,7 +1932,18 @@ 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"?>';
xmlBody = versionContent + xmlBody;
}
return xmlBody;
};
bodyData = bodyType === TEXT_XML ?
getXmlVersionContent(bodyData) :
bodyData;
updateOptions = {
mode: rDataMode,
raw: bodyType !== APP_JSON ?