ng-openapi 0.0.2 → 0.0.3

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/cli.cjs +61 -16
  2. package/index.js +57 -13
  3. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
 
27
27
  // src/lib/cli.ts
28
28
  var import_commander = require("commander");
29
- var path6 = __toESM(require("path"));
29
+ var path7 = __toESM(require("path"));
30
30
  var fs4 = __toESM(require("fs"));
31
31
 
32
32
  // src/lib/core/swagger-parser.ts
@@ -85,6 +85,10 @@ var SERVICE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((controllerName) =
85
85
  * Do not edit this file manually
86
86
  */
87
87
  `, "SERVICE_GENERATOR_HEADER_COMMENT");
88
+ var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
89
+ * Do not edit this file manually
90
+ */
91
+ `;
88
92
 
89
93
  // src/lib/generators/type/type.generator.ts
90
94
  var TypeGenerator = class {
@@ -705,9 +709,48 @@ var DateTransformerGenerator = class {
705
709
  }
706
710
  };
707
711
 
712
+ // src/lib/generators/utility/main-index.generator.ts
713
+ var path4 = __toESM(require("path"));
714
+ var MainIndexGenerator = class {
715
+ static {
716
+ __name(this, "MainIndexGenerator");
717
+ }
718
+ project;
719
+ config;
720
+ constructor(project, config) {
721
+ this.project = project;
722
+ this.config = config;
723
+ }
724
+ generateMainIndex(outputRoot) {
725
+ const indexPath = path4.join(outputRoot, "index.ts");
726
+ const sourceFile = this.project.createSourceFile(indexPath, "", {
727
+ overwrite: true
728
+ });
729
+ sourceFile.insertText(0, MAIN_INDEX_GENERATOR_HEADER_COMMENT);
730
+ sourceFile.addExportDeclaration({
731
+ moduleSpecifier: "./models"
732
+ });
733
+ sourceFile.addExportDeclaration({
734
+ moduleSpecifier: "./services"
735
+ });
736
+ sourceFile.addExportDeclaration({
737
+ moduleSpecifier: "./tokens"
738
+ });
739
+ if (this.config.options.dateType === "Date") {
740
+ sourceFile.addExportDeclaration({
741
+ moduleSpecifier: "./utils/date-transformer"
742
+ });
743
+ }
744
+ sourceFile.addExportDeclaration({
745
+ moduleSpecifier: "./utils/file-download"
746
+ });
747
+ sourceFile.saveSync();
748
+ }
749
+ };
750
+
708
751
  // src/lib/generators/service/service.generator.ts
709
752
  var import_ts_morph3 = require("ts-morph");
710
- var path4 = __toESM(require("path"));
753
+ var path5 = __toESM(require("path"));
711
754
 
712
755
  // src/lib/utils/string.utils.ts
713
756
  function camelCase(str) {
@@ -1434,7 +1477,7 @@ var ServiceGenerator = class {
1434
1477
  this.methodGenerator = new ServiceMethodGenerator(config);
1435
1478
  }
1436
1479
  generate(outputRoot) {
1437
- const outputDir = path4.join(outputRoot, "services");
1480
+ const outputDir = path5.join(outputRoot, "services");
1438
1481
  const paths = this.extractPaths();
1439
1482
  const controllerGroups = this.groupPathsByController(paths);
1440
1483
  Object.entries(controllerGroups).forEach(([controllerName, operations]) => {
@@ -1444,7 +1487,7 @@ var ServiceGenerator = class {
1444
1487
  extractPaths() {
1445
1488
  const paths = [];
1446
1489
  const swaggerPaths = this.spec.paths || {};
1447
- Object.entries(swaggerPaths).forEach(([path7, pathItem]) => {
1490
+ Object.entries(swaggerPaths).forEach(([path8, pathItem]) => {
1448
1491
  const methods = [
1449
1492
  "get",
1450
1493
  "post",
@@ -1458,7 +1501,7 @@ var ServiceGenerator = class {
1458
1501
  if (pathItem[method]) {
1459
1502
  const operation = pathItem[method];
1460
1503
  paths.push({
1461
- path: path7,
1504
+ path: path8,
1462
1505
  method: method.toUpperCase(),
1463
1506
  operationId: operation.operationId,
1464
1507
  summary: operation.summary,
@@ -1490,12 +1533,12 @@ var ServiceGenerator = class {
1490
1533
  }
1491
1534
  groupPathsByController(paths) {
1492
1535
  const groups = {};
1493
- paths.forEach((path7) => {
1536
+ paths.forEach((path8) => {
1494
1537
  let controllerName = "Default";
1495
- if (path7.tags && path7.tags.length > 0) {
1496
- controllerName = path7.tags[0];
1538
+ if (path8.tags && path8.tags.length > 0) {
1539
+ controllerName = path8.tags[0];
1497
1540
  } else {
1498
- const pathParts = path7.path.split("/").filter((p) => p && !p.startsWith("{"));
1541
+ const pathParts = path8.path.split("/").filter((p) => p && !p.startsWith("{"));
1499
1542
  if (pathParts.length > 1) {
1500
1543
  controllerName = pascalCase(pathParts[1]);
1501
1544
  }
@@ -1504,13 +1547,13 @@ var ServiceGenerator = class {
1504
1547
  if (!groups[controllerName]) {
1505
1548
  groups[controllerName] = [];
1506
1549
  }
1507
- groups[controllerName].push(path7);
1550
+ groups[controllerName].push(path8);
1508
1551
  });
1509
1552
  return groups;
1510
1553
  }
1511
1554
  generateServiceFile(controllerName, operations, outputDir) {
1512
1555
  const fileName = `${kebabCase(controllerName)}.service.ts`;
1513
- const filePath = path4.join(outputDir, fileName);
1556
+ const filePath = path5.join(outputDir, fileName);
1514
1557
  const sourceFile = this.project.createSourceFile(filePath, "", {
1515
1558
  overwrite: true
1516
1559
  });
@@ -1667,7 +1710,7 @@ var ServiceGenerator = class {
1667
1710
 
1668
1711
  // src/lib/generators/service/service-index.generator.ts
1669
1712
  var fs2 = __toESM(require("fs"));
1670
- var path5 = __toESM(require("path"));
1713
+ var path6 = __toESM(require("path"));
1671
1714
  var ServiceIndexGenerator = class {
1672
1715
  static {
1673
1716
  __name(this, "ServiceIndexGenerator");
@@ -1677,8 +1720,8 @@ var ServiceIndexGenerator = class {
1677
1720
  this.project = project;
1678
1721
  }
1679
1722
  generateIndex(outputRoot) {
1680
- const servicesDir = path5.join(outputRoot, "services");
1681
- const indexPath = path5.join(servicesDir, "index.ts");
1723
+ const servicesDir = path6.join(outputRoot, "services");
1724
+ const indexPath = path6.join(servicesDir, "index.ts");
1682
1725
  const sourceFile = this.project.createSourceFile(indexPath, "", {
1683
1726
  overwrite: true
1684
1727
  });
@@ -1740,6 +1783,8 @@ async function generateFromConfig(config) {
1740
1783
  indexGenerator.generateIndex(outputPath);
1741
1784
  console.log(`\u2705 Angular services generated`);
1742
1785
  }
1786
+ const mainIndexGenerator = new MainIndexGenerator(project, config);
1787
+ mainIndexGenerator.generateMainIndex(outputPath);
1743
1788
  console.log("\u{1F389} Generation completed successfully at:", outputPath);
1744
1789
  } catch (error) {
1745
1790
  if (error instanceof Error) {
@@ -1755,7 +1800,7 @@ __name(generateFromConfig, "generateFromConfig");
1755
1800
  // src/lib/cli.ts
1756
1801
  var program = new import_commander.Command();
1757
1802
  async function loadConfigFile(configPath) {
1758
- const resolvedPath = path6.resolve(configPath);
1803
+ const resolvedPath = path7.resolve(configPath);
1759
1804
  if (!fs4.existsSync(resolvedPath)) {
1760
1805
  throw new Error(`Configuration file not found: ${resolvedPath}`);
1761
1806
  }
@@ -1781,7 +1826,7 @@ async function generateFromOptions(options) {
1781
1826
  const config = await loadConfigFile(options.config);
1782
1827
  await generateFromConfig(config);
1783
1828
  } else if (options.input) {
1784
- const inputPath = path6.resolve(options.input);
1829
+ const inputPath = path7.resolve(options.input);
1785
1830
  if (!fs4.existsSync(inputPath)) {
1786
1831
  console.error(`Error: Input file not found: ${inputPath}`);
1787
1832
  process.exit(1);
package/index.js CHANGED
@@ -127,6 +127,10 @@ var SERVICE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((controllerName) =
127
127
  * Do not edit this file manually
128
128
  */
129
129
  `, "SERVICE_GENERATOR_HEADER_COMMENT");
130
+ var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
131
+ * Do not edit this file manually
132
+ */
133
+ `;
130
134
 
131
135
  // src/lib/generators/type/type.generator.ts
132
136
  var _TypeGenerator = class _TypeGenerator {
@@ -745,9 +749,47 @@ var _DateTransformerGenerator = class _DateTransformerGenerator {
745
749
  __name(_DateTransformerGenerator, "DateTransformerGenerator");
746
750
  var DateTransformerGenerator = _DateTransformerGenerator;
747
751
 
752
+ // src/lib/generators/utility/main-index.generator.ts
753
+ var path4 = __toESM(require("path"));
754
+ var _MainIndexGenerator = class _MainIndexGenerator {
755
+ constructor(project, config) {
756
+ __publicField(this, "project");
757
+ __publicField(this, "config");
758
+ this.project = project;
759
+ this.config = config;
760
+ }
761
+ generateMainIndex(outputRoot) {
762
+ const indexPath = path4.join(outputRoot, "index.ts");
763
+ const sourceFile = this.project.createSourceFile(indexPath, "", {
764
+ overwrite: true
765
+ });
766
+ sourceFile.insertText(0, MAIN_INDEX_GENERATOR_HEADER_COMMENT);
767
+ sourceFile.addExportDeclaration({
768
+ moduleSpecifier: "./models"
769
+ });
770
+ sourceFile.addExportDeclaration({
771
+ moduleSpecifier: "./services"
772
+ });
773
+ sourceFile.addExportDeclaration({
774
+ moduleSpecifier: "./tokens"
775
+ });
776
+ if (this.config.options.dateType === "Date") {
777
+ sourceFile.addExportDeclaration({
778
+ moduleSpecifier: "./utils/date-transformer"
779
+ });
780
+ }
781
+ sourceFile.addExportDeclaration({
782
+ moduleSpecifier: "./utils/file-download"
783
+ });
784
+ sourceFile.saveSync();
785
+ }
786
+ };
787
+ __name(_MainIndexGenerator, "MainIndexGenerator");
788
+ var MainIndexGenerator = _MainIndexGenerator;
789
+
748
790
  // src/lib/generators/service/service.generator.ts
749
791
  var import_ts_morph3 = require("ts-morph");
750
- var path4 = __toESM(require("path"));
792
+ var path5 = __toESM(require("path"));
751
793
 
752
794
  // src/lib/utils/string.utils.ts
753
795
  function camelCase(str) {
@@ -1478,7 +1520,7 @@ var _ServiceGenerator = class _ServiceGenerator {
1478
1520
  this.methodGenerator = new ServiceMethodGenerator(config);
1479
1521
  }
1480
1522
  generate(outputRoot) {
1481
- const outputDir = path4.join(outputRoot, "services");
1523
+ const outputDir = path5.join(outputRoot, "services");
1482
1524
  const paths = this.extractPaths();
1483
1525
  const controllerGroups = this.groupPathsByController(paths);
1484
1526
  Object.entries(controllerGroups).forEach(([controllerName, operations]) => {
@@ -1488,7 +1530,7 @@ var _ServiceGenerator = class _ServiceGenerator {
1488
1530
  extractPaths() {
1489
1531
  const paths = [];
1490
1532
  const swaggerPaths = this.spec.paths || {};
1491
- Object.entries(swaggerPaths).forEach(([path6, pathItem]) => {
1533
+ Object.entries(swaggerPaths).forEach(([path7, pathItem]) => {
1492
1534
  const methods = [
1493
1535
  "get",
1494
1536
  "post",
@@ -1502,7 +1544,7 @@ var _ServiceGenerator = class _ServiceGenerator {
1502
1544
  if (pathItem[method]) {
1503
1545
  const operation = pathItem[method];
1504
1546
  paths.push({
1505
- path: path6,
1547
+ path: path7,
1506
1548
  method: method.toUpperCase(),
1507
1549
  operationId: operation.operationId,
1508
1550
  summary: operation.summary,
@@ -1534,12 +1576,12 @@ var _ServiceGenerator = class _ServiceGenerator {
1534
1576
  }
1535
1577
  groupPathsByController(paths) {
1536
1578
  const groups = {};
1537
- paths.forEach((path6) => {
1579
+ paths.forEach((path7) => {
1538
1580
  let controllerName = "Default";
1539
- if (path6.tags && path6.tags.length > 0) {
1540
- controllerName = path6.tags[0];
1581
+ if (path7.tags && path7.tags.length > 0) {
1582
+ controllerName = path7.tags[0];
1541
1583
  } else {
1542
- const pathParts = path6.path.split("/").filter((p) => p && !p.startsWith("{"));
1584
+ const pathParts = path7.path.split("/").filter((p) => p && !p.startsWith("{"));
1543
1585
  if (pathParts.length > 1) {
1544
1586
  controllerName = pascalCase(pathParts[1]);
1545
1587
  }
@@ -1548,13 +1590,13 @@ var _ServiceGenerator = class _ServiceGenerator {
1548
1590
  if (!groups[controllerName]) {
1549
1591
  groups[controllerName] = [];
1550
1592
  }
1551
- groups[controllerName].push(path6);
1593
+ groups[controllerName].push(path7);
1552
1594
  });
1553
1595
  return groups;
1554
1596
  }
1555
1597
  generateServiceFile(controllerName, operations, outputDir) {
1556
1598
  const fileName = `${kebabCase(controllerName)}.service.ts`;
1557
- const filePath = path4.join(outputDir, fileName);
1599
+ const filePath = path5.join(outputDir, fileName);
1558
1600
  const sourceFile = this.project.createSourceFile(filePath, "", {
1559
1601
  overwrite: true
1560
1602
  });
@@ -1714,15 +1756,15 @@ var ServiceGenerator = _ServiceGenerator;
1714
1756
 
1715
1757
  // src/lib/generators/service/service-index.generator.ts
1716
1758
  var fs2 = __toESM(require("fs"));
1717
- var path5 = __toESM(require("path"));
1759
+ var path6 = __toESM(require("path"));
1718
1760
  var _ServiceIndexGenerator = class _ServiceIndexGenerator {
1719
1761
  constructor(project) {
1720
1762
  __publicField(this, "project");
1721
1763
  this.project = project;
1722
1764
  }
1723
1765
  generateIndex(outputRoot) {
1724
- const servicesDir = path5.join(outputRoot, "services");
1725
- const indexPath = path5.join(servicesDir, "index.ts");
1766
+ const servicesDir = path6.join(outputRoot, "services");
1767
+ const indexPath = path6.join(servicesDir, "index.ts");
1726
1768
  const sourceFile = this.project.createSourceFile(indexPath, "", {
1727
1769
  overwrite: true
1728
1770
  });
@@ -1787,6 +1829,8 @@ function generateFromConfig(config) {
1787
1829
  indexGenerator.generateIndex(outputPath);
1788
1830
  console.log(`\u2705 Angular services generated`);
1789
1831
  }
1832
+ const mainIndexGenerator = new MainIndexGenerator(project, config);
1833
+ mainIndexGenerator.generateMainIndex(outputPath);
1790
1834
  console.log("\u{1F389} Generation completed successfully at:", outputPath);
1791
1835
  } catch (error) {
1792
1836
  if (error instanceof Error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-openapi",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Generate Angular services and TypeScript types from OpenAPI/Swagger specifications",
5
5
  "keywords": [
6
6
  "angular",