From 04e877379149431d30d070b0edc86cd614c43f12 Mon Sep 17 00:00:00 2001 From: David Velasquez Date: Mon, 8 Jun 2026 16:40:01 -0500 Subject: [PATCH 1/2] Fix: honor `nullable: true` on object types with additionalProperties `nonArraySchemaObjectTypeToTs` wraps the non-dictionary return in its `case "object"` branch via `appendNullToUnion(..., item.nullable)`, but the dictionary return (`additionalProperties` is truthy) did not. The same pattern exists in `schemaObjectTypeNode`, which short-circuits to `createDictionaryType` before reaching the switch and also dropped `item.nullable`. Every other type branch handles `item.nullable`; these two dictionary paths were the only exceptions. Result: schemas like type: object additionalProperties: true nullable: true generated `{ [key: string]: any }` instead of `{ [key: string]: any } | null`, silently dropping the null case. Added regression coverage for both shapes: - `additionalProperties: true` + `nullable: true` - `additionalProperties: { type: "string" }` + `nullable: true` --- spec/common/types.spec.ts | 18 ++++++++++++++++++ src/common/util.ts | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/common/types.spec.ts b/spec/common/types.spec.ts index 8e2d7e5..e4a2789 100644 --- a/spec/common/types.spec.ts +++ b/spec/common/types.spec.ts @@ -70,6 +70,12 @@ export type MyDictionaryValueNested = { }; }; }; +export type MyNullableDictionary = { + [key: string]: any; +} | null; +export type MyNullableDictionaryString = { + [key: string]: string; +} | null; `; describe("makeTypes", () => { @@ -293,6 +299,18 @@ describe("makeTypes", () => { }, }, }, + MyNullableDictionary: { + type: "object", + additionalProperties: true, + nullable: true, + }, + MyNullableDictionaryString: { + type: "object", + additionalProperties: { + type: "string", + }, + nullable: true, + }, }, }, }; diff --git a/src/common/util.ts b/src/common/util.ts index e5387f1..89ec5e6 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -137,7 +137,7 @@ export function schemaObjectTypeNode( } if (item.additionalProperties) { - return createDictionaryType($refs, item); + return appendNullToUnion(createDictionaryType($refs, item), item.nullable); } if (item.properties) { @@ -253,7 +253,10 @@ export function nonArraySchemaObjectTypeToTs( ); case "object": { if (item.additionalProperties) { - return createDictionaryType($refs, item); + return appendNullToUnion( + createDictionaryType($refs, item), + item.nullable + ); } return appendNullToUnion( From 8d393b25acd603e5bdc948c4f11ba2654aa525ae Mon Sep 17 00:00:00 2001 From: David Velasquez Date: Mon, 8 Jun 2026 16:46:34 -0500 Subject: [PATCH 2/2] Update changelog for nullable dictionary types fix --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 77c4805..25e0710 100644 --- a/changelog.md +++ b/changelog.md @@ -59,3 +59,7 @@ A major release with breaking changes. Involves updating type signatures to matc ### 3.5.4 - Fix for @tanstack/query v5.89.0 onError, onSuccess and onSettled signature change referenced in issue 9660 + +### 3.5.5 + +- Fix `nullable: true` not being honored for `object` types with `additionalProperties` (dictionary types). Both code paths in `src/common/util.ts` now wrap the dictionary type with `appendNullToUnion` so `| null` is appended when `nullable: true` is set.