diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 69b9714..d3dc190 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -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 = ''; + xmlBody = versionContent + xmlBody; + } + return xmlBody; + }; + bodyData = bodyType === TEXT_XML ? + getXmlVersionContent(bodyData) : + bodyData; updateOptions = { mode: rDataMode, raw: bodyType !== APP_JSON ? diff --git a/test/unit/base.test.js b/test/unit/base.test.js index f2c0d11..29807e7 100644 --- a/test/unit/base.test.js +++ b/test/unit/base.test.js @@ -1152,9 +1152,13 @@ describe('CONVERT FUNCTION TESTS ', function() { expect(conversionResult.result).to.equal(true); expect(conversionResult.output[0].data.item[0].request.body.raw) .to.equal( + '' + '' + - ' ' + - ' 500 '); + ' ' + + '500 ' + + '' + ); done(); }); }); diff --git a/test/unit/util.test.js b/test/unit/util.test.js index 0dec2c8..cce84a8 100644 --- a/test/unit/util.test.js +++ b/test/unit/util.test.js @@ -1664,7 +1664,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () { examples: { xml: { summary: 'A list containing two items', - value: 'text/plain description' + value: 'test' } } } @@ -1675,7 +1675,9 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () { exampleParametersResolution: 'example' }); resultBody = (result.body.raw); - expect(resultBody).to.equal('text/plain description'); + expect(resultBody).to.equal( + 'test' + ); expect(result.contentHeader).to.deep.include( { key: 'Content-Type', value: 'text/xml' }); expect(result.body.options.raw.language).to.equal('xml'); @@ -1839,7 +1841,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () { examples: { xml: { summary: 'A list containing two items', - value: 'text/plain description' + value: 'test' } } } @@ -1850,7 +1852,9 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () { requestParametersResolution: 'example' }); resultBody = (result.body.raw); - expect(resultBody).to.equal('text/plain description'); + expect(resultBody).to.equal( + 'test' + ); expect(result.contentHeader).to.deep.include( { key: 'Content-Type', value: 'text/xml' }); expect(result.body.options.raw.language).to.equal('xml');