Skip to content

Commit 1151a54

Browse files
authored
fix(ISSUE-810): oneOf/allOf/anyOf fixing (#830)
* fix(ISSUE-810): oneOf/allOf/anyOf with empty definitions at yaml generating error solving, also add tests * fix(ISSUE-810): tests additional and immutable
1 parent bb52401 commit 1151a54

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ export function tsTupleOf(types: string[]): string {
218218
export function tsIntersectionOf(types: string[]): string {
219219
const typesWithValues = types.filter(Boolean);
220220

221+
if (!typesWithValues.length) return "undefined"; // usually allOf/anyOf with empty input - so it's undefined
222+
221223
if (typesWithValues.length === 1) return typesWithValues[0]; // don’t add parentheses around one thing
222224
return `(${typesWithValues.join(") & (")})`;
223225
}
@@ -233,6 +235,8 @@ export function tsReadonly(immutable: boolean): string {
233235

234236
/** Convert [X, Y, Z] into X | Y | Z */
235237
export function tsUnionOf(types: Array<string | number | boolean>): string {
238+
if (!types.length) return "undefined"; // usually oneOf with empty input - so it's undefined
239+
236240
if (types.length === 1) return `${types[0]}`; // don’t add parentheses around one thing
237241
return `(${types.join(") | (")})`;
238242
}

test/v3/specs/one-of-empty.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: 3.0
2+
paths:
3+
/test:
4+
get:
5+
tags:
6+
- test
7+
summary: "Just a test path"
8+
responses:
9+
200:
10+
description: A list of types.
11+
components:
12+
schemas:
13+
Example:
14+
description: Enum with null and nullable
15+
type: object
16+
properties:
17+
emptyAllOf:
18+
allOf: []
19+
emptyOneOf:
20+
oneOf: []
21+
emptyAnyOf:
22+
anyOf: []

0 commit comments

Comments
 (0)