Skip to content

Commit 21a6400

Browse files
committed
feat: support OpenAPI 3.1 array-valued type fields
OpenAPI 3.1 uses type arrays (e.g. ["string", "null"]) instead of nullable: true. The switch statement only matched string types, causing all array-typed properties to resolve as unknown.
1 parent dba0b82 commit 21a6400

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/utils.ts

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

240240
// Handle types based on the "type" property
241241
if ("type" in schema) {
242+
// OpenAPI 3.1 supports type as an array, e.g. ["string", "null"]
243+
if (Array.isArray(schema.type)) {
244+
const types = (schema.type as string[]).filter((t) => t !== "null");
245+
const hasNull = (schema.type as string[]).includes("null");
246+
const nullSuffix = hasNull ? " | null" : "";
247+
if (types.length === 0) return `unknown${nullable}`;
248+
// Resolve each type individually by recursing with a single-type schema
249+
const resolved = types.map((t) => getTypeFromSchema({ ...schema, type: t } as OpenAPIV3.SchemaObject));
250+
return resolved.filter(Boolean).join(" | ") + nullSuffix + nullable;
251+
}
252+
242253
switch (schema.type) {
243254
case "string":
244255
// Special case for binary format strings

0 commit comments

Comments
 (0)