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

Add support for x-headers extension #147

Merged
merged 2 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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