mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
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:
@@ -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 ?
|
||||
|
||||
@@ -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(
|
||||
'<?xml version="1.0" encoding="utf-8"?>' +
|
||||
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">' +
|
||||
' <soap:Body> <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver">' +
|
||||
' <ubiNum>500</ubiNum> </NumberToWords> </soap:Body> </soap:Envelope>');
|
||||
' <soap:Body> <NumberToWords ' +
|
||||
'xmlns="http://www.dataaccess.com/webservicesserver"> ' +
|
||||
'<ubiNum>500</ubiNum> </NumberToWords> </soap:Body> ' +
|
||||
'</soap:Envelope>'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1664,7 +1664,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
|
||||
examples: {
|
||||
xml: {
|
||||
summary: 'A list containing two items',
|
||||
value: 'text/plain description'
|
||||
value: '<AnXMLObject>test</AnXMLObject>'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
'<?xml version="1.0" encoding="utf-8"?><AnXMLObject>test</AnXMLObject>'
|
||||
);
|
||||
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: '<AnXMLObject>test</AnXMLObject>'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
'<?xml version="1.0" encoding="utf-8"?><AnXMLObject>test</AnXMLObject>'
|
||||
);
|
||||
expect(result.contentHeader).to.deep.include(
|
||||
{ key: 'Content-Type', value: 'text/xml' });
|
||||
expect(result.body.options.raw.language).to.equal('xml');
|
||||
|
||||
Reference in New Issue
Block a user