mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
added a function for header checking.
This commit is contained in:
28
lib/util.js
28
lib/util.js
@@ -12,7 +12,6 @@ const sdk = require('postman-collection'),
|
||||
},
|
||||
URLENCODED = 'application/x-www-form-urlencoded',
|
||||
APP_JSON = 'application/json',
|
||||
APP_VND_JSON = 'application/vnd.api+json',
|
||||
APP_JS = 'application/javascript',
|
||||
APP_XML = 'application/xml',
|
||||
TEXT_XML = 'text/xml',
|
||||
@@ -110,6 +109,16 @@ module.exports = {
|
||||
.replace(/(\{[^\/\{\}]+\})(?!\})/g, '{$1}');
|
||||
},
|
||||
|
||||
checkHeaderType: function(cTypeHeader) {
|
||||
if (cTypeHeader.startsWith('application') && cTypeHeader.endsWith('json')) {
|
||||
return true;
|
||||
}
|
||||
if ((cTypeHeader.startsWith('application') && cTypeHeader.endsWith('xml')) || cTypeHeader === TEXT_XML) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the neccessary server variables to the
|
||||
* something that can be added to the collection
|
||||
@@ -579,16 +588,12 @@ module.exports = {
|
||||
};
|
||||
}
|
||||
|
||||
_.each([APP_JSON, APP_XML, APP_VND_JSON], (supportedCType) => {
|
||||
// these are the content-types that we'd prefer to generate a body for
|
||||
// in this order
|
||||
if (contentObj[supportedCType]) {
|
||||
cTypeHeader = supportedCType;
|
||||
for (let cType in contentObj) {
|
||||
if (this.checkHeaderType(cType)) {
|
||||
cTypeHeader = cType;
|
||||
hasComputedType = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// if no JSON or XML, take whatever we have
|
||||
if (!hasComputedType) {
|
||||
@@ -607,7 +612,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
responseBody = this.convertToPmBodyData(contentObj[cTypeHeader], cTypeHeader, this.options.indentCharacter);
|
||||
if (cTypeHeader.startsWith('application') && cTypeHeader.endsWith('json')) {
|
||||
if (this.checkHeaderType(cTypeHeader) && cTypeHeader.endsWith('json')) {
|
||||
responseBody = JSON.stringify(responseBody, null, this.options.indentCharacter);
|
||||
}
|
||||
else if (typeof responseBody !== 'string') {
|
||||
@@ -720,8 +725,7 @@ module.exports = {
|
||||
bodyObj.schema = this.getRefObject(bodyObj.schema.$ref);
|
||||
}
|
||||
if (this.options.schemaFaker) {
|
||||
if (contentType === APP_XML || contentType === TEXT_XML ||
|
||||
(contentType.startsWith('application') && contentType.endsWith('xml'))) {
|
||||
if (this.checkHeaderType(contentType) && contentType.endsWith('xml')) {
|
||||
schemaType = SCHEMA_FORMATS.XML;
|
||||
}
|
||||
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components, schemaType, indentCharacter);
|
||||
|
||||
Reference in New Issue
Block a user