Skip to content

Commit 8495795

Browse files
committed
Support booleans as query parameters
1 parent 79aba63 commit 8495795

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/compileValueSchema.ts

+22
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,28 @@ function compileBooleanSchema(compiler: Compiler, schema: OpenAPIBooleanSchema)
809809
return [...nodes, ...enumCheck];
810810
}
811811

812+
// Try to convert the value to a boolean
813+
nodes.push(
814+
builders.ifStatement(
815+
builders.binaryExpression('===', value, builders.literal('true')),
816+
builders.blockStatement([
817+
builders.expressionStatement(
818+
builders.assignmentExpression('=', value, builders.literal(true)),
819+
),
820+
]),
821+
),
822+
);
823+
nodes.push(
824+
builders.ifStatement(
825+
builders.binaryExpression('===', value, builders.literal('false')),
826+
builders.blockStatement([
827+
builders.expressionStatement(
828+
builders.assignmentExpression('=', value, builders.literal(false)),
829+
),
830+
]),
831+
),
832+
);
833+
812834
nodes.push(
813835
builders.ifStatement(
814836
builders.binaryExpression(

tests/gitbook.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ test('GET orgs/microsoft/collections?limit=10', () => {
7676
});
7777
});
7878

79+
test('GET orgs/microsoft/collections?nested=true', () => {
80+
const result = validateRequest({
81+
path: '/orgs/microsoft/collections',
82+
method: 'get',
83+
headers: {
84+
'content-type': 'application/json',
85+
},
86+
query: {
87+
nested: 'true',
88+
},
89+
});
90+
expect(result).toMatchObject({
91+
params: {
92+
organizationId: 'microsoft',
93+
},
94+
query: {
95+
nested: true,
96+
},
97+
});
98+
});
99+
79100
test('POST orgs/appleId/custom-fields', () => {
80101
const result = validateRequest({
81102
path: '/orgs/appleId/spaces',

0 commit comments

Comments
 (0)