@sdk-it/typescript 0.48.0 → 0.48.1

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.js CHANGED
@@ -496,7 +496,15 @@ var TypeScriptEmitter = class {
496
496
  return this.oneOf(schemas, required);
497
497
  }
498
498
  enum(values, required) {
499
- const enumValues = values.map((val) => typeof val === "string" ? `'${val}'` : `${val}`).join(" | ");
499
+ const enumValues = values.map((val) => {
500
+ if (typeof val === "string") {
501
+ return `'${val}'`;
502
+ }
503
+ if (val !== null && typeof val === "object") {
504
+ return constType(val);
505
+ }
506
+ return `${val}`;
507
+ }).join(" | ");
500
508
  return appendOptional(enumValues, required);
501
509
  }
502
510
  /**
@@ -548,7 +556,7 @@ var TypeScriptEmitter = class {
548
556
  return this.enum(schema.enum, required);
549
557
  }
550
558
  if (schema.const !== void 0) {
551
- return constType(schema.const);
559
+ return appendOptional(constType(schema.const), required);
552
560
  }
553
561
  const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
554
562
  if (!types.length) {
@@ -824,7 +832,11 @@ var ZodEmitter = class {
824
832
  const property = discriminatorOf(this.#spec, schema);
825
833
  return property === void 0 ? void 0 : `z.discriminatedUnion(${JSON.stringify(property)}, [${branches.join(", ")}])`;
826
834
  }
827
- enum(values) {
835
+ enum(members) {
836
+ if (members.some((member) => member !== null && typeof member === "object")) {
837
+ return `z.union([${members.map(constSchema).join(", ")}])`;
838
+ }
839
+ const values = members.map((member) => JSON.stringify(member));
828
840
  if (values.length === 1) {
829
841
  return `z.literal(${values.join(", ")})`;
830
842
  }
@@ -946,9 +958,8 @@ var ZodEmitter = class {
946
958
  return `${constSchema(schema.const)}${this.#suffixes(JSON.stringify(schema.default), required, false)}`;
947
959
  }
948
960
  if (schema.enum && Array.isArray(schema.enum)) {
949
- const enumVals = schema.enum.map((val) => JSON.stringify(val));
950
- const defaultValue = enumVals.includes(JSON.stringify(schema.default)) ? JSON.stringify(schema.default) : void 0;
951
- return `${this.enum(enumVals)}${this.#suffixes(defaultValue, required, false)}`;
961
+ const defaultValue = schema.enum.map((member) => JSON.stringify(member)).includes(JSON.stringify(schema.default)) ? JSON.stringify(schema.default) : void 0;
962
+ return `${this.enum(schema.enum)}${this.#suffixes(defaultValue, required, false)}`;
952
963
  }
953
964
  const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
954
965
  if (!types.length) {