Skip to content

Commit

Permalink
keep type information for nullable fields when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
WickyNilliams committed Jan 30, 2024
1 parent cc95995 commit db5ee1f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/openapi-typescript/src/transform/schema-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,13 @@ export function defaultSchemaObjectTransform(schemaObject: SchemaObject | Refere
}

// nullable (3.0)
if (schemaObject.nullable) finalType = tsUnionOf(finalType || "unknown", "null");
if (schemaObject.nullable) {
if ("type" in schemaObject) {
finalType = tsUnionOf(finalType || "Record<string, unknown>", "null");
} else {
finalType = tsUnionOf(finalType || "unknown", "null");
}
}

if (finalType) return finalType;

Expand Down

0 comments on commit db5ee1f

Please sign in to comment.