@eventcatalog/generator-openapi 5.0.5 → 6.0.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.
- package/dist/index.js +124 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -102
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -640,7 +640,7 @@ var import_chalk = __toESM(require("chalk"));
|
|
|
640
640
|
// package.json
|
|
641
641
|
var package_default = {
|
|
642
642
|
name: "@eventcatalog/generator-openapi",
|
|
643
|
-
version: "
|
|
643
|
+
version: "6.0.0",
|
|
644
644
|
description: "OpenAPI generator for EventCatalog",
|
|
645
645
|
scripts: {
|
|
646
646
|
build: "tsup",
|
|
@@ -676,7 +676,7 @@ var package_default = {
|
|
|
676
676
|
dependencies: {
|
|
677
677
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
678
678
|
"@changesets/cli": "^2.27.7",
|
|
679
|
-
"@eventcatalog/sdk": "^2.
|
|
679
|
+
"@eventcatalog/sdk": "^2.3.7",
|
|
680
680
|
chalk: "^4",
|
|
681
681
|
"js-yaml": "^4.1.0",
|
|
682
682
|
"openapi-types": "^12.1.3",
|
|
@@ -1608,109 +1608,129 @@ var index_default = async (_, options) => {
|
|
|
1608
1608
|
} = (0, import_sdk2.default)(process.env.PROJECT_DIR);
|
|
1609
1609
|
const { services = [], saveParsedSpecFile = false } = options;
|
|
1610
1610
|
for (const serviceSpec of services) {
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
let serviceSpecifications = service.specifications;
|
|
1625
|
-
let servicePath = options.domain ? (0, import_node_path.join)("../", "domains", options.domain.id, "services", service.id) : (0, import_node_path.join)("../", "services", service.id);
|
|
1626
|
-
if (options.writeFilesToRoot) {
|
|
1627
|
-
servicePath = service.id;
|
|
1628
|
-
}
|
|
1629
|
-
if (options.domain) {
|
|
1630
|
-
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
1631
|
-
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
1632
|
-
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
1633
|
-
console.log(import_chalk3.default.blue(`
|
|
1634
|
-
Processing domain: ${domainName} (v${domainVersion})`));
|
|
1635
|
-
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
1636
|
-
await versionDomain(domainId);
|
|
1637
|
-
console.log(import_chalk3.default.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
1611
|
+
const specFiles = Array.isArray(serviceSpec.path) ? serviceSpec.path : [serviceSpec.path];
|
|
1612
|
+
const specs = specFiles.map(async (specFile) => {
|
|
1613
|
+
try {
|
|
1614
|
+
await import_swagger_parser2.default.validate(specFile);
|
|
1615
|
+
const document = await import_swagger_parser2.default.dereference(specFile);
|
|
1616
|
+
return {
|
|
1617
|
+
document,
|
|
1618
|
+
path: specFile
|
|
1619
|
+
};
|
|
1620
|
+
} catch (error) {
|
|
1621
|
+
console.error(import_chalk3.default.red(`Failed to parse OpenAPI file: ${serviceSpec.path}`));
|
|
1622
|
+
console.error(import_chalk3.default.red(error));
|
|
1623
|
+
return null;
|
|
1638
1624
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1625
|
+
});
|
|
1626
|
+
const validSpecs = await Promise.all(specs);
|
|
1627
|
+
const validSpecFiles = validSpecs.filter((v) => v !== null);
|
|
1628
|
+
const orderedSpecs = validSpecFiles.sort((a, b) => {
|
|
1629
|
+
const versionA = a?.document.info.version ?? "";
|
|
1630
|
+
const versionB = b?.document.info.version ?? "";
|
|
1631
|
+
return versionA.localeCompare(versionB);
|
|
1632
|
+
});
|
|
1633
|
+
for (const specification of orderedSpecs) {
|
|
1634
|
+
const document = specification.document;
|
|
1635
|
+
const version = document.info.version;
|
|
1636
|
+
const specPath = specification.path;
|
|
1637
|
+
const service = buildService({ ...serviceSpec, path: specPath }, document);
|
|
1638
|
+
let serviceMarkdown = service.markdown;
|
|
1639
|
+
let serviceSpecificationsFiles = [];
|
|
1640
|
+
let serviceSpecifications = service.specifications;
|
|
1641
|
+
let servicePath = options.domain ? (0, import_node_path.join)("../", "domains", options.domain.id, "services", service.id) : (0, import_node_path.join)("../", "services", service.id);
|
|
1642
|
+
if (options.writeFilesToRoot) {
|
|
1643
|
+
servicePath = service.id;
|
|
1648
1644
|
}
|
|
1649
|
-
if (
|
|
1650
|
-
|
|
1645
|
+
if (options.domain) {
|
|
1646
|
+
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
1647
|
+
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
1648
|
+
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
1649
|
+
console.log(import_chalk3.default.blue(`
|
|
1650
|
+
Processing domain: ${domainName} (v${domainVersion})`));
|
|
1651
|
+
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
1652
|
+
await versionDomain(domainId);
|
|
1653
|
+
console.log(import_chalk3.default.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
1654
|
+
}
|
|
1655
|
+
if (!domain || domain && domain.version !== domainVersion) {
|
|
1656
|
+
await writeDomain({
|
|
1657
|
+
id: domainId,
|
|
1658
|
+
name: domainName,
|
|
1659
|
+
version: domainVersion,
|
|
1660
|
+
markdown: defaultMarkdown(),
|
|
1661
|
+
...options.domain?.owners ? { owners: options.domain.owners } : {}
|
|
1662
|
+
});
|
|
1663
|
+
console.log(import_chalk3.default.cyan(` - Domain (v${domainVersion}) created`));
|
|
1664
|
+
}
|
|
1665
|
+
if (currentDomain && currentDomain.version === domainVersion) {
|
|
1666
|
+
console.log(import_chalk3.default.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));
|
|
1667
|
+
}
|
|
1668
|
+
await addServiceToDomain(domainId, { id: service.id, version: service.version }, domainVersion);
|
|
1651
1669
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
owners: service.setMessageOwnersToServiceOwners ? service.owners : []
|
|
1657
|
-
});
|
|
1658
|
-
let owners = service.owners || [];
|
|
1659
|
-
let repository = null;
|
|
1660
|
-
let styles2 = null;
|
|
1661
|
-
const latestServiceInCatalog = await getService(service.id, "latest");
|
|
1662
|
-
console.log(import_chalk3.default.blue(`Processing service: ${document.info.title} (v${version})`));
|
|
1663
|
-
if (latestServiceInCatalog) {
|
|
1664
|
-
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
1665
|
-
serviceSpecificationsFiles = await getSpecificationFilesForService(service.id, "latest");
|
|
1666
|
-
sends = latestServiceInCatalog.sends || [];
|
|
1667
|
-
owners = latestServiceInCatalog.owners || [];
|
|
1668
|
-
repository = latestServiceInCatalog.repository || null;
|
|
1669
|
-
styles2 = latestServiceInCatalog.styles || null;
|
|
1670
|
-
serviceSpecifications = {
|
|
1671
|
-
...serviceSpecifications,
|
|
1672
|
-
...latestServiceInCatalog.specifications
|
|
1673
|
-
};
|
|
1674
|
-
if (latestServiceInCatalog.version !== version) {
|
|
1670
|
+
const latestServiceInCatalog = await getService(service.id, "latest");
|
|
1671
|
+
const versionTheService = latestServiceInCatalog && latestServiceInCatalog.version !== version;
|
|
1672
|
+
console.log(import_chalk3.default.blue(`Processing service: ${document.info.title} (v${version})`));
|
|
1673
|
+
if (versionTheService) {
|
|
1675
1674
|
await versionService(service.id);
|
|
1676
1675
|
console.log(import_chalk3.default.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
|
|
1677
1676
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1677
|
+
let { sends, receives } = await processMessagesForOpenAPISpec(specPath, document, servicePath, {
|
|
1678
|
+
...options,
|
|
1679
|
+
owners: service.setMessageOwnersToServiceOwners ? service.owners : [],
|
|
1680
|
+
serviceHasMultipleSpecFiles: Array.isArray(serviceSpec.path)
|
|
1681
|
+
});
|
|
1682
|
+
let owners = service.owners || [];
|
|
1683
|
+
let repository = null;
|
|
1684
|
+
let styles2 = null;
|
|
1685
|
+
const persistPreviousSpecificationFiles = Array.isArray(serviceSpec.path) === false;
|
|
1686
|
+
if (latestServiceInCatalog) {
|
|
1687
|
+
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
1688
|
+
serviceSpecificationsFiles = await getSpecificationFilesForService(service.id, "latest");
|
|
1689
|
+
sends = latestServiceInCatalog.sends || [];
|
|
1690
|
+
owners = latestServiceInCatalog.owners || [];
|
|
1691
|
+
repository = latestServiceInCatalog.repository || null;
|
|
1692
|
+
styles2 = latestServiceInCatalog.styles || null;
|
|
1693
|
+
serviceSpecifications = {
|
|
1694
|
+
...serviceSpecifications,
|
|
1695
|
+
...persistPreviousSpecificationFiles ? latestServiceInCatalog.specifications : {}
|
|
1696
|
+
};
|
|
1697
|
+
if (latestServiceInCatalog.version === version) {
|
|
1698
|
+
receives = latestServiceInCatalog.receives ? [...latestServiceInCatalog.receives, ...receives] : receives;
|
|
1699
|
+
}
|
|
1701
1700
|
}
|
|
1702
|
-
|
|
1703
|
-
for (const specFile of specFiles) {
|
|
1704
|
-
await addFileToService(
|
|
1705
|
-
service.id,
|
|
1701
|
+
await writeService(
|
|
1706
1702
|
{
|
|
1707
|
-
|
|
1708
|
-
|
|
1703
|
+
...service,
|
|
1704
|
+
markdown: serviceMarkdown,
|
|
1705
|
+
specifications: serviceSpecifications,
|
|
1706
|
+
sends,
|
|
1707
|
+
receives,
|
|
1708
|
+
...owners ? { owners } : {},
|
|
1709
|
+
...repository ? { repository } : {},
|
|
1710
|
+
...styles2 ? { styles: styles2 } : {}
|
|
1709
1711
|
},
|
|
1710
|
-
|
|
1712
|
+
{ path: (0, import_node_path.join)(servicePath), override: true }
|
|
1711
1713
|
);
|
|
1714
|
+
const specFiles2 = [
|
|
1715
|
+
// add any previous spec files to the list
|
|
1716
|
+
...persistPreviousSpecificationFiles ? serviceSpecificationsFiles : [],
|
|
1717
|
+
{
|
|
1718
|
+
content: saveParsedSpecFile ? getParsedSpecFile({ ...serviceSpec, path: specPath }, document) : await getRawSpecFile({ ...serviceSpec, path: specPath }),
|
|
1719
|
+
fileName: service.schemaPath
|
|
1720
|
+
}
|
|
1721
|
+
];
|
|
1722
|
+
for (const specFile of specFiles2) {
|
|
1723
|
+
await addFileToService(
|
|
1724
|
+
service.id,
|
|
1725
|
+
{
|
|
1726
|
+
fileName: specFile.fileName,
|
|
1727
|
+
content: specFile.content
|
|
1728
|
+
},
|
|
1729
|
+
version
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
console.log(import_chalk3.default.cyan(` - Service (v${version}) created`));
|
|
1712
1733
|
}
|
|
1713
|
-
console.log(import_chalk3.default.cyan(` - Service (v${version}) created`));
|
|
1714
1734
|
}
|
|
1715
1735
|
};
|
|
1716
1736
|
var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, options) => {
|
|
@@ -1737,9 +1757,9 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1737
1757
|
if (preserveExistingMessages) {
|
|
1738
1758
|
messageMarkdown = catalogedMessage.markdown;
|
|
1739
1759
|
}
|
|
1740
|
-
if (catalogedMessage.version !== version) {
|
|
1760
|
+
if (catalogedMessage.version !== version && !options.serviceHasMultipleSpecFiles) {
|
|
1741
1761
|
await versionMessage(message.id);
|
|
1742
|
-
console.log(import_chalk3.default.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
|
|
1762
|
+
console.log(import_chalk3.default.cyan(` - Versioned previous message: ${message.id} (v${catalogedMessage.version})`));
|
|
1743
1763
|
}
|
|
1744
1764
|
}
|
|
1745
1765
|
let messagePath = (0, import_node_path.join)(servicePath, folder, message.id);
|
|
@@ -1754,7 +1774,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1754
1774
|
// only if its defined add it to the sidebar
|
|
1755
1775
|
...sidebarBadgeType === "HTTP_METHOD" ? { sidebar } : {}
|
|
1756
1776
|
},
|
|
1757
|
-
{ path: messagePath, override: true }
|
|
1777
|
+
{ path: options.pathForMessages || messagePath, override: true }
|
|
1758
1778
|
);
|
|
1759
1779
|
if (messageAction === "sends") {
|
|
1760
1780
|
sends.push({
|
|
@@ -1816,17 +1836,19 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1816
1836
|
return { receives, sends };
|
|
1817
1837
|
};
|
|
1818
1838
|
var getParsedSpecFile = (service, document) => {
|
|
1819
|
-
const
|
|
1839
|
+
const specPath = service.path;
|
|
1840
|
+
const isSpecFileJSON = specPath.endsWith(".json");
|
|
1820
1841
|
return isSpecFileJSON ? JSON.stringify(document, null, 2) : import_js_yaml.default.dump(document, { noRefs: true });
|
|
1821
1842
|
};
|
|
1822
1843
|
var getRawSpecFile = async (service) => {
|
|
1823
|
-
|
|
1824
|
-
|
|
1844
|
+
const specPath = service.path;
|
|
1845
|
+
if (specPath.startsWith("http")) {
|
|
1846
|
+
const file = await fetch(specPath, { method: "GET" });
|
|
1825
1847
|
if (!file.ok) {
|
|
1826
|
-
throw new Error(`Failed to fetch file: ${
|
|
1848
|
+
throw new Error(`Failed to fetch file: ${specPath}, status: ${file.status}`);
|
|
1827
1849
|
}
|
|
1828
1850
|
return await file.text();
|
|
1829
1851
|
}
|
|
1830
|
-
return await (0, import_promises.readFile)(
|
|
1852
|
+
return await (0, import_promises.readFile)(specPath, "utf8");
|
|
1831
1853
|
};
|
|
1832
1854
|
//# sourceMappingURL=index.js.map
|