Skip to content

Commit 61b32a5

Browse files
feat: ouput boolean query parameters as booleans, not string enums
chore: fix error chore: fix error chore: fix error chore: remove comments chore: revert changes fix: approach fix: bug
1 parent 68ead3b commit 61b32a5

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

packages/openapi-generator/src/knownImports.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ export const KNOWN_IMPORTS: KnownImports = {
338338
E.right({ type: 'string', format: 'number', decodedType: 'bigint' }),
339339
BooleanFromNumber: () =>
340340
E.right({ type: 'number', enum: [0, 1], decodedType: 'boolean' }),
341-
BooleanFromString: () =>
342-
E.right({ type: 'string', enum: ['true', 'false'], decodedType: 'boolean' }),
341+
BooleanFromString: () => E.right({ type: 'boolean' }),
343342
DateFromISOString: () =>
344343
E.right({ type: 'string', format: 'date-time', title: 'ISO Date String' }),
345344
DateFromNumber: () =>

packages/openapi-generator/src/optimize.ts

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ function consolidateUnion(schema: Schema): Schema {
4040
const consolidatableTypes = ['boolean', 'number', 'string'];
4141
const innerSchemas = schema.schemas.map(optimize);
4242

43+
const booleanSchemas = innerSchemas.filter(
44+
(s) => s.type === 'boolean' || s.decodedType === 'boolean',
45+
);
46+
47+
if (booleanSchemas.length === innerSchemas.length && booleanSchemas.length > 0) {
48+
return { type: 'boolean' };
49+
}
50+
4351
const isConsolidatableType = (s: Schema): boolean => {
4452
return (
4553
(s.primitive && consolidatableTypes.includes(s.type)) ||

packages/openapi-generator/test/openapi/misc.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,3 @@ testCase("route with record types", ROUTE_WITH_RECORD_TYPES, {
292292
}
293293
}
294294
});
295-

packages/openapi-generator/test/openapi/union.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ testCase("route with consolidatable union schemas", ROUTE_WITH_CONSOLIDATABLE_UN
215215
required: true,
216216
schema: {
217217
oneOf: [
218-
{ type: 'string', format: 'number' },
219-
{ type: 'string', enum: ['true', 'false'] }
218+
{ type: 'boolean' },
219+
{ type: 'string', format: 'number' }
220220
]
221221
}
222222
},
@@ -227,15 +227,15 @@ testCase("route with consolidatable union schemas", ROUTE_WITH_CONSOLIDATABLE_UN
227227
schema: {
228228
oneOf: [
229229
{ type: 'string' },
230-
{ type: 'string', enum: ['true', 'false'] }
230+
{ type: 'boolean' }
231231
]
232232
}
233233
},
234234
{
235235
name: 'firstNonUnion',
236236
in: 'query',
237237
required: true,
238-
schema: { type: 'string', enum: ['true', 'false'] }
238+
schema: { type: 'boolean' }
239239
},
240240
{
241241
name: 'secondNonUnion',

0 commit comments

Comments
 (0)