@devries-cameron20 / composio-1 / commits / 3ca07210d
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.

test(json-schema): drive strict-mode cases from a shared corpus

strict-cases.json (one byte-identical copy per language, next to object-cases.json) pins the exact strict schema or the reported incompatibilities for 44 shapes: optional widening at every depth, nullable type arrays, compositions, enum/const wrapping, annotation stripping, keyword-named and prototype-named properties, dynamic-key and free-form objects, allOf/prefixItems, $defs recursion, dangling and external refs, malformed required, non-object roots, plus null-omission argument pairs. The TypeScript suite pins the implementation and the Python suite checks parity against the same file. Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com> Claude-Session: https://claude.ai/code/session_01TDrxCHn2hg51HmxVstSUgs

jkomyno committed Aug 26, 2026 at 17:37 UTC 3ca07210d3e28759606b69aeb1e75e146a6da50d
6 files changed +3943
python/tests/fixtures/json-schema-conversion/strict-cases.json new
+1835
@@ -0,0 +1,1835 @@
1 +{
2 + "cases": [
3 + {
4 + "id": "flat-all-required-unchanged",
5 + "description": "An already-strict schema is returned unchanged with no changes.",
6 + "schema": {
7 + "type": "object",
8 + "properties": {
9 + "query": {
10 + "type": "string"
11 + }
12 + },
13 + "required": ["query"],
14 + "additionalProperties": false
15 + },
16 + "strict": {
17 + "schema": {
18 + "type": "object",
19 + "properties": {
20 + "query": {
21 + "type": "string"
22 + }
23 + },
24 + "required": ["query"],
25 + "additionalProperties": false
26 + }
27 + }
28 + },
29 + {
30 + "id": "nested-optional-property-widened",
31 + "description": "Optional properties stay, become required and accept null at every depth.",
32 + "schema": {
33 + "type": "object",
34 + "properties": {
35 + "cfg": {
36 + "type": "object",
37 + "properties": {
38 + "url": {
39 + "type": "string"
40 + },
41 + "note": {
42 + "type": "string",
43 + "description": "optional note"
44 + }
45 + },
46 + "required": ["url"]
47 + }
48 + },
49 + "required": ["cfg"]
50 + },
51 + "strict": {
52 + "schema": {
53 + "type": "object",
54 + "properties": {
55 + "cfg": {
56 + "type": "object",
57 + "properties": {
58 + "url": {
59 + "type": "string"
60 + },
61 + "note": {
62 + "type": ["string", "null"],
63 + "description": "optional note"
64 + }
65 + },
66 + "required": ["url", "note"],
67 + "additionalProperties": false
68 + }
69 + },
70 + "required": ["cfg"],
71 + "additionalProperties": false
72 + }
73 + },
74 + "changes": [
75 + {
76 + "path": "properties.cfg.properties.note",
77 + "reason": "optional-property-nullable"
78 + }
79 + ],
80 + "arguments": [
81 + {
82 + "input": {
83 + "cfg": {
84 + "url": "u",
85 + "note": null
86 + }
87 + },
88 + "output": {
89 + "cfg": {
90 + "url": "u"
91 + }
92 + }
93 + }
94 + ]
95 + },
96 + {
97 + "id": "no-required-array-widens-every-property",
98 + "description": "An object without `required` requires and widens every property.",
99 + "schema": {
100 + "type": "object",
101 + "properties": {
102 + "a": {
103 + "type": "string"
104 + },
105 + "b": {
106 + "type": "number"
107 + }
108 + }
109 + },
110 + "strict": {
111 + "schema": {
112 + "type": "object",
113 + "properties": {
114 + "a": {
115 + "type": ["string", "null"]
116 + },
117 + "b": {
118 + "type": ["number", "null"]
119 + }
120 + },
121 + "required": ["a", "b"],
122 + "additionalProperties": false
123 + }
124 + },
125 + "changes": [
126 + {
127 + "path": "properties.a",
128 + "reason": "optional-property-nullable"
129 + },
130 + {
131 + "path": "properties.b",
132 + "reason": "optional-property-nullable"
133 + }
134 + ],
135 + "arguments": [
136 + {
137 + "input": {
138 + "a": null,
139 + "b": 1,
140 + "unknown": null
141 + },
142 + "output": {
143 + "b": 1,
144 + "unknown": null
145 + }
146 + }
147 + ]
148 + },
149 + {
150 + "id": "required-empty-array-widens-every-property",
151 + "description": "An empty `required` array is the same as an absent one.",
152 + "schema": {
153 + "type": "object",
154 + "properties": {
155 + "a": {
156 + "type": "string"
157 + }
158 + },
159 + "required": []
160 + },
161 + "strict": {
162 + "schema": {
163 + "type": "object",
164 + "properties": {
165 + "a": {
166 + "type": ["string", "null"]
167 + }
168 + },
169 + "required": ["a"],
170 + "additionalProperties": false
171 + }
172 + },
173 + "changes": [
174 + {
175 + "path": "properties.a",
176 + "reason": "optional-property-nullable"
177 + }
178 + ]
179 + },
180 + {
181 + "id": "nullable-type-array-kept",
182 + "description": "A `type` array with null is accepted by the API and left alone.",
183 + "schema": {
184 + "type": "object",
185 + "properties": {
186 + "id": {
187 + "type": ["string", "null"],
188 + "description": "identifier"
189 + }
190 + },
191 + "required": ["id"]
192 + },
193 + "strict": {
194 + "schema": {
195 + "type": "object",
196 + "properties": {
197 + "id": {
198 + "type": ["string", "null"],
199 + "description": "identifier"
200 + }
201 + },
202 + "required": ["id"],
203 + "additionalProperties": false
204 + }
205 + },
206 + "arguments": [
207 + {
208 + "input": {
209 + "id": null
210 + },
211 + "output": {
212 + "id": null
213 + }
214 + }
215 + ]
216 + },
217 + {
218 + "id": "nullable-object-stays-nullable",
219 + "description": "A nullable object keeps its type array; only its own properties are closed.",
220 + "schema": {
221 + "type": "object",
222 + "properties": {
223 + "cfg": {
224 + "type": ["object", "null"],
225 + "properties": {
226 + "a": {
227 + "type": "string"
228 + }
229 + },
230 + "required": ["a"]
231 + }
232 + },
233 + "required": ["cfg"]
234 + },
235 + "strict": {
236 + "schema": {
237 + "type": "object",
238 + "properties": {
239 + "cfg": {
240 + "type": ["object", "null"],
241 + "properties": {
242 + "a": {
243 + "type": "string"
244 + }
245 + },
246 + "required": ["a"],
247 + "additionalProperties": false
248 + }
249 + },
250 + "required": ["cfg"],
251 + "additionalProperties": false
252 + }
253 + },
254 + "arguments": [
255 + {
256 + "input": {
257 + "cfg": null
258 + },
259 + "output": {
260 + "cfg": null
261 + }
262 + },
263 + {
264 + "input": {
265 + "cfg": {
266 + "a": "x"
267 + }
268 + },
269 + "output": {
270 + "cfg": {
271 + "a": "x"
272 + }
273 + }
274 + }
275 + ]
276 + },
277 + {
278 + "id": "nullable-array-kept",
279 + "description": "A nullable array keeps its type array and items.",
280 + "schema": {
281 + "type": "object",
282 + "properties": {
283 + "xs": {
284 + "type": ["array", "null"],
285 + "items": {
286 + "type": "string"
287 + }
288 + }
289 + },
290 + "required": ["xs"]
291 + },
292 + "strict": {
293 + "schema": {
294 + "type": "object",
295 + "properties": {
296 + "xs": {
297 + "type": ["array", "null"],
298 + "items": {
299 + "type": "string"
300 + }
301 + }
302 + },
303 + "required": ["xs"],
304 + "additionalProperties": false
305 + }
306 + }
307 + },
308 + {
309 + "id": "optional-any-of-gets-null-branch",
310 + "description": "An optional composition gains a null branch instead of a sibling type.",
311 + "schema": {
312 + "type": "object",
313 + "properties": {
314 + "value": {
315 + "anyOf": [
316 + {
317 + "type": "string"
318 + },
319 + {
320 + "type": "number"
321 + }
322 + ]
323 + }
324 + }
325 + },
326 + "strict": {
327 + "schema": {
328 + "type": "object",
329 + "properties": {
330 + "value": {
331 + "anyOf": [
332 + {
333 + "type": "string"
334 + },
335 + {
336 + "type": "number"
337 + },
338 + {
339 + "type": "null"
340 + }
341 + ]
342 + }
343 + },
344 + "required": ["value"],
345 + "additionalProperties": false
346 + }
347 + },
348 + "changes": [
349 + {
350 + "path": "properties.value",
351 + "reason": "optional-property-nullable"
352 + }
353 + ]
354 + },
355 + {
356 + "id": "any-of-already-nullable-unchanged",
357 + "description": "A composition that already accepts null is not widened twice.",
358 + "schema": {
359 + "type": "object",
360 + "properties": {
361 + "value": {
362 + "anyOf": [
363 + {
364 + "type": "string"
365 + },
366 + {
367 + "type": "null"
368 + }
369 + ]
370 + }
371 + }
372 + },
373 + "strict": {
374 + "schema": {
375 + "type": "object",
376 + "properties": {
377 + "value": {
378 + "anyOf": [
379 + {
380 + "type": "string"
381 + },
382 + {
383 + "type": "null"
384 + }
385 + ]
386 + }
387 + },
388 + "required": ["value"],
389 + "additionalProperties": false
390 + }
391 + },
392 + "changes": [
393 + {
394 + "path": "properties.value",
395 + "reason": "optional-property-nullable"
396 + }
397 + ],
398 + "arguments": [
399 + {
400 + "input": {
401 + "value": null
402 + },
403 + "output": {
404 + "value": null
405 + }
406 + }
407 + ]
408 + },
409 + {
410 + "id": "optional-enum-only-wrapped",
411 + "description": "An enum-only property is wrapped so the annotation stays outside the anyOf.",
412 + "schema": {
413 + "type": "object",
414 + "properties": {
415 + "choice": {
416 + "enum": ["a", "b"],
417 + "description": "pick one",
418 + "title": "Choice"
419 + }
420 + }
421 + },
422 + "strict": {
423 + "schema": {
424 + "type": "object",
425 + "properties": {
426 + "choice": {
427 + "description": "pick one",
428 + "title": "Choice",
429 + "anyOf": [
430 + {
431 + "enum": ["a", "b"]
432 + },
433 + {
434 + "type": "null"
435 + }
436 + ]
437 + }
438 + },
439 + "required": ["choice"],
440 + "additionalProperties": false
441 + }
442 + },
443 + "changes": [
444 + {
445 + "path": "properties.choice",
446 + "reason": "optional-property-nullable"
447 + }
448 + ],
449 + "arguments": [
450 + {
451 + "input": {
452 + "choice": null
453 + },
454 + "output": {}
455 + }
456 + ]
457 + },
458 + {
459 + "id": "optional-const-wrapped",
460 + "description": "A const-only property is wrapped in an anyOf with a null branch.",
461 + "schema": {
462 + "type": "object",
463 + "properties": {
464 + "kind": {
465 + "const": "fixed"
466 + }
467 + }
468 + },
469 + "strict": {
470 + "schema": {
471 + "type": "object",
472 + "properties": {
473 + "kind": {
474 + "anyOf": [
475 + {
476 + "const": "fixed"
477 + },
478 + {
479 + "type": "null"
480 + }
481 + ]
482 + }
483 + },
484 + "required": ["kind"],
485 + "additionalProperties": false
486 + }
487 + },
488 + "changes": [
489 + {
490 + "path": "properties.kind",
491 + "reason": "optional-property-nullable"
492 + }
493 + ]
494 + },
495 + {
496 + "id": "optional-empty-schema-unchanged",
497 + "description": "An empty schema already accepts null and is left alone.",
498 + "schema": {
499 + "type": "object",
500 + "properties": {
501 + "anything": {}
502 + }
503 + },
504 + "strict": {
505 + "schema": {
506 + "type": "object",
507 + "properties": {
508 + "anything": {}
509 + },
510 + "required": ["anything"],
511 + "additionalProperties": false
512 + }
513 + },
514 + "changes": [
515 + {
516 + "path": "properties.anything",
517 + "reason": "optional-property-nullable"
518 + }
519 + ]
520 + },
521 + {
522 + "id": "multi-type-array-gains-null",
523 + "description": "A multi-type array gains null instead of being converted to anyOf.",
524 + "schema": {
525 + "type": "object",
526 + "properties": {
527 + "value": {
528 + "type": ["string", "number"]
529 + }
530 + }
531 + },
532 + "strict": {
533 + "schema": {
534 + "type": "object",
535 + "properties": {
536 + "value": {
537 + "type": ["string", "number", "null"]
538 + }
539 + },
540 + "required": ["value"],
541 + "additionalProperties": false
542 + }
543 + },
544 + "changes": [
545 + {
546 + "path": "properties.value",
547 + "reason": "optional-property-nullable"
548 + }
549 + ]
550 + },
551 + {
552 + "id": "one-of-converted-to-any-of",
553 + "description": "oneOf is unsupported and becomes anyOf.",
554 + "schema": {
555 + "type": "object",
556 + "properties": {
557 + "either": {
558 + "oneOf": [
559 + {
560 + "type": "string"
561 + },
562 + {
563 + "type": "number"
564 + }
565 + ]
566 + }
567 + },
568 + "required": ["either"]
569 + },
570 + "strict": {
571 + "schema": {
572 + "type": "object",
573 + "properties": {
574 + "either": {
575 + "anyOf": [
576 + {
577 + "type": "string"
578 + },
579 + {
580 + "type": "number"
581 + }
582 + ]
583 + }
584 + },
585 + "required": ["either"],
586 + "additionalProperties": false
587 + }
588 + },
589 + "changes": [
590 + {
591 + "path": "properties.either",
592 + "reason": "one-of-converted"
593 + }
594 + ]
595 + },
596 + {
597 + "id": "array-items-object-normalized",
598 + "description": "Objects inside array items are closed and widened.",
599 + "schema": {
600 + "type": "object",
601 + "properties": {
602 + "rows": {
603 + "type": "array",
604 + "items": {
605 + "type": "object",
606 + "properties": {
607 + "id": {
608 + "type": "string"
609 + },
610 + "tag": {
611 + "type": "string"
612 + }
613 + },
614 + "required": ["id"]
615 + }
616 + }
617 + },
618 + "required": ["rows"]
619 + },
620 + "strict": {
621 + "schema": {
622 + "type": "object",
623 + "properties": {
624 + "rows": {
625 + "type": "array",
626 + "items": {
627 + "type": "object",
628 + "properties": {
629 + "id": {
630 + "type": "string"
631 + },
632 + "tag": {
633 + "type": ["string", "null"]
634 + }
635 + },
636 + "required": ["id", "tag"],
637 + "additionalProperties": false
638 + }
639 + }
640 + },
641 + "required": ["rows"],
642 + "additionalProperties": false
643 + }
644 + },
645 + "changes": [
646 + {
647 + "path": "properties.rows.items.properties.tag",
648 + "reason": "optional-property-nullable"
649 + }
650 + ],
651 + "arguments": [
652 + {
653 + "input": {
654 + "rows": [
655 + {
656 + "id": "1",
657 + "tag": null
658 + },
659 + null
660 + ]
661 + },
662 + "output": {
663 + "rows": [
664 + {
665 + "id": "1"
666 + },
667 + null
668 + ]
669 + }
670 + }
671 + ]
672 + },
673 + {
674 + "id": "tuple-items-normalized",
675 + "description": "Objects inside tuple-form items are normalized too.",
676 + "schema": {
677 + "type": "object",
678 + "properties": {
679 + "pair": {
680 + "type": "array",
681 + "items": [
682 + {
683 + "type": "object",
684 + "properties": {
685 + "x": {
686 + "type": "number"
687 + }
688 + }
689 + },
690 + {
691 + "type": "string"
692 + }
693 + ]
694 + }
695 + },
696 + "required": ["pair"]
697 + },
698 + "strict": {
699 + "schema": {
700 + "type": "object",
701 + "properties": {
702 + "pair": {
703 + "type": "array",
704 + "items": [
705 + {
706 + "type": "object",
707 + "properties": {
708 + "x": {
709 + "type": ["number", "null"]
710 + }
711 + },
712 + "required": ["x"],
713 + "additionalProperties": false
714 + },
715 + {
716 + "type": "string"
717 + }
718 + ]
719 + }
720 + },
721 + "required": ["pair"],
722 + "additionalProperties": false
723 + }
724 + },
725 + "changes": [
726 + {
727 + "path": "properties.pair.items[0].properties.x",
728 + "reason": "optional-property-nullable"
729 + }
730 + ]
731 + },
732 + {
733 + "id": "default-and-examples-stripped",
734 + "description": "Annotation keywords the API rejects are stripped and reported.",
735 + "schema": {
736 + "type": "object",
737 + "properties": {
738 + "name": {
739 + "type": "string",
740 + "examples": ["a"],
741 + "default": "x"
742 + }
743 + },
744 + "required": ["name"]
745 + },
746 + "strict": {
747 + "schema": {
748 + "type": "object",
749 + "properties": {
750 + "name": {
751 + "type": "string"
752 + }
753 + },
754 + "required": ["name"],
755 + "additionalProperties": false
756 + }
757 + },
758 + "changes": [
759 + {
760 + "path": "properties.name",
761 + "reason": "unsupported-keyword-stripped"
762 + },
763 + {
764 + "path": "properties.name",
765 + "reason": "unsupported-keyword-stripped"
766 + }
767 + ]
768 + },
769 + {
770 + "id": "enum-values-are-data-not-keywords",
771 + "description": "Keys inside enum/const values are data and must not be treated as keywords.",
772 + "schema": {
773 + "type": "object",
774 + "properties": {
775 + "opts": {
776 + "enum": [
777 + {
778 + "default": 1,
779 + "properties": {}
780 + },
781 + null
782 + ]
783 + }
784 + },
785 + "required": ["opts"]
786 + },
787 + "strict": {
788 + "schema": {
789 + "type": "object",
790 + "properties": {
791 + "opts": {
792 + "enum": [
793 + {
794 + "default": 1,
795 + "properties": {}
796 + },
797 + null
798 + ]
799 + }
800 + },
801 + "required": ["opts"],
802 + "additionalProperties": false
803 + }
804 + },
805 + "arguments": [
806 + {
807 + "input": {
808 + "opts": null
809 + },
810 + "output": {
811 + "opts": null
812 + }
813 + }
814 + ]
815 + },
816 + {
817 + "id": "property-names-are-not-keywords",
818 + "description": "Properties named like keywords are ordinary properties.",
819 + "schema": {
820 + "type": "object",
821 + "properties": {
822 + "default": {
823 + "type": "string"
824 + },
825 + "$ref": {
826 + "type": "string"
827 + },
828 + "type": {
829 + "type": "string"
830 + },
831 + "properties": {
832 + "type": "object",
833 + "properties": {
834 + "x": {
835 + "type": "string"
836 + }
837 + }
838 + }
839 + }
840 + },
841 + "strict": {
842 + "schema": {
843 + "type": "object",
844 + "properties": {
845 + "default": {
846 + "type": ["string", "null"]
847 + },
848 + "$ref": {
849 + "type": ["string", "null"]
850 + },
851 + "type": {
852 + "type": ["string", "null"]
853 + },
854 + "properties": {
855 + "type": ["object", "null"],
856 + "properties": {
857 + "x": {
858 + "type": ["string", "null"]
859 + }
860 + },
861 + "required": ["x"],
862 + "additionalProperties": false
863 + }
864 + },
865 + "required": ["default", "$ref", "type", "properties"],
866 + "additionalProperties": false
867 + }
868 + },
869 + "changes": [
870 + {
871 + "path": "properties.properties.properties.x",
872 + "reason": "optional-property-nullable"
873 + },
874 + {
875 + "path": "properties.default",
876 + "reason": "optional-property-nullable"
877 + },
878 + {
879 + "path": "properties.$ref",
880 + "reason": "optional-property-nullable"
881 + },
882 + {
883 + "path": "properties.type",
884 + "reason": "optional-property-nullable"
885 + },
886 + {
887 + "path": "properties.properties",
888 + "reason": "optional-property-nullable"
889 + }
890 + ],
891 + "arguments": [
892 + {
893 + "input": {
894 + "default": null,
895 + "$ref": "x",
896 + "type": null,
897 + "properties": {
898 + "x": null
899 + }
900 + },
901 + "output": {
902 + "$ref": "x",
903 + "properties": {}
904 + }
905 + }
906 + ]
907 + },
908 + {
909 + "id": "prototype-key-property-name",
910 + "description": "A property named __proto__ or constructor is handled as a plain name.",
911 + "schema": {
912 + "type": "object",
913 + "properties": {
914 + "__proto__": {
915 + "type": "string"
916 + },
917 + "constructor": {
918 + "type": "number"
919 + }
920 + }
921 + },
922 + "strict": {
923 + "schema": {
924 + "type": "object",
925 + "properties": {
926 + "__proto__": {
927 + "type": ["string", "null"]
928 + },
929 + "constructor": {
930 + "type": ["number", "null"]
931 + }
932 + },
933 + "required": ["__proto__", "constructor"],
934 + "additionalProperties": false
935 + }
936 + },
937 + "changes": [
938 + {
939 + "path": "properties.__proto__",
940 + "reason": "optional-property-nullable"
941 + },
942 + {
943 + "path": "properties.constructor",
944 + "reason": "optional-property-nullable"
945 + }
946 + ]
947 + },
948 + {
949 + "id": "schema-valued-additional-properties-unsupported",
950 + "description": "A map-style object cannot be expressed and is reported, not closed.",
951 + "schema": {
952 + "type": "object",
953 + "properties": {
954 + "headers": {
955 + "type": "object",
956 + "additionalProperties": {
957 + "type": "string"
958 + }
959 + }
960 + },
961 + "required": ["headers"]
962 + },
963 + "strict": {
964 + "unsupported": [
965 + {
966 + "path": "properties.headers",
967 + "keyword": "additionalProperties"
968 + }
969 + ]
970 + }
971 + },
972 + {
973 + "id": "additional-properties-true-unsupported",
974 + "description": "An explicitly open object is reported.",
975 + "schema": {
976 + "type": "object",
977 + "properties": {
978 + "open": {
979 + "type": "object",
980 + "additionalProperties": true
981 + }
982 + },
983 + "required": ["open"]
984 + },
985 + "strict": {
986 + "unsupported": [
987 + {
988 + "path": "properties.open",
989 + "keyword": "additionalProperties"
990 + }
991 + ]
992 + }
993 + },
994 + {
995 + "id": "additional-properties-empty-schema-unsupported",
996 + "description": "An empty-schema additionalProperties accepts anything and is reported.",
997 + "schema": {
998 + "type": "object",
999 + "properties": {
1000 + "open": {
1001 + "type": "object",
1002 + "additionalProperties": {}
1003 + }
1004 + },
1005 + "required": ["open"]
1006 + },
1007 + "strict": {
1008 + "unsupported": [
1009 + {
1010 + "path": "properties.open",
1011 + "keyword": "additionalProperties"
1012 + }
1013 + ]
1014 + }
1015 + },
1016 + {
1017 + "id": "free-form-object-unsupported",
1018 + "description": "A property-less object accepts arbitrary keys and is reported.",
1019 + "schema": {
1020 + "type": "object",
1021 + "properties": {
1022 + "meta": {
1023 + "type": "object",
1024 + "description": "any json"
1025 + }
1026 + },
1027 + "required": ["meta"]
1028 + },
1029 + "strict": {
1030 + "unsupported": [
1031 + {
1032 + "path": "properties.meta",
1033 + "keyword": "properties"
1034 + }
1035 + ]
1036 + }
1037 + },
1038 + {
1039 + "id": "pattern-properties-unsupported",
1040 + "description": "patternProperties cannot be expressed and is reported.",
1041 + "schema": {
1042 + "type": "object",
1043 + "properties": {
1044 + "tagged": {
1045 + "type": "object",
1046 + "patternProperties": {
1047 + "^x-": {
1048 + "type": "string"
1049 + }
1050 + }
1051 + }
1052 + },
1053 + "required": ["tagged"]
1054 + },
1055 + "strict": {
1056 + "unsupported": [
1057 + {
1058 + "path": "properties.tagged",
1059 + "keyword": "patternProperties"
1060 + }
1061 + ]
1062 + }
1063 + },
1064 + {
1065 + "id": "empty-closed-object-representable",
1066 + "description": "An object closed with no properties is representable.",
1067 + "schema": {
1068 + "type": "object",
1069 + "properties": {
1070 + "empty": {
1071 + "type": "object",
1072 + "additionalProperties": false
1073 + }
1074 + },
1075 + "required": ["empty"]
1076 + },
1077 + "strict": {
1078 + "schema": {
1079 + "type": "object",
1080 + "properties": {
1081 + "empty": {
1082 + "type": "object",
1083 + "additionalProperties": false,
1084 + "properties": {},
1085 + "required": []
1086 + }
1087 + },
1088 + "required": ["empty"],
1089 + "additionalProperties": false
1090 + }
1091 + }
1092 + },
1093 + {
1094 + "id": "all-of-unsupported",
1095 + "description": "allOf has no lossless rewrite and is reported.",
1096 + "schema": {
1097 + "type": "object",
1098 + "properties": {
1099 + "all": {
1100 + "allOf": [
1101 + {
1102 + "type": "string"
1103 + }
1104 + ]
1105 + }
1106 + },
1107 + "required": ["all"]
1108 + },
1109 + "strict": {
1110 + "unsupported": [
1111 + {
1112 + "path": "properties.all",
1113 + "keyword": "allOf"
1114 + }
1115 + ]
1116 + }
1117 + },
1118 + {
1119 + "id": "prefix-items-unsupported",
1120 + "description": "prefixItems has no lossless rewrite and is reported.",
1121 + "schema": {
1122 + "type": "object",
1123 + "properties": {
1124 + "pair": {
1125 + "type": "array",
1126 + "prefixItems": [
1127 + {
1128 + "type": "number"
1129 + }
1130 + ]
1131 + }
1132 + },
1133 + "required": ["pair"]
1134 + },
1135 + "strict": {
1136 + "unsupported": [
1137 + {
1138 + "path": "properties.pair",
1139 + "keyword": "prefixItems"
1140 + }
1141 + ]
1142 + }
1143 + },
1144 + {
1145 + "id": "defs-ref-kept-and-definition-normalized",
1146 + "description": "Local $refs are kept and the definition is normalized where it is declared.",
1147 + "schema": {
1148 + "type": "object",
1149 + "properties": {
1150 + "cfg": {
1151 + "$ref": "#/$defs/Config"
1152 + }
1153 + },
1154 + "required": ["cfg"],
1155 + "$defs": {
1156 + "Config": {
1157 + "type": "object",
1158 + "properties": {
1159 + "url": {
1160 + "type": "string"
1161 + },
1162 + "note": {
1163 + "type": "string"
1164 + }
1165 + },
1166 + "required": ["url"]
1167 + }
1168 + }
1169 + },
1170 + "strict": {
1171 + "schema": {
1172 + "type": "object",
1173 + "properties": {
1174 + "cfg": {
1175 + "$ref": "#/$defs/Config"
1176 + }
1177 + },
1178 + "required": ["cfg"],
1179 + "$defs": {
1180 + "Config": {
1181 + "type": "object",
1182 + "properties": {
1183 + "url": {
1184 + "type": "string"
1185 + },
1186 + "note": {
1187 + "type": ["string", "null"]
1188 + }
1189 + },
1190 + "required": ["url", "note"],
1191 + "additionalProperties": false
1192 + }
1193 + },
1194 + "additionalProperties": false
1195 + }
1196 + },
1197 + "changes": [
1198 + {
1199 + "path": "$defs.Config.properties.note",
1200 + "reason": "optional-property-nullable"
1201 + }
1202 + ],
1203 + "arguments": [
1204 + {
1205 + "input": {
1206 + "cfg": {
1207 + "url": "u",
1208 + "note": null
1209 + }
1210 + },
1211 + "output": {
1212 + "cfg": {
1213 + "url": "u"
1214 + }
1215 + }
1216 + }
1217 + ]
1218 + },
1219 + {
1220 + "id": "optional-ref-widened-with-null-branch",
1221 + "description": "An optional $ref property is widened with an anyOf null branch.",
1222 + "schema": {
1223 + "type": "object",
1224 + "properties": {
1225 + "cfg": {
1226 + "$ref": "#/$defs/Config",
1227 + "description": "optional"
1228 + }
1229 + },
1230 + "$defs": {
1231 + "Config": {
1232 + "type": "object",
1233 + "properties": {
1234 + "url": {
1235 + "type": "string"
1236 + }
1237 + },
1238 + "required": ["url"]
1239 + }
1240 + }
1241 + },
1242 + "strict": {
1243 + "schema": {
1244 + "type": "object",
1245 + "properties": {
1246 + "cfg": {
1247 + "description": "optional",
1248 + "anyOf": [
1249 + {
1250 + "$ref": "#/$defs/Config"
1251 + },
1252 + {
1253 + "type": "null"
1254 + }
1255 + ]
1256 + }
1257 + },
1258 + "$defs": {
1259 + "Config": {
1260 + "type": "object",
1261 + "properties": {
1262 + "url": {
1263 + "type": "string"
1264 + }
1265 + },
1266 + "required": ["url"],
1267 + "additionalProperties": false
1268 + }
1269 + },
1270 + "required": ["cfg"],
1271 + "additionalProperties": false
1272 + }
1273 + },
1274 + "changes": [
1275 + {
1276 + "path": "properties.cfg",
1277 + "reason": "optional-property-nullable"
1278 + }
1279 + ],
1280 + "arguments": [
1281 + {
1282 + "input": {
1283 + "cfg": null
1284 + },
1285 + "output": {}
1286 + }
1287 + ]
1288 + },
1289 + {
1290 + "id": "recursive-defs-kept",
1291 + "description": "Self-recursive definitions are representable.",
1292 + "schema": {
1293 + "type": "object",
1294 + "properties": {
1295 + "node": {
1296 + "$ref": "#/$defs/Node"
1297 + }
1298 + },
1299 + "required": ["node"],
1300 + "$defs": {
1301 + "Node": {
1302 + "type": "object",
1303 + "properties": {
1304 + "child": {
1305 + "$ref": "#/$defs/Node"
1306 + },
1307 + "label": {
1308 + "type": "string"
1309 + }
1310 + },
1311 + "required": ["label"]
1312 + }
1313 + }
1314 + },
1315 + "strict": {
1316 + "schema": {
1317 + "type": "object",
1318 + "properties": {
1319 + "node": {
1320 + "$ref": "#/$defs/Node"
1321 + }
1322 + },
1323 + "required": ["node"],
1324 + "$defs": {
1325 + "Node": {
1326 + "type": "object",
1327 + "properties": {
1328 + "child": {
1329 + "anyOf": [
1330 + {
1331 + "$ref": "#/$defs/Node"
1332 + },
1333 + {
1334 + "type": "null"
1335 + }
1336 + ]
1337 + },
1338 + "label": {
1339 + "type": "string"
1340 + }
1341 + },
1342 + "required": ["child", "label"],
1343 + "additionalProperties": false
1344 + }
1345 + },
1346 + "additionalProperties": false
1347 + }
1348 + },
1349 + "changes": [
1350 + {
1351 + "path": "$defs.Node.properties.child",
1352 + "reason": "optional-property-nullable"
1353 + }
1354 + ],
1355 + "arguments": [
1356 + {
1357 + "input": {
1358 + "node": {
1359 + "label": "a",
1360 + "child": {
1361 + "label": "b",
1362 + "child": null
1363 + }
1364 + }
1365 + },
1366 + "output": {
1367 + "node": {
1368 + "label": "a",
1369 + "child": {
1370 + "label": "b"
1371 + }
1372 + }
1373 + }
1374 + }
1375 + ]
1376 + },
1377 + {
1378 + "id": "mutually-recursive-defs-kept",
1379 + "description": "Mutually recursive definitions are representable.",
1380 + "schema": {
1381 + "type": "object",
1382 + "properties": {
1383 + "a": {
1384 + "$ref": "#/$defs/A"
1385 + }
1386 + },
1387 + "required": ["a"],
1388 + "$defs": {
1389 + "A": {
1390 + "type": "object",
1391 + "properties": {
1392 + "b": {
1393 + "$ref": "#/$defs/B"
1394 + }
1395 + }
1396 + },
1397 + "B": {
1398 + "type": "object",
1399 + "properties": {
1400 + "a": {
1401 + "$ref": "#/$defs/A"
1402 + }
1403 + }
1404 + }
1405 + }
1406 + },
1407 + "strict": {
1408 + "schema": {
1409 + "type": "object",
1410 + "properties": {
1411 + "a": {
1412 + "$ref": "#/$defs/A"
1413 + }
1414 + },
1415 + "required": ["a"],
1416 + "$defs": {
1417 + "A": {
1418 + "type": "object",
1419 + "properties": {
1420 + "b": {
1421 + "anyOf": [
1422 + {
1423 + "$ref": "#/$defs/B"
1424 + },
1425 + {
1426 + "type": "null"
1427 + }
1428 + ]
1429 + }
1430 + },
1431 + "required": ["b"],
1432 + "additionalProperties": false
1433 + },
1434 + "B": {
1435 + "type": "object",
1436 + "properties": {
1437 + "a": {
1438 + "anyOf": [
1439 + {
1440 + "$ref": "#/$defs/A"
1441 + },
1442 + {
1443 + "type": "null"
1444 + }
1445 + ]
1446 + }
1447 + },
1448 + "required": ["a"],
1449 + "additionalProperties": false
1450 + }
1451 + },
1452 + "additionalProperties": false
1453 + }
1454 + },
1455 + "changes": [
1456 + {
1457 + "path": "$defs.A.properties.b",
1458 + "reason": "optional-property-nullable"
1459 + },
1460 + {
1461 + "path": "$defs.B.properties.a",
1462 + "reason": "optional-property-nullable"
1463 + }
1464 + ]
1465 + },
1466 + {
1467 + "id": "legacy-definitions-ref-kept",
1468 + "description": "Legacy definitions are supported like $defs.",
1469 + "schema": {
1470 + "type": "object",
1471 + "properties": {
1472 + "cfg": {
1473 + "$ref": "#/definitions/Config"
1474 + }
1475 + },
1476 + "required": ["cfg"],
1477 + "definitions": {
1478 + "Config": {
1479 + "type": "object",
1480 + "properties": {
1481 + "url": {
1482 + "type": "string"
1483 + }
1484 + }
1485 + }
1486 + }
1487 + },
1488 + "strict": {
1489 + "schema": {
1490 + "type": "object",
1491 + "properties": {
1492 + "cfg": {
1493 + "$ref": "#/definitions/Config"
1494 + }
1495 + },
1496 + "required": ["cfg"],
1497 + "definitions": {
1498 + "Config": {
1499 + "type": "object",
1500 + "properties": {
1501 + "url": {
1502 + "type": ["string", "null"]
1503 + }
1504 + },
1505 + "required": ["url"],
1506 + "additionalProperties": false
1507 + }
1508 + },
1509 + "additionalProperties": false
1510 + }
1511 + },
1512 + "changes": [
1513 + {
1514 + "path": "definitions.Config.properties.url",
1515 + "reason": "optional-property-nullable"
1516 + }
1517 + ]
1518 + },
1519 + {
1520 + "id": "ref-into-properties-kept",
1521 + "description": "A local $ref outside $defs resolves and is kept.",
1522 + "schema": {
1523 + "type": "object",
1524 + "properties": {
1525 + "a": {
1526 + "type": "object",
1527 + "properties": {
1528 + "x": {
1529 + "type": "string"
1530 + }
1531 + },
1532 + "required": ["x"]
1533 + },
1534 + "b": {
1535 + "$ref": "#/properties/a"
1536 + }
1537 + },
1538 + "required": ["a", "b"]
1539 + },
1540 + "strict": {
1541 + "schema": {
1542 + "type": "object",
1543 + "properties": {
1544 + "a": {
1545 + "type": "object",
1546 + "properties": {
1547 + "x": {
1548 + "type": "string"
1549 + }
1550 + },
1551 + "required": ["x"],
1552 + "additionalProperties": false
1553 + },
1554 + "b": {
1555 + "$ref": "#/properties/a"
1556 + }
1557 + },
1558 + "required": ["a", "b"],
1559 + "additionalProperties": false
1560 + }
1561 + }
1562 + },
1563 + {
1564 + "id": "dangling-ref-unsupported",
1565 + "description": "A $ref without a target is reported at its own path.",
1566 + "schema": {
1567 + "type": "object",
1568 + "properties": {
1569 + "cfg": {
1570 + "$ref": "#/$defs/Nope"
1571 + }
1572 + },
1573 + "required": ["cfg"]
1574 + },
1575 + "strict": {
1576 + "unsupported": [
1577 + {
1578 + "path": "properties.cfg",
1579 + "keyword": "$ref"
1580 + }
1581 + ]
1582 + }
1583 + },
1584 + {
1585 + "id": "external-ref-unsupported",
1586 + "description": "A $ref outside the document is reported.",
1587 + "schema": {
1588 + "type": "object",
1589 + "properties": {
1590 + "cfg": {
1591 + "$ref": "https://example.com/schema.json"
1592 + }
1593 + },
1594 + "required": ["cfg"]
1595 + },
1596 + "strict": {
1597 + "unsupported": [
1598 + {
1599 + "path": "properties.cfg",
1600 + "keyword": "$ref"
1601 + }
1602 + ]
1603 + }
1604 + },
1605 + {
1606 + "id": "duplicate-required-deduped",
1607 + "description": "Duplicate required entries are removed.",
1608 + "schema": {
1609 + "type": "object",
1610 + "properties": {
1611 + "a": {
1612 + "type": "string"
1613 + }
1614 + },
1615 + "required": ["a", "a"]
1616 + },
1617 + "strict": {
1618 + "schema": {
1619 + "type": "object",
1620 + "properties": {
1621 + "a": {
1622 + "type": "string"
1623 + }
1624 + },
1625 + "required": ["a"],
1626 + "additionalProperties": false
1627 + }
1628 + }
1629 + },
1630 + {
1631 + "id": "required-unknown-names-dropped",
1632 + "description": "Required names without a property are dropped from required.",
1633 + "schema": {
1634 + "type": "object",
1635 + "properties": {
1636 + "a": {
1637 + "type": "string"
1638 + }
1639 + },
1640 + "required": ["a", "ghost"]
1641 + },
1642 + "strict": {
1643 + "schema": {
1644 + "type": "object",
1645 + "properties": {
1646 + "a": {
1647 + "type": "string"
1648 + }
1649 + },
1650 + "required": ["a"],
1651 + "additionalProperties": false
1652 + }
1653 + }
1654 + },
1655 + {
1656 + "id": "required-not-an-array-ignored",
1657 + "description": "A malformed required is treated as absent.",
1658 + "schema": {
1659 + "type": "object",
1660 + "properties": {
1661 + "a": {
1662 + "type": "string"
1663 + }
1664 + },
1665 + "required": "a"
1666 + },
1667 + "strict": {
1668 + "schema": {
1669 + "type": "object",
1670 + "properties": {
1671 + "a": {
1672 + "type": ["string", "null"]
1673 + }
1674 + },
1675 + "required": ["a"],
1676 + "additionalProperties": false
1677 + }
1678 + },
1679 + "changes": [
1680 + {
1681 + "path": "properties.a",
1682 + "reason": "optional-property-nullable"
1683 + }
1684 + ]
1685 + },
1686 + {
1687 + "id": "description-kept-on-widened-node",
1688 + "description": "Annotations survive widening.",
1689 + "schema": {
1690 + "type": "object",
1691 + "properties": {
1692 + "a": {
1693 + "type": "integer",
1694 + "description": "count",
1695 + "title": "Count",
1696 + "minimum": 0
1697 + }
1698 + }
1699 + },
1700 + "strict": {
1701 + "schema": {
1702 + "type": "object",
1703 + "properties": {
1704 + "a": {
1705 + "type": ["integer", "null"],
1706 + "description": "count",
1707 + "title": "Count",
1708 + "minimum": 0
1709 + }
1710 + },
1711 + "required": ["a"],
1712 + "additionalProperties": false
1713 + }
1714 + },
1715 + "changes": [
1716 + {
1717 + "path": "properties.a",
1718 + "reason": "optional-property-nullable"
1719 + }
1720 + ]
1721 + },
1722 + {
1723 + "id": "non-object-root-unsupported",
1724 + "description": "The root must be an object.",
1725 + "schema": {
1726 + "type": "string"
1727 + },
1728 + "strict": {
1729 + "unsupported": [
1730 + {
1731 + "path": "",
1732 + "keyword": "type"
1733 + }
1734 + ]
1735 + }
1736 + },
1737 + {
1738 + "id": "nullable-root-unsupported",
1739 + "description": "The root must not be nullable.",
1740 + "schema": {
1741 + "type": ["object", "null"],
1742 + "properties": {
1743 + "a": {
1744 + "type": "string"
1745 + }
1746 + }
1747 + },
1748 + "strict": {
1749 + "unsupported": [
1750 + {
1751 + "path": "",
1752 + "keyword": "type"
1753 + }
1754 + ]
1755 + },
1756 + "changes": [
1757 + {
1758 + "path": "properties.a",
1759 + "reason": "optional-property-nullable"
1760 + }
1761 + ]
1762 + },
1763 + {
1764 + "id": "properties-without-type-become-object",
1765 + "description": "A node with properties but no type is treated as an object.",
1766 + "schema": {
1767 + "type": "object",
1768 + "properties": {
1769 + "cfg": {
1770 + "properties": {
1771 + "a": {
1772 + "type": "string"
1773 + }
1774 + }
1775 + }
1776 + },
1777 + "required": ["cfg"]
1778 + },
1779 + "strict": {
1780 + "schema": {
1781 + "type": "object",
1782 + "properties": {
1783 + "cfg": {
1784 + "properties": {
1785 + "a": {
1786 + "type": ["string", "null"]
1787 + }
1788 + },
1789 + "type": "object",
1790 + "required": ["a"],
1791 + "additionalProperties": false
1792 + }
1793 + },
1794 + "required": ["cfg"],
1795 + "additionalProperties": false
1796 + }
1797 + },
1798 + "changes": [
1799 + {
1800 + "path": "properties.cfg.properties.a",
1801 + "reason": "optional-property-nullable"
1802 + }
1803 + ]
1804 + },
1805 + {
1806 + "id": "root-without-type-become-object",
1807 + "description": "A root with properties but no type is treated as an object.",
1808 + "schema": {
1809 + "properties": {
1810 + "a": {
1811 + "type": "string"
1812 + }
1813 + }
1814 + },
1815 + "strict": {
1816 + "schema": {
1817 + "properties": {
1818 + "a": {
1819 + "type": ["string", "null"]
1820 + }
1821 + },
1822 + "type": "object",
1823 + "required": ["a"],
1824 + "additionalProperties": false
1825 + }
1826 + },
1827 + "changes": [
1828 + {
1829 + "path": "properties.a",
1830 + "reason": "optional-property-nullable"
1831 + }
1832 + ]
1833 + }
1834 + ]
1835 +}
python/tests/fixtures/json_schema_conversion_corpus.py
+73
@@ -13,6 +13,9 @@ from pathlib import Path
13 from pydantic import BaseModel, ConfigDict, Field
14
15 CORPUS_PATH = Path(__file__).parent / "json-schema-conversion" / "object-cases.json"
16 +STRICT_CORPUS_PATH = (
17 + Path(__file__).parent / "json-schema-conversion" / "strict-cases.json"
18 +)
19
20 Language = t.Literal["zod", "effect", "python"]
21 LANGUAGES: t.Tuple[Language, ...] = ("zod", "effect", "python")
@@ -125,3 +128,73 @@ def find_case(case_id: str) -> CorpusCase:
128 if case.id == case_id:
129 return case
130 raise LookupError(f"Corpus is missing the {case_id} case")
131 +
132 +
133 +class StrictIncompatibility(BaseModel):
134 + model_config = ConfigDict(extra="forbid")
135 +
136 + path: str
137 + keyword: str = Field(min_length=1)
138 +
139 +
140 +class StrictChange(BaseModel):
141 + model_config = ConfigDict(extra="forbid")
142 +
143 + path: str
144 + reason: str = Field(min_length=1)
145 +
146 +
147 +class StrictArguments(BaseModel):
148 + model_config = ConfigDict(extra="forbid")
149 +
150 + input: t.Dict[str, t.Any]
151 + output: t.Dict[str, t.Any]
152 +
153 +
154 +class StrictExpectation(BaseModel):
155 + """Either the exact strict schema, or the constructs reported as unsupported."""
156 +
157 + model_config = ConfigDict(extra="forbid")
158 +
159 + schema_: t.Optional[t.Dict[str, t.Any]] = Field(default=None, alias="schema")
160 + unsupported: t.Optional[t.List[StrictIncompatibility]] = Field(
161 + default=None, min_length=1
162 + )
163 +
164 +
165 +class StrictCase(BaseModel):
166 + model_config = ConfigDict(extra="forbid")
167 +
168 + id: str = Field(min_length=1)
169 + description: t.Optional[str] = None
170 + schema_: t.Dict[str, t.Any] = Field(alias="schema")
171 + strict: StrictExpectation
172 + changes: t.Optional[t.List[StrictChange]] = None
173 + arguments: t.Optional[t.List[StrictArguments]] = None
174 +
175 +
176 +class StrictCorpus(BaseModel):
177 + model_config = ConfigDict(extra="forbid")
178 +
179 + cases: t.List[StrictCase] = Field(min_length=1)
180 +
181 +
182 +_cached_strict: t.Optional[t.List[StrictCase]] = None
183 +
184 +
185 +def load_strict_cases() -> t.List[StrictCase]:
186 + """Decode the shared strict-mode corpus (byte-identical copy per language)."""
187 + global _cached_strict
188 + if _cached_strict is None:
189 + cases = StrictCorpus.model_validate(
190 + json.loads(STRICT_CORPUS_PATH.read_text())
191 + ).cases
192 + seen: t.Set[str] = set()
193 + for case in cases:
194 + if case.id in seen:
195 + raise ValueError(f"Duplicate strict case id: {case.id}")
196 + seen.add(case.id)
197 + if (case.strict.schema_ is None) == (case.strict.unsupported is None):
198 + raise ValueError(f"Strict case {case.id} must pin exactly one outcome")
199 + _cached_strict = cases
200 + return _cached_strict
python/tests/test_strict_schema_corpus.py new
+80
@@ -0,0 +1,80 @@
1 +"""Drive to_strict_json_schema from the shared strict-mode corpus.
2 +
3 +The corpus pins the exact output of the TypeScript implementation, so this
4 +suite is the cross-SDK parity check for strict normalization.
5 +"""
6 +
7 +import copy
8 +
9 +import pytest
10 +
11 +from composio.utils.strict_schema import omit_null_tool_arguments, to_strict_json_schema
12 +from tests.fixtures.json_schema_conversion_corpus import load_strict_cases
13 +
14 +
15 +def assert_strict_shape(node, path=""):
16 + """Structural invariants OpenAI enforces on every node of a strict schema."""
17 + if isinstance(node, list):
18 + for index, item in enumerate(node):
19 + assert_strict_shape(item, f"{path}[{index}]")
20 + return
21 + if not isinstance(node, dict):
22 + return
23 + if "anyOf" in node:
24 + assert "type" not in node, f"{path}: type beside anyOf"
25 + for keyword in (
26 + "default",
27 + "examples",
28 + "oneOf",
29 + "patternProperties",
30 + "allOf",
31 + "prefixItems",
32 + ):
33 + assert keyword not in node, f"{path}: {keyword}"
34 + node_type = node.get("type")
35 + is_object = node_type == "object" or (
36 + isinstance(node_type, list) and "object" in node_type
37 + )
38 + if is_object or "properties" in node:
39 + properties = node.get("properties") or {}
40 + assert node.get("required") == list(properties.keys()), f"{path}: required"
41 + assert node.get("additionalProperties") is False, (
42 + f"{path}: additionalProperties"
43 + )
44 + for key, child in node.items():
45 + if key in ("enum", "const"):
46 + continue
47 + child_path = f"{path}.{key}" if path else key
48 + if key in ("properties", "$defs", "definitions") and isinstance(child, dict):
49 + # Keys of these maps are names, not keywords.
50 + for name, sub in child.items():
51 + assert_strict_shape(sub, f"{child_path}.{name}")
52 + continue
53 + assert_strict_shape(child, child_path)
54 +
55 +
56 +@pytest.mark.parametrize("case", load_strict_cases(), ids=lambda case: case.id)
57 +def test_strict_corpus_case(case):
58 + snapshot = copy.deepcopy(case.schema_)
59 + result = to_strict_json_schema(case.schema_)
60 +
61 + assert case.schema_ == snapshot, "input mutated"
62 + if case.strict.unsupported is not None:
63 + assert [(e.path, e.keyword) for e in result.unsupported] == [
64 + (e.path, e.keyword) for e in case.strict.unsupported
65 + ]
66 + else:
67 + assert result.unsupported == []
68 + assert result.schema == case.strict.schema_
69 + assert_strict_shape(result.schema)
70 + again = to_strict_json_schema(result.schema)
71 + assert again.schema == result.schema, "not idempotent"
72 + assert again.changes == []
73 + assert [(c.path, c.reason) for c in result.changes] == [
74 + (c.path, c.reason) for c in (case.changes or [])
75 + ]
76 + assert result.total_changes == len(result.changes)
77 + for arguments in case.arguments or []:
78 + assert (
79 + omit_null_tool_arguments(arguments.input, result.source) == arguments.output
80 + )
ts/packages/core/test/fixtures/json-schema-conversion/corpus.ts
+41
@@ -10,6 +10,7 @@
10 import * as z from 'zod';
11
12 import corpusDocument from './object-cases.json';
13 +import strictDocument from './strict-cases.json';
14
15 const JsonObject = z.record(z.string(), z.unknown());
16
@@ -83,3 +84,43 @@ export const loadObjectCases = (): ReadonlyArray<CorpusCase> => {
84 /** Acceptance for one language: the shared flag unless a declared divergence overrides it. */
85 export const acceptedFor = (instance: CorpusInstance, language: CorpusLanguage): boolean =>
86 instance[language]?.accepted ?? instance.accepted;
87 +
88 +const StrictIncompatibility = z.object({ path: z.string(), keyword: z.string().min(1) });
89 +const StrictChange = z.object({ path: z.string(), reason: z.string().min(1) });
90 +const StrictArguments = z.object({ input: JsonObject, output: JsonObject });
91 +
92 +/**
93 + * One strict-mode normalization case: either the exact strict schema the
94 + * rewrite must produce, or the constructs it must report as unsupported.
95 + */
96 +const StrictCase = z.object({
97 + id: z.string().min(1),
98 + description: z.string().optional(),
99 + schema: JsonObject,
100 + strict: z.union([
101 + z.object({ schema: JsonObject }),
102 + z.object({ unsupported: z.array(StrictIncompatibility).min(1) }),
103 + ]),
104 + changes: z.array(StrictChange).optional(),
105 + arguments: z.array(StrictArguments).optional(),
106 +});
107 +
108 +const StrictCorpus = z.object({ cases: z.array(StrictCase).min(1) });
109 +
110 +export type StrictCase = z.infer<typeof StrictCase>;
111 +
112 +let cachedStrict: ReadonlyArray<StrictCase> | undefined;
113 +
114 +/** Decode the shared strict-mode corpus (byte-identical copy per language). */
115 +export const loadStrictCases = (): ReadonlyArray<StrictCase> => {
116 + if (!cachedStrict) {
117 + const { cases } = StrictCorpus.parse(strictDocument);
118 + const seen = new Set<string>();
119 + for (const testCase of cases) {
120 + if (seen.has(testCase.id)) throw new Error(`Duplicate strict case id: ${testCase.id}`);
121 + seen.add(testCase.id);
122 + }
123 + cachedStrict = cases;
124 + }
125 + return cachedStrict;
126 +};
ts/packages/core/test/fixtures/json-schema-conversion/strict-cases.json new
+1835
@@ -0,0 +1,1835 @@
1 +{
2 + "cases": [
3 + {
4 + "id": "flat-all-required-unchanged",
5 + "description": "An already-strict schema is returned unchanged with no changes.",
6 + "schema": {
7 + "type": "object",
8 + "properties": {
9 + "query": {
10 + "type": "string"
11 + }
12 + },
13 + "required": ["query"],
14 + "additionalProperties": false
15 + },
16 + "strict": {
17 + "schema": {
18 + "type": "object",
19 + "properties": {
20 + "query": {
21 + "type": "string"
22 + }
23 + },
24 + "required": ["query"],
25 + "additionalProperties": false
26 + }
27 + }
28 + },
29 + {
30 + "id": "nested-optional-property-widened",
31 + "description": "Optional properties stay, become required and accept null at every depth.",
32 + "schema": {
33 + "type": "object",
34 + "properties": {
35 + "cfg": {
36 + "type": "object",
37 + "properties": {
38 + "url": {
39 + "type": "string"
40 + },
41 + "note": {
42 + "type": "string",
43 + "description": "optional note"
44 + }
45 + },
46 + "required": ["url"]
47 + }
48 + },
49 + "required": ["cfg"]
50 + },
51 + "strict": {
52 + "schema": {
53 + "type": "object",
54 + "properties": {
55 + "cfg": {
56 + "type": "object",
57 + "properties": {
58 + "url": {
59 + "type": "string"
60 + },
61 + "note": {
62 + "type": ["string", "null"],
63 + "description": "optional note"
64 + }
65 + },
66 + "required": ["url", "note"],
67 + "additionalProperties": false
68 + }
69 + },
70 + "required": ["cfg"],
71 + "additionalProperties": false
72 + }
73 + },
74 + "changes": [
75 + {
76 + "path": "properties.cfg.properties.note",
77 + "reason": "optional-property-nullable"
78 + }
79 + ],
80 + "arguments": [
81 + {
82 + "input": {
83 + "cfg": {
84 + "url": "u",
85 + "note": null
86 + }
87 + },
88 + "output": {
89 + "cfg": {
90 + "url": "u"
91 + }
92 + }
93 + }
94 + ]
95 + },
96 + {
97 + "id": "no-required-array-widens-every-property",
98 + "description": "An object without `required` requires and widens every property.",
99 + "schema": {
100 + "type": "object",
101 + "properties": {
102 + "a": {
103 + "type": "string"
104 + },
105 + "b": {
106 + "type": "number"
107 + }
108 + }
109 + },
110 + "strict": {
111 + "schema": {
112 + "type": "object",
113 + "properties": {
114 + "a": {
115 + "type": ["string", "null"]
116 + },
117 + "b": {
118 + "type": ["number", "null"]
119 + }
120 + },
121 + "required": ["a", "b"],
122 + "additionalProperties": false
123 + }
124 + },
125 + "changes": [
126 + {
127 + "path": "properties.a",
128 + "reason": "optional-property-nullable"
129 + },
130 + {
131 + "path": "properties.b",
132 + "reason": "optional-property-nullable"
133 + }
134 + ],
135 + "arguments": [
136 + {
137 + "input": {
138 + "a": null,
139 + "b": 1,
140 + "unknown": null
141 + },
142 + "output": {
143 + "b": 1,
144 + "unknown": null
145 + }
146 + }
147 + ]
148 + },
149 + {
150 + "id": "required-empty-array-widens-every-property",
151 + "description": "An empty `required` array is the same as an absent one.",
152 + "schema": {
153 + "type": "object",
154 + "properties": {
155 + "a": {
156 + "type": "string"
157 + }
158 + },
159 + "required": []
160 + },
161 + "strict": {
162 + "schema": {
163 + "type": "object",
164 + "properties": {
165 + "a": {
166 + "type": ["string", "null"]
167 + }
168 + },
169 + "required": ["a"],
170 + "additionalProperties": false
171 + }
172 + },
173 + "changes": [
174 + {
175 + "path": "properties.a",
176 + "reason": "optional-property-nullable"
177 + }
178 + ]
179 + },
180 + {
181 + "id": "nullable-type-array-kept",
182 + "description": "A `type` array with null is accepted by the API and left alone.",
183 + "schema": {
184 + "type": "object",
185 + "properties": {
186 + "id": {
187 + "type": ["string", "null"],
188 + "description": "identifier"
189 + }
190 + },
191 + "required": ["id"]
192 + },
193 + "strict": {
194 + "schema": {
195 + "type": "object",
196 + "properties": {
197 + "id": {
198 + "type": ["string", "null"],
199 + "description": "identifier"
200 + }
201 + },
202 + "required": ["id"],
203 + "additionalProperties": false
204 + }
205 + },
206 + "arguments": [
207 + {
208 + "input": {
209 + "id": null
210 + },
211 + "output": {
212 + "id": null
213 + }
214 + }
215 + ]
216 + },
217 + {
218 + "id": "nullable-object-stays-nullable",
219 + "description": "A nullable object keeps its type array; only its own properties are closed.",
220 + "schema": {
221 + "type": "object",
222 + "properties": {
223 + "cfg": {
224 + "type": ["object", "null"],
225 + "properties": {
226 + "a": {
227 + "type": "string"
228 + }
229 + },
230 + "required": ["a"]
231 + }
232 + },
233 + "required": ["cfg"]
234 + },
235 + "strict": {
236 + "schema": {
237 + "type": "object",
238 + "properties": {
239 + "cfg": {
240 + "type": ["object", "null"],
241 + "properties": {
242 + "a": {
243 + "type": "string"
244 + }
245 + },
246 + "required": ["a"],
247 + "additionalProperties": false
248 + }
249 + },
250 + "required": ["cfg"],
251 + "additionalProperties": false
252 + }
253 + },
254 + "arguments": [
255 + {
256 + "input": {
257 + "cfg": null
258 + },
259 + "output": {
260 + "cfg": null
261 + }
262 + },
263 + {
264 + "input": {
265 + "cfg": {
266 + "a": "x"
267 + }
268 + },
269 + "output": {
270 + "cfg": {
271 + "a": "x"
272 + }
273 + }
274 + }
275 + ]
276 + },
277 + {
278 + "id": "nullable-array-kept",
279 + "description": "A nullable array keeps its type array and items.",
280 + "schema": {
281 + "type": "object",
282 + "properties": {
283 + "xs": {
284 + "type": ["array", "null"],
285 + "items": {
286 + "type": "string"
287 + }
288 + }
289 + },
290 + "required": ["xs"]
291 + },
292 + "strict": {
293 + "schema": {
294 + "type": "object",
295 + "properties": {
296 + "xs": {
297 + "type": ["array", "null"],
298 + "items": {
299 + "type": "string"
300 + }
301 + }
302 + },
303 + "required": ["xs"],
304 + "additionalProperties": false
305 + }
306 + }
307 + },
308 + {
309 + "id": "optional-any-of-gets-null-branch",
310 + "description": "An optional composition gains a null branch instead of a sibling type.",
311 + "schema": {
312 + "type": "object",
313 + "properties": {
314 + "value": {
315 + "anyOf": [
316 + {
317 + "type": "string"
318 + },
319 + {
320 + "type": "number"
321 + }
322 + ]
323 + }
324 + }
325 + },
326 + "strict": {
327 + "schema": {
328 + "type": "object",
329 + "properties": {
330 + "value": {
331 + "anyOf": [
332 + {
333 + "type": "string"
334 + },
335 + {
336 + "type": "number"
337 + },
338 + {
339 + "type": "null"
340 + }
341 + ]
342 + }
343 + },
344 + "required": ["value"],
345 + "additionalProperties": false
346 + }
347 + },
348 + "changes": [
349 + {
350 + "path": "properties.value",
351 + "reason": "optional-property-nullable"
352 + }
353 + ]
354 + },
355 + {
356 + "id": "any-of-already-nullable-unchanged",
357 + "description": "A composition that already accepts null is not widened twice.",
358 + "schema": {
359 + "type": "object",
360 + "properties": {
361 + "value": {
362 + "anyOf": [
363 + {
364 + "type": "string"
365 + },
366 + {
367 + "type": "null"
368 + }
369 + ]
370 + }
371 + }
372 + },
373 + "strict": {
374 + "schema": {
375 + "type": "object",
376 + "properties": {
377 + "value": {
378 + "anyOf": [
379 + {
380 + "type": "string"
381 + },
382 + {
383 + "type": "null"
384 + }
385 + ]
386 + }
387 + },
388 + "required": ["value"],
389 + "additionalProperties": false
390 + }
391 + },
392 + "changes": [
393 + {
394 + "path": "properties.value",
395 + "reason": "optional-property-nullable"
396 + }
397 + ],
398 + "arguments": [
399 + {
400 + "input": {
401 + "value": null
402 + },
403 + "output": {
404 + "value": null
405 + }
406 + }
407 + ]
408 + },
409 + {
410 + "id": "optional-enum-only-wrapped",
411 + "description": "An enum-only property is wrapped so the annotation stays outside the anyOf.",
412 + "schema": {
413 + "type": "object",
414 + "properties": {
415 + "choice": {
416 + "enum": ["a", "b"],
417 + "description": "pick one",
418 + "title": "Choice"
419 + }
420 + }
421 + },
422 + "strict": {
423 + "schema": {
424 + "type": "object",
425 + "properties": {
426 + "choice": {
427 + "description": "pick one",
428 + "title": "Choice",
429 + "anyOf": [
430 + {
431 + "enum": ["a", "b"]
432 + },
433 + {
434 + "type": "null"
435 + }
436 + ]
437 + }
438 + },
439 + "required": ["choice"],
440 + "additionalProperties": false
441 + }
442 + },
443 + "changes": [
444 + {
445 + "path": "properties.choice",
446 + "reason": "optional-property-nullable"
447 + }
448 + ],
449 + "arguments": [
450 + {
451 + "input": {
452 + "choice": null
453 + },
454 + "output": {}
455 + }
456 + ]
457 + },
458 + {
459 + "id": "optional-const-wrapped",
460 + "description": "A const-only property is wrapped in an anyOf with a null branch.",
461 + "schema": {
462 + "type": "object",
463 + "properties": {
464 + "kind": {
465 + "const": "fixed"
466 + }
467 + }
468 + },
469 + "strict": {
470 + "schema": {
471 + "type": "object",
472 + "properties": {
473 + "kind": {
474 + "anyOf": [
475 + {
476 + "const": "fixed"
477 + },
478 + {
479 + "type": "null"
480 + }
481 + ]
482 + }
483 + },
484 + "required": ["kind"],
485 + "additionalProperties": false
486 + }
487 + },
488 + "changes": [
489 + {
490 + "path": "properties.kind",
491 + "reason": "optional-property-nullable"
492 + }
493 + ]
494 + },
495 + {
496 + "id": "optional-empty-schema-unchanged",
497 + "description": "An empty schema already accepts null and is left alone.",
498 + "schema": {
499 + "type": "object",
500 + "properties": {
501 + "anything": {}
502 + }
503 + },
504 + "strict": {
505 + "schema": {
506 + "type": "object",
507 + "properties": {
508 + "anything": {}
509 + },
510 + "required": ["anything"],
511 + "additionalProperties": false
512 + }
513 + },
514 + "changes": [
515 + {
516 + "path": "properties.anything",
517 + "reason": "optional-property-nullable"
518 + }
519 + ]
520 + },
521 + {
522 + "id": "multi-type-array-gains-null",
523 + "description": "A multi-type array gains null instead of being converted to anyOf.",
524 + "schema": {
525 + "type": "object",
526 + "properties": {
527 + "value": {
528 + "type": ["string", "number"]
529 + }
530 + }
531 + },
532 + "strict": {
533 + "schema": {
534 + "type": "object",
535 + "properties": {
536 + "value": {
537 + "type": ["string", "number", "null"]
538 + }
539 + },
540 + "required": ["value"],
541 + "additionalProperties": false
542 + }
543 + },
544 + "changes": [
545 + {
546 + "path": "properties.value",
547 + "reason": "optional-property-nullable"
548 + }
549 + ]
550 + },
551 + {
552 + "id": "one-of-converted-to-any-of",
553 + "description": "oneOf is unsupported and becomes anyOf.",
554 + "schema": {
555 + "type": "object",
556 + "properties": {
557 + "either": {
558 + "oneOf": [
559 + {
560 + "type": "string"
561 + },
562 + {
563 + "type": "number"
564 + }
565 + ]
566 + }
567 + },
568 + "required": ["either"]
569 + },
570 + "strict": {
571 + "schema": {
572 + "type": "object",
573 + "properties": {
574 + "either": {
575 + "anyOf": [
576 + {
577 + "type": "string"
578 + },
579 + {
580 + "type": "number"
581 + }
582 + ]
583 + }
584 + },
585 + "required": ["either"],
586 + "additionalProperties": false
587 + }
588 + },
589 + "changes": [
590 + {
591 + "path": "properties.either",
592 + "reason": "one-of-converted"
593 + }
594 + ]
595 + },
596 + {
597 + "id": "array-items-object-normalized",
598 + "description": "Objects inside array items are closed and widened.",
599 + "schema": {
600 + "type": "object",
601 + "properties": {
602 + "rows": {
603 + "type": "array",
604 + "items": {
605 + "type": "object",
606 + "properties": {
607 + "id": {
608 + "type": "string"
609 + },
610 + "tag": {
611 + "type": "string"
612 + }
613 + },
614 + "required": ["id"]
615 + }
616 + }
617 + },
618 + "required": ["rows"]
619 + },
620 + "strict": {
621 + "schema": {
622 + "type": "object",
623 + "properties": {
624 + "rows": {
625 + "type": "array",
626 + "items": {
627 + "type": "object",
628 + "properties": {
629 + "id": {
630 + "type": "string"
631 + },
632 + "tag": {
633 + "type": ["string", "null"]
634 + }
635 + },
636 + "required": ["id", "tag"],
637 + "additionalProperties": false
638 + }
639 + }
640 + },
641 + "required": ["rows"],
642 + "additionalProperties": false
643 + }
644 + },
645 + "changes": [
646 + {
647 + "path": "properties.rows.items.properties.tag",
648 + "reason": "optional-property-nullable"
649 + }
650 + ],
651 + "arguments": [
652 + {
653 + "input": {
654 + "rows": [
655 + {
656 + "id": "1",
657 + "tag": null
658 + },
659 + null
660 + ]
661 + },
662 + "output": {
663 + "rows": [
664 + {
665 + "id": "1"
666 + },
667 + null
668 + ]
669 + }
670 + }
671 + ]
672 + },
673 + {
674 + "id": "tuple-items-normalized",
675 + "description": "Objects inside tuple-form items are normalized too.",
676 + "schema": {
677 + "type": "object",
678 + "properties": {
679 + "pair": {
680 + "type": "array",
681 + "items": [
682 + {
683 + "type": "object",
684 + "properties": {
685 + "x": {
686 + "type": "number"
687 + }
688 + }
689 + },
690 + {
691 + "type": "string"
692 + }
693 + ]
694 + }
695 + },
696 + "required": ["pair"]
697 + },
698 + "strict": {
699 + "schema": {
700 + "type": "object",
701 + "properties": {
702 + "pair": {
703 + "type": "array",
704 + "items": [
705 + {
706 + "type": "object",
707 + "properties": {
708 + "x": {
709 + "type": ["number", "null"]
710 + }
711 + },
712 + "required": ["x"],
713 + "additionalProperties": false
714 + },
715 + {
716 + "type": "string"
717 + }
718 + ]
719 + }
720 + },
721 + "required": ["pair"],
722 + "additionalProperties": false
723 + }
724 + },
725 + "changes": [
726 + {
727 + "path": "properties.pair.items[0].properties.x",
728 + "reason": "optional-property-nullable"
729 + }
730 + ]
731 + },
732 + {
733 + "id": "default-and-examples-stripped",
734 + "description": "Annotation keywords the API rejects are stripped and reported.",
735 + "schema": {
736 + "type": "object",
737 + "properties": {
738 + "name": {
739 + "type": "string",
740 + "examples": ["a"],
741 + "default": "x"
742 + }
743 + },
744 + "required": ["name"]
745 + },
746 + "strict": {
747 + "schema": {
748 + "type": "object",
749 + "properties": {
750 + "name": {
751 + "type": "string"
752 + }
753 + },
754 + "required": ["name"],
755 + "additionalProperties": false
756 + }
757 + },
758 + "changes": [
759 + {
760 + "path": "properties.name",
761 + "reason": "unsupported-keyword-stripped"
762 + },
763 + {
764 + "path": "properties.name",
765 + "reason": "unsupported-keyword-stripped"
766 + }
767 + ]
768 + },
769 + {
770 + "id": "enum-values-are-data-not-keywords",
771 + "description": "Keys inside enum/const values are data and must not be treated as keywords.",
772 + "schema": {
773 + "type": "object",
774 + "properties": {
775 + "opts": {
776 + "enum": [
777 + {
778 + "default": 1,
779 + "properties": {}
780 + },
781 + null
782 + ]
783 + }
784 + },
785 + "required": ["opts"]
786 + },
787 + "strict": {
788 + "schema": {
789 + "type": "object",
790 + "properties": {
791 + "opts": {
792 + "enum": [
793 + {
794 + "default": 1,
795 + "properties": {}
796 + },
797 + null
798 + ]
799 + }
800 + },
801 + "required": ["opts"],
802 + "additionalProperties": false
803 + }
804 + },
805 + "arguments": [
806 + {
807 + "input": {
808 + "opts": null
809 + },
810 + "output": {
811 + "opts": null
812 + }
813 + }
814 + ]
815 + },
816 + {
817 + "id": "property-names-are-not-keywords",
818 + "description": "Properties named like keywords are ordinary properties.",
819 + "schema": {
820 + "type": "object",
821 + "properties": {
822 + "default": {
823 + "type": "string"
824 + },
825 + "$ref": {
826 + "type": "string"
827 + },
828 + "type": {
829 + "type": "string"
830 + },
831 + "properties": {
832 + "type": "object",
833 + "properties": {
834 + "x": {
835 + "type": "string"
836 + }
837 + }
838 + }
839 + }
840 + },
841 + "strict": {
842 + "schema": {
843 + "type": "object",
844 + "properties": {
845 + "default": {
846 + "type": ["string", "null"]
847 + },
848 + "$ref": {
849 + "type": ["string", "null"]
850 + },
851 + "type": {
852 + "type": ["string", "null"]
853 + },
854 + "properties": {
855 + "type": ["object", "null"],
856 + "properties": {
857 + "x": {
858 + "type": ["string", "null"]
859 + }
860 + },
861 + "required": ["x"],
862 + "additionalProperties": false
863 + }
864 + },
865 + "required": ["default", "$ref", "type", "properties"],
866 + "additionalProperties": false
867 + }
868 + },
869 + "changes": [
870 + {
871 + "path": "properties.properties.properties.x",
872 + "reason": "optional-property-nullable"
873 + },
874 + {
875 + "path": "properties.default",
876 + "reason": "optional-property-nullable"
877 + },
878 + {
879 + "path": "properties.$ref",
880 + "reason": "optional-property-nullable"
881 + },
882 + {
883 + "path": "properties.type",
884 + "reason": "optional-property-nullable"
885 + },
886 + {
887 + "path": "properties.properties",
888 + "reason": "optional-property-nullable"
889 + }
890 + ],
891 + "arguments": [
892 + {
893 + "input": {
894 + "default": null,
895 + "$ref": "x",
896 + "type": null,
897 + "properties": {
898 + "x": null
899 + }
900 + },
901 + "output": {
902 + "$ref": "x",
903 + "properties": {}
904 + }
905 + }
906 + ]
907 + },
908 + {
909 + "id": "prototype-key-property-name",
910 + "description": "A property named __proto__ or constructor is handled as a plain name.",
911 + "schema": {
912 + "type": "object",
913 + "properties": {
914 + "__proto__": {
915 + "type": "string"
916 + },
917 + "constructor": {
918 + "type": "number"
919 + }
920 + }
921 + },
922 + "strict": {
923 + "schema": {
924 + "type": "object",
925 + "properties": {
926 + "__proto__": {
927 + "type": ["string", "null"]
928 + },
929 + "constructor": {
930 + "type": ["number", "null"]
931 + }
932 + },
933 + "required": ["__proto__", "constructor"],
934 + "additionalProperties": false
935 + }
936 + },
937 + "changes": [
938 + {
939 + "path": "properties.__proto__",
940 + "reason": "optional-property-nullable"
941 + },
942 + {
943 + "path": "properties.constructor",
944 + "reason": "optional-property-nullable"
945 + }
946 + ]
947 + },
948 + {
949 + "id": "schema-valued-additional-properties-unsupported",
950 + "description": "A map-style object cannot be expressed and is reported, not closed.",
951 + "schema": {
952 + "type": "object",
953 + "properties": {
954 + "headers": {
955 + "type": "object",
956 + "additionalProperties": {
957 + "type": "string"
958 + }
959 + }
960 + },
961 + "required": ["headers"]
962 + },
963 + "strict": {
964 + "unsupported": [
965 + {
966 + "path": "properties.headers",
967 + "keyword": "additionalProperties"
968 + }
969 + ]
970 + }
971 + },
972 + {
973 + "id": "additional-properties-true-unsupported",
974 + "description": "An explicitly open object is reported.",
975 + "schema": {
976 + "type": "object",
977 + "properties": {
978 + "open": {
979 + "type": "object",
980 + "additionalProperties": true
981 + }
982 + },
983 + "required": ["open"]
984 + },
985 + "strict": {
986 + "unsupported": [
987 + {
988 + "path": "properties.open",
989 + "keyword": "additionalProperties"
990 + }
991 + ]
992 + }
993 + },
994 + {
995 + "id": "additional-properties-empty-schema-unsupported",
996 + "description": "An empty-schema additionalProperties accepts anything and is reported.",
997 + "schema": {
998 + "type": "object",
999 + "properties": {
1000 + "open": {
1001 + "type": "object",
1002 + "additionalProperties": {}
1003 + }
1004 + },
1005 + "required": ["open"]
1006 + },
1007 + "strict": {
1008 + "unsupported": [
1009 + {
1010 + "path": "properties.open",
1011 + "keyword": "additionalProperties"
1012 + }
1013 + ]
1014 + }
1015 + },
1016 + {
1017 + "id": "free-form-object-unsupported",
1018 + "description": "A property-less object accepts arbitrary keys and is reported.",
1019 + "schema": {
1020 + "type": "object",
1021 + "properties": {
1022 + "meta": {
1023 + "type": "object",
1024 + "description": "any json"
1025 + }
1026 + },
1027 + "required": ["meta"]
1028 + },
1029 + "strict": {
1030 + "unsupported": [
1031 + {
1032 + "path": "properties.meta",
1033 + "keyword": "properties"
1034 + }
1035 + ]
1036 + }
1037 + },
1038 + {
1039 + "id": "pattern-properties-unsupported",
1040 + "description": "patternProperties cannot be expressed and is reported.",
1041 + "schema": {
1042 + "type": "object",
1043 + "properties": {
1044 + "tagged": {
1045 + "type": "object",
1046 + "patternProperties": {
1047 + "^x-": {
1048 + "type": "string"
1049 + }
1050 + }
1051 + }
1052 + },
1053 + "required": ["tagged"]
1054 + },
1055 + "strict": {
1056 + "unsupported": [
1057 + {
1058 + "path": "properties.tagged",
1059 + "keyword": "patternProperties"
1060 + }
1061 + ]
1062 + }
1063 + },
1064 + {
1065 + "id": "empty-closed-object-representable",
1066 + "description": "An object closed with no properties is representable.",
1067 + "schema": {
1068 + "type": "object",
1069 + "properties": {
1070 + "empty": {
1071 + "type": "object",
1072 + "additionalProperties": false
1073 + }
1074 + },
1075 + "required": ["empty"]
1076 + },
1077 + "strict": {
1078 + "schema": {
1079 + "type": "object",
1080 + "properties": {
1081 + "empty": {
1082 + "type": "object",
1083 + "additionalProperties": false,
1084 + "properties": {},
1085 + "required": []
1086 + }
1087 + },
1088 + "required": ["empty"],
1089 + "additionalProperties": false
1090 + }
1091 + }
1092 + },
1093 + {
1094 + "id": "all-of-unsupported",
1095 + "description": "allOf has no lossless rewrite and is reported.",
1096 + "schema": {
1097 + "type": "object",
1098 + "properties": {
1099 + "all": {
1100 + "allOf": [
1101 + {
1102 + "type": "string"
1103 + }
1104 + ]
1105 + }
1106 + },
1107 + "required": ["all"]
1108 + },
1109 + "strict": {
1110 + "unsupported": [
1111 + {
1112 + "path": "properties.all",
1113 + "keyword": "allOf"
1114 + }
1115 + ]
1116 + }
1117 + },
1118 + {
1119 + "id": "prefix-items-unsupported",
1120 + "description": "prefixItems has no lossless rewrite and is reported.",
1121 + "schema": {
1122 + "type": "object",
1123 + "properties": {
1124 + "pair": {
1125 + "type": "array",
1126 + "prefixItems": [
1127 + {
1128 + "type": "number"
1129 + }
1130 + ]
1131 + }
1132 + },
1133 + "required": ["pair"]
1134 + },
1135 + "strict": {
1136 + "unsupported": [
1137 + {
1138 + "path": "properties.pair",
1139 + "keyword": "prefixItems"
1140 + }
1141 + ]
1142 + }
1143 + },
1144 + {
1145 + "id": "defs-ref-kept-and-definition-normalized",
1146 + "description": "Local $refs are kept and the definition is normalized where it is declared.",
1147 + "schema": {
1148 + "type": "object",
1149 + "properties": {
1150 + "cfg": {
1151 + "$ref": "#/$defs/Config"
1152 + }
1153 + },
1154 + "required": ["cfg"],
1155 + "$defs": {
1156 + "Config": {
1157 + "type": "object",
1158 + "properties": {
1159 + "url": {
1160 + "type": "string"
1161 + },
1162 + "note": {
1163 + "type": "string"
1164 + }
1165 + },
1166 + "required": ["url"]
1167 + }
1168 + }
1169 + },
1170 + "strict": {
1171 + "schema": {
1172 + "type": "object",
1173 + "properties": {
1174 + "cfg": {
1175 + "$ref": "#/$defs/Config"
1176 + }
1177 + },
1178 + "required": ["cfg"],
1179 + "$defs": {
1180 + "Config": {
1181 + "type": "object",
1182 + "properties": {
1183 + "url": {
1184 + "type": "string"
1185 + },
1186 + "note": {
1187 + "type": ["string", "null"]
1188 + }
1189 + },
1190 + "required": ["url", "note"],
1191 + "additionalProperties": false
1192 + }
1193 + },
1194 + "additionalProperties": false
1195 + }
1196 + },
1197 + "changes": [
1198 + {
1199 + "path": "$defs.Config.properties.note",
1200 + "reason": "optional-property-nullable"
1201 + }
1202 + ],
1203 + "arguments": [
1204 + {
1205 + "input": {
1206 + "cfg": {
1207 + "url": "u",
1208 + "note": null
1209 + }
1210 + },
1211 + "output": {
1212 + "cfg": {
1213 + "url": "u"
1214 + }
1215 + }
1216 + }
1217 + ]
1218 + },
1219 + {
1220 + "id": "optional-ref-widened-with-null-branch",
1221 + "description": "An optional $ref property is widened with an anyOf null branch.",
1222 + "schema": {
1223 + "type": "object",
1224 + "properties": {
1225 + "cfg": {
1226 + "$ref": "#/$defs/Config",
1227 + "description": "optional"
1228 + }
1229 + },
1230 + "$defs": {
1231 + "Config": {
1232 + "type": "object",
1233 + "properties": {
1234 + "url": {
1235 + "type": "string"
1236 + }
1237 + },
1238 + "required": ["url"]
1239 + }
1240 + }
1241 + },
1242 + "strict": {
1243 + "schema": {
1244 + "type": "object",
1245 + "properties": {
1246 + "cfg": {
1247 + "description": "optional",
1248 + "anyOf": [
1249 + {
1250 + "$ref": "#/$defs/Config"
1251 + },
1252 + {
1253 + "type": "null"
1254 + }
1255 + ]
1256 + }
1257 + },
1258 + "$defs": {
1259 + "Config": {
1260 + "type": "object",
1261 + "properties": {
1262 + "url": {
1263 + "type": "string"
1264 + }
1265 + },
1266 + "required": ["url"],
1267 + "additionalProperties": false
1268 + }
1269 + },
1270 + "required": ["cfg"],
1271 + "additionalProperties": false
1272 + }
1273 + },
1274 + "changes": [
1275 + {
1276 + "path": "properties.cfg",
1277 + "reason": "optional-property-nullable"
1278 + }
1279 + ],
1280 + "arguments": [
1281 + {
1282 + "input": {
1283 + "cfg": null
1284 + },
1285 + "output": {}
1286 + }
1287 + ]
1288 + },
1289 + {
1290 + "id": "recursive-defs-kept",
1291 + "description": "Self-recursive definitions are representable.",
1292 + "schema": {
1293 + "type": "object",
1294 + "properties": {
1295 + "node": {
1296 + "$ref": "#/$defs/Node"
1297 + }
1298 + },
1299 + "required": ["node"],
1300 + "$defs": {
1301 + "Node": {
1302 + "type": "object",
1303 + "properties": {
1304 + "child": {
1305 + "$ref": "#/$defs/Node"
1306 + },
1307 + "label": {
1308 + "type": "string"
1309 + }
1310 + },
1311 + "required": ["label"]
1312 + }
1313 + }
1314 + },
1315 + "strict": {
1316 + "schema": {
1317 + "type": "object",
1318 + "properties": {
1319 + "node": {
1320 + "$ref": "#/$defs/Node"
1321 + }
1322 + },
1323 + "required": ["node"],
1324 + "$defs": {
1325 + "Node": {
1326 + "type": "object",
1327 + "properties": {
1328 + "child": {
1329 + "anyOf": [
1330 + {
1331 + "$ref": "#/$defs/Node"
1332 + },
1333 + {
1334 + "type": "null"
1335 + }
1336 + ]
1337 + },
1338 + "label": {
1339 + "type": "string"
1340 + }
1341 + },
1342 + "required": ["child", "label"],
1343 + "additionalProperties": false
1344 + }
1345 + },
1346 + "additionalProperties": false
1347 + }
1348 + },
1349 + "changes": [
1350 + {
1351 + "path": "$defs.Node.properties.child",
1352 + "reason": "optional-property-nullable"
1353 + }
1354 + ],
1355 + "arguments": [
1356 + {
1357 + "input": {
1358 + "node": {
1359 + "label": "a",
1360 + "child": {
1361 + "label": "b",
1362 + "child": null
1363 + }
1364 + }
1365 + },
1366 + "output": {
1367 + "node": {
1368 + "label": "a",
1369 + "child": {
1370 + "label": "b"
1371 + }
1372 + }
1373 + }
1374 + }
1375 + ]
1376 + },
1377 + {
1378 + "id": "mutually-recursive-defs-kept",
1379 + "description": "Mutually recursive definitions are representable.",
1380 + "schema": {
1381 + "type": "object",
1382 + "properties": {
1383 + "a": {
1384 + "$ref": "#/$defs/A"
1385 + }
1386 + },
1387 + "required": ["a"],
1388 + "$defs": {
1389 + "A": {
1390 + "type": "object",
1391 + "properties": {
1392 + "b": {
1393 + "$ref": "#/$defs/B"
1394 + }
1395 + }
1396 + },
1397 + "B": {
1398 + "type": "object",
1399 + "properties": {
1400 + "a": {
1401 + "$ref": "#/$defs/A"
1402 + }
1403 + }
1404 + }
1405 + }
1406 + },
1407 + "strict": {
1408 + "schema": {
1409 + "type": "object",
1410 + "properties": {
1411 + "a": {
1412 + "$ref": "#/$defs/A"
1413 + }
1414 + },
1415 + "required": ["a"],
1416 + "$defs": {
1417 + "A": {
1418 + "type": "object",
1419 + "properties": {
1420 + "b": {
1421 + "anyOf": [
1422 + {
1423 + "$ref": "#/$defs/B"
1424 + },
1425 + {
1426 + "type": "null"
1427 + }
1428 + ]
1429 + }
1430 + },
1431 + "required": ["b"],
1432 + "additionalProperties": false
1433 + },
1434 + "B": {
1435 + "type": "object",
1436 + "properties": {
1437 + "a": {
1438 + "anyOf": [
1439 + {
1440 + "$ref": "#/$defs/A"
1441 + },
1442 + {
1443 + "type": "null"
1444 + }
1445 + ]
1446 + }
1447 + },
1448 + "required": ["a"],
1449 + "additionalProperties": false
1450 + }
1451 + },
1452 + "additionalProperties": false
1453 + }
1454 + },
1455 + "changes": [
1456 + {
1457 + "path": "$defs.A.properties.b",
1458 + "reason": "optional-property-nullable"
1459 + },
1460 + {
1461 + "path": "$defs.B.properties.a",
1462 + "reason": "optional-property-nullable"
1463 + }
1464 + ]
1465 + },
1466 + {
1467 + "id": "legacy-definitions-ref-kept",
1468 + "description": "Legacy definitions are supported like $defs.",
1469 + "schema": {
1470 + "type": "object",
1471 + "properties": {
1472 + "cfg": {
1473 + "$ref": "#/definitions/Config"
1474 + }
1475 + },
1476 + "required": ["cfg"],
1477 + "definitions": {
1478 + "Config": {
1479 + "type": "object",
1480 + "properties": {
1481 + "url": {
1482 + "type": "string"
1483 + }
1484 + }
1485 + }
1486 + }
1487 + },
1488 + "strict": {
1489 + "schema": {
1490 + "type": "object",
1491 + "properties": {
1492 + "cfg": {
1493 + "$ref": "#/definitions/Config"
1494 + }
1495 + },
1496 + "required": ["cfg"],
1497 + "definitions": {
1498 + "Config": {
1499 + "type": "object",
1500 + "properties": {
1501 + "url": {
1502 + "type": ["string", "null"]
1503 + }
1504 + },
1505 + "required": ["url"],
1506 + "additionalProperties": false
1507 + }
1508 + },
1509 + "additionalProperties": false
1510 + }
1511 + },
1512 + "changes": [
1513 + {
1514 + "path": "definitions.Config.properties.url",
1515 + "reason": "optional-property-nullable"
1516 + }
1517 + ]
1518 + },
1519 + {
1520 + "id": "ref-into-properties-kept",
1521 + "description": "A local $ref outside $defs resolves and is kept.",
1522 + "schema": {
1523 + "type": "object",
1524 + "properties": {
1525 + "a": {
1526 + "type": "object",
1527 + "properties": {
1528 + "x": {
1529 + "type": "string"
1530 + }
1531 + },
1532 + "required": ["x"]
1533 + },
1534 + "b": {
1535 + "$ref": "#/properties/a"
1536 + }
1537 + },
1538 + "required": ["a", "b"]
1539 + },
1540 + "strict": {
1541 + "schema": {
1542 + "type": "object",
1543 + "properties": {
1544 + "a": {
1545 + "type": "object",
1546 + "properties": {
1547 + "x": {
1548 + "type": "string"
1549 + }
1550 + },
1551 + "required": ["x"],
1552 + "additionalProperties": false
1553 + },
1554 + "b": {
1555 + "$ref": "#/properties/a"
1556 + }
1557 + },
1558 + "required": ["a", "b"],
1559 + "additionalProperties": false
1560 + }
1561 + }
1562 + },
1563 + {
1564 + "id": "dangling-ref-unsupported",
1565 + "description": "A $ref without a target is reported at its own path.",
1566 + "schema": {
1567 + "type": "object",
1568 + "properties": {
1569 + "cfg": {
1570 + "$ref": "#/$defs/Nope"
1571 + }
1572 + },
1573 + "required": ["cfg"]
1574 + },
1575 + "strict": {
1576 + "unsupported": [
1577 + {
1578 + "path": "properties.cfg",
1579 + "keyword": "$ref"
1580 + }
1581 + ]
1582 + }
1583 + },
1584 + {
1585 + "id": "external-ref-unsupported",
1586 + "description": "A $ref outside the document is reported.",
1587 + "schema": {
1588 + "type": "object",
1589 + "properties": {
1590 + "cfg": {
1591 + "$ref": "https://example.com/schema.json"
1592 + }
1593 + },
1594 + "required": ["cfg"]
1595 + },
1596 + "strict": {
1597 + "unsupported": [
1598 + {
1599 + "path": "properties.cfg",
1600 + "keyword": "$ref"
1601 + }
1602 + ]
1603 + }
1604 + },
1605 + {
1606 + "id": "duplicate-required-deduped",
1607 + "description": "Duplicate required entries are removed.",
1608 + "schema": {
1609 + "type": "object",
1610 + "properties": {
1611 + "a": {
1612 + "type": "string"
1613 + }
1614 + },
1615 + "required": ["a", "a"]
1616 + },
1617 + "strict": {
1618 + "schema": {
1619 + "type": "object",
1620 + "properties": {
1621 + "a": {
1622 + "type": "string"
1623 + }
1624 + },
1625 + "required": ["a"],
1626 + "additionalProperties": false
1627 + }
1628 + }
1629 + },
1630 + {
1631 + "id": "required-unknown-names-dropped",
1632 + "description": "Required names without a property are dropped from required.",
1633 + "schema": {
1634 + "type": "object",
1635 + "properties": {
1636 + "a": {
1637 + "type": "string"
1638 + }
1639 + },
1640 + "required": ["a", "ghost"]
1641 + },
1642 + "strict": {
1643 + "schema": {
1644 + "type": "object",
1645 + "properties": {
1646 + "a": {
1647 + "type": "string"
1648 + }
1649 + },
1650 + "required": ["a"],
1651 + "additionalProperties": false
1652 + }
1653 + }
1654 + },
1655 + {
1656 + "id": "required-not-an-array-ignored",
1657 + "description": "A malformed required is treated as absent.",
1658 + "schema": {
1659 + "type": "object",
1660 + "properties": {
1661 + "a": {
1662 + "type": "string"
1663 + }
1664 + },
1665 + "required": "a"
1666 + },
1667 + "strict": {
1668 + "schema": {
1669 + "type": "object",
1670 + "properties": {
1671 + "a": {
1672 + "type": ["string", "null"]
1673 + }
1674 + },
1675 + "required": ["a"],
1676 + "additionalProperties": false
1677 + }
1678 + },
1679 + "changes": [
1680 + {
1681 + "path": "properties.a",
1682 + "reason": "optional-property-nullable"
1683 + }
1684 + ]
1685 + },
1686 + {
1687 + "id": "description-kept-on-widened-node",
1688 + "description": "Annotations survive widening.",
1689 + "schema": {
1690 + "type": "object",
1691 + "properties": {
1692 + "a": {
1693 + "type": "integer",
1694 + "description": "count",
1695 + "title": "Count",
1696 + "minimum": 0
1697 + }
1698 + }
1699 + },
1700 + "strict": {
1701 + "schema": {
1702 + "type": "object",
1703 + "properties": {
1704 + "a": {
1705 + "type": ["integer", "null"],
1706 + "description": "count",
1707 + "title": "Count",
1708 + "minimum": 0
1709 + }
1710 + },
1711 + "required": ["a"],
1712 + "additionalProperties": false
1713 + }
1714 + },
1715 + "changes": [
1716 + {
1717 + "path": "properties.a",
1718 + "reason": "optional-property-nullable"
1719 + }
1720 + ]
1721 + },
1722 + {
1723 + "id": "non-object-root-unsupported",
1724 + "description": "The root must be an object.",
1725 + "schema": {
1726 + "type": "string"
1727 + },
1728 + "strict": {
1729 + "unsupported": [
1730 + {
1731 + "path": "",
1732 + "keyword": "type"
1733 + }
1734 + ]
1735 + }
1736 + },
1737 + {
1738 + "id": "nullable-root-unsupported",
1739 + "description": "The root must not be nullable.",
1740 + "schema": {
1741 + "type": ["object", "null"],
1742 + "properties": {
1743 + "a": {
1744 + "type": "string"
1745 + }
1746 + }
1747 + },
1748 + "strict": {
1749 + "unsupported": [
1750 + {
1751 + "path": "",
1752 + "keyword": "type"
1753 + }
1754 + ]
1755 + },
1756 + "changes": [
1757 + {
1758 + "path": "properties.a",
1759 + "reason": "optional-property-nullable"
1760 + }
1761 + ]
1762 + },
1763 + {
1764 + "id": "properties-without-type-become-object",
1765 + "description": "A node with properties but no type is treated as an object.",
1766 + "schema": {
1767 + "type": "object",
1768 + "properties": {
1769 + "cfg": {
1770 + "properties": {
1771 + "a": {
1772 + "type": "string"
1773 + }
1774 + }
1775 + }
1776 + },
1777 + "required": ["cfg"]
1778 + },
1779 + "strict": {
1780 + "schema": {
1781 + "type": "object",
1782 + "properties": {
1783 + "cfg": {
1784 + "properties": {
1785 + "a": {
1786 + "type": ["string", "null"]
1787 + }
1788 + },
1789 + "type": "object",
1790 + "required": ["a"],
1791 + "additionalProperties": false
1792 + }
1793 + },
1794 + "required": ["cfg"],
1795 + "additionalProperties": false
1796 + }
1797 + },
1798 + "changes": [
1799 + {
1800 + "path": "properties.cfg.properties.a",
1801 + "reason": "optional-property-nullable"
1802 + }
1803 + ]
1804 + },
1805 + {
1806 + "id": "root-without-type-become-object",
1807 + "description": "A root with properties but no type is treated as an object.",
1808 + "schema": {
1809 + "properties": {
1810 + "a": {
1811 + "type": "string"
1812 + }
1813 + }
1814 + },
1815 + "strict": {
1816 + "schema": {
1817 + "properties": {
1818 + "a": {
1819 + "type": ["string", "null"]
1820 + }
1821 + },
1822 + "type": "object",
1823 + "required": ["a"],
1824 + "additionalProperties": false
1825 + }
1826 + },
1827 + "changes": [
1828 + {
1829 + "path": "properties.a",
1830 + "reason": "optional-property-nullable"
1831 + }
1832 + ]
1833 + }
1834 + ]
1835 +}
ts/packages/core/test/utils/jsonSchema.strict.corpus.test.ts new
+79
@@ -0,0 +1,79 @@
1 +import { describe, it, expect } from 'vitest';
2 +import { omitNullToolArguments, toStrictJsonSchema } from '../../src/utils/jsonSchema';
3 +import { loadStrictCases } from '../fixtures/json-schema-conversion/corpus';
4 +
5 +/** Structural invariants OpenAI enforces on every node of a strict schema. */
6 +function assertStrictShape(node: unknown, path = ''): void {
7 + if (Array.isArray(node)) {
8 + node.forEach((item, index) => assertStrictShape(item, `${path}[${index}]`));
9 + return;
10 + }
11 + if (!node || typeof node !== 'object') return;
12 + const record = node as Record<string, unknown>;
13 + if (record.anyOf !== undefined) {
14 + expect(record.type, `${path}: type beside anyOf`).toBeUndefined();
15 + }
16 + for (const keyword of [
17 + 'default',
18 + 'examples',
19 + 'oneOf',
20 + 'patternProperties',
21 + 'allOf',
22 + 'prefixItems',
23 + ]) {
24 + expect(record[keyword], `${path}: ${keyword}`).toBeUndefined();
25 + }
26 + const isObject =
27 + record.type === 'object' || (Array.isArray(record.type) && record.type.includes('object'));
28 + if (isObject || record.properties !== undefined) {
29 + const properties = (record.properties ?? {}) as Record<string, unknown>;
30 + expect(record.required, `${path}: required`).toEqual(Object.keys(properties));
31 + expect(record.additionalProperties, `${path}: additionalProperties`).toBe(false);
32 + }
33 + for (const [key, child] of Object.entries(record)) {
34 + if (key === 'enum' || key === 'const') continue;
35 + const childPath = path ? `${path}.${key}` : key;
36 + if (
37 + (key === 'properties' || key === '$defs' || key === 'definitions') &&
38 + child &&
39 + typeof child === 'object'
40 + ) {
41 + // Keys of these maps are names, not keywords.
42 + for (const [name, sub] of Object.entries(child as Record<string, unknown>)) {
43 + assertStrictShape(sub, `${childPath}.${name}`);
44 + }
45 + continue;
46 + }
47 + assertStrictShape(child, childPath);
48 + }
49 +}
50 +
51 +describe('toStrictJsonSchema (shared corpus)', () => {
52 + for (const testCase of loadStrictCases()) {
53 + it(testCase.id, () => {
54 + const snapshot = JSON.parse(JSON.stringify(testCase.schema));
55 + const result = toStrictJsonSchema(testCase.schema);
56 +
57 + expect(testCase.schema, 'input mutated').toEqual(snapshot);
58 + if ('unsupported' in testCase.strict) {
59 + expect(result.unsupported.map(({ path, keyword }) => ({ path, keyword }))).toEqual(
60 + testCase.strict.unsupported
61 + );
62 + } else {
63 + expect(result.unsupported).toEqual([]);
64 + expect(result.schema).toEqual(testCase.strict.schema);
65 + assertStrictShape(result.schema);
66 + const again = toStrictJsonSchema(result.schema);
67 + expect(again.schema, 'not idempotent').toEqual(result.schema);
68 + expect(again.changes).toEqual([]);
69 + }
70 + expect(result.changes.map(({ path, reason }) => ({ path, reason }))).toEqual(
71 + testCase.changes ?? []
72 + );
73 + expect(result.totalChanges).toBe(result.changes.length);
74 + for (const { input, output } of testCase.arguments ?? []) {
75 + expect(omitNullToolArguments(input, result.source)).toEqual(output);
76 + }
77 + });
78 + }
79 +});