@ng-openapi/zod 0.0.2-pr-26-feature-zod-c60713a.0 → 0.0.2-pr-32-feature-zod-5c9aca1.0

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.
Files changed (4) hide show
  1. package/index.cjs +36 -127
  2. package/index.d.ts +1 -1
  3. package/index.js +36 -127
  4. package/package.json +1 -1
package/index.cjs CHANGED
@@ -48,78 +48,6 @@ function pascalCase(str2) {
48
48
  }
49
49
  __name(pascalCase, "pascalCase");
50
50
 
51
- // ../../shared/src/utils/functions/collect-used-types.ts
52
- function collectUsedTypes(operations) {
53
- const usedTypes = /* @__PURE__ */ new Set();
54
- usedTypes.add("RequestOptions");
55
- operations.forEach((operation) => {
56
- operation.parameters?.forEach((param) => {
57
- collectTypesFromSchema(param.schema || param, usedTypes);
58
- });
59
- if (operation.requestBody) {
60
- collectTypesFromRequestBody(operation.requestBody, usedTypes);
61
- }
62
- if (operation.responses) {
63
- Object.values(operation.responses).forEach((response) => {
64
- collectTypesFromResponse(response, usedTypes);
65
- });
66
- }
67
- });
68
- return usedTypes;
69
- }
70
- __name(collectUsedTypes, "collectUsedTypes");
71
- function collectTypesFromSchema(schema2, usedTypes) {
72
- if (!schema2) return;
73
- if (schema2.$ref) {
74
- const refName = schema2.$ref.split("/").pop();
75
- if (refName) {
76
- usedTypes.add(pascalCase(refName));
77
- }
78
- }
79
- if (schema2.type === "array" && schema2.items) {
80
- collectTypesFromSchema(schema2.items, usedTypes);
81
- }
82
- if (schema2.type === "object" && schema2.properties) {
83
- Object.values(schema2.properties).forEach((prop) => {
84
- collectTypesFromSchema(prop, usedTypes);
85
- });
86
- }
87
- if (schema2.allOf) {
88
- schema2.allOf.forEach((subSchema) => {
89
- collectTypesFromSchema(subSchema, usedTypes);
90
- });
91
- }
92
- if (schema2.oneOf) {
93
- schema2.oneOf.forEach((subSchema) => {
94
- collectTypesFromSchema(subSchema, usedTypes);
95
- });
96
- }
97
- if (schema2.anyOf) {
98
- schema2.anyOf.forEach((subSchema) => {
99
- collectTypesFromSchema(subSchema, usedTypes);
100
- });
101
- }
102
- }
103
- __name(collectTypesFromSchema, "collectTypesFromSchema");
104
- function collectTypesFromRequestBody(requestBody, usedTypes) {
105
- const content = requestBody.content || {};
106
- Object.values(content).forEach((mediaType) => {
107
- if (mediaType.schema) {
108
- collectTypesFromSchema(mediaType.schema, usedTypes);
109
- }
110
- });
111
- }
112
- __name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
113
- function collectTypesFromResponse(response, usedTypes) {
114
- const content = response.content || {};
115
- Object.values(content).forEach((mediaType) => {
116
- if (mediaType.schema) {
117
- collectTypesFromSchema(mediaType.schema, usedTypes);
118
- }
119
- });
120
- }
121
- __name(collectTypesFromResponse, "collectTypesFromResponse");
122
-
123
51
  // ../../shared/src/utils/functions/extract-paths.ts
124
52
  function extractPaths(swaggerPaths = {}, methods = [
125
53
  "get",
@@ -195,6 +123,14 @@ var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated prov
195
123
  * Do not edit this file manually
196
124
  */
197
125
  `;
126
+ var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
127
+ * Do not edit this file manually
128
+ */
129
+ `, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
130
+ var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
131
+ * Do not edit this file manually
132
+ */
133
+ `;
198
134
 
199
135
  // ../../../node_modules/js-yaml/dist/js-yaml.mjs
200
136
  function isNothing(subject) {
@@ -2894,11 +2830,13 @@ var safeLoad = renamed("safeLoad", "load");
2894
2830
  var safeLoadAll = renamed("safeLoadAll", "loadAll");
2895
2831
  var safeDump = renamed("safeDump", "dump");
2896
2832
 
2897
- // src/lib/zod-schema.builder.ts
2833
+ // src/lib/utils/is-reference-object.ts
2898
2834
  function isReferenceObject(obj) {
2899
2835
  return obj && typeof obj === "object" && "$ref" in obj;
2900
2836
  }
2901
2837
  __name(isReferenceObject, "isReferenceObject");
2838
+
2839
+ // src/lib/zod-schema.builder.ts
2902
2840
  var ZodSchemaBuilder = class {
2903
2841
  static {
2904
2842
  __name(this, "ZodSchemaBuilder");
@@ -2906,7 +2844,6 @@ var ZodSchemaBuilder = class {
2906
2844
  parser;
2907
2845
  config;
2908
2846
  options;
2909
- constsCounter = {};
2910
2847
  constructor(parser, config, options) {
2911
2848
  this.parser = parser;
2912
2849
  this.config = config;
@@ -2944,7 +2881,7 @@ var ZodSchemaBuilder = class {
2944
2881
  zodSchema = "z.any()";
2945
2882
  }
2946
2883
  if (!buildOptions.required && schema2.default !== void 0) {
2947
- const defaultValue = this.generateDefaultValue(schema2.default, name);
2884
+ const defaultValue = this.generateDefaultValue(schema2.default);
2948
2885
  zodSchema = `${zodSchema}.default(${defaultValue})`;
2949
2886
  } else if (!buildOptions.required && nullable) {
2950
2887
  zodSchema = `${zodSchema}.nullish()`;
@@ -2970,15 +2907,17 @@ var ZodSchemaBuilder = class {
2970
2907
  return buildOptions.coerce ? "z.coerce.date()" : "z.date()";
2971
2908
  }
2972
2909
  return buildOptions.coerce ? "z.coerce.string().date()" : "z.string().date()";
2973
- case "date-time":
2910
+ case "date-time": {
2974
2911
  if (this.config.options?.dateType === "Date") {
2975
2912
  return buildOptions.coerce ? "z.coerce.date()" : "z.date()";
2976
2913
  }
2977
2914
  const datetimeOptions = this.options.dateTime ? `, ${JSON.stringify(this.options.dateTime)}` : "";
2978
2915
  return buildOptions.coerce ? `z.coerce.string().datetime(${datetimeOptions})` : `z.string().datetime(${datetimeOptions})`;
2979
- case "time":
2916
+ }
2917
+ case "time": {
2980
2918
  const timeOptions = this.options.time ? `, ${JSON.stringify(this.options.time)}` : "";
2981
2919
  return buildOptions.coerce ? `z.coerce.string().time(${timeOptions})` : `z.string().time(${timeOptions})`;
2920
+ }
2982
2921
  case "email":
2983
2922
  return buildOptions.coerce ? "z.coerce.string().email()" : "z.string().email()";
2984
2923
  case "uri":
@@ -3128,7 +3067,7 @@ ${properties.join(",\n")}
3128
3067
  }
3129
3068
  return schema2.type || "any";
3130
3069
  }
3131
- generateDefaultValue(defaultValue, name) {
3070
+ generateDefaultValue(defaultValue) {
3132
3071
  if (typeof defaultValue === "string") {
3133
3072
  return `'${this.escapeString(defaultValue)}'`;
3134
3073
  }
@@ -3161,10 +3100,6 @@ ${properties.join(",\n")}
3161
3100
  };
3162
3101
 
3163
3102
  // src/lib/zod-schema.generator.ts
3164
- function isReferenceObject2(obj) {
3165
- return obj && typeof obj === "object" && "$ref" in obj;
3166
- }
3167
- __name(isReferenceObject2, "isReferenceObject");
3168
3103
  var ZodSchemaGenerator = class {
3169
3104
  static {
3170
3105
  __name(this, "ZodSchemaGenerator");
@@ -3302,21 +3237,21 @@ var ZodSchemaGenerator = class {
3302
3237
  };
3303
3238
  }
3304
3239
  resolveRequestBody(requestBody) {
3305
- if (isReferenceObject2(requestBody)) {
3240
+ if (isReferenceObject(requestBody)) {
3306
3241
  const resolved = this.parser.resolveReference(requestBody.$ref);
3307
3242
  return resolved;
3308
3243
  }
3309
3244
  return requestBody;
3310
3245
  }
3311
3246
  resolveResponse(response) {
3312
- if (isReferenceObject2(response)) {
3247
+ if (isReferenceObject(response)) {
3313
3248
  const resolved = this.parser.resolveReference(response.$ref);
3314
3249
  return resolved;
3315
3250
  }
3316
3251
  return response;
3317
3252
  }
3318
3253
  resolveSchema(schema2) {
3319
- if (isReferenceObject2(schema2)) {
3254
+ if (isReferenceObject(schema2)) {
3320
3255
  const resolved = this.parser.resolveReference(schema2.$ref);
3321
3256
  return resolved;
3322
3257
  }
@@ -3324,11 +3259,11 @@ var ZodSchemaGenerator = class {
3324
3259
  }
3325
3260
  shouldCoerce(type2) {
3326
3261
  const typeMap = {
3327
- "path": "param",
3328
- "query": "query",
3329
- "header": "header",
3330
- "body": "body",
3331
- "response": "response"
3262
+ path: "param",
3263
+ query: "query",
3264
+ header: "header",
3265
+ body: "body",
3266
+ response: "response"
3332
3267
  };
3333
3268
  const mappedType = typeMap[type2] || type2;
3334
3269
  if (typeof this.options.coerce === "boolean") {
@@ -3338,11 +3273,11 @@ var ZodSchemaGenerator = class {
3338
3273
  }
3339
3274
  isStrict(type2) {
3340
3275
  const typeMap = {
3341
- "path": "param",
3342
- "query": "query",
3343
- "header": "header",
3344
- "body": "body",
3345
- "response": "response"
3276
+ path: "param",
3277
+ query: "query",
3278
+ header: "header",
3279
+ body: "body",
3280
+ response: "response"
3346
3281
  };
3347
3282
  const mappedType = typeMap[type2] || type2;
3348
3283
  if (typeof this.options.strict === "boolean") {
@@ -3369,31 +3304,19 @@ var ZodIndexGenerator = class {
3369
3304
  const sourceFile = this.project.createSourceFile(indexPath, "", {
3370
3305
  overwrite: true
3371
3306
  });
3372
- sourceFile.insertText(0, this.generateHeaderComment());
3307
+ sourceFile.insertText(0, ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT);
3373
3308
  const validatorFiles = fs.readdirSync(validatorsDir).filter((file) => file.endsWith(".validator.ts")).map((file) => file.replace(".validator.ts", ""));
3374
3309
  validatorFiles.forEach((fileName) => {
3375
3310
  sourceFile.addExportDeclaration({
3376
- namedExports: [
3377
- "*"
3378
- ],
3379
3311
  moduleSpecifier: `./${fileName}.validator`
3380
3312
  });
3381
3313
  });
3382
3314
  sourceFile.formatText();
3383
3315
  sourceFile.saveSync();
3384
3316
  }
3385
- generateHeaderComment() {
3386
- return `/**
3387
- * Validators Index
3388
- * Generated by ng-openapi
3389
- * Do not edit manually
3390
- */
3391
-
3392
- `;
3393
- }
3394
3317
  };
3395
3318
 
3396
- // src/lib/zod.generator.ts
3319
+ // src/lib/utils/default-options.ts
3397
3320
  var DEFAULT_OPTIONS = {
3398
3321
  strict: false,
3399
3322
  coerce: false,
@@ -3405,6 +3328,8 @@ var DEFAULT_OPTIONS = {
3405
3328
  response: true
3406
3329
  }
3407
3330
  };
3331
+
3332
+ // src/lib/zod.generator.ts
3408
3333
  var ZodGenerator = class {
3409
3334
  static {
3410
3335
  __name(this, "ZodGenerator");
@@ -3471,23 +3396,14 @@ var ZodGenerator = class {
3471
3396
  const sourceFile = this.project.createSourceFile(filePath, "", {
3472
3397
  overwrite: true
3473
3398
  });
3474
- sourceFile.insertText(0, this.generateHeaderComment(validatorName));
3399
+ sourceFile.insertText(0, ZOD_PLUGIN_GENERATOR_HEADER_COMMENT(validatorName));
3475
3400
  this.addImports(sourceFile, operations);
3476
3401
  for (const operation of operations) {
3477
3402
  await this.generateOperationValidators(sourceFile, operation);
3478
3403
  }
3479
- sourceFile.formatText();
3404
+ sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3480
3405
  sourceFile.saveSync();
3481
3406
  }
3482
- generateHeaderComment(validatorName) {
3483
- return `/**
3484
- * ${validatorName} Validators
3485
- * Generated by ng-openapi
3486
- * Do not edit manually
3487
- */
3488
-
3489
- `;
3490
- }
3491
3407
  addImports(sourceFile, operations) {
3492
3408
  sourceFile.addImportDeclaration({
3493
3409
  namedImports: [
@@ -3495,13 +3411,6 @@ var ZodGenerator = class {
3495
3411
  ],
3496
3412
  moduleSpecifier: "zod"
3497
3413
  });
3498
- const usedTypes = collectUsedTypes(operations);
3499
- if (usedTypes.size > 0) {
3500
- sourceFile.addImportDeclaration({
3501
- namedImports: Array.from(usedTypes).sort(),
3502
- moduleSpecifier: "../models"
3503
- });
3504
- }
3505
3414
  }
3506
3415
  async generateOperationValidators(sourceFile, operation) {
3507
3416
  const operationName = this.getOperationName(operation);
package/index.d.ts CHANGED
@@ -168,6 +168,7 @@ interface ZodPluginOptions {
168
168
  precision?: -1 | 0 | 1 | 2 | 3;
169
169
  };
170
170
  }
171
+
171
172
  declare class ZodGenerator implements IPluginGenerator {
172
173
  private project;
173
174
  private parser;
@@ -180,7 +181,6 @@ declare class ZodGenerator implements IPluginGenerator {
180
181
  generate(outputRoot: string): Promise<void>;
181
182
  private groupPathsByController;
182
183
  private generateValidatorFile;
183
- private generateHeaderComment;
184
184
  private addImports;
185
185
  private generateOperationValidators;
186
186
  private generateParameterValidators;
package/index.js CHANGED
@@ -14,78 +14,6 @@ function pascalCase(str2) {
14
14
  }
15
15
  __name(pascalCase, "pascalCase");
16
16
 
17
- // ../../shared/src/utils/functions/collect-used-types.ts
18
- function collectUsedTypes(operations) {
19
- const usedTypes = /* @__PURE__ */ new Set();
20
- usedTypes.add("RequestOptions");
21
- operations.forEach((operation) => {
22
- operation.parameters?.forEach((param) => {
23
- collectTypesFromSchema(param.schema || param, usedTypes);
24
- });
25
- if (operation.requestBody) {
26
- collectTypesFromRequestBody(operation.requestBody, usedTypes);
27
- }
28
- if (operation.responses) {
29
- Object.values(operation.responses).forEach((response) => {
30
- collectTypesFromResponse(response, usedTypes);
31
- });
32
- }
33
- });
34
- return usedTypes;
35
- }
36
- __name(collectUsedTypes, "collectUsedTypes");
37
- function collectTypesFromSchema(schema2, usedTypes) {
38
- if (!schema2) return;
39
- if (schema2.$ref) {
40
- const refName = schema2.$ref.split("/").pop();
41
- if (refName) {
42
- usedTypes.add(pascalCase(refName));
43
- }
44
- }
45
- if (schema2.type === "array" && schema2.items) {
46
- collectTypesFromSchema(schema2.items, usedTypes);
47
- }
48
- if (schema2.type === "object" && schema2.properties) {
49
- Object.values(schema2.properties).forEach((prop) => {
50
- collectTypesFromSchema(prop, usedTypes);
51
- });
52
- }
53
- if (schema2.allOf) {
54
- schema2.allOf.forEach((subSchema) => {
55
- collectTypesFromSchema(subSchema, usedTypes);
56
- });
57
- }
58
- if (schema2.oneOf) {
59
- schema2.oneOf.forEach((subSchema) => {
60
- collectTypesFromSchema(subSchema, usedTypes);
61
- });
62
- }
63
- if (schema2.anyOf) {
64
- schema2.anyOf.forEach((subSchema) => {
65
- collectTypesFromSchema(subSchema, usedTypes);
66
- });
67
- }
68
- }
69
- __name(collectTypesFromSchema, "collectTypesFromSchema");
70
- function collectTypesFromRequestBody(requestBody, usedTypes) {
71
- const content = requestBody.content || {};
72
- Object.values(content).forEach((mediaType) => {
73
- if (mediaType.schema) {
74
- collectTypesFromSchema(mediaType.schema, usedTypes);
75
- }
76
- });
77
- }
78
- __name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
79
- function collectTypesFromResponse(response, usedTypes) {
80
- const content = response.content || {};
81
- Object.values(content).forEach((mediaType) => {
82
- if (mediaType.schema) {
83
- collectTypesFromSchema(mediaType.schema, usedTypes);
84
- }
85
- });
86
- }
87
- __name(collectTypesFromResponse, "collectTypesFromResponse");
88
-
89
17
  // ../../shared/src/utils/functions/extract-paths.ts
90
18
  function extractPaths(swaggerPaths = {}, methods = [
91
19
  "get",
@@ -161,6 +89,14 @@ var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated prov
161
89
  * Do not edit this file manually
162
90
  */
163
91
  `;
92
+ var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
93
+ * Do not edit this file manually
94
+ */
95
+ `, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
96
+ var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
97
+ * Do not edit this file manually
98
+ */
99
+ `;
164
100
 
165
101
  // ../../../node_modules/js-yaml/dist/js-yaml.mjs
166
102
  function isNothing(subject) {
@@ -2860,11 +2796,13 @@ var safeLoad = renamed("safeLoad", "load");
2860
2796
  var safeLoadAll = renamed("safeLoadAll", "loadAll");
2861
2797
  var safeDump = renamed("safeDump", "dump");
2862
2798
 
2863
- // src/lib/zod-schema.builder.ts
2799
+ // src/lib/utils/is-reference-object.ts
2864
2800
  function isReferenceObject(obj) {
2865
2801
  return obj && typeof obj === "object" && "$ref" in obj;
2866
2802
  }
2867
2803
  __name(isReferenceObject, "isReferenceObject");
2804
+
2805
+ // src/lib/zod-schema.builder.ts
2868
2806
  var ZodSchemaBuilder = class {
2869
2807
  static {
2870
2808
  __name(this, "ZodSchemaBuilder");
@@ -2872,7 +2810,6 @@ var ZodSchemaBuilder = class {
2872
2810
  parser;
2873
2811
  config;
2874
2812
  options;
2875
- constsCounter = {};
2876
2813
  constructor(parser, config, options) {
2877
2814
  this.parser = parser;
2878
2815
  this.config = config;
@@ -2910,7 +2847,7 @@ var ZodSchemaBuilder = class {
2910
2847
  zodSchema = "z.any()";
2911
2848
  }
2912
2849
  if (!buildOptions.required && schema2.default !== void 0) {
2913
- const defaultValue = this.generateDefaultValue(schema2.default, name);
2850
+ const defaultValue = this.generateDefaultValue(schema2.default);
2914
2851
  zodSchema = `${zodSchema}.default(${defaultValue})`;
2915
2852
  } else if (!buildOptions.required && nullable) {
2916
2853
  zodSchema = `${zodSchema}.nullish()`;
@@ -2936,15 +2873,17 @@ var ZodSchemaBuilder = class {
2936
2873
  return buildOptions.coerce ? "z.coerce.date()" : "z.date()";
2937
2874
  }
2938
2875
  return buildOptions.coerce ? "z.coerce.string().date()" : "z.string().date()";
2939
- case "date-time":
2876
+ case "date-time": {
2940
2877
  if (this.config.options?.dateType === "Date") {
2941
2878
  return buildOptions.coerce ? "z.coerce.date()" : "z.date()";
2942
2879
  }
2943
2880
  const datetimeOptions = this.options.dateTime ? `, ${JSON.stringify(this.options.dateTime)}` : "";
2944
2881
  return buildOptions.coerce ? `z.coerce.string().datetime(${datetimeOptions})` : `z.string().datetime(${datetimeOptions})`;
2945
- case "time":
2882
+ }
2883
+ case "time": {
2946
2884
  const timeOptions = this.options.time ? `, ${JSON.stringify(this.options.time)}` : "";
2947
2885
  return buildOptions.coerce ? `z.coerce.string().time(${timeOptions})` : `z.string().time(${timeOptions})`;
2886
+ }
2948
2887
  case "email":
2949
2888
  return buildOptions.coerce ? "z.coerce.string().email()" : "z.string().email()";
2950
2889
  case "uri":
@@ -3094,7 +3033,7 @@ ${properties.join(",\n")}
3094
3033
  }
3095
3034
  return schema2.type || "any";
3096
3035
  }
3097
- generateDefaultValue(defaultValue, name) {
3036
+ generateDefaultValue(defaultValue) {
3098
3037
  if (typeof defaultValue === "string") {
3099
3038
  return `'${this.escapeString(defaultValue)}'`;
3100
3039
  }
@@ -3127,10 +3066,6 @@ ${properties.join(",\n")}
3127
3066
  };
3128
3067
 
3129
3068
  // src/lib/zod-schema.generator.ts
3130
- function isReferenceObject2(obj) {
3131
- return obj && typeof obj === "object" && "$ref" in obj;
3132
- }
3133
- __name(isReferenceObject2, "isReferenceObject");
3134
3069
  var ZodSchemaGenerator = class {
3135
3070
  static {
3136
3071
  __name(this, "ZodSchemaGenerator");
@@ -3268,21 +3203,21 @@ var ZodSchemaGenerator = class {
3268
3203
  };
3269
3204
  }
3270
3205
  resolveRequestBody(requestBody) {
3271
- if (isReferenceObject2(requestBody)) {
3206
+ if (isReferenceObject(requestBody)) {
3272
3207
  const resolved = this.parser.resolveReference(requestBody.$ref);
3273
3208
  return resolved;
3274
3209
  }
3275
3210
  return requestBody;
3276
3211
  }
3277
3212
  resolveResponse(response) {
3278
- if (isReferenceObject2(response)) {
3213
+ if (isReferenceObject(response)) {
3279
3214
  const resolved = this.parser.resolveReference(response.$ref);
3280
3215
  return resolved;
3281
3216
  }
3282
3217
  return response;
3283
3218
  }
3284
3219
  resolveSchema(schema2) {
3285
- if (isReferenceObject2(schema2)) {
3220
+ if (isReferenceObject(schema2)) {
3286
3221
  const resolved = this.parser.resolveReference(schema2.$ref);
3287
3222
  return resolved;
3288
3223
  }
@@ -3290,11 +3225,11 @@ var ZodSchemaGenerator = class {
3290
3225
  }
3291
3226
  shouldCoerce(type2) {
3292
3227
  const typeMap = {
3293
- "path": "param",
3294
- "query": "query",
3295
- "header": "header",
3296
- "body": "body",
3297
- "response": "response"
3228
+ path: "param",
3229
+ query: "query",
3230
+ header: "header",
3231
+ body: "body",
3232
+ response: "response"
3298
3233
  };
3299
3234
  const mappedType = typeMap[type2] || type2;
3300
3235
  if (typeof this.options.coerce === "boolean") {
@@ -3304,11 +3239,11 @@ var ZodSchemaGenerator = class {
3304
3239
  }
3305
3240
  isStrict(type2) {
3306
3241
  const typeMap = {
3307
- "path": "param",
3308
- "query": "query",
3309
- "header": "header",
3310
- "body": "body",
3311
- "response": "response"
3242
+ path: "param",
3243
+ query: "query",
3244
+ header: "header",
3245
+ body: "body",
3246
+ response: "response"
3312
3247
  };
3313
3248
  const mappedType = typeMap[type2] || type2;
3314
3249
  if (typeof this.options.strict === "boolean") {
@@ -3335,31 +3270,19 @@ var ZodIndexGenerator = class {
3335
3270
  const sourceFile = this.project.createSourceFile(indexPath, "", {
3336
3271
  overwrite: true
3337
3272
  });
3338
- sourceFile.insertText(0, this.generateHeaderComment());
3273
+ sourceFile.insertText(0, ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT);
3339
3274
  const validatorFiles = fs.readdirSync(validatorsDir).filter((file) => file.endsWith(".validator.ts")).map((file) => file.replace(".validator.ts", ""));
3340
3275
  validatorFiles.forEach((fileName) => {
3341
3276
  sourceFile.addExportDeclaration({
3342
- namedExports: [
3343
- "*"
3344
- ],
3345
3277
  moduleSpecifier: `./${fileName}.validator`
3346
3278
  });
3347
3279
  });
3348
3280
  sourceFile.formatText();
3349
3281
  sourceFile.saveSync();
3350
3282
  }
3351
- generateHeaderComment() {
3352
- return `/**
3353
- * Validators Index
3354
- * Generated by ng-openapi
3355
- * Do not edit manually
3356
- */
3357
-
3358
- `;
3359
- }
3360
3283
  };
3361
3284
 
3362
- // src/lib/zod.generator.ts
3285
+ // src/lib/utils/default-options.ts
3363
3286
  var DEFAULT_OPTIONS = {
3364
3287
  strict: false,
3365
3288
  coerce: false,
@@ -3371,6 +3294,8 @@ var DEFAULT_OPTIONS = {
3371
3294
  response: true
3372
3295
  }
3373
3296
  };
3297
+
3298
+ // src/lib/zod.generator.ts
3374
3299
  var ZodGenerator = class {
3375
3300
  static {
3376
3301
  __name(this, "ZodGenerator");
@@ -3437,23 +3362,14 @@ var ZodGenerator = class {
3437
3362
  const sourceFile = this.project.createSourceFile(filePath, "", {
3438
3363
  overwrite: true
3439
3364
  });
3440
- sourceFile.insertText(0, this.generateHeaderComment(validatorName));
3365
+ sourceFile.insertText(0, ZOD_PLUGIN_GENERATOR_HEADER_COMMENT(validatorName));
3441
3366
  this.addImports(sourceFile, operations);
3442
3367
  for (const operation of operations) {
3443
3368
  await this.generateOperationValidators(sourceFile, operation);
3444
3369
  }
3445
- sourceFile.formatText();
3370
+ sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3446
3371
  sourceFile.saveSync();
3447
3372
  }
3448
- generateHeaderComment(validatorName) {
3449
- return `/**
3450
- * ${validatorName} Validators
3451
- * Generated by ng-openapi
3452
- * Do not edit manually
3453
- */
3454
-
3455
- `;
3456
- }
3457
3373
  addImports(sourceFile, operations) {
3458
3374
  sourceFile.addImportDeclaration({
3459
3375
  namedImports: [
@@ -3461,13 +3377,6 @@ var ZodGenerator = class {
3461
3377
  ],
3462
3378
  moduleSpecifier: "zod"
3463
3379
  });
3464
- const usedTypes = collectUsedTypes(operations);
3465
- if (usedTypes.size > 0) {
3466
- sourceFile.addImportDeclaration({
3467
- namedImports: Array.from(usedTypes).sort(),
3468
- moduleSpecifier: "../models"
3469
- });
3470
- }
3471
3380
  }
3472
3381
  async generateOperationValidators(sourceFile, operation) {
3473
3382
  const operationName = this.getOperationName(operation);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-openapi/zod",
3
- "version": "0.0.2-pr-26-feature-zod-c60713a.0",
3
+ "version": "0.0.2-pr-32-feature-zod-5c9aca1.0",
4
4
  "description": "Zod validation plugin for ng-openapi - Generate Zod schemas from OpenAPI specifications",
5
5
  "keywords": [
6
6
  "angular",