Skip to content

Commit

Permalink
Merge pull request #1105 from shockey/bug/1103-integer-zero-query-bui…
Browse files Browse the repository at this point in the history
…lder

Include `0` values in query strings
  • Loading branch information
shockey authored Jul 12, 2017
2 parents 3a993d8 + 1a9ca25 commit 11b90f7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export function queryBuilder({req, value, parameter}) {
value = 'false'
}

if (value === 0 && ['number', 'integer'].indexOf(parameter.type) > -1) {
value = '0'
}

if (value) {
req.query[parameter.name] = {
collectionFormat: parameter.collectionFormat,
Expand Down
57 changes: 57 additions & 0 deletions test/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,63 @@ describe('execute', () => {
})
})

it('should include values and defaults that are falsy', function () {
// Given
const spec = {
host: 'swagger.io',
basePath: '/v1',
paths: {
'/one': {
get: {
operationId: 'getMe',
parameters: [
{
name: 'zero',
in: 'query',
type: 'integer'
},
{
name: 'false',
in: 'query',
type: 'boolean'
},
{
name: 'zeroDefault',
in: 'query',
type: 'integer',
default: 0
},
{
name: 'falseDefault',
in: 'query',
type: 'boolean',
default: false
},
]
}
}
}
}

// When
const req = buildRequest({
spec,
operationId: 'getMe',
parameters: {
false: false,
zero: 0
}
})

// Then
expect(req).toEqual({
url: 'http://swagger.io/v1/one?zero=0&false=false&zeroDefault=0&falseDefault=false',
method: 'GET',
credentials: 'same-origin',
headers: { }
})
})

it('should include values for boolean query parameters', function () {
// Given
const spec = {
Expand Down

0 comments on commit 11b90f7

Please sign in to comment.