@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.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ type Props = {
|
|
|
13
13
|
writeFilesToRoot?: boolean;
|
|
14
14
|
sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
|
|
15
15
|
httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
|
|
16
|
+
preserveExistingMessages?: boolean;
|
|
16
17
|
};
|
|
17
18
|
declare const _default: (_: any, options: Props) => Promise<void>;
|
|
18
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type Props = {
|
|
|
13
13
|
writeFilesToRoot?: boolean;
|
|
14
14
|
sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
|
|
15
15
|
httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
|
|
16
|
+
preserveExistingMessages?: boolean;
|
|
16
17
|
};
|
|
17
18
|
declare const _default: (_: any, options: Props) => Promise<void>;
|
|
18
19
|
|
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,115 +1608,136 @@ 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) => {
|
|
1717
1737
|
const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
|
|
1718
1738
|
const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
|
|
1719
1739
|
const version = document.info.version;
|
|
1740
|
+
const preserveExistingMessages = options.preserveExistingMessages ?? true;
|
|
1720
1741
|
let receives = [], sends = [];
|
|
1721
1742
|
for (const operation of operations) {
|
|
1722
1743
|
const { requestBodiesAndResponses, sidebar, ...message } = await buildMessage(pathToSpec, document, operation);
|
|
@@ -1733,10 +1754,12 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1733
1754
|
} = getMessageTypeUtils(process.env.PROJECT_DIR, messageType);
|
|
1734
1755
|
const catalogedMessage = await getMessage(message.id, "latest");
|
|
1735
1756
|
if (catalogedMessage) {
|
|
1736
|
-
|
|
1737
|
-
|
|
1757
|
+
if (preserveExistingMessages) {
|
|
1758
|
+
messageMarkdown = catalogedMessage.markdown;
|
|
1759
|
+
}
|
|
1760
|
+
if (catalogedMessage.version !== version && !options.serviceHasMultipleSpecFiles) {
|
|
1738
1761
|
await versionMessage(message.id);
|
|
1739
|
-
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})`));
|
|
1740
1763
|
}
|
|
1741
1764
|
}
|
|
1742
1765
|
let messagePath = (0, import_node_path.join)(servicePath, folder, message.id);
|
|
@@ -1751,7 +1774,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1751
1774
|
// only if its defined add it to the sidebar
|
|
1752
1775
|
...sidebarBadgeType === "HTTP_METHOD" ? { sidebar } : {}
|
|
1753
1776
|
},
|
|
1754
|
-
{ path: messagePath, override: true }
|
|
1777
|
+
{ path: options.pathForMessages || messagePath, override: true }
|
|
1755
1778
|
);
|
|
1756
1779
|
if (messageAction === "sends") {
|
|
1757
1780
|
sends.push({
|
|
@@ -1813,17 +1836,19 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1813
1836
|
return { receives, sends };
|
|
1814
1837
|
};
|
|
1815
1838
|
var getParsedSpecFile = (service, document) => {
|
|
1816
|
-
const
|
|
1839
|
+
const specPath = service.path;
|
|
1840
|
+
const isSpecFileJSON = specPath.endsWith(".json");
|
|
1817
1841
|
return isSpecFileJSON ? JSON.stringify(document, null, 2) : import_js_yaml.default.dump(document, { noRefs: true });
|
|
1818
1842
|
};
|
|
1819
1843
|
var getRawSpecFile = async (service) => {
|
|
1820
|
-
|
|
1821
|
-
|
|
1844
|
+
const specPath = service.path;
|
|
1845
|
+
if (specPath.startsWith("http")) {
|
|
1846
|
+
const file = await fetch(specPath, { method: "GET" });
|
|
1822
1847
|
if (!file.ok) {
|
|
1823
|
-
throw new Error(`Failed to fetch file: ${
|
|
1848
|
+
throw new Error(`Failed to fetch file: ${specPath}, status: ${file.status}`);
|
|
1824
1849
|
}
|
|
1825
1850
|
return await file.text();
|
|
1826
1851
|
}
|
|
1827
|
-
return await (0, import_promises.readFile)(
|
|
1852
|
+
return await (0, import_promises.readFile)(specPath, "utf8");
|
|
1828
1853
|
};
|
|
1829
1854
|
//# sourceMappingURL=index.js.map
|