Skip to content

Commit a980cd5

Browse files
committed
fix: correctly transform untyped nullable field to
1 parent f229f24 commit a980cd5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.changeset/large-ways-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
Correctly transform untyped nullable fields to `unknown`

packages/openapi-typescript/src/transform/schema-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export function defaultSchemaObjectTransform(schemaObject: SchemaObject | Refere
267267
}
268268

269269
// nullable (3.0)
270-
if (schemaObject.nullable) finalType = tsUnionOf(finalType || "Record<string, unknown>", "null");
270+
if (schemaObject.nullable) finalType = tsUnionOf(finalType || "unknown", "null");
271271

272272
if (finalType) return finalType;
273273

packages/openapi-typescript/test/schema-object.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ describe("Schema Object", () => {
374374
const generated = transformSchemaObject({}, options);
375375
expect(generated).toBe(`unknown`);
376376
});
377+
378+
test("unknown nullable", () => {
379+
const generated = transformSchemaObject({ nullable: true }, options);
380+
expect(generated).toBe(`unknown`);
381+
});
377382
});
378383

379384
describe("schema composition", () => {

0 commit comments

Comments
 (0)