@eventcatalog/generator-openapi 5.0.4 → 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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +128 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -103
- 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.mjs
CHANGED
|
@@ -629,7 +629,7 @@ import chalk from "chalk";
|
|
|
629
629
|
// package.json
|
|
630
630
|
var package_default = {
|
|
631
631
|
name: "@eventcatalog/generator-openapi",
|
|
632
|
-
version: "
|
|
632
|
+
version: "6.0.0",
|
|
633
633
|
description: "OpenAPI generator for EventCatalog",
|
|
634
634
|
scripts: {
|
|
635
635
|
build: "tsup",
|
|
@@ -665,7 +665,7 @@ var package_default = {
|
|
|
665
665
|
dependencies: {
|
|
666
666
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
667
667
|
"@changesets/cli": "^2.27.7",
|
|
668
|
-
"@eventcatalog/sdk": "^2.
|
|
668
|
+
"@eventcatalog/sdk": "^2.3.7",
|
|
669
669
|
chalk: "^4",
|
|
670
670
|
"js-yaml": "^4.1.0",
|
|
671
671
|
"openapi-types": "^12.1.3",
|
|
@@ -1597,115 +1597,136 @@ var index_default = async (_, options) => {
|
|
|
1597
1597
|
} = utils2(process.env.PROJECT_DIR);
|
|
1598
1598
|
const { services = [], saveParsedSpecFile = false } = options;
|
|
1599
1599
|
for (const serviceSpec of services) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
let serviceSpecifications = service.specifications;
|
|
1614
|
-
let servicePath = options.domain ? join("../", "domains", options.domain.id, "services", service.id) : join("../", "services", service.id);
|
|
1615
|
-
if (options.writeFilesToRoot) {
|
|
1616
|
-
servicePath = service.id;
|
|
1617
|
-
}
|
|
1618
|
-
if (options.domain) {
|
|
1619
|
-
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
1620
|
-
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
1621
|
-
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
1622
|
-
console.log(chalk3.blue(`
|
|
1623
|
-
Processing domain: ${domainName} (v${domainVersion})`));
|
|
1624
|
-
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
1625
|
-
await versionDomain(domainId);
|
|
1626
|
-
console.log(chalk3.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
1600
|
+
const specFiles = Array.isArray(serviceSpec.path) ? serviceSpec.path : [serviceSpec.path];
|
|
1601
|
+
const specs = specFiles.map(async (specFile) => {
|
|
1602
|
+
try {
|
|
1603
|
+
await SwaggerParser2.validate(specFile);
|
|
1604
|
+
const document = await SwaggerParser2.dereference(specFile);
|
|
1605
|
+
return {
|
|
1606
|
+
document,
|
|
1607
|
+
path: specFile
|
|
1608
|
+
};
|
|
1609
|
+
} catch (error) {
|
|
1610
|
+
console.error(chalk3.red(`Failed to parse OpenAPI file: ${serviceSpec.path}`));
|
|
1611
|
+
console.error(chalk3.red(error));
|
|
1612
|
+
return null;
|
|
1627
1613
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1614
|
+
});
|
|
1615
|
+
const validSpecs = await Promise.all(specs);
|
|
1616
|
+
const validSpecFiles = validSpecs.filter((v) => v !== null);
|
|
1617
|
+
const orderedSpecs = validSpecFiles.sort((a, b) => {
|
|
1618
|
+
const versionA = a?.document.info.version ?? "";
|
|
1619
|
+
const versionB = b?.document.info.version ?? "";
|
|
1620
|
+
return versionA.localeCompare(versionB);
|
|
1621
|
+
});
|
|
1622
|
+
for (const specification of orderedSpecs) {
|
|
1623
|
+
const document = specification.document;
|
|
1624
|
+
const version = document.info.version;
|
|
1625
|
+
const specPath = specification.path;
|
|
1626
|
+
const service = buildService({ ...serviceSpec, path: specPath }, document);
|
|
1627
|
+
let serviceMarkdown = service.markdown;
|
|
1628
|
+
let serviceSpecificationsFiles = [];
|
|
1629
|
+
let serviceSpecifications = service.specifications;
|
|
1630
|
+
let servicePath = options.domain ? join("../", "domains", options.domain.id, "services", service.id) : join("../", "services", service.id);
|
|
1631
|
+
if (options.writeFilesToRoot) {
|
|
1632
|
+
servicePath = service.id;
|
|
1637
1633
|
}
|
|
1638
|
-
if (
|
|
1639
|
-
|
|
1634
|
+
if (options.domain) {
|
|
1635
|
+
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
1636
|
+
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
1637
|
+
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
1638
|
+
console.log(chalk3.blue(`
|
|
1639
|
+
Processing domain: ${domainName} (v${domainVersion})`));
|
|
1640
|
+
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
1641
|
+
await versionDomain(domainId);
|
|
1642
|
+
console.log(chalk3.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
1643
|
+
}
|
|
1644
|
+
if (!domain || domain && domain.version !== domainVersion) {
|
|
1645
|
+
await writeDomain({
|
|
1646
|
+
id: domainId,
|
|
1647
|
+
name: domainName,
|
|
1648
|
+
version: domainVersion,
|
|
1649
|
+
markdown: defaultMarkdown(),
|
|
1650
|
+
...options.domain?.owners ? { owners: options.domain.owners } : {}
|
|
1651
|
+
});
|
|
1652
|
+
console.log(chalk3.cyan(` - Domain (v${domainVersion}) created`));
|
|
1653
|
+
}
|
|
1654
|
+
if (currentDomain && currentDomain.version === domainVersion) {
|
|
1655
|
+
console.log(chalk3.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));
|
|
1656
|
+
}
|
|
1657
|
+
await addServiceToDomain(domainId, { id: service.id, version: service.version }, domainVersion);
|
|
1640
1658
|
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
owners: service.setMessageOwnersToServiceOwners ? service.owners : []
|
|
1646
|
-
});
|
|
1647
|
-
let owners = service.owners || [];
|
|
1648
|
-
let repository = null;
|
|
1649
|
-
let styles2 = null;
|
|
1650
|
-
const latestServiceInCatalog = await getService(service.id, "latest");
|
|
1651
|
-
console.log(chalk3.blue(`Processing service: ${document.info.title} (v${version})`));
|
|
1652
|
-
if (latestServiceInCatalog) {
|
|
1653
|
-
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
1654
|
-
serviceSpecificationsFiles = await getSpecificationFilesForService(service.id, "latest");
|
|
1655
|
-
sends = latestServiceInCatalog.sends || [];
|
|
1656
|
-
owners = latestServiceInCatalog.owners || [];
|
|
1657
|
-
repository = latestServiceInCatalog.repository || null;
|
|
1658
|
-
styles2 = latestServiceInCatalog.styles || null;
|
|
1659
|
-
serviceSpecifications = {
|
|
1660
|
-
...serviceSpecifications,
|
|
1661
|
-
...latestServiceInCatalog.specifications
|
|
1662
|
-
};
|
|
1663
|
-
if (latestServiceInCatalog.version !== version) {
|
|
1659
|
+
const latestServiceInCatalog = await getService(service.id, "latest");
|
|
1660
|
+
const versionTheService = latestServiceInCatalog && latestServiceInCatalog.version !== version;
|
|
1661
|
+
console.log(chalk3.blue(`Processing service: ${document.info.title} (v${version})`));
|
|
1662
|
+
if (versionTheService) {
|
|
1664
1663
|
await versionService(service.id);
|
|
1665
1664
|
console.log(chalk3.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
|
|
1666
1665
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1666
|
+
let { sends, receives } = await processMessagesForOpenAPISpec(specPath, document, servicePath, {
|
|
1667
|
+
...options,
|
|
1668
|
+
owners: service.setMessageOwnersToServiceOwners ? service.owners : [],
|
|
1669
|
+
serviceHasMultipleSpecFiles: Array.isArray(serviceSpec.path)
|
|
1670
|
+
});
|
|
1671
|
+
let owners = service.owners || [];
|
|
1672
|
+
let repository = null;
|
|
1673
|
+
let styles2 = null;
|
|
1674
|
+
const persistPreviousSpecificationFiles = Array.isArray(serviceSpec.path) === false;
|
|
1675
|
+
if (latestServiceInCatalog) {
|
|
1676
|
+
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
1677
|
+
serviceSpecificationsFiles = await getSpecificationFilesForService(service.id, "latest");
|
|
1678
|
+
sends = latestServiceInCatalog.sends || [];
|
|
1679
|
+
owners = latestServiceInCatalog.owners || [];
|
|
1680
|
+
repository = latestServiceInCatalog.repository || null;
|
|
1681
|
+
styles2 = latestServiceInCatalog.styles || null;
|
|
1682
|
+
serviceSpecifications = {
|
|
1683
|
+
...serviceSpecifications,
|
|
1684
|
+
...persistPreviousSpecificationFiles ? latestServiceInCatalog.specifications : {}
|
|
1685
|
+
};
|
|
1686
|
+
if (latestServiceInCatalog.version === version) {
|
|
1687
|
+
receives = latestServiceInCatalog.receives ? [...latestServiceInCatalog.receives, ...receives] : receives;
|
|
1688
|
+
}
|
|
1690
1689
|
}
|
|
1691
|
-
|
|
1692
|
-
for (const specFile of specFiles) {
|
|
1693
|
-
await addFileToService(
|
|
1694
|
-
service.id,
|
|
1690
|
+
await writeService(
|
|
1695
1691
|
{
|
|
1696
|
-
|
|
1697
|
-
|
|
1692
|
+
...service,
|
|
1693
|
+
markdown: serviceMarkdown,
|
|
1694
|
+
specifications: serviceSpecifications,
|
|
1695
|
+
sends,
|
|
1696
|
+
receives,
|
|
1697
|
+
...owners ? { owners } : {},
|
|
1698
|
+
...repository ? { repository } : {},
|
|
1699
|
+
...styles2 ? { styles: styles2 } : {}
|
|
1698
1700
|
},
|
|
1699
|
-
|
|
1701
|
+
{ path: join(servicePath), override: true }
|
|
1700
1702
|
);
|
|
1703
|
+
const specFiles2 = [
|
|
1704
|
+
// add any previous spec files to the list
|
|
1705
|
+
...persistPreviousSpecificationFiles ? serviceSpecificationsFiles : [],
|
|
1706
|
+
{
|
|
1707
|
+
content: saveParsedSpecFile ? getParsedSpecFile({ ...serviceSpec, path: specPath }, document) : await getRawSpecFile({ ...serviceSpec, path: specPath }),
|
|
1708
|
+
fileName: service.schemaPath
|
|
1709
|
+
}
|
|
1710
|
+
];
|
|
1711
|
+
for (const specFile of specFiles2) {
|
|
1712
|
+
await addFileToService(
|
|
1713
|
+
service.id,
|
|
1714
|
+
{
|
|
1715
|
+
fileName: specFile.fileName,
|
|
1716
|
+
content: specFile.content
|
|
1717
|
+
},
|
|
1718
|
+
version
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
console.log(chalk3.cyan(` - Service (v${version}) created`));
|
|
1701
1722
|
}
|
|
1702
|
-
console.log(chalk3.cyan(` - Service (v${version}) created`));
|
|
1703
1723
|
}
|
|
1704
1724
|
};
|
|
1705
1725
|
var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, options) => {
|
|
1706
1726
|
const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
|
|
1707
1727
|
const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
|
|
1708
1728
|
const version = document.info.version;
|
|
1729
|
+
const preserveExistingMessages = options.preserveExistingMessages ?? true;
|
|
1709
1730
|
let receives = [], sends = [];
|
|
1710
1731
|
for (const operation of operations) {
|
|
1711
1732
|
const { requestBodiesAndResponses, sidebar, ...message } = await buildMessage(pathToSpec, document, operation);
|
|
@@ -1722,10 +1743,12 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1722
1743
|
} = getMessageTypeUtils(process.env.PROJECT_DIR, messageType);
|
|
1723
1744
|
const catalogedMessage = await getMessage(message.id, "latest");
|
|
1724
1745
|
if (catalogedMessage) {
|
|
1725
|
-
|
|
1726
|
-
|
|
1746
|
+
if (preserveExistingMessages) {
|
|
1747
|
+
messageMarkdown = catalogedMessage.markdown;
|
|
1748
|
+
}
|
|
1749
|
+
if (catalogedMessage.version !== version && !options.serviceHasMultipleSpecFiles) {
|
|
1727
1750
|
await versionMessage(message.id);
|
|
1728
|
-
console.log(chalk3.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
|
|
1751
|
+
console.log(chalk3.cyan(` - Versioned previous message: ${message.id} (v${catalogedMessage.version})`));
|
|
1729
1752
|
}
|
|
1730
1753
|
}
|
|
1731
1754
|
let messagePath = join(servicePath, folder, message.id);
|
|
@@ -1740,7 +1763,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1740
1763
|
// only if its defined add it to the sidebar
|
|
1741
1764
|
...sidebarBadgeType === "HTTP_METHOD" ? { sidebar } : {}
|
|
1742
1765
|
},
|
|
1743
|
-
{ path: messagePath, override: true }
|
|
1766
|
+
{ path: options.pathForMessages || messagePath, override: true }
|
|
1744
1767
|
);
|
|
1745
1768
|
if (messageAction === "sends") {
|
|
1746
1769
|
sends.push({
|
|
@@ -1802,18 +1825,20 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1802
1825
|
return { receives, sends };
|
|
1803
1826
|
};
|
|
1804
1827
|
var getParsedSpecFile = (service, document) => {
|
|
1805
|
-
const
|
|
1828
|
+
const specPath = service.path;
|
|
1829
|
+
const isSpecFileJSON = specPath.endsWith(".json");
|
|
1806
1830
|
return isSpecFileJSON ? JSON.stringify(document, null, 2) : yaml.dump(document, { noRefs: true });
|
|
1807
1831
|
};
|
|
1808
1832
|
var getRawSpecFile = async (service) => {
|
|
1809
|
-
|
|
1810
|
-
|
|
1833
|
+
const specPath = service.path;
|
|
1834
|
+
if (specPath.startsWith("http")) {
|
|
1835
|
+
const file = await fetch(specPath, { method: "GET" });
|
|
1811
1836
|
if (!file.ok) {
|
|
1812
|
-
throw new Error(`Failed to fetch file: ${
|
|
1837
|
+
throw new Error(`Failed to fetch file: ${specPath}, status: ${file.status}`);
|
|
1813
1838
|
}
|
|
1814
1839
|
return await file.text();
|
|
1815
1840
|
}
|
|
1816
|
-
return await readFile(
|
|
1841
|
+
return await readFile(specPath, "utf8");
|
|
1817
1842
|
};
|
|
1818
1843
|
export {
|
|
1819
1844
|
index_default as default
|