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

Commit afbf934

Browse files
committed
Build on top of #163 to add support for falsy query and header values as well
1 parent b70fb90 commit afbf934

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe('path values', () => {
191191
).toBe('https://example.com/param-path/456');
192192
});
193193

194-
test('should add non-undefined values to the url', () => {
194+
test('should add falsy values to the url', () => {
195195
expect(
196196
oasToHar(
197197
{},
@@ -271,6 +271,25 @@ describe('query values', () => {
271271
).log.entries[0].request.queryString,
272272
).toEqual([{ name: 'a', value: 'test' }]);
273273
});
274+
275+
test('should add falsy values to the querystring', () => {
276+
expect(
277+
oasToHar(
278+
{},
279+
{
280+
path: '/param-path',
281+
method: 'get',
282+
parameters: [
283+
{
284+
name: 'id',
285+
in: 'query'
286+
},
287+
],
288+
},
289+
{ query: { id: 0 } },
290+
).log.entries[0].request.queryString,
291+
).toEqual([{ name: 'id', value: '0' }]);
292+
});
274293
});
275294

276295
describe('header values', () => {
@@ -389,6 +408,25 @@ describe('header values', () => {
389408
).log.entries[0].request.headers,
390409
).toEqual([{ name: 'Accept', value: 'application/xml' }]);
391410
});
411+
412+
test('should add falsy values to the headers', () => {
413+
expect(
414+
oasToHar(
415+
{},
416+
{
417+
path: '/param-path',
418+
method: 'get',
419+
parameters: [
420+
{
421+
name: 'id',
422+
in: 'header'
423+
},
424+
],
425+
},
426+
{ header: { id: 0 } },
427+
).log.entries[0].request.headers,
428+
).toEqual([{ name: 'id', value: '0' }]);
429+
});
392430
});
393431

394432
const pathOperation = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = (
124124
if (queryStrings && queryStrings.length) {
125125
queryStrings.forEach(queryString => {
126126
const value = formatter(formData, queryString, 'query', true);
127-
if (!value) return;
127+
if (typeof value === 'undefined') return;
128128
har.queryString.push({
129129
name: queryString.name,
130130
value: String(value),
@@ -152,7 +152,7 @@ module.exports = (
152152
if (headers && headers.length) {
153153
headers.forEach(header => {
154154
const value = formatter(formData, header, 'header', true);
155-
if (!value) return;
155+
if (typeof value === 'undefined') return;
156156
har.headers.push({
157157
name: header.name,
158158
value: String(value),

0 commit comments

Comments
 (0)