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

Commit 128599d

Browse files
author
Dom Harrington
committed
1 parent 09bee48 commit 128599d

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

example/swagger-files/x-headers.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"openapi": "3.0.0",
3+
"servers": [
4+
{
5+
"url": "http://httpbin.org"
6+
}
7+
],
8+
"info": {
9+
"version": "1.0.0",
10+
"title": "x-headers demo"
11+
},
12+
"paths": {
13+
"/post": {
14+
"post": {
15+
"summary": "Should send static x-headers with the request",
16+
"description": "",
17+
"parameters": [],
18+
"responses": {
19+
"200": {
20+
"description": "Successful"
21+
}
22+
}
23+
}
24+
}
25+
},
26+
"x-headers": [
27+
{
28+
"key": "x-api-key",
29+
"value": "static-value"
30+
}
31+
]
32+
}

packages/api-explorer/__tests__/lib/oas-to-har.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,3 +1184,16 @@ describe('content-type & accept header', () => {
11841184
).toEqual([{ name: 'Content-Type', value: 'application/json' }]);
11851185
});
11861186
});
1187+
1188+
describe('x-headers', () => {
1189+
it('should append any static headers to the request', () => {
1190+
expect(oasToHar({
1191+
'x-headers': [
1192+
{
1193+
key: 'x-api-key',
1194+
value: '123456',
1195+
},
1196+
],
1197+
}).log.entries[0].request.headers).toEqual([{ name: 'x-api-key', value: '123456' }])
1198+
});
1199+
});

packages/api-explorer/src/lib/oas-to-har.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ module.exports = (
160160
});
161161
}
162162

163+
// x-headers static headers
164+
if (oas['x-headers']) {
165+
oas['x-headers'].forEach((header) => {
166+
har.headers.push({
167+
name: header.key,
168+
value: String(header.value),
169+
});
170+
});
171+
}
172+
163173
const schema = getSchema(pathOperation, oas) || { schema: {} };
164174

165175
function stringify(json) {

0 commit comments

Comments
 (0)