@devries-cameron20 / composio Mirror · read-only / commits / 8b6fc2472
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 20:45 UTC

Fix additional properties in jsonschema to zod conversion (#1841)

Musthaq Ahamad committed Aug 12, 2025 at 13:06 UTC 8b6fc2472ad3239e4a88efd6b42ed88b11fff294
23 files changed +345 -45
pnpm-lock.yaml
+8 -24
@@ -621,8 +621,8 @@ importers:
621 specifier: 0.1.0-alpha.31
622 version: 0.1.0-alpha.31
623 '@composio/json-schema-to-zod':
624 - specifier: 0.1.11
625 - version: 0.1.11
624 + specifier: 0.1.12
625 + version: 0.1.12
626 '@types/json-schema':
627 specifier: ^7.0.15
628 version: 7.0.15
@@ -1216,8 +1216,8 @@ packages:
1216 '@composio/client@0.1.0-alpha.31':
1217 resolution: {integrity: sha512-DVPVCMDXzoQn1aUZx38e8s5+gA/J/c6FpVfS1rzUnMKCRSuXXrOoKXFAvoRME5pcaKN2Wjux5ARyvIPBugNoMA==}
1218
1219 - '@composio/json-schema-to-zod@0.1.11':
1220 - resolution: {integrity: sha512-6gcCof9xqLhmmHSCvWLW/E16PKr5C1dWJ9AOk4FJU8JA7gSt8JEdFHBwx80dyprBJdwPF6R54nlkmpXrEwApzg==}
1219 + '@composio/json-schema-to-zod@0.1.12':
1220 + resolution: {integrity: sha512-rI3JSVG6Kgdo/sJoFlisY5ous8v408WykFlkQ1wz114jPJTVcJLWPGY9b8VwO3Neu6B2zYay99yg7fEJHoZjYw==}
1221
1222 '@composio/mcp@1.0.3-0':
1223 resolution: {integrity: sha512-IpbfST0SSs/CEv+PIf6+EL0feNuJhQyUrOHJLPge8NhyLLrCyVqvujRIPyRUUjy0NDsked/Mm5VpJmYM6OACbg==}
@@ -7292,7 +7292,7 @@ snapshots:
7292
7293 '@composio/client@0.1.0-alpha.31': {}
7294
7295 - '@composio/json-schema-to-zod@0.1.11':
7295 + '@composio/json-schema-to-zod@0.1.12':
7296 dependencies:
7297 '@types/json-schema': 7.0.15
7298 zod: 3.25.67
@@ -9740,14 +9740,6 @@ snapshots:
9740 chai: 5.2.0
9741 tinyrainbow: 2.0.0
9742
9743 - '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9744 - dependencies:
9745 - '@vitest/spy': 3.2.4
9746 - estree-walker: 3.0.3
9747 - magic-string: 0.30.17
9748 - optionalDependencies:
9749 - vite: 6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9750 -
9743 '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9744 dependencies:
9745 '@vitest/spy': 3.2.4
@@ -9756,14 +9748,6 @@ snapshots:
9748 optionalDependencies:
9749 vite: 6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9750
9759 - '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9760 - dependencies:
9761 - '@vitest/spy': 3.2.4
9762 - estree-walker: 3.0.3
9763 - magic-string: 0.30.17
9764 - optionalDependencies:
9765 - vite: 6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9766 -
9751 '@vitest/pretty-format@3.2.4':
9752 dependencies:
9753 tinyrainbow: 2.0.0
@@ -9793,7 +9777,7 @@ snapshots:
9777 sirv: 3.0.1
9778 tinyglobby: 0.2.14
9779 tinyrainbow: 2.0.0
9796 - vitest: 3.2.4(@types/node@24.0.3)(@vitest/ui@3.2.4)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9780 + vitest: 3.2.4(@types/node@22.15.32)(@vitest/ui@3.2.4)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9781
9782 '@vitest/utils@3.2.4':
9783 dependencies:
@@ -12879,7 +12863,7 @@ snapshots:
12863 dependencies:
12864 '@types/chai': 5.2.2
12865 '@vitest/expect': 3.2.4
12882 - '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12866 + '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12867 '@vitest/pretty-format': 3.2.4
12868 '@vitest/runner': 3.2.4
12869 '@vitest/snapshot': 3.2.4
@@ -12963,7 +12947,7 @@ snapshots:
12947 dependencies:
12948 '@types/chai': 5.2.2
12949 '@vitest/expect': 3.2.4
12966 - '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12950 + '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12951 '@vitest/pretty-format': 3.2.4
12952 '@vitest/runner': 3.2.4
12953 '@vitest/snapshot': 3.2.4
ts/packages/core/CHANGELOG.md
+7
@@ -1,5 +1,12 @@
1 # @composio/core
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- Updated dependencies
8 + - @composio/json-schema-to-zod@0.1.12
9 +
10 ## 0.1.41
11
12 ### Patch Changes
ts/packages/core/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/core",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -45,7 +45,7 @@
45 },
46 "dependencies": {
47 "@composio/client": "0.1.0-alpha.31",
48 - "@composio/json-schema-to-zod": "0.1.11",
48 + "@composio/json-schema-to-zod": "0.1.12",
49 "@types/json-schema": "^7.0.15",
50 "chalk": "^4.1.2",
51 "openai": "^4.94.0",
ts/packages/json-schema-to-zod/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/json-schema-to-zod
2
3 +## 0.1.12
4 +
5 +### Patch Changes
6 +
7 +- Fix additionalProperties to be always present
8 +
9 ## 0.1.11
10
11 ### Patch Changes
ts/packages/json-schema-to-zod/package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/json-schema-to-zod",
3 - "version": "0.1.11",
3 + "version": "0.1.12",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
ts/packages/json-schema-to-zod/src/parsers/parse-object.ts
+2 -1
@@ -160,7 +160,8 @@ export function parseObject(
160 output = propertiesSchema.catchall(additionalProperties);
161 }
162 } else {
163 - output = zodSchema!;
163 + // When additionalProperties is not specified, default to allowing any additional properties
164 + output = propertiesSchema.catchall(z.any());
165 }
166 } else {
167 if (hasPatternProperties) {
ts/packages/json-schema-to-zod/test/json-to-zod.test.ts
+255 -1
@@ -198,7 +198,7 @@ describe('jsonSchemaToZod', () => {
198 expect(() => zodSchema.parse({ age: 30 })).toThrow();
199 });
200
201 - it('should validate additional properties', () => {
201 + it('should validate additional properties when set to false', () => {
202 const schema: JsonSchema = {
203 type: 'object',
204 properties: {
@@ -211,6 +211,260 @@ describe('jsonSchemaToZod', () => {
211 expect(() => zodSchema.parse({ name: 'John', extra: 'field' })).toThrow();
212 });
213
214 + it('should allow any additional properties when set to true', () => {
215 + const schema: JsonSchema = {
216 + type: 'object',
217 + properties: {
218 + name: { type: 'string' },
219 + },
220 + additionalProperties: true,
221 + };
222 + const zodSchema = jsonSchemaToZod(schema);
223 + expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
224 + expect(zodSchema.parse({ name: 'John', extra: 'field' })).toEqual({
225 + name: 'John',
226 + extra: 'field',
227 + });
228 + expect(zodSchema.parse({ name: 'John', age: 30, city: 'NYC' })).toEqual({
229 + name: 'John',
230 + age: 30,
231 + city: 'NYC',
232 + });
233 + });
234 +
235 + it('should validate additional properties against a schema', () => {
236 + const schema: JsonSchema = {
237 + type: 'object',
238 + properties: {
239 + name: { type: 'string' },
240 + },
241 + additionalProperties: { type: 'number' },
242 + };
243 + const zodSchema = jsonSchemaToZod(schema);
244 + expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
245 + expect(zodSchema.parse({ name: 'John', age: 30 })).toEqual({
246 + name: 'John',
247 + age: 30,
248 + });
249 + expect(() => zodSchema.parse({ name: 'John', extra: 'field' })).toThrow();
250 + });
251 +
252 + it('should validate additional properties with complex schema', () => {
253 + const schema: JsonSchema = {
254 + type: 'object',
255 + properties: {
256 + name: { type: 'string' },
257 + },
258 + additionalProperties: {
259 + type: 'object',
260 + properties: {
261 + value: { type: 'string' },
262 + count: { type: 'number' },
263 + },
264 + required: ['value'],
265 + },
266 + };
267 + const zodSchema = jsonSchemaToZod(schema);
268 + expect(
269 + zodSchema.parse({
270 + name: 'John',
271 + metadata: { value: 'test', count: 5 },
272 + })
273 + ).toEqual({
274 + name: 'John',
275 + metadata: { value: 'test', count: 5 },
276 + });
277 + expect(
278 + zodSchema.parse({
279 + name: 'John',
280 + metadata: { value: 'test' },
281 + })
282 + ).toEqual({
283 + name: 'John',
284 + metadata: { value: 'test' },
285 + });
286 + expect(() =>
287 + zodSchema.parse({
288 + name: 'John',
289 + metadata: { count: 5 }, // missing required 'value'
290 + })
291 + ).toThrow();
292 + });
293 +
294 + it('should allow any additional properties when additionalProperties is not specified', () => {
295 + const schema: JsonSchema = {
296 + type: 'object',
297 + properties: {
298 + name: { type: 'string' },
299 + },
300 + };
301 + const zodSchema = jsonSchemaToZod(schema);
302 + expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
303 + expect(zodSchema.parse({ name: 'John', extra: 'field' })).toEqual({
304 + name: 'John',
305 + extra: 'field',
306 + });
307 + });
308 +
309 + it('should handle additionalProperties with patternProperties', () => {
310 + const schema: JsonSchema = {
311 + type: 'object',
312 + properties: {
313 + name: { type: 'string' },
314 + },
315 + patternProperties: {
316 + '^prefix_': { type: 'string' },
317 + },
318 + additionalProperties: { type: 'number' },
319 + };
320 + const zodSchema = jsonSchemaToZod(schema);
321 +
322 + // Should allow defined properties
323 + expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
324 +
325 + // Should allow pattern properties
326 + expect(
327 + zodSchema.parse({
328 + name: 'John',
329 + prefix_test: 'value',
330 + })
331 + ).toEqual({
332 + name: 'John',
333 + prefix_test: 'value',
334 + });
335 +
336 + // Should allow additional properties matching the schema
337 + expect(
338 + zodSchema.parse({
339 + name: 'John',
340 + age: 30,
341 + })
342 + ).toEqual({
343 + name: 'John',
344 + age: 30,
345 + });
346 +
347 + // Should reject additional properties not matching the schema
348 + expect(() =>
349 + zodSchema.parse({
350 + name: 'John',
351 + extra: 'field', // string, but additionalProperties expects number
352 + })
353 + ).toThrow();
354 + });
355 +
356 + it('should handle object with no properties but with additionalProperties schema', () => {
357 + const schema: JsonSchema = {
358 + type: 'object',
359 + additionalProperties: { type: 'string' },
360 + };
361 + const zodSchema = jsonSchemaToZod(schema);
362 + expect(zodSchema.parse({})).toEqual({});
363 + expect(zodSchema.parse({ key1: 'value1', key2: 'value2' })).toEqual({
364 + key1: 'value1',
365 + key2: 'value2',
366 + });
367 + expect(() => zodSchema.parse({ key1: 123 })).toThrow();
368 + });
369 +
370 + it('should handle additionalProperties: false with patternProperties', () => {
371 + const schema: JsonSchema = {
372 + type: 'object',
373 + properties: {
374 + name: { type: 'string' },
375 + },
376 + patternProperties: {
377 + '^prefix_': { type: 'string' },
378 + },
379 + additionalProperties: false,
380 + };
381 + const zodSchema = jsonSchemaToZod(schema);
382 +
383 + expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });
384 + expect(
385 + zodSchema.parse({
386 + name: 'John',
387 + prefix_test: 'value',
388 + })
389 + ).toEqual({
390 + name: 'John',
391 + prefix_test: 'value',
392 + });
393 +
394 + // Should reject properties that don't match patterns or defined properties
395 + expect(() =>
396 + zodSchema.parse({
397 + name: 'John',
398 + extra: 'field',
399 + })
400 + ).toThrow();
401 + });
402 +
403 + it('should handle empty object with additionalProperties: true', () => {
404 + const schema: JsonSchema = {
405 + type: 'object',
406 + additionalProperties: true,
407 + };
408 + const zodSchema = jsonSchemaToZod(schema);
409 + expect(zodSchema.parse({})).toEqual({});
410 + expect(zodSchema.parse({ any: 'value', another: 123 })).toEqual({
411 + any: 'value',
412 + another: 123,
413 + });
414 + });
415 +
416 + it('should handle empty object with additionalProperties: false', () => {
417 + const schema: JsonSchema = {
418 + type: 'object',
419 + additionalProperties: false,
420 + };
421 + const zodSchema = jsonSchemaToZod(schema);
422 + expect(zodSchema.parse({})).toEqual({});
423 + expect(() => zodSchema.parse({ any: 'value' })).toThrow();
424 + });
425 +
426 + it('should handle nested additionalProperties', () => {
427 + const schema: JsonSchema = {
428 + type: 'object',
429 + properties: {
430 + config: {
431 + type: 'object',
432 + properties: {
433 + name: { type: 'string' },
434 + },
435 + additionalProperties: { type: 'number' },
436 + },
437 + },
438 + additionalProperties: { type: 'string' },
439 + };
440 + const zodSchema = jsonSchemaToZod(schema);
441 +
442 + expect(
443 + zodSchema.parse({
444 + config: { name: 'test', timeout: 5000 },
445 + env: 'production',
446 + })
447 + ).toEqual({
448 + config: { name: 'test', timeout: 5000 },
449 + env: 'production',
450 + });
451 +
452 + // Should reject nested additional properties that don't match schema
453 + expect(() =>
454 + zodSchema.parse({
455 + config: { name: 'test', timeout: 'invalid' }, // should be number
456 + })
457 + ).toThrow();
458 +
459 + // Should reject top-level additional properties that don't match schema
460 + expect(() =>
461 + zodSchema.parse({
462 + config: { name: 'test' },
463 + count: 123, // should be string
464 + })
465 + ).toThrow();
466 + });
467 +
468 it('should validate pattern properties', () => {
469 const schema: JsonSchema = {
470 type: 'object',
ts/packages/providers/anthropic/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/anthropic
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/anthropic/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/anthropic",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "Non-Agentic Provider for Anthropic in Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -35,7 +35,7 @@
35 "packageManager": "pnpm@10.8.0",
36 "peerDependencies": {
37 "@anthropic-ai/sdk": "^0.52.0",
38 - "@composio/core": "0.1.41"
38 + "@composio/core": "0.1.42"
39 },
40 "devDependencies": {
41 "@composio/core": "workspace:*",
ts/packages/providers/cloudflare/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/cloudflare
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/cloudflare/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/cloudflare",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -31,7 +31,7 @@
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 "@cloudflare/workers-types": "^4.20250416.0",
34 - "@composio/core": "0.1.41"
34 + "@composio/core": "0.1.42"
35 },
36 "devDependencies": {
37 "@composio/core": "workspace:*",
ts/packages/providers/google/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/google
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/google/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/google",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "Google GenAI Provider for Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -36,7 +36,7 @@
36 "license": "ISC",
37 "packageManager": "pnpm@10.8.0",
38 "peerDependencies": {
39 - "@composio/core": "0.1.41",
39 + "@composio/core": "0.1.42",
40 "@google/genai": "^1.1.0"
41 },
42 "devDependencies": {
ts/packages/providers/langchain/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/langchain
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/langchain/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/langchain",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "dist/index.js",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.41",
33 + "@composio/core": "0.1.42",
34 "@langchain/core": "^0.3.63"
35 },
36 "devDependencies": {
ts/packages/providers/mastra/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/mastra
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/mastra/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/mastra",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "Agentic Provider for mastra in Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -34,7 +34,7 @@
34 "license": "ISC",
35 "packageManager": "pnpm@10.8.0",
36 "peerDependencies": {
37 - "@composio/core": "0.1.41",
37 + "@composio/core": "0.1.42",
38 "@mastra/core": "^0.10.0"
39 },
40 "devDependencies": {
ts/packages/providers/openai-agents/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/vercel
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/openai-agents/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/openai-agents",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.41",
33 + "@composio/core": "0.1.42",
34 "@openai/agents": "^0.0.7"
35 },
36 "devDependencies": {
ts/packages/providers/openai/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/openai
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/openai/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/openai",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.41",
33 + "@composio/core": "0.1.42",
34 "openai": "^4.3.8"
35 },
36 "devDependencies": {
ts/packages/providers/vercel/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/vercel
2
3 +## 0.1.42
4 +
5 +### Patch Changes
6 +
7 +- @composio/core@0.1.42
8 +
9 ## 0.1.41
10
11 ### Patch Changes
ts/packages/providers/vercel/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/vercel",
3 - "version": "0.1.41",
3 + "version": "0.1.42",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.41",
33 + "@composio/core": "0.1.42",
34 "ai": "^4.3.8"
35 },
36 "devDependencies": {