Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Fix additional properties in jsonschema to zod conversion (#1841)
Musthaq Ahamad8b6fc2472ad3
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 05671b913..29523a495 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -621,8 +621,8 @@ importers:specifier: 0.1.0-alpha.31version: 0.1.0-alpha.31'@composio/json-schema-to-zod':- specifier: 0.1.11- version: 0.1.11+ specifier: 0.1.12+ version: 0.1.12'@types/json-schema':specifier: ^7.0.15version: 7.0.15@@ -1216,8 +1216,8 @@ packages:'@composio/[email protected]':resolution: {integrity: sha512-DVPVCMDXzoQn1aUZx38e8s5+gA/J/c6FpVfS1rzUnMKCRSuXXrOoKXFAvoRME5pcaKN2Wjux5ARyvIPBugNoMA==}- '@composio/[email protected]':- resolution: {integrity: sha512-6gcCof9xqLhmmHSCvWLW/E16PKr5C1dWJ9AOk4FJU8JA7gSt8JEdFHBwx80dyprBJdwPF6R54nlkmpXrEwApzg==}+ '@composio/[email protected]':+ resolution: {integrity: sha512-rI3JSVG6Kgdo/sJoFlisY5ous8v408WykFlkQ1wz114jPJTVcJLWPGY9b8VwO3Neu6B2zYay99yg7fEJHoZjYw==}'@composio/[email protected]':resolution: {integrity: sha512-IpbfST0SSs/CEv+PIf6+EL0feNuJhQyUrOHJLPge8NhyLLrCyVqvujRIPyRUUjy0NDsked/Mm5VpJmYM6OACbg==}@@ -7292,7 +7292,7 @@ snapshots:'@composio/[email protected]': {}- '@composio/[email protected]':+ '@composio/[email protected]':dependencies:'@types/json-schema': 7.0.15zod: 3.25.67@@ -9740,14 +9740,6 @@ snapshots:chai: 5.2.0tinyrainbow: 2.0.0- '@vitest/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':- dependencies:- '@vitest/spy': 3.2.4- estree-walker: 3.0.3- magic-string: 0.30.17- optionalDependencies:-'@vitest/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':dependencies:'@vitest/spy': 3.2.4@@ -9756,14 +9748,6 @@ snapshots:optionalDependencies:- '@vitest/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':- dependencies:- '@vitest/spy': 3.2.4- estree-walker: 3.0.3- magic-string: 0.30.17- optionalDependencies:-'@vitest/[email protected]':dependencies:tinyrainbow: 2.0.0@@ -9793,7 +9777,7 @@ snapshots:sirv: 3.0.1tinyglobby: 0.2.14tinyrainbow: 2.0.0- vitest: 3.2.4(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])+ vitest: 3.2.4(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])'@vitest/[email protected]':dependencies:@@ -12879,7 +12863,7 @@ snapshots:dependencies:'@types/chai': 5.2.2'@vitest/expect': 3.2.4- '@vitest/mocker': 3.2.4([email protected](@types/[email protected])([email protected])([email protected])([email protected]))+ '@vitest/mocker': 3.2.4([email protected](@types/[email protected])([email protected])([email protected])([email protected]))'@vitest/pretty-format': 3.2.4'@vitest/runner': 3.2.4'@vitest/snapshot': 3.2.4@@ -12963,7 +12947,7 @@ snapshots:dependencies:'@types/chai': 5.2.2'@vitest/expect': 3.2.4- '@vitest/mocker': 3.2.4([email protected](@types/[email protected])([email protected])([email protected])([email protected]))+ '@vitest/mocker': 3.2.4([email protected](@types/[email protected])([email protected])([email protected])([email protected]))'@vitest/pretty-format': 3.2.4'@vitest/runner': 3.2.4'@vitest/snapshot': 3.2.4diff --git a/ts/packages/core/CHANGELOG.md b/ts/packages/core/CHANGELOG.mdindex dde29c7d3..94989d3ff 100644--- a/ts/packages/core/CHANGELOG.md+++ b/ts/packages/core/CHANGELOG.md@@ -1,5 +1,12 @@# @composio/core+## 0.1.42++### Patch Changes++- Updated dependencies+ - @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/core/package.json b/ts/packages/core/package.jsonindex 90583ddbb..c1dc8c6cd 100644--- a/ts/packages/core/package.json+++ b/ts/packages/core/package.json@@ -1,6 +1,6 @@{"name": "@composio/core",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "src/index.ts","type": "module",@@ -45,7 +45,7 @@},"dependencies": {"@composio/client": "0.1.0-alpha.31",- "@composio/json-schema-to-zod": "0.1.11",+ "@composio/json-schema-to-zod": "0.1.12","@types/json-schema": "^7.0.15","chalk": "^4.1.2","openai": "^4.94.0",diff --git a/ts/packages/json-schema-to-zod/CHANGELOG.md b/ts/packages/json-schema-to-zod/CHANGELOG.mdindex b965a9881..f69e8cd92 100644--- a/ts/packages/json-schema-to-zod/CHANGELOG.md+++ b/ts/packages/json-schema-to-zod/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/json-schema-to-zod+## 0.1.12++### Patch Changes++- Fix additionalProperties to be always present+## 0.1.11### Patch Changesdiff --git a/ts/packages/json-schema-to-zod/package.json b/ts/packages/json-schema-to-zod/package.jsonindex 2c351794b..8795d5abb 100644--- a/ts/packages/json-schema-to-zod/package.json+++ b/ts/packages/json-schema-to-zod/package.json@@ -1,6 +1,6 @@{"name": "@composio/json-schema-to-zod",- "version": "0.1.11",+ "version": "0.1.12","description": "","main": "src/index.ts","type": "module",diff --git a/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts b/ts/packages/json-schema-to-zod/src/parsers/parse-object.tsindex 2c83cb79e..5ee8e4ebf 100644--- a/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts+++ b/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts@@ -160,7 +160,8 @@ export function parseObject(output = propertiesSchema.catchall(additionalProperties);}} else {- output = zodSchema!;+ // When additionalProperties is not specified, default to allowing any additional properties+ output = propertiesSchema.catchall(z.any());}} else {if (hasPatternProperties) {diff --git a/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts b/ts/packages/json-schema-to-zod/test/json-to-zod.test.tsindex f058e9294..7a2dc7636 100644--- a/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts+++ b/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts@@ -198,7 +198,7 @@ describe('jsonSchemaToZod', () => {expect(() => zodSchema.parse({ age: 30 })).toThrow();});- it('should validate additional properties', () => {+ it('should validate additional properties when set to false', () => {const schema: JsonSchema = {type: 'object',properties: {@@ -211,6 +211,260 @@ describe('jsonSchemaToZod', () => {expect(() => zodSchema.parse({ name: 'John', extra: 'field' })).toThrow();});+ it('should allow any additional properties when set to true', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ additionalProperties: true,+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });+ expect(zodSchema.parse({ name: 'John', extra: 'field' })).toEqual({+ name: 'John',+ extra: 'field',+ });+ expect(zodSchema.parse({ name: 'John', age: 30, city: 'NYC' })).toEqual({+ name: 'John',+ age: 30,+ city: 'NYC',+ });+ });++ it('should validate additional properties against a schema', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ additionalProperties: { type: 'number' },+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });+ expect(zodSchema.parse({ name: 'John', age: 30 })).toEqual({+ name: 'John',+ age: 30,+ });+ expect(() => zodSchema.parse({ name: 'John', extra: 'field' })).toThrow();+ });++ it('should validate additional properties with complex schema', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ additionalProperties: {+ type: 'object',+ properties: {+ value: { type: 'string' },+ count: { type: 'number' },+ },+ required: ['value'],+ },+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(+ zodSchema.parse({+ name: 'John',+ metadata: { value: 'test', count: 5 },+ })+ ).toEqual({+ name: 'John',+ metadata: { value: 'test', count: 5 },+ });+ expect(+ zodSchema.parse({+ name: 'John',+ metadata: { value: 'test' },+ })+ ).toEqual({+ name: 'John',+ metadata: { value: 'test' },+ });+ expect(() =>+ zodSchema.parse({+ name: 'John',+ metadata: { count: 5 }, // missing required 'value'+ })+ ).toThrow();+ });++ it('should allow any additional properties when additionalProperties is not specified', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });+ expect(zodSchema.parse({ name: 'John', extra: 'field' })).toEqual({+ name: 'John',+ extra: 'field',+ });+ });++ it('should handle additionalProperties with patternProperties', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ patternProperties: {+ '^prefix_': { type: 'string' },+ },+ additionalProperties: { type: 'number' },+ };+ const zodSchema = jsonSchemaToZod(schema);++ // Should allow defined properties+ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });++ // Should allow pattern properties+ expect(+ zodSchema.parse({+ name: 'John',+ prefix_test: 'value',+ })+ ).toEqual({+ name: 'John',+ prefix_test: 'value',+ });++ // Should allow additional properties matching the schema+ expect(+ zodSchema.parse({+ name: 'John',+ age: 30,+ })+ ).toEqual({+ name: 'John',+ age: 30,+ });++ // Should reject additional properties not matching the schema+ expect(() =>+ zodSchema.parse({+ name: 'John',+ extra: 'field', // string, but additionalProperties expects number+ })+ ).toThrow();+ });++ it('should handle object with no properties but with additionalProperties schema', () => {+ const schema: JsonSchema = {+ type: 'object',+ additionalProperties: { type: 'string' },+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({})).toEqual({});+ expect(zodSchema.parse({ key1: 'value1', key2: 'value2' })).toEqual({+ key1: 'value1',+ key2: 'value2',+ });+ expect(() => zodSchema.parse({ key1: 123 })).toThrow();+ });++ it('should handle additionalProperties: false with patternProperties', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ patternProperties: {+ '^prefix_': { type: 'string' },+ },+ additionalProperties: false,+ };+ const zodSchema = jsonSchemaToZod(schema);++ expect(zodSchema.parse({ name: 'John' })).toEqual({ name: 'John' });+ expect(+ zodSchema.parse({+ name: 'John',+ prefix_test: 'value',+ })+ ).toEqual({+ name: 'John',+ prefix_test: 'value',+ });++ // Should reject properties that don't match patterns or defined properties+ expect(() =>+ zodSchema.parse({+ name: 'John',+ extra: 'field',+ })+ ).toThrow();+ });++ it('should handle empty object with additionalProperties: true', () => {+ const schema: JsonSchema = {+ type: 'object',+ additionalProperties: true,+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({})).toEqual({});+ expect(zodSchema.parse({ any: 'value', another: 123 })).toEqual({+ any: 'value',+ another: 123,+ });+ });++ it('should handle empty object with additionalProperties: false', () => {+ const schema: JsonSchema = {+ type: 'object',+ additionalProperties: false,+ };+ const zodSchema = jsonSchemaToZod(schema);+ expect(zodSchema.parse({})).toEqual({});+ expect(() => zodSchema.parse({ any: 'value' })).toThrow();+ });++ it('should handle nested additionalProperties', () => {+ const schema: JsonSchema = {+ type: 'object',+ properties: {+ config: {+ type: 'object',+ properties: {+ name: { type: 'string' },+ },+ additionalProperties: { type: 'number' },+ },+ },+ additionalProperties: { type: 'string' },+ };+ const zodSchema = jsonSchemaToZod(schema);++ expect(+ zodSchema.parse({+ config: { name: 'test', timeout: 5000 },+ env: 'production',+ })+ ).toEqual({+ config: { name: 'test', timeout: 5000 },+ env: 'production',+ });++ // Should reject nested additional properties that don't match schema+ expect(() =>+ zodSchema.parse({+ config: { name: 'test', timeout: 'invalid' }, // should be number+ })+ ).toThrow();++ // Should reject top-level additional properties that don't match schema+ expect(() =>+ zodSchema.parse({+ config: { name: 'test' },+ count: 123, // should be string+ })+ ).toThrow();+ });+it('should validate pattern properties', () => {const schema: JsonSchema = {type: 'object',diff --git a/ts/packages/providers/anthropic/CHANGELOG.md b/ts/packages/providers/anthropic/CHANGELOG.mdindex f00c6d2cb..44455978f 100644--- a/ts/packages/providers/anthropic/CHANGELOG.md+++ b/ts/packages/providers/anthropic/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/anthropic+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/anthropic/package.json b/ts/packages/providers/anthropic/package.jsonindex 442363740..1eea4c201 100644--- a/ts/packages/providers/anthropic/package.json+++ b/ts/packages/providers/anthropic/package.json@@ -1,6 +1,6 @@{"name": "@composio/anthropic",- "version": "0.1.41",+ "version": "0.1.42","description": "Non-Agentic Provider for Anthropic in Composio SDK","main": "src/index.ts","type": "module",@@ -35,7 +35,7 @@"packageManager": "[email protected]","peerDependencies": {"@anthropic-ai/sdk": "^0.52.0",- "@composio/core": "0.1.41"+ "@composio/core": "0.1.42"},"devDependencies": {"@composio/core": "workspace:*",diff --git a/ts/packages/providers/cloudflare/CHANGELOG.md b/ts/packages/providers/cloudflare/CHANGELOG.mdindex f01b38331..b73b3a43d 100644--- a/ts/packages/providers/cloudflare/CHANGELOG.md+++ b/ts/packages/providers/cloudflare/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/cloudflare+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/cloudflare/package.json b/ts/packages/providers/cloudflare/package.jsonindex 8f35efa21..dc3b07592 100644--- a/ts/packages/providers/cloudflare/package.json+++ b/ts/packages/providers/cloudflare/package.json@@ -1,6 +1,6 @@{"name": "@composio/cloudflare",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "src/index.ts","type": "module",@@ -31,7 +31,7 @@"packageManager": "[email protected]","peerDependencies": {"@cloudflare/workers-types": "^4.20250416.0",- "@composio/core": "0.1.41"+ "@composio/core": "0.1.42"},"devDependencies": {"@composio/core": "workspace:*",diff --git a/ts/packages/providers/google/CHANGELOG.md b/ts/packages/providers/google/CHANGELOG.mdindex 2a02fa2c4..c082b8c4c 100644--- a/ts/packages/providers/google/CHANGELOG.md+++ b/ts/packages/providers/google/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/google+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/google/package.json b/ts/packages/providers/google/package.jsonindex 1a46fc56e..e9832e16a 100644--- a/ts/packages/providers/google/package.json+++ b/ts/packages/providers/google/package.json@@ -1,6 +1,6 @@{"name": "@composio/google",- "version": "0.1.41",+ "version": "0.1.42","description": "Google GenAI Provider for Composio SDK","main": "src/index.ts","type": "module",@@ -36,7 +36,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","@google/genai": "^1.1.0"},"devDependencies": {diff --git a/ts/packages/providers/langchain/CHANGELOG.md b/ts/packages/providers/langchain/CHANGELOG.mdindex 2f2672fd1..4d25a9ef2 100644--- a/ts/packages/providers/langchain/CHANGELOG.md+++ b/ts/packages/providers/langchain/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/langchain+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/langchain/package.json b/ts/packages/providers/langchain/package.jsonindex 5f730b4ce..be4b9430c 100644--- a/ts/packages/providers/langchain/package.json+++ b/ts/packages/providers/langchain/package.json@@ -1,6 +1,6 @@{"name": "@composio/langchain",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "dist/index.js","type": "module",@@ -30,7 +30,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","@langchain/core": "^0.3.63"},"devDependencies": {diff --git a/ts/packages/providers/mastra/CHANGELOG.md b/ts/packages/providers/mastra/CHANGELOG.mdindex 0c415ff45..31c1ffbfb 100644--- a/ts/packages/providers/mastra/CHANGELOG.md+++ b/ts/packages/providers/mastra/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/mastra+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/mastra/package.json b/ts/packages/providers/mastra/package.jsonindex 44998376e..3bbdd6b94 100644--- a/ts/packages/providers/mastra/package.json+++ b/ts/packages/providers/mastra/package.json@@ -1,6 +1,6 @@{"name": "@composio/mastra",- "version": "0.1.41",+ "version": "0.1.42","description": "Agentic Provider for mastra in Composio SDK","main": "src/index.ts","type": "module",@@ -34,7 +34,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","@mastra/core": "^0.10.0"},"devDependencies": {diff --git a/ts/packages/providers/openai-agents/CHANGELOG.md b/ts/packages/providers/openai-agents/CHANGELOG.mdindex e0f9a071d..7082cbc10 100644--- a/ts/packages/providers/openai-agents/CHANGELOG.md+++ b/ts/packages/providers/openai-agents/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/vercel+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/openai-agents/package.json b/ts/packages/providers/openai-agents/package.jsonindex 4a86ca90a..0a60b3286 100644--- a/ts/packages/providers/openai-agents/package.json+++ b/ts/packages/providers/openai-agents/package.json@@ -1,6 +1,6 @@{"name": "@composio/openai-agents",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "src/index.ts","type": "module",@@ -30,7 +30,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","@openai/agents": "^0.0.7"},"devDependencies": {diff --git a/ts/packages/providers/openai/CHANGELOG.md b/ts/packages/providers/openai/CHANGELOG.mdindex 2dc9114d2..00a4e0b82 100644--- a/ts/packages/providers/openai/CHANGELOG.md+++ b/ts/packages/providers/openai/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/openai+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/openai/package.json b/ts/packages/providers/openai/package.jsonindex 4102b723c..1bf2e4d3d 100644--- a/ts/packages/providers/openai/package.json+++ b/ts/packages/providers/openai/package.json@@ -1,6 +1,6 @@{"name": "@composio/openai",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "src/index.ts","type": "module",@@ -30,7 +30,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","openai": "^4.3.8"},"devDependencies": {diff --git a/ts/packages/providers/vercel/CHANGELOG.md b/ts/packages/providers/vercel/CHANGELOG.mdindex e0f9a071d..7082cbc10 100644--- a/ts/packages/providers/vercel/CHANGELOG.md+++ b/ts/packages/providers/vercel/CHANGELOG.md@@ -1,5 +1,11 @@# @composio/vercel+## 0.1.42++### Patch Changes++- @composio/[email protected]+## 0.1.41### Patch Changesdiff --git a/ts/packages/providers/vercel/package.json b/ts/packages/providers/vercel/package.jsonindex 07c402f17..5d96e468d 100644--- a/ts/packages/providers/vercel/package.json+++ b/ts/packages/providers/vercel/package.json@@ -1,6 +1,6 @@{"name": "@composio/vercel",- "version": "0.1.41",+ "version": "0.1.42","description": "","main": "src/index.ts","type": "module",@@ -30,7 +30,7 @@"license": "ISC","packageManager": "[email protected]","peerDependencies": {- "@composio/core": "0.1.41",+ "@composio/core": "0.1.42","ai": "^4.3.8"},"devDependencies": {