Skip to content

Commit 2cdccc0

Browse files
committed
shouldnt remove 0 values from query params
1 parent 804bebb commit 2cdccc0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/types/operation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ Operation.prototype.encodeQueryParam = function (arg, maskPasswords) {
12421242
if(maskPasswords) {
12431243
return "******";
12441244
}
1245-
if(arg) {
1245+
if(arg !== undefined && arg !== null) {
12461246
return encodeURIComponent(arg);
12471247
}
12481248
else {
@@ -1262,4 +1262,4 @@ var mask = function(value, format) {
12621262
return '******';
12631263
}
12641264
return value;
1265-
}
1265+
}

test/client.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,41 @@ describe('SwaggerClient', function () {
16191619
});
16201620
});
16211621

1622+
1623+
it('doesnt remove 0 from query params', function(done) {
1624+
var spec = {
1625+
basePath: '/double/',
1626+
paths: {
1627+
'/foo': {
1628+
get: {
1629+
tags: [
1630+
'test'
1631+
],
1632+
operationId: 'slash',
1633+
parameters: [{
1634+
in: 'query',
1635+
name: 'bar',
1636+
type: 'integer',
1637+
required: false
1638+
}],
1639+
}
1640+
}
1641+
}
1642+
};
1643+
new SwaggerClient({
1644+
url: 'http://localhost:8000/v2/swagger.json',
1645+
spec: spec,
1646+
usePromise: true
1647+
}).then(function(client) {
1648+
var mock = client.test.slash({bar: 0}, {mock: true});
1649+
expect(mock.url).toBe('http://localhost:8000/double/foo?bar=0');
1650+
1651+
done();
1652+
}).catch(function(exception) {
1653+
done(exception);
1654+
});
1655+
});
1656+
16221657
it('honors allowEmptyValue #825 in arrays', function(done) {
16231658
var spec = {
16241659
basePath: '/double/',

0 commit comments

Comments
 (0)