Skip to content

Commit 888e8a5

Browse files
committed
fix(ISSUE-810): oneOf/allOf/anyOf with empty definitions at yaml generating error solving, also add tests
1 parent fec06c6 commit 888e8a5

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export function tsTupleOf(types: string[]): string {
180180
export function tsIntersectionOf(types: string[]): string {
181181
const typesWithValues = types.filter(Boolean);
182182

183+
if (!typesWithValues.length) return "undefined"; // usually allOf/anyOf with empty input - so it's undefined
184+
183185
if (typesWithValues.length === 1) return typesWithValues[0]; // don’t add parentheses around one thing
184186
return `(${typesWithValues.join(") & (")})`;
185187
}
@@ -195,6 +197,8 @@ export function tsReadonly(immutable: boolean): string {
195197

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

test/v3/expected/one-of-empty.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* This file was auto-generated by openapi-typescript.
3+
* Do not make direct changes to the file.
4+
*/
5+
6+
export interface paths {
7+
"/test": {
8+
get: {
9+
responses: {
10+
/** A list of types. */
11+
200: unknown;
12+
};
13+
};
14+
};
15+
}
16+
17+
export interface components {
18+
schemas: {
19+
/** @description Enum with null and nullable */
20+
Example: {
21+
emptyAllOf?: undefined;
22+
emptyOneOf?: undefined;
23+
emptyAnyOf?: undefined;
24+
};
25+
};
26+
}
27+
28+
export interface operations {}
29+
30+
export interface external {}

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)