Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #147 from readmeio/feature/x-headers
Browse files Browse the repository at this point in the history
Add support for x-headers extension
  • Loading branch information
domharrington committed Sep 13, 2018
2 parents 8aa6286 + 9ea564a commit 91b43f1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example/swagger-files/x-headers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"openapi": "3.0.0",
"servers": [
{
"url": "http://httpbin.org"
}
],
"info": {
"version": "1.0.0",
"title": "x-headers demo"
},
"paths": {
"/post": {
"post": {
"summary": "Should send static x-headers with the request",
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "Successful"
}
}
}
}
},
"x-headers": [
{
"key": "x-api-key",
"value": "static-value"
}
]
}
15 changes: 15 additions & 0 deletions packages/api-explorer/__tests__/lib/oas-to-har.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,18 @@ describe('content-type & accept header', () => {
).toEqual([{ name: 'Content-Type', value: 'application/json' }]);
});
});

describe('x-headers', () => {
it('should append any static headers to the request', () => {
expect(
oasToHar({
'x-headers': [
{
key: 'x-api-key',
value: '123456',
},
],
}).log.entries[0].request.headers,
).toEqual([{ name: 'x-api-key', value: '123456' }]);
});
});
10 changes: 10 additions & 0 deletions packages/api-explorer/src/lib/oas-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ module.exports = (
});
}

// x-headers static headers
if (oas['x-headers']) {
oas['x-headers'].forEach(header => {
har.headers.push({
name: header.key,
value: String(header.value),
});
});
}

const schema = getSchema(pathOperation, oas) || { schema: {} };

function stringify(json) {
Expand Down

0 comments on commit 91b43f1

Please sign in to comment.