Skip to content

Commit 2b6b18c

Browse files
committed
fix: handle OpenAPI 3.1 null type to prevent unknown in union types
Schemas with { type: "null" } (used in 3.1 for nullable refs via anyOf) were falling through to the default case, producing T | unknown instead of T | null.
1 parent 728acf5 commit 2b6b18c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ export function getTypeFromSchema(
239239

240240
// Handle types based on the "type" property
241241
if ("type" in schema) {
242+
// OpenAPI 3.1 "null" type (e.g. in anyOf: [{ $ref: "..." }, { type: "null" }])
243+
if ((schema.type as string) === "null") return "null";
244+
242245
// OpenAPI 3.1 supports type as an array, e.g. ["string", "null"]
243246
if (Array.isArray(schema.type)) {
244247
const types = (schema.type as string[]).filter((t) => t !== "null");

0 commit comments

Comments
 (0)