mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
made some changes
This commit is contained in:
25
lib/util.js
25
lib/util.js
@@ -13,7 +13,6 @@ const sdk = require('postman-collection'),
|
||||
URLENCODED = 'application/x-www-form-urlencoded',
|
||||
APP_JSON = 'application/json',
|
||||
APP_JS = 'application/javascript',
|
||||
APP_XML = 'application/xml',
|
||||
TEXT_XML = 'text/xml',
|
||||
TEXT_PLAIN = 'text/plain',
|
||||
TEXT_HTML = 'text/html',
|
||||
@@ -114,7 +113,7 @@ module.exports = {
|
||||
* @param {string} cTypeHeader - the content type header string
|
||||
* @returns {string} format of content type header
|
||||
*/
|
||||
getContentTypeHeader: function(cTypeHeader) {
|
||||
getContentTypeHeaderFormat: function(cTypeHeader) {
|
||||
if (cTypeHeader.startsWith('application') && cTypeHeader.endsWith('json')) {
|
||||
return 'json';
|
||||
}
|
||||
@@ -594,7 +593,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
for (let cType in contentObj) {
|
||||
if (this.getContentTypeHeader(cType)) {
|
||||
if (this.getContentTypeHeaderFormat(cType)) {
|
||||
cTypeHeader = cType;
|
||||
hasComputedType = true;
|
||||
}
|
||||
@@ -617,7 +616,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
responseBody = this.convertToPmBodyData(contentObj[cTypeHeader], cTypeHeader, this.options.indentCharacter);
|
||||
if (this.getContentTypeHeader(cTypeHeader) === 'json') {
|
||||
if (this.getContentTypeHeaderFormat(cTypeHeader) === 'json') {
|
||||
responseBody = JSON.stringify(responseBody, null, this.options.indentCharacter);
|
||||
}
|
||||
else if (typeof responseBody !== 'string') {
|
||||
@@ -730,7 +729,7 @@ module.exports = {
|
||||
bodyObj.schema = this.getRefObject(bodyObj.schema.$ref);
|
||||
}
|
||||
if (this.options.schemaFaker) {
|
||||
if (this.getContentTypeHeader(contentType) === 'xml') {
|
||||
if (this.getContentTypeHeaderFormat(contentType) === 'xml') {
|
||||
schemaType = SCHEMA_FORMATS.XML;
|
||||
}
|
||||
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components, schemaType, indentCharacter);
|
||||
@@ -1169,23 +1168,11 @@ module.exports = {
|
||||
if (responseBodyWrapper.contentTypeHeader) {
|
||||
// we could infer the content-type header from the body
|
||||
responseHeaders.push({ key: 'Content-Type', value: responseBodyWrapper.contentTypeHeader });
|
||||
if (this.getContentTypeHeader(responseBodyWrapper.contentTypeHeader) === 'json' &&
|
||||
responseBodyWrapper.contentTypeHeader.endsWith('json')) {
|
||||
previewLanguage = 'json';
|
||||
}
|
||||
else if (this.getContentTypeHeader(responseBodyWrapper.contentTypeHeader) === 'xml' &&
|
||||
responseBodyWrapper.contentTypeHeader.endsWith('xml')) {
|
||||
previewLanguage = 'xml';
|
||||
}
|
||||
previewLanguage = this.getContentTypeHeaderFormat(responseBodyWrapper.contentTypeHeader);
|
||||
}
|
||||
else if (response.content && Object.keys(response.content).length > 0) {
|
||||
responseHeaders.push({ key: 'Content-Type', value: Object.keys(response.content)[0] });
|
||||
if (Object.keys(response.content)[0] === APP_JSON) {
|
||||
previewLanguage = 'json';
|
||||
}
|
||||
else if (Object.keys(response.content)[0] === APP_XML) {
|
||||
previewLanguage = 'xml';
|
||||
}
|
||||
previewLanguage = this.getContentTypeHeaderFormat(Object.keys(response.content)[0]);
|
||||
}
|
||||
else {
|
||||
responseHeaders.push({ key: 'Content-Type', value: TEXT_PLAIN });
|
||||
|
||||
@@ -166,12 +166,12 @@ describe('INTERFACE FUNCTION TESTS ', function () {
|
||||
|
||||
describe('Validate content type header function', function() {
|
||||
it('should checks for custom type JSON header', function() {
|
||||
let result = utils.getContentTypeHeader('application/vnd.retailer+json');
|
||||
let result = utils.getContentTypeHeaderFormat('application/vnd.retailer+json');
|
||||
expect(result).to.equal('json');
|
||||
});
|
||||
|
||||
it('should checks for custom type xml header', function() {
|
||||
let result = utils.getContentTypeHeader('application/vnd.retailer+xml');
|
||||
let result = utils.getContentTypeHeaderFormat('application/vnd.retailer+xml');
|
||||
expect(result).to.equal('xml');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user