@composio/json-schema-to-zod 0.1.10-next.5 → 0.1.11

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
@@ -177,6 +177,22 @@ var parseArray = (jsonSchema, refs) => {
177
177
  "maxItems",
178
178
  (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
179
179
  );
180
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minItems !== "number") {
181
+ zodSchema = extendSchemaWithMessage(
182
+ zodSchema,
183
+ { ...jsonSchema, minItems: jsonSchema.min },
184
+ "minItems",
185
+ (zs, minItems, errorMessage) => zs.min(minItems, errorMessage)
186
+ );
187
+ }
188
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maxItems !== "number") {
189
+ zodSchema = extendSchemaWithMessage(
190
+ zodSchema,
191
+ { ...jsonSchema, maxItems: jsonSchema.max },
192
+ "maxItems",
193
+ (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
194
+ );
195
+ }
180
196
  return zodSchema;
181
197
  };
182
198
 
@@ -356,6 +372,22 @@ var parseNumber = (jsonSchema) => {
356
372
  (zs, exclusiveMaximum, errorMsg) => zs.lt(exclusiveMaximum, errorMsg)
357
373
  );
358
374
  }
375
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minimum !== "number") {
376
+ zodSchema = extendSchemaWithMessage(
377
+ zodSchema,
378
+ { ...jsonSchema, minimum: jsonSchema.min },
379
+ "minimum",
380
+ (zs, minimum, errorMsg) => zs.gte(minimum, errorMsg)
381
+ );
382
+ }
383
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maximum !== "number") {
384
+ zodSchema = extendSchemaWithMessage(
385
+ zodSchema,
386
+ { ...jsonSchema, maximum: jsonSchema.max },
387
+ "maximum",
388
+ (zs, maximum, errorMsg) => zs.lte(maximum, errorMsg)
389
+ );
390
+ }
359
391
  return zodSchema;
360
392
  };
361
393
 
@@ -626,15 +658,48 @@ var parseString = (jsonSchema) => {
626
658
  "maxLength",
627
659
  (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
628
660
  );
661
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minLength !== "number") {
662
+ zodSchema = extendSchemaWithMessage(
663
+ zodSchema,
664
+ { ...jsonSchema, minLength: jsonSchema.min },
665
+ "minLength",
666
+ (zs, minLength, errorMsg) => zs.min(minLength, errorMsg)
667
+ );
668
+ }
669
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maxLength !== "number") {
670
+ zodSchema = extendSchemaWithMessage(
671
+ zodSchema,
672
+ { ...jsonSchema, maxLength: jsonSchema.max },
673
+ "maxLength",
674
+ (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
675
+ );
676
+ }
629
677
  return zodSchema;
630
678
  };
631
679
 
632
680
  // src/parsers/parse-schema.ts
633
681
  var addDescribes = (jsonSchema, zodSchema) => {
682
+ let description = "";
634
683
  if (jsonSchema.description) {
635
- zodSchema = zodSchema.describe(jsonSchema.description);
684
+ description = jsonSchema.description;
636
685
  } else if (jsonSchema.title) {
637
- zodSchema = zodSchema.describe(jsonSchema.title);
686
+ description = jsonSchema.title;
687
+ }
688
+ if (jsonSchema.example !== void 0) {
689
+ const exampleText = `Example: ${JSON.stringify(jsonSchema.example)}`;
690
+ description = description ? `${description}
691
+ ${exampleText}` : exampleText;
692
+ } else if (jsonSchema.examples !== void 0 && Array.isArray(jsonSchema.examples)) {
693
+ const examples = jsonSchema.examples;
694
+ if (examples && examples.length && examples.length > 0) {
695
+ const exampleText = examples.length === 1 ? `Example: ${JSON.stringify(examples[0])}` : `Examples:
696
+ ${examples.map((ex) => ` ${JSON.stringify(ex)}`).join("\n")}`;
697
+ description = description ? `${description}
698
+ ${exampleText}` : exampleText;
699
+ }
700
+ }
701
+ if (description) {
702
+ zodSchema = zodSchema.describe(description);
638
703
  }
639
704
  return zodSchema;
640
705
  };
package/dist/index.js CHANGED
@@ -141,6 +141,22 @@ var parseArray = (jsonSchema, refs) => {
141
141
  "maxItems",
142
142
  (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
143
143
  );
144
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minItems !== "number") {
145
+ zodSchema = extendSchemaWithMessage(
146
+ zodSchema,
147
+ { ...jsonSchema, minItems: jsonSchema.min },
148
+ "minItems",
149
+ (zs, minItems, errorMessage) => zs.min(minItems, errorMessage)
150
+ );
151
+ }
152
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maxItems !== "number") {
153
+ zodSchema = extendSchemaWithMessage(
154
+ zodSchema,
155
+ { ...jsonSchema, maxItems: jsonSchema.max },
156
+ "maxItems",
157
+ (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
158
+ );
159
+ }
144
160
  return zodSchema;
145
161
  };
146
162
 
@@ -320,6 +336,22 @@ var parseNumber = (jsonSchema) => {
320
336
  (zs, exclusiveMaximum, errorMsg) => zs.lt(exclusiveMaximum, errorMsg)
321
337
  );
322
338
  }
339
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minimum !== "number") {
340
+ zodSchema = extendSchemaWithMessage(
341
+ zodSchema,
342
+ { ...jsonSchema, minimum: jsonSchema.min },
343
+ "minimum",
344
+ (zs, minimum, errorMsg) => zs.gte(minimum, errorMsg)
345
+ );
346
+ }
347
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maximum !== "number") {
348
+ zodSchema = extendSchemaWithMessage(
349
+ zodSchema,
350
+ { ...jsonSchema, maximum: jsonSchema.max },
351
+ "maximum",
352
+ (zs, maximum, errorMsg) => zs.lte(maximum, errorMsg)
353
+ );
354
+ }
323
355
  return zodSchema;
324
356
  };
325
357
 
@@ -590,15 +622,48 @@ var parseString = (jsonSchema) => {
590
622
  "maxLength",
591
623
  (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
592
624
  );
625
+ if (typeof jsonSchema.min === "number" && typeof jsonSchema.minLength !== "number") {
626
+ zodSchema = extendSchemaWithMessage(
627
+ zodSchema,
628
+ { ...jsonSchema, minLength: jsonSchema.min },
629
+ "minLength",
630
+ (zs, minLength, errorMsg) => zs.min(minLength, errorMsg)
631
+ );
632
+ }
633
+ if (typeof jsonSchema.max === "number" && typeof jsonSchema.maxLength !== "number") {
634
+ zodSchema = extendSchemaWithMessage(
635
+ zodSchema,
636
+ { ...jsonSchema, maxLength: jsonSchema.max },
637
+ "maxLength",
638
+ (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
639
+ );
640
+ }
593
641
  return zodSchema;
594
642
  };
595
643
 
596
644
  // src/parsers/parse-schema.ts
597
645
  var addDescribes = (jsonSchema, zodSchema) => {
646
+ let description = "";
598
647
  if (jsonSchema.description) {
599
- zodSchema = zodSchema.describe(jsonSchema.description);
648
+ description = jsonSchema.description;
600
649
  } else if (jsonSchema.title) {
601
- zodSchema = zodSchema.describe(jsonSchema.title);
650
+ description = jsonSchema.title;
651
+ }
652
+ if (jsonSchema.example !== void 0) {
653
+ const exampleText = `Example: ${JSON.stringify(jsonSchema.example)}`;
654
+ description = description ? `${description}
655
+ ${exampleText}` : exampleText;
656
+ } else if (jsonSchema.examples !== void 0 && Array.isArray(jsonSchema.examples)) {
657
+ const examples = jsonSchema.examples;
658
+ if (examples && examples.length && examples.length > 0) {
659
+ const exampleText = examples.length === 1 ? `Example: ${JSON.stringify(examples[0])}` : `Examples:
660
+ ${examples.map((ex) => ` ${JSON.stringify(ex)}`).join("\n")}`;
661
+ description = description ? `${description}
662
+ ${exampleText}` : exampleText;
663
+ }
664
+ }
665
+ if (description) {
666
+ zodSchema = zodSchema.describe(description);
602
667
  }
603
668
  return zodSchema;
604
669
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/json-schema-to-zod",
3
- "version": "0.1.10-next.5",
3
+ "version": "0.1.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",