@ng-openapi/zod 0.0.2-pr-32-feature-zod-5c9aca1.0 → 0.0.2-pr-32-feature-zod-d5a9e54.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 (3) hide show
  1. package/index.cjs +13 -6
  2. package/index.js +13 -6
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -3398,11 +3398,15 @@ var ZodGenerator = class {
3398
3398
  });
3399
3399
  sourceFile.insertText(0, ZOD_PLUGIN_GENERATOR_HEADER_COMMENT(validatorName));
3400
3400
  this.addImports(sourceFile, operations);
3401
+ const _statements = [];
3401
3402
  for (const operation of operations) {
3402
- await this.generateOperationValidators(sourceFile, operation);
3403
+ const statements = await this.generateOperationValidators(sourceFile, operation);
3404
+ _statements.push(...statements);
3405
+ }
3406
+ if (_statements.length > 0) {
3407
+ sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3408
+ sourceFile.saveSync();
3403
3409
  }
3404
- sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3405
- sourceFile.saveSync();
3406
3410
  }
3407
3411
  addImports(sourceFile, operations) {
3408
3412
  sourceFile.addImportDeclaration({
@@ -3414,24 +3418,27 @@ var ZodGenerator = class {
3414
3418
  }
3415
3419
  async generateOperationValidators(sourceFile, operation) {
3416
3420
  const operationName = this.getOperationName(operation);
3421
+ const statements = [];
3417
3422
  if (this.shouldGenerate("param") || this.shouldGenerate("query") || this.shouldGenerate("header")) {
3418
3423
  const params = await this.generateParameterValidators(operation, operationName);
3419
3424
  if (params.length > 0) {
3420
- sourceFile.addStatements(params);
3425
+ statements.push(...params);
3421
3426
  }
3422
3427
  }
3423
3428
  if (this.shouldGenerate("body") && operation.requestBody) {
3424
3429
  const bodyValidators = await this.schemaGenerator.generateBodyValidator(operation, operationName);
3425
3430
  if (bodyValidators.length > 0) {
3426
- sourceFile.addStatements(bodyValidators);
3431
+ statements.push(...bodyValidators);
3427
3432
  }
3428
3433
  }
3429
3434
  if (this.shouldGenerate("response")) {
3430
3435
  const responseValidators = await this.schemaGenerator.generateResponseValidators(operation, operationName);
3431
3436
  if (responseValidators.length > 0) {
3432
- sourceFile.addStatements(responseValidators);
3437
+ statements.push(...responseValidators);
3433
3438
  }
3434
3439
  }
3440
+ sourceFile.addStatements(statements);
3441
+ return statements;
3435
3442
  }
3436
3443
  async generateParameterValidators(operation, operationName) {
3437
3444
  const statements = [];
package/index.js CHANGED
@@ -3364,11 +3364,15 @@ var ZodGenerator = class {
3364
3364
  });
3365
3365
  sourceFile.insertText(0, ZOD_PLUGIN_GENERATOR_HEADER_COMMENT(validatorName));
3366
3366
  this.addImports(sourceFile, operations);
3367
+ const _statements = [];
3367
3368
  for (const operation of operations) {
3368
- await this.generateOperationValidators(sourceFile, operation);
3369
+ const statements = await this.generateOperationValidators(sourceFile, operation);
3370
+ _statements.push(...statements);
3371
+ }
3372
+ if (_statements.length > 0) {
3373
+ sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3374
+ sourceFile.saveSync();
3369
3375
  }
3370
- sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
3371
- sourceFile.saveSync();
3372
3376
  }
3373
3377
  addImports(sourceFile, operations) {
3374
3378
  sourceFile.addImportDeclaration({
@@ -3380,24 +3384,27 @@ var ZodGenerator = class {
3380
3384
  }
3381
3385
  async generateOperationValidators(sourceFile, operation) {
3382
3386
  const operationName = this.getOperationName(operation);
3387
+ const statements = [];
3383
3388
  if (this.shouldGenerate("param") || this.shouldGenerate("query") || this.shouldGenerate("header")) {
3384
3389
  const params = await this.generateParameterValidators(operation, operationName);
3385
3390
  if (params.length > 0) {
3386
- sourceFile.addStatements(params);
3391
+ statements.push(...params);
3387
3392
  }
3388
3393
  }
3389
3394
  if (this.shouldGenerate("body") && operation.requestBody) {
3390
3395
  const bodyValidators = await this.schemaGenerator.generateBodyValidator(operation, operationName);
3391
3396
  if (bodyValidators.length > 0) {
3392
- sourceFile.addStatements(bodyValidators);
3397
+ statements.push(...bodyValidators);
3393
3398
  }
3394
3399
  }
3395
3400
  if (this.shouldGenerate("response")) {
3396
3401
  const responseValidators = await this.schemaGenerator.generateResponseValidators(operation, operationName);
3397
3402
  if (responseValidators.length > 0) {
3398
- sourceFile.addStatements(responseValidators);
3403
+ statements.push(...responseValidators);
3399
3404
  }
3400
3405
  }
3406
+ sourceFile.addStatements(statements);
3407
+ return statements;
3401
3408
  }
3402
3409
  async generateParameterValidators(operation, operationName) {
3403
3410
  const statements = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-openapi/zod",
3
- "version": "0.0.2-pr-32-feature-zod-5c9aca1.0",
3
+ "version": "0.0.2-pr-32-feature-zod-d5a9e54.0",
4
4
  "description": "Zod validation plugin for ng-openapi - Generate Zod schemas from OpenAPI specifications",
5
5
  "keywords": [
6
6
  "angular",
@@ -60,7 +60,7 @@
60
60
  "peerDependencies": {
61
61
  "ng-openapi": ">=0.2",
62
62
  "ts-morph": "*",
63
- "zod": ">=3"
63
+ "zod": ">=4"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "ng-openapi": {