Skip to content

Commit

Permalink
Fix response headers being rendered incorrectly. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickwb authored and kevinrenskers committed Jan 10, 2017
1 parent 8af068e commit 1456475
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions consistency-helpers.js
Expand Up @@ -39,6 +39,16 @@ function makeConsistent(obj, types) {
delete obj.securedBy;
}

// Fix inconsistency between request headers and response headers from raml-1-parser.
// https://github.com/raml-org/raml-js-parser-2/issues/582
if (Array.isArray(obj.headers)) {
obj.headers.forEach((hdr) => {
if (typeof hdr.key === 'undefined' && hdr.name) {
hdr.key = hdr.name;
}
});
}

Object.keys(obj).forEach((key) => {
const value = obj[key];
makeConsistent(value, types);
Expand Down
12 changes: 12 additions & 0 deletions test/consistent-headers.raml
@@ -0,0 +1,12 @@
#%RAML 1.0
title: Consistent Headers


/A:
get:
headers:
X-Some-Header: string
responses:
200:
headers:
X-Some-Other-Header: string
26 changes: 26 additions & 0 deletions test/consistent-headers.spec.js
@@ -0,0 +1,26 @@
/* eslint-env node, mocha */

'use strict';

const raml2obj = require('..');
const assert = require('assert');

describe('raml2obj', () => {
describe('consistent-headers.raml', () => {
let obj;

before((done) => {
raml2obj.parse('test/consistent-headers.raml').then((result) => {
obj = result;
done();
}, (error) => {
console.log('error', error);
});
});

it('should have keys on both request and response headers', () => {
assert.strictEqual(obj.resources[0].methods[0].headers[0].key, 'X-Some-Header');
assert.strictEqual(obj.resources[0].methods[0].responses[0].headers[0].key, 'X-Some-Other-Header');
});
});
});

0 comments on commit 1456475

Please sign in to comment.