@devries-cameron20 / composio-1 / commits / 9d26fb88c
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(core): fold OpenAPI `nullable` into the type in strict tool schemas (#4997)

## Summary Anthropic strict tool use rejects OpenAPI `nullable` on an object schema ("For 'object' type, property 'nullable' is not supported"), with a 400 for the whole request. `toStrictJsonSchema` passed the keyword through. That blocks https://github.com/ComposioHQ/composio/pull/4940, where Vercel strict mode now sends the strict schema as is instead of a Zod rendering that dropped `nullable`. Part of https://github.com/ComposioHQ/composio/issues/4911. Designated PR reviewer: [@jkomyno](mailto:alberto@composio.dev). ## Changes - **Strict rewrite (TypeScript and Python):** `nullable` is removed at every depth. A node with `nullable: true` is widened the way optional properties already are: `null` joins a lone `type` (`["object", "null"]`), a lone `anyOf` gains a null branch, and anything else (a typed `enum`, say) is wrapped in `anyOf: [node, {type: "null"}]`. This matches the Zod conversion, which accepts `null` for `nullable: true` whatever the other keywords say. The rewrite is reported as a new `nullable-converted` change. `nullable: false`, or a `true` that changes nothing, is reported as `unsupported-keyword-stripped`. - **Null check:** the shared null check treats `nullable: true` as accepting `null`. Without this, `omitNullToolArguments` would drop the `null` the model can now send for a required nullable property, and the call would fail validation. **Behavior change:** a `null` for an *optional* `nullable: true` property is now kept rather than treated as "omitted", which is what already happens when a property's `type` includes `null`. - **Shared corpus:** adds the case `openapi-nullable-folded`, covering an object, a string, a typed enum, an untyped node, `nullable: false`, and nullable array items, along with the argument behavior. The json-schema-to-zod v3 fingerprint snapshot only gains lines for the new case. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - `@composio/core`: vitest (1926 passed) and `tsc --noEmit` - `@composio/json-schema-to-zod`: vitest (2305 passed, on zod 3.25, 4.1.13 and 4.5) - Python: `pytest tests/test_strict_schema*.py` (155 passed, shared corpus included), plus ruff and mypy - `validate:changesets` - Results over the 930-tool fixture (`ts/packages/cli/test/__mocks__/tools.json`): | | Before | After | |---|---|---| | Strict-compatible tools | 816 | 816 | | Tools with `nullable` in the strict output | 76 | 0 | | Failures in the OpenAI `openai/lib/transform` oracle | 0 | 0 | - Live strict requests for the 5 tools with `nullable` on an object: - OpenAI (gpt-5-mini): 200 for all 5. - Anthropic (claude-haiku-5-5): `GITHUB_CREATE_A_CODESPACE_FOR_THE_AUTHENTICATED_USER` now returns 200. The other 4 no longer fail on `nullable` but now fail on "For 'number'/'integer' type, properties maximum, minimum are not supported". See below. ## Checklist - [ ] I have read the Code of Conduct and this PR adheres to it - [ ] I have read and understand every line of this diff, including any LLM-generated code - [x] Any third-party docs links or promotional content follow the [third-party links policy](https://github.com/ComposioHQ/composio/blob/next/CONTRIBUTING.md#third-party-links-in-docs) - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published packages ## Additional context **Not covered here:** Anthropic strict mode also rejects numeric `minimum`/`maximum`, which 29 of the 816 strict-compatible tools carry. Before #4940 the Zod rendering kept those keywords too, so this failure is older and is not a #4940 regression. `toStrictJsonSchema` follows the OpenAI contract, which accepts them. Fixing it means a separate model-facing rewrite for Anthropic strict mode, for example moving the bounds into the description while the tool's own schema still validates the arguments. That belongs in its own change.

Alberto Schiabel committed Oct 20, 2026 at 20:01 UTC 9d26fb88ccc1c6bdb5c4635ed5d6cfebbae5dc3b
7 files changed +965 -5
.changeset/strict-openapi-nullable.md new
+7
@@ -0,0 +1,7 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Fold OpenAPI `nullable` into the type in strict tool schemas
6 +
7 +`toStrictJsonSchema` no longer passes OpenAPI `nullable` through. Anthropic strict tool use rejects it on an object schema with a 400 for the whole request. A node with `nullable: true` now accepts `null` through its `type` (`["object", "null"]`) or a null branch, matching how the tool's arguments are validated, and the rewrite is reported as a `nullable-converted` change. `nullable: false` is removed as an `unsupported-keyword-stripped` change. `omitNullToolArguments` now keeps a `null` for a property marked `nullable: true`, as it already does for one whose `type` includes `null`.
python/composio/utils/strict_schema.py
+46 -2
@@ -111,6 +111,7 @@ StrictSchemaChangeReason = t.Literal[
111 "optional-property-nullable",
112 "unsupported-keyword-stripped",
113 "one-of-converted",
114 + "nullable-converted",
115 ]
116
117
@@ -227,6 +228,11 @@ class _NullCheck:
228 emits instead of the one it was given: the rewrite types every node that
229 declares ``properties`` as an object, so such a node stops accepting null.
230
231 + ``follow_refs=False`` makes every ``$ref`` reject null without resolving
232 + it. Folding ``nullable`` needs that, because a ``$ref`` can lead back to
233 + the node being folded, whose source still accepts null. It costs at most
234 + a redundant null branch.
235 +
236 One instance serves every check against a document, and an answer is
237 computed once per node. A reference cycle never yields a null by itself,
238 so a node met again while it is being evaluated counts as rejecting. An
@@ -240,9 +246,15 @@ class _NullCheck:
246 one of them neither repeats the work nor trusts the answer.
247 """
248
243 - def __init__(self, root: dict[str, t.Any], strict_output: bool = False) -> None:
249 + def __init__(
250 + self,
251 + root: dict[str, t.Any],
252 + strict_output: bool = False,
253 + follow_refs: bool = True,
254 + ) -> None:
255 self.root = root
256 self.strict_output = strict_output
257 + self.follow_refs = follow_refs
258 # id(node) -> (node, answer, what it leans on). Holding the node keeps
259 # its id from being reused while the answer is remembered.
260 self.answers: dict[int, tuple[dict[str, t.Any], bool, int]] = {}
@@ -318,6 +330,10 @@ class _NullCheck:
330 return result
331
332 def _keywords_accept(self, node: dict[str, t.Any]) -> bool:
333 + # OpenAPI ``nullable: true`` admits null whatever the other keywords
334 + # say, as the Zod conversion reads it.
335 + if node.get("nullable") is True:
336 + return True
337 accepts = self.accepts
338 node_type = node.get("type")
339 if isinstance(node_type, str) and node_type != "null":
@@ -335,6 +351,8 @@ class _NullCheck:
351 if "const" in node and node["const"] is not None:
352 return False
353 if "$ref" in node:
354 + if not self.follow_refs:
355 + return False
356 ref = node["$ref"]
357 resolution = (
358 _try_resolve_pointer(self.root, ref) if isinstance(ref, str) else None
@@ -389,6 +407,9 @@ class _Walker:
407 self.total_changes = 0
408 self.unsupported: list[StrictSchemaIncompatibility] = []
409 self.null_check = _NullCheck(root, strict_output=True)
410 + self.null_check_without_refs = _NullCheck(
411 + root, strict_output=True, follow_refs=False
412 + )
413 # Resolved references, re-checked against the rewritten schema.
414 self.references: list[tuple[str, str]] = []
415
@@ -448,6 +469,8 @@ class _Walker:
469
470 node: dict[str, t.Any] = {}
471 for key, child in value.items():
472 + if key == "nullable":
473 + continue
474 if key in STRICT_STRIP_KEYWORDS:
475 self.record(
476 path, "unsupported-keyword-stripped", f'keyword "{key}" removed'
@@ -479,6 +502,25 @@ class _Walker:
502 if "properties" in node and not isinstance(node["properties"], dict):
503 self.reject(path, "properties", "properties is not an object")
504
505 + normalized = self.normalize_node(node, mode, depth, path)
506 + if "nullable" not in value:
507 + return normalized
508 + widened = (
509 + _widen_to_nullable(normalized, self.null_check_without_refs)
510 + if value["nullable"] is True
511 + else normalized
512 + )
513 + if widened is normalized:
514 + self.record(
515 + path, "unsupported-keyword-stripped", 'keyword "nullable" removed'
516 + )
517 + else:
518 + self.record(path, "nullable-converted", "nullable became a null type")
519 + return widened
520 +
521 + def normalize_node(
522 + self, node: dict[str, t.Any], mode: str, depth: int, path: str
523 + ) -> dict[str, t.Any]:
524 out = self.walk_children(node, mode, depth, path)
525
526 ref = node.get("$ref")
@@ -553,7 +595,9 @@ def to_strict_json_schema(schema: t.Any) -> StrictJsonSchemaResult:
595 Applies the strict contract at every depth: every object lists all of its
596 properties in ``required`` and is closed; optional properties are widened
597 to accept ``null`` instead of being dropped; ``oneOf`` becomes ``anyOf``;
556 - ``default`` and ``examples`` are stripped; local ``$ref`` pointers into
598 + ``default`` and ``examples`` are stripped; OpenAPI ``nullable`` is
599 + stripped and a node that set it to ``true`` accepts ``null``; local
600 + ``$ref`` pointers into
601 ``$defs`` or ``definitions`` are kept and the definitions are normalized
602 where they are declared; ``required`` arrays are de-duplicated last.
603 Constructs strict mode cannot express are listed in ``unsupported``; when
python/tests/fixtures/json-schema-conversion/strict-cases.json
+294
@@ -952,6 +952,300 @@
952 }
953 }
954 },
955 + {
956 + "id": "openapi-nullable-folded",
957 + "description": "OpenAPI `nullable`, which Anthropic rejects on an object, is removed; `true` widens the node to accept null the way the Zod conversion reads it, including on a typed enum, and `false` is dropped.",
958 + "schema": {
959 + "type": "object",
960 + "properties": {
961 + "cfg": {
962 + "type": "object",
963 + "nullable": true,
964 + "properties": {
965 + "a": {
966 + "type": "string"
967 + }
968 + },
969 + "required": ["a"]
970 + },
971 + "note": {
972 + "type": "string",
973 + "nullable": true
974 + },
975 + "mode": {
976 + "type": "string",
977 + "enum": ["asc", "desc"],
978 + "nullable": true
979 + },
980 + "untyped": {
981 + "nullable": true,
982 + "description": "anything"
983 + },
984 + "count": {
985 + "type": "integer",
986 + "nullable": false
987 + },
988 + "rows": {
989 + "type": "array",
990 + "items": {
991 + "type": "object",
992 + "nullable": true,
993 + "properties": {
994 + "id": {
995 + "type": "string"
996 + }
997 + }
998 + }
999 + }
1000 + },
1001 + "required": ["cfg", "mode", "count", "rows"]
1002 + },
1003 + "strict": {
1004 + "schema": {
1005 + "type": "object",
1006 + "properties": {
1007 + "cfg": {
1008 + "type": ["object", "null"],
1009 + "properties": {
1010 + "a": {
1011 + "type": "string"
1012 + }
1013 + },
1014 + "required": ["a"],
1015 + "additionalProperties": false
1016 + },
1017 + "note": {
1018 + "type": ["string", "null"]
1019 + },
1020 + "mode": {
1021 + "anyOf": [
1022 + {
1023 + "type": "string",
1024 + "enum": ["asc", "desc"]
1025 + },
1026 + {
1027 + "type": "null"
1028 + }
1029 + ]
1030 + },
1031 + "untyped": {
1032 + "description": "anything"
1033 + },
1034 + "count": {
1035 + "type": "integer"
1036 + },
1037 + "rows": {
1038 + "type": "array",
1039 + "items": {
1040 + "type": ["object", "null"],
1041 + "properties": {
1042 + "id": {
1043 + "type": ["string", "null"]
1044 + }
1045 + },
1046 + "required": ["id"],
1047 + "additionalProperties": false
1048 + }
1049 + }
1050 + },
1051 + "required": ["cfg", "note", "mode", "untyped", "count", "rows"],
1052 + "additionalProperties": false
1053 + }
1054 + },
1055 + "changes": [
1056 + {
1057 + "path": "properties.cfg",
1058 + "reason": "nullable-converted"
1059 + },
1060 + {
1061 + "path": "properties.note",
1062 + "reason": "nullable-converted"
1063 + },
1064 + {
1065 + "path": "properties.mode",
1066 + "reason": "nullable-converted"
1067 + },
1068 + {
1069 + "path": "properties.untyped",
1070 + "reason": "unsupported-keyword-stripped"
1071 + },
1072 + {
1073 + "path": "properties.count",
1074 + "reason": "unsupported-keyword-stripped"
1075 + },
1076 + {
1077 + "path": "properties.rows.items.properties.id",
1078 + "reason": "optional-property-nullable"
1079 + },
1080 + {
1081 + "path": "properties.rows.items",
1082 + "reason": "nullable-converted"
1083 + },
1084 + {
1085 + "path": "properties.note",
1086 + "reason": "optional-property-nullable"
1087 + },
1088 + {
1089 + "path": "properties.untyped",
1090 + "reason": "optional-property-nullable"
1091 + }
1092 + ],
1093 + "arguments": [
1094 + {
1095 + "input": {
1096 + "cfg": null,
1097 + "note": null,
1098 + "mode": null,
1099 + "untyped": null,
1100 + "count": null,
1101 + "rows": [
1102 + null,
1103 + {
1104 + "id": null
1105 + }
1106 + ]
1107 + },
1108 + "output": {
1109 + "cfg": null,
1110 + "note": null,
1111 + "mode": null,
1112 + "untyped": null,
1113 + "rows": [null, {}]
1114 + }
1115 + }
1116 + ]
1117 + },
1118 + {
1119 + "id": "recursive-nullable-union-gets-null-branch",
1120 + "description": "A `nullable: true` union that refers back to itself, or a nullable reference to the root, gains a null branch, because a reference never counts as accepting null here; a reference that does accept null costs a redundant branch.",
1121 + "schema": {
1122 + "type": "object",
1123 + "properties": {
1124 + "a": {
1125 + "$ref": "#/$defs/A"
1126 + },
1127 + "b": {
1128 + "$ref": "#/$defs/B"
1129 + },
1130 + "self": {
1131 + "$ref": "#",
1132 + "nullable": true
1133 + }
1134 + },
1135 + "required": ["a", "b", "self"],
1136 + "$defs": {
1137 + "A": {
1138 + "anyOf": [
1139 + {
1140 + "$ref": "#/$defs/A"
1141 + },
1142 + {
1143 + "type": "string"
1144 + }
1145 + ],
1146 + "nullable": true
1147 + },
1148 + "B": {
1149 + "anyOf": [
1150 + {
1151 + "$ref": "#/$defs/Nullable"
1152 + },
1153 + {
1154 + "type": "string"
1155 + }
1156 + ],
1157 + "nullable": true
1158 + },
1159 + "Nullable": {
1160 + "type": ["string", "null"]
1161 + }
1162 + }
1163 + },
1164 + "strict": {
1165 + "schema": {
1166 + "type": "object",
1167 + "properties": {
1168 + "a": {
1169 + "$ref": "#/$defs/A"
1170 + },
1171 + "b": {
1172 + "$ref": "#/$defs/B"
1173 + },
1174 + "self": {
1175 + "anyOf": [
1176 + {
1177 + "$ref": "#"
1178 + },
1179 + {
1180 + "type": "null"
1181 + }
1182 + ]
1183 + }
1184 + },
1185 + "required": ["a", "b", "self"],
1186 + "$defs": {
1187 + "A": {
1188 + "anyOf": [
1189 + {
1190 + "$ref": "#/$defs/A"
1191 + },
1192 + {
1193 + "type": "string"
1194 + },
1195 + {
1196 + "type": "null"
1197 + }
1198 + ]
1199 + },
1200 + "B": {
1201 + "anyOf": [
1202 + {
1203 + "$ref": "#/$defs/Nullable"
1204 + },
1205 + {
1206 + "type": "string"
1207 + },
1208 + {
1209 + "type": "null"
1210 + }
1211 + ]
1212 + },
1213 + "Nullable": {
1214 + "type": ["string", "null"]
1215 + }
1216 + },
1217 + "additionalProperties": false
1218 + }
1219 + },
1220 + "changes": [
1221 + {
1222 + "path": "properties.self",
1223 + "reason": "nullable-converted"
1224 + },
1225 + {
1226 + "path": "$defs.A",
1227 + "reason": "nullable-converted"
1228 + },
1229 + {
1230 + "path": "$defs.B",
1231 + "reason": "nullable-converted"
1232 + }
1233 + ],
1234 + "arguments": [
1235 + {
1236 + "input": {
1237 + "a": null,
1238 + "b": null,
1239 + "self": null
1240 + },
1241 + "output": {
1242 + "a": null,
1243 + "b": null,
1244 + "self": null
1245 + }
1246 + }
1247 + ]
1248 + },
1249 {
1250 "id": "enum-values-are-data-not-keywords",
1251 "description": "Keys inside enum/const values are data and must not be treated as keywords.",
ts/packages/core/src/utils/jsonSchema.ts
+39 -3
@@ -518,9 +518,14 @@ export function jsonSchemaToZodSchema<T extends z.ZodTypeAny>(
518 * (`default`, `examples`, or a string `format` outside the accepted list)
519 * was removed.
520 * - `one-of-converted` — `oneOf` (unsupported) became `anyOf`.
521 + * - `nullable-converted` — OpenAPI `nullable: true`, which Anthropic rejects
522 + * on an object, became a `null` member of `type` or a null branch.
523 */
524 export type StrictSchemaChangeReason =
523 - 'optional-property-nullable' | 'unsupported-keyword-stripped' | 'one-of-converted';
525 + | 'optional-property-nullable'
526 + | 'unsupported-keyword-stripped'
527 + | 'one-of-converted'
528 + | 'nullable-converted';
529
530 /** A single lossless rewrite applied by {@link toStrictJsonSchema}. */
531 export interface StrictSchemaChange {
@@ -698,6 +703,11 @@ function resolveLocalRefs(node: unknown, root: Record<string, unknown>): unknown
703 * the one it was given: the rewrite types every node that declares
704 * `properties` as an object, so such a node stops accepting null.
705 *
706 + * `followRefs: false` makes every `$ref` reject null without resolving it.
707 + * Folding `nullable` needs that, because a `$ref` can lead back to the node
708 + * being folded, whose source still accepts null. It costs at most a
709 + * redundant null branch.
710 + *
711 * One check serves a whole document, and an answer is computed once per node.
712 * A reference cycle never yields a null by itself, so a node met again while
713 * it is being evaluated counts as rejecting. An answer that leans on that is
@@ -712,7 +722,8 @@ function resolveLocalRefs(node: unknown, root: Record<string, unknown>): unknown
722 */
723 function createNullCheck(
724 root: Record<string, unknown>,
715 - strictOutput = false
725 + strictOutput = false,
726 + followRefs = true
727 ): (schema: unknown) => boolean {
728 // Markers for what an answer leans on, besides the depth of a node on the path.
729 const NOTHING = MAX_NULL_CHECK_DEPTH + 1;
@@ -791,12 +802,16 @@ function createNullCheck(
802 };
803
804 const keywordsAccept = (node: Record<string, unknown>): boolean => {
805 + // OpenAPI `nullable: true` admits null whatever the other keywords say,
806 + // as the Zod conversion reads it.
807 + if (node.nullable === true) return true;
808 if (typeof node.type === 'string' && node.type !== 'null') return false;
809 if (Array.isArray(node.type) && !node.type.includes('null')) return false;
810 if (strictOutput && !('type' in node) && isPlainObject(node.properties)) return false;
811 if (Array.isArray(node.enum) && !node.enum.includes(null)) return false;
812 if ('const' in node && node.const !== null) return false;
813 if ('$ref' in node) {
814 + if (!followRefs) return false;
815 const resolution =
816 typeof node.$ref === 'string' ? tryResolvePointer(root, node.$ref) : undefined;
817 if (resolution === undefined || resolution.kind === 'unresolved') return false;
@@ -834,7 +849,8 @@ function createNullCheck(
849 * before executing the tool (see {@link omitNullToolArguments});
850 * - `type` arrays are kept as-is (the API accepts them); `oneOf` becomes
851 * `anyOf`; `default`, `examples`, and a string `format` the API does
837 - * not accept are stripped;
852 + * not accept are stripped; OpenAPI `nullable` is stripped too, and a
853 + * node that set it to `true` is widened to accept `null`;
854 * - local `$ref`s into `$defs`/`definitions` are kept (the API supports
855 * them, including recursion) and the definitions themselves are
856 * normalized; an optional `$ref` property is widened with an `anyOf`
@@ -864,6 +880,7 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
880
881 const root: Record<string, unknown> = isPlainObject(schema) ? schema : {};
882 const acceptsNullInOutput = createNullCheck(root, true);
883 + const acceptsNullWithoutRefs = createNullCheck(root, true, false);
884
885 function walkChildren(
886 node: Record<string, unknown>,
@@ -915,6 +932,7 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
932
933 const node: Record<string, unknown> = {};
934 for (const [key, child] of Object.entries(value)) {
935 + if (key === 'nullable') continue;
936 if (STRICT_STRIP_KEYWORDS.has(key)) {
937 recordChange({
938 path,
@@ -968,6 +986,24 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
986 unsupported.push({ path, keyword: 'properties', detail: 'properties is not an object' });
987 }
988
989 + const normalized = normalizeNode(node, mode, depth, path);
990 + if (!('nullable' in value)) return normalized;
991 + const widened =
992 + value.nullable === true ? widenToNullable(normalized, acceptsNullWithoutRefs) : normalized;
993 + recordChange(
994 + widened === normalized
995 + ? { path, reason: 'unsupported-keyword-stripped', detail: 'keyword "nullable" removed' }
996 + : { path, reason: 'nullable-converted', detail: 'nullable became a null type' }
997 + );
998 + return widened;
999 + }
1000 +
1001 + function normalizeNode(
1002 + node: Record<string, unknown>,
1003 + mode: StrictWalkMode,
1004 + depth: number,
1005 + path: string
1006 + ): Record<string, unknown> {
1007 const out = walkChildren(node, mode, depth, path);
1008
1009 if (typeof node.$ref === 'string') {
ts/packages/core/test/fixtures/json-schema-conversion/generate-strict-cases.mjs
+54
@@ -154,6 +154,44 @@ const cases = [
154 { additionalProperties: false }
155 ),
156 ],
157 + [
158 + 'openapi-nullable-folded',
159 + 'OpenAPI `nullable`, which Anthropic rejects on an object, is removed; `true` widens the node to accept null the way the Zod conversion reads it, including on a typed enum, and `false` is dropped.',
160 + obj(
161 + {
162 + cfg: {
163 + type: 'object',
164 + nullable: true,
165 + properties: { a: { type: 'string' } },
166 + required: ['a'],
167 + },
168 + note: { type: 'string', nullable: true },
169 + mode: { type: 'string', enum: ['asc', 'desc'], nullable: true },
170 + untyped: { nullable: true, description: 'anything' },
171 + count: { type: 'integer', nullable: false },
172 + rows: {
173 + type: 'array',
174 + items: { type: 'object', nullable: true, properties: { id: { type: 'string' } } },
175 + },
176 + },
177 + ['cfg', 'mode', 'count', 'rows']
178 + ),
179 + ],
180 + [
181 + 'recursive-nullable-union-gets-null-branch',
182 + 'A `nullable: true` union that refers back to itself, or a nullable reference to the root, gains a null branch, because a reference never counts as accepting null here; a reference that does accept null costs a redundant branch.',
183 + obj(
184 + { a: { $ref: '#/$defs/A' }, b: { $ref: '#/$defs/B' }, self: { $ref: '#', nullable: true } },
185 + ['a', 'b', 'self'],
186 + {
187 + $defs: {
188 + A: { anyOf: [{ $ref: '#/$defs/A' }, { type: 'string' }], nullable: true },
189 + B: { anyOf: [{ $ref: '#/$defs/Nullable' }, { type: 'string' }], nullable: true },
190 + Nullable: { type: ['string', 'null'] },
191 + },
192 + }
193 + ),
194 + ],
195 [
196 'enum-values-are-data-not-keywords',
197 'Keys inside enum/const values are data and must not be treated as keywords.',
@@ -540,6 +578,22 @@ const cases = [
578 ],
579 ];
580 const argumentCases = {
581 + 'recursive-nullable-union-gets-null-branch': [
582 + { input: { a: null, b: null, self: null }, output: { a: null, b: null, self: null } },
583 + ],
584 + 'openapi-nullable-folded': [
585 + {
586 + input: {
587 + cfg: null,
588 + note: null,
589 + mode: null,
590 + untyped: null,
591 + count: null,
592 + rows: [null, { id: null }],
593 + },
594 + output: { cfg: null, note: null, mode: null, untyped: null, rows: [null, {}] },
595 + },
596 + ],
597 'optional-ref-to-typeless-object-wrapped': [
598 { input: { cfg: null }, output: { cfg: null } },
599 { input: { cfg: { url: 'u' } }, output: { cfg: { url: 'u' } } },
ts/packages/core/test/fixtures/json-schema-conversion/strict-cases.json
+294
@@ -952,6 +952,300 @@
952 }
953 }
954 },
955 + {
956 + "id": "openapi-nullable-folded",
957 + "description": "OpenAPI `nullable`, which Anthropic rejects on an object, is removed; `true` widens the node to accept null the way the Zod conversion reads it, including on a typed enum, and `false` is dropped.",
958 + "schema": {
959 + "type": "object",
960 + "properties": {
961 + "cfg": {
962 + "type": "object",
963 + "nullable": true,
964 + "properties": {
965 + "a": {
966 + "type": "string"
967 + }
968 + },
969 + "required": ["a"]
970 + },
971 + "note": {
972 + "type": "string",
973 + "nullable": true
974 + },
975 + "mode": {
976 + "type": "string",
977 + "enum": ["asc", "desc"],
978 + "nullable": true
979 + },
980 + "untyped": {
981 + "nullable": true,
982 + "description": "anything"
983 + },
984 + "count": {
985 + "type": "integer",
986 + "nullable": false
987 + },
988 + "rows": {
989 + "type": "array",
990 + "items": {
991 + "type": "object",
992 + "nullable": true,
993 + "properties": {
994 + "id": {
995 + "type": "string"
996 + }
997 + }
998 + }
999 + }
1000 + },
1001 + "required": ["cfg", "mode", "count", "rows"]
1002 + },
1003 + "strict": {
1004 + "schema": {
1005 + "type": "object",
1006 + "properties": {
1007 + "cfg": {
1008 + "type": ["object", "null"],
1009 + "properties": {
1010 + "a": {
1011 + "type": "string"
1012 + }
1013 + },
1014 + "required": ["a"],
1015 + "additionalProperties": false
1016 + },
1017 + "note": {
1018 + "type": ["string", "null"]
1019 + },
1020 + "mode": {
1021 + "anyOf": [
1022 + {
1023 + "type": "string",
1024 + "enum": ["asc", "desc"]
1025 + },
1026 + {
1027 + "type": "null"
1028 + }
1029 + ]
1030 + },
1031 + "untyped": {
1032 + "description": "anything"
1033 + },
1034 + "count": {
1035 + "type": "integer"
1036 + },
1037 + "rows": {
1038 + "type": "array",
1039 + "items": {
1040 + "type": ["object", "null"],
1041 + "properties": {
1042 + "id": {
1043 + "type": ["string", "null"]
1044 + }
1045 + },
1046 + "required": ["id"],
1047 + "additionalProperties": false
1048 + }
1049 + }
1050 + },
1051 + "required": ["cfg", "note", "mode", "untyped", "count", "rows"],
1052 + "additionalProperties": false
1053 + }
1054 + },
1055 + "changes": [
1056 + {
1057 + "path": "properties.cfg",
1058 + "reason": "nullable-converted"
1059 + },
1060 + {
1061 + "path": "properties.note",
1062 + "reason": "nullable-converted"
1063 + },
1064 + {
1065 + "path": "properties.mode",
1066 + "reason": "nullable-converted"
1067 + },
1068 + {
1069 + "path": "properties.untyped",
1070 + "reason": "unsupported-keyword-stripped"
1071 + },
1072 + {
1073 + "path": "properties.count",
1074 + "reason": "unsupported-keyword-stripped"
1075 + },
1076 + {
1077 + "path": "properties.rows.items.properties.id",
1078 + "reason": "optional-property-nullable"
1079 + },
1080 + {
1081 + "path": "properties.rows.items",
1082 + "reason": "nullable-converted"
1083 + },
1084 + {
1085 + "path": "properties.note",
1086 + "reason": "optional-property-nullable"
1087 + },
1088 + {
1089 + "path": "properties.untyped",
1090 + "reason": "optional-property-nullable"
1091 + }
1092 + ],
1093 + "arguments": [
1094 + {
1095 + "input": {
1096 + "cfg": null,
1097 + "note": null,
1098 + "mode": null,
1099 + "untyped": null,
1100 + "count": null,
1101 + "rows": [
1102 + null,
1103 + {
1104 + "id": null
1105 + }
1106 + ]
1107 + },
1108 + "output": {
1109 + "cfg": null,
1110 + "note": null,
1111 + "mode": null,
1112 + "untyped": null,
1113 + "rows": [null, {}]
1114 + }
1115 + }
1116 + ]
1117 + },
1118 + {
1119 + "id": "recursive-nullable-union-gets-null-branch",
1120 + "description": "A `nullable: true` union that refers back to itself, or a nullable reference to the root, gains a null branch, because a reference never counts as accepting null here; a reference that does accept null costs a redundant branch.",
1121 + "schema": {
1122 + "type": "object",
1123 + "properties": {
1124 + "a": {
1125 + "$ref": "#/$defs/A"
1126 + },
1127 + "b": {
1128 + "$ref": "#/$defs/B"
1129 + },
1130 + "self": {
1131 + "$ref": "#",
1132 + "nullable": true
1133 + }
1134 + },
1135 + "required": ["a", "b", "self"],
1136 + "$defs": {
1137 + "A": {
1138 + "anyOf": [
1139 + {
1140 + "$ref": "#/$defs/A"
1141 + },
1142 + {
1143 + "type": "string"
1144 + }
1145 + ],
1146 + "nullable": true
1147 + },
1148 + "B": {
1149 + "anyOf": [
1150 + {
1151 + "$ref": "#/$defs/Nullable"
1152 + },
1153 + {
1154 + "type": "string"
1155 + }
1156 + ],
1157 + "nullable": true
1158 + },
1159 + "Nullable": {
1160 + "type": ["string", "null"]
1161 + }
1162 + }
1163 + },
1164 + "strict": {
1165 + "schema": {
1166 + "type": "object",
1167 + "properties": {
1168 + "a": {
1169 + "$ref": "#/$defs/A"
1170 + },
1171 + "b": {
1172 + "$ref": "#/$defs/B"
1173 + },
1174 + "self": {
1175 + "anyOf": [
1176 + {
1177 + "$ref": "#"
1178 + },
1179 + {
1180 + "type": "null"
1181 + }
1182 + ]
1183 + }
1184 + },
1185 + "required": ["a", "b", "self"],
1186 + "$defs": {
1187 + "A": {
1188 + "anyOf": [
1189 + {
1190 + "$ref": "#/$defs/A"
1191 + },
1192 + {
1193 + "type": "string"
1194 + },
1195 + {
1196 + "type": "null"
1197 + }
1198 + ]
1199 + },
1200 + "B": {
1201 + "anyOf": [
1202 + {
1203 + "$ref": "#/$defs/Nullable"
1204 + },
1205 + {
1206 + "type": "string"
1207 + },
1208 + {
1209 + "type": "null"
1210 + }
1211 + ]
1212 + },
1213 + "Nullable": {
1214 + "type": ["string", "null"]
1215 + }
1216 + },
1217 + "additionalProperties": false
1218 + }
1219 + },
1220 + "changes": [
1221 + {
1222 + "path": "properties.self",
1223 + "reason": "nullable-converted"
1224 + },
1225 + {
1226 + "path": "$defs.A",
1227 + "reason": "nullable-converted"
1228 + },
1229 + {
1230 + "path": "$defs.B",
1231 + "reason": "nullable-converted"
1232 + }
1233 + ],
1234 + "arguments": [
1235 + {
1236 + "input": {
1237 + "a": null,
1238 + "b": null,
1239 + "self": null
1240 + },
1241 + "output": {
1242 + "a": null,
1243 + "b": null,
1244 + "self": null
1245 + }
1246 + }
1247 + ]
1248 + },
1249 {
1250 "id": "enum-values-are-data-not-keywords",
1251 "description": "Keys inside enum/const values are data and must not be treated as keywords.",
ts/packages/json-schema-to-zod/test/__snapshots__/v3-output-fingerprint.test.ts.snap
+231
@@ -4990,6 +4990,237 @@ exports[`v3 output fingerprint > matches the pinned snapshot for the shared stri
4990 },
4991 "id": "accepted-string-formats-kept",
4992 },
4993 + {
4994 + "fingerprint": {
4995 + "def": {
4996 + "catchall": {
4997 + "typeName": "ZodNever",
4998 + },
4999 + "shape": {
5000 + "cfg": {
5001 + "innerType": {
5002 + "catchall": {
5003 + "typeName": "ZodNever",
5004 + },
5005 + "shape": {
5006 + "a": {
5007 + "checks": [],
5008 + "typeName": "ZodString",
5009 + },
5010 + },
5011 + "typeName": "ZodObject",
5012 + "unknownKeys": "strict",
5013 + },
5014 + "typeName": "ZodNullable",
5015 + },
5016 + "count": {
5017 + "checks": [
5018 + {
5019 + "kind": "int",
5020 + "message": undefined,
5021 + },
5022 + ],
5023 + "typeName": "ZodNumber",
5024 + },
5025 + "mode": {
5026 + "innerType": {
5027 + "left": {
5028 + "checks": [],
5029 + "typeName": "ZodString",
5030 + },
5031 + "right": {
5032 + "typeName": "ZodEnum",
5033 + "values": [
5034 + "asc",
5035 + "desc",
5036 + ],
5037 + },
5038 + "typeName": "ZodIntersection",
5039 + },
5040 + "typeName": "ZodNullable",
5041 + },
5042 + "note": {
5043 + "innerType": {
5044 + "innerType": {
5045 + "checks": [],
5046 + "typeName": "ZodString",
5047 + },
5048 + "typeName": "ZodNullable",
5049 + },
5050 + "typeName": "ZodOptional",
5051 + },
5052 + "rows": {
5053 + "element": {
5054 + "innerType": {
5055 + "catchall": {
5056 + "typeName": "ZodNever",
5057 + },
5058 + "shape": {
5059 + "id": {
5060 + "innerType": {
5061 + "checks": [],
5062 + "typeName": "ZodString",
5063 + },
5064 + "typeName": "ZodOptional",
5065 + },
5066 + },
5067 + "typeName": "ZodObject",
5068 + "unknownKeys": "strict",
5069 + },
5070 + "typeName": "ZodNullable",
5071 + },
5072 + "typeName": "ZodArray",
5073 + },
5074 + "untyped": {
5075 + "description": "anything",
5076 + "innerType": {
5077 + "description": "anything",
5078 + "innerType": {
5079 + "typeName": "ZodAny",
5080 + },
5081 + "typeName": "ZodNullable",
5082 + },
5083 + "typeName": "ZodOptional",
5084 + },
5085 + },
5086 + "typeName": "ZodObject",
5087 + "unknownKeys": "strict",
5088 + },
5089 + "jsonSchema": {
5090 + "$schema": "http://json-schema.org/draft-07/schema#",
5091 + "additionalProperties": false,
5092 + "properties": {
5093 + "cfg": {
5094 + "anyOf": [
5095 + {
5096 + "additionalProperties": false,
5097 + "properties": {
5098 + "a": {
5099 + "type": "string",
5100 + },
5101 + },
5102 + "required": [
5103 + "a",
5104 + ],
5105 + "type": "object",
5106 + },
5107 + {
5108 + "type": "null",
5109 + },
5110 + ],
5111 + },
5112 + "count": {
5113 + "type": "integer",
5114 + },
5115 + "mode": {
5116 + "anyOf": [
5117 + {
5118 + "allOf": [
5119 + {
5120 + "type": "string",
5121 + },
5122 + {
5123 + "enum": [
5124 + "asc",
5125 + "desc",
5126 + ],
5127 + "type": "string",
5128 + },
5129 + ],
5130 + },
5131 + {
5132 + "type": "null",
5133 + },
5134 + ],
5135 + },
5136 + "note": {
5137 + "type": [
5138 + "string",
5139 + "null",
5140 + ],
5141 + },
5142 + "rows": {
5143 + "items": {
5144 + "anyOf": [
5145 + {
5146 + "additionalProperties": false,
5147 + "properties": {
5148 + "id": {
5149 + "type": "string",
5150 + },
5151 + },
5152 + "type": "object",
5153 + },
5154 + {
5155 + "type": "null",
5156 + },
5157 + ],
5158 + },
5159 + "type": "array",
5160 + },
5161 + "untyped": {
5162 + "anyOf": [
5163 + {},
5164 + {
5165 + "type": "null",
5166 + },
5167 + ],
5168 + "description": "anything",
5169 + },
5170 + },
5171 + "required": [
5172 + "cfg",
5173 + "mode",
5174 + "count",
5175 + "rows",
5176 + ],
5177 + "type": "object",
5178 + },
5179 + },
5180 + "id": "openapi-nullable-folded",
5181 + },
5182 + {
5183 + "fingerprint": {
5184 + "def": {
5185 + "catchall": {
5186 + "typeName": "ZodNever",
5187 + },
5188 + "guarded": true,
5189 + "shape": {
5190 + "a": {
5191 + "guarded": true,
5192 + "typeName": "ZodAny",
5193 + },
5194 + "b": {
5195 + "guarded": true,
5196 + "typeName": "ZodAny",
5197 + },
5198 + "self": {
5199 + "guarded": true,
5200 + "typeName": "ZodAny",
5201 + },
5202 + },
5203 + "typeName": "ZodObject",
5204 + "unknownKeys": "strict",
5205 + },
5206 + "jsonSchema": {
5207 + "$schema": "http://json-schema.org/draft-07/schema#",
5208 + "additionalProperties": false,
5209 + "properties": {
5210 + "a": {},
5211 + "b": {},
5212 + "self": {},
5213 + },
5214 + "required": [
5215 + "a",
5216 + "b",
5217 + "self",
5218 + ],
5219 + "type": "object",
5220 + },
5221 + },
5222 + "id": "recursive-nullable-union-gets-null-branch",
5223 + },
5224 {
5225 "fingerprint": {
5226 "def": {