Skip to content

Commit a9b1831

Browse files
committed
WIP: OAS3 query parameters
1 parent e114650 commit a9b1831

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/execute/oas3-parameter-builders.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import stylize from './oas3-style-serializer'
22
export default {
3-
path
3+
path,
4+
query
45
}
56

67
function path({req, value, parameter}) {
@@ -14,3 +15,31 @@ function path({req, value, parameter}) {
1415

1516
req.url = req.url.replace(`{${name}}`, styledValue)
1617
}
18+
19+
function query({req, value, parameter}) {
20+
req.query = req.query || {}
21+
22+
if (value === false) {
23+
value = 'false'
24+
}
25+
26+
if (value === 0) {
27+
value = '0'
28+
}
29+
30+
if (value) {
31+
req.query[parameter.name] = {
32+
value: stylize({
33+
key: parameter.name,
34+
value,
35+
style: parameter.style || 'form',
36+
explode: parameter.explode || true
37+
})
38+
}
39+
}
40+
else if (parameter.allowEmptyValue) {
41+
const paramName = parameter.name
42+
req.query[paramName] = req.query[paramName] || {}
43+
req.query[paramName].allowEmptyValue = true
44+
}
45+
}

src/execute/oas3-style-serializer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ function encodeArray({key, value, style, explode}) {
2626
return prev + `,${curr}`
2727
}, '')
2828
}
29+
if (style === 'form') {
30+
return value.join(',')
31+
}
2932
}
3033

3134
function encodeObject({key, value, style, explode}) {
@@ -81,4 +84,7 @@ function encodePrimitive({key, value, style, explode}) {
8184
if (style === 'matrix') {
8285
return `;${key}=${value}`
8386
}
87+
if (style === 'form') {
88+
return value
89+
}
8490
}

test/oas3/execute/style-explode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ describe('buildRequest w/ `style` & `explode` - OpenAPI Specification 3.0', func
831831
})
832832
})
833833
describe('query parameters', function () {
834-
describe.skip('primitive values', function () {
834+
describe('primitive values', function () {
835835
const VALUE = 5
836836

837837
it('default: should build a query parameter in form/explode format', function () {
@@ -946,7 +946,7 @@ describe('buildRequest w/ `style` & `explode` - OpenAPI Specification 3.0', func
946946
})
947947
})
948948
})
949-
describe.skip('array values', function () {
949+
describe('array values', function () {
950950
const VALUE = [3, 4, 5]
951951

952952
it('default: should build a query parameter in form/explode format', function () {

0 commit comments

Comments
 (0)