changed the order of content type headers in openapi spec file and giving json as a first preference

This commit is contained in:
Dhroov Gupta
2019-07-24 16:05:18 +05:30
parent 7c66411426
commit 012f35bb1f
3 changed files with 9 additions and 15 deletions

View File

@@ -602,25 +602,19 @@ module.exports = {
responseBody: ''
};
}
let headers = Object.keys(contentObj),
result = [];
let headers = Object.keys(contentObj);
for (let i = 0; i < headers.length; i++) {
let headerFamily = this.getHeaderFamily(headers[i]);
if (headerFamily !== HEADER_TYPE.INVALID) {
result.push(headerFamily);
cTypeHeader = headers[i];
hasComputedType = true;
if (headerFamily === HEADER_TYPE.JSON) {
break;
}
}
}
if (result[HEADER_TYPE.JSON]) {
cTypeHeader = result[HEADER_TYPE.JSON];
hasComputedType = true;
}
else if (result[HEADER_TYPE.XML]) {
cTypeHeader = result[HEADER_TYPE.XML];
hasComputedType = true;
}
// if no JSON or XML, take whatever we have
if (!hasComputedType) {
cTypes = Object.keys(contentObj);

View File

@@ -30,13 +30,13 @@
"200": {
"description": "Ok: Successfully processed the request.",
"content": {
"application/vnd.retailer.v3+json": {
"application/vnd.retailer.v3+xml": {
"schema": {
"type": "integer",
"format": "int32"
}
},
"application/vnd.retailer.v3+xml": {
"application/vnd.retailer.v3+json": {
"schema": {
"type": "integer",
"format": "int32"

View File

@@ -41,7 +41,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});
it('should generate collection for a custom content type headers requests.' +
it('Should generate collection for a custom content type headers requests' +
specPath4, function(done) {
var openapi = fs.readFileSync(specPath4, 'utf8');
Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {