Skip to content

Commit 22ddd55

Browse files
committed
refactor: dedup code
1 parent 7b5e118 commit 22ddd55

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/targets/java/restclient.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,15 @@ module.exports = function (source, options) {
121121

122122
if (Object.keys(source.queryObj).length) {
123123
code.push(1, '.uri("%s", uriBuilder -> {', source.url)
124+
124125
Object.keys(source.queryObj).forEach(function (key) {
125126
const value = source.queryObj[key]
126-
if (Array.isArray(value)) {
127-
value.forEach(function (val) {
128-
code.push(2, 'uriBuilder.queryParam("%qd", "%qd");', key, val)
129-
})
130-
} else {
131-
code.push(2, 'uriBuilder.queryParam("%qd", "%qd");', key, value)
132-
}
127+
const iterable = Array.isArray(value) ? value : [value]
128+
iterable.forEach(function (val) {
129+
code.push(2, 'uriBuilder.queryParam("%qd", "%qd");', key, val)
130+
})
133131
})
132+
134133
code.push(2, 'return uriBuilder.build();')
135134
code.push(1, '})')
136135
} else {

0 commit comments

Comments
 (0)