@composio/json-schema-to-zod 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -105,7 +105,7 @@ function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
105
105
  // src/utils/its.ts
106
106
  var its = {
107
107
  an: {
108
- object: (x) => x.type === "object",
108
+ object: (x) => x.type === "object" || !x.type && (x.properties !== void 0 || x.additionalProperties !== void 0 || x.patternProperties !== void 0),
109
109
  array: (x) => x.type === "array",
110
110
  anyOf: (x) => x.anyOf !== void 0,
111
111
  allOf: (x) => x.allOf !== void 0,
@@ -473,16 +473,17 @@ function parseObjectProperties(objectSchema, refs) {
473
473
  }
474
474
  function parseObject(objectSchema, refs) {
475
475
  const hasPatternProperties = Object.keys(objectSchema.patternProperties ?? {}).length > 0;
476
- const propertiesSchema = parseObjectProperties(objectSchema, refs);
476
+ const normalizedSchema = objectSchema.type === "object" ? objectSchema : { ...objectSchema, type: "object" };
477
+ const propertiesSchema = parseObjectProperties(normalizedSchema, refs);
477
478
  let zodSchema = propertiesSchema;
478
- const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
479
+ const additionalProperties = normalizedSchema.additionalProperties !== void 0 ? parseSchema(normalizedSchema.additionalProperties, {
479
480
  ...refs,
480
481
  path: [...refs.path, "additionalProperties"]
481
482
  }) : void 0;
482
- const isAdditionalPropertiesTrue = objectSchema.additionalProperties === true;
483
- if (objectSchema.patternProperties) {
483
+ const isAdditionalPropertiesTrue = normalizedSchema.additionalProperties === true;
484
+ if (normalizedSchema.patternProperties) {
484
485
  const parsedPatternProperties = Object.fromEntries(
485
- Object.entries(objectSchema.patternProperties).map(([key, value]) => {
486
+ Object.entries(normalizedSchema.patternProperties).map(([key, value]) => {
486
487
  return [
487
488
  key,
488
489
  parseSchema(value, {
@@ -516,11 +517,11 @@ function parseObject(objectSchema, refs) {
516
517
  zodSchema = z14.record(patternPropertyValues[0]);
517
518
  }
518
519
  }
519
- const objectPropertyKeys = new Set(Object.keys(objectSchema.properties ?? {}));
520
+ const objectPropertyKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));
520
521
  zodSchema = zodSchema.superRefine((value, ctx) => {
521
522
  for (const key in value) {
522
523
  let wasMatched = objectPropertyKeys.has(key);
523
- for (const patternPropertyKey in objectSchema.patternProperties) {
524
+ for (const patternPropertyKey in normalizedSchema.patternProperties) {
524
525
  const regex = new RegExp(patternPropertyKey);
525
526
  if (key.match(regex)) {
526
527
  wasMatched = true;
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
69
69
  // src/utils/its.ts
70
70
  var its = {
71
71
  an: {
72
- object: (x) => x.type === "object",
72
+ object: (x) => x.type === "object" || !x.type && (x.properties !== void 0 || x.additionalProperties !== void 0 || x.patternProperties !== void 0),
73
73
  array: (x) => x.type === "array",
74
74
  anyOf: (x) => x.anyOf !== void 0,
75
75
  allOf: (x) => x.allOf !== void 0,
@@ -437,16 +437,17 @@ function parseObjectProperties(objectSchema, refs) {
437
437
  }
438
438
  function parseObject(objectSchema, refs) {
439
439
  const hasPatternProperties = Object.keys(objectSchema.patternProperties ?? {}).length > 0;
440
- const propertiesSchema = parseObjectProperties(objectSchema, refs);
440
+ const normalizedSchema = objectSchema.type === "object" ? objectSchema : { ...objectSchema, type: "object" };
441
+ const propertiesSchema = parseObjectProperties(normalizedSchema, refs);
441
442
  let zodSchema = propertiesSchema;
442
- const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
443
+ const additionalProperties = normalizedSchema.additionalProperties !== void 0 ? parseSchema(normalizedSchema.additionalProperties, {
443
444
  ...refs,
444
445
  path: [...refs.path, "additionalProperties"]
445
446
  }) : void 0;
446
- const isAdditionalPropertiesTrue = objectSchema.additionalProperties === true;
447
- if (objectSchema.patternProperties) {
447
+ const isAdditionalPropertiesTrue = normalizedSchema.additionalProperties === true;
448
+ if (normalizedSchema.patternProperties) {
448
449
  const parsedPatternProperties = Object.fromEntries(
449
- Object.entries(objectSchema.patternProperties).map(([key, value]) => {
450
+ Object.entries(normalizedSchema.patternProperties).map(([key, value]) => {
450
451
  return [
451
452
  key,
452
453
  parseSchema(value, {
@@ -480,11 +481,11 @@ function parseObject(objectSchema, refs) {
480
481
  zodSchema = z14.record(patternPropertyValues[0]);
481
482
  }
482
483
  }
483
- const objectPropertyKeys = new Set(Object.keys(objectSchema.properties ?? {}));
484
+ const objectPropertyKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));
484
485
  zodSchema = zodSchema.superRefine((value, ctx) => {
485
486
  for (const key in value) {
486
487
  let wasMatched = objectPropertyKeys.has(key);
487
- for (const patternPropertyKey in objectSchema.patternProperties) {
488
+ for (const patternPropertyKey in normalizedSchema.patternProperties) {
488
489
  const regex = new RegExp(patternPropertyKey);
489
490
  if (key.match(regex)) {
490
491
  wasMatched = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/json-schema-to-zod",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",