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

View File

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

View File

@@ -41,7 +41,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
done(); 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) { specPath4, function(done) {
var openapi = fs.readFileSync(specPath4, 'utf8'); var openapi = fs.readFileSync(specPath4, 'utf8');
Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => { Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {