Skip to content

Commit 1512306

Browse files
authored
Merge pull request #1093 from extempl/master
Fix boolean false parameter
2 parents 420ca04 + 581cb5c commit 1512306

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/execute.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ export function pathBuilder({req, value, parameter}) {
193193
// Add a query to the `query` object, which will later be stringified into the URL's search
194194
export function queryBuilder({req, value, parameter}) {
195195
req.query = req.query || {}
196+
197+
if (value === false && parameter.type === 'boolean') {
198+
value = 'false'
199+
}
200+
196201
if (value) {
197202
req.query[parameter.name] = {
198203
collectionFormat: parameter.collectionFormat,

test/execute.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,39 @@ describe('execute', () => {
379379
})
380380
})
381381

382+
it('should correctly process boolean parameters', function () {
383+
// Given
384+
const spec = {
385+
host: 'swagger.io',
386+
basePath: '/v1',
387+
consumes: ['application/json'],
388+
paths: {
389+
'/pets/findByStatus': {
390+
get: {
391+
operationId: 'getMe',
392+
parameters: [{
393+
in: 'query',
394+
name: 'status',
395+
type: 'boolean',
396+
required: false
397+
}]
398+
}
399+
}
400+
}
401+
}
402+
403+
// When
404+
const req = buildRequest({spec, operationId: 'getMe', parameters: {status: false}})
405+
406+
// Then
407+
expect(req).toEqual({
408+
url: 'http://swagger.io/v1/pets/findByStatus?status=false',
409+
method: 'GET',
410+
credentials: 'same-origin',
411+
headers: { }
412+
})
413+
})
414+
382415
it('should throw error if there is no parameter value', function () {
383416
// Given
384417
const spec = {

0 commit comments

Comments
 (0)