@eventcatalog/generator-openapi 5.0.1 → 5.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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Service, Domain } from './types.mjs';
2
2
  import 'openapi-types';
3
3
 
4
+ type MESSAGE_TYPE = 'command' | 'query' | 'event';
5
+ type HTTP_METHOD = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
6
+ type HTTP_METHOD_TO_MESSAGE_TYPE = Partial<Record<HTTP_METHOD, MESSAGE_TYPE>>;
4
7
  type Props = {
5
8
  services: Service[];
6
9
  domain?: Domain;
@@ -9,7 +12,8 @@ type Props = {
9
12
  licenseKey?: string;
10
13
  writeFilesToRoot?: boolean;
11
14
  sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
15
+ httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
12
16
  };
13
17
  declare const _default: (_: any, options: Props) => Promise<void>;
14
18
 
15
- export { _default as default };
19
+ export { type HTTP_METHOD, type HTTP_METHOD_TO_MESSAGE_TYPE, _default as default };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Service, Domain } from './types.js';
2
2
  import 'openapi-types';
3
3
 
4
+ type MESSAGE_TYPE = 'command' | 'query' | 'event';
5
+ type HTTP_METHOD = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
6
+ type HTTP_METHOD_TO_MESSAGE_TYPE = Partial<Record<HTTP_METHOD, MESSAGE_TYPE>>;
4
7
  type Props = {
5
8
  services: Service[];
6
9
  domain?: Domain;
@@ -9,7 +12,8 @@ type Props = {
9
12
  licenseKey?: string;
10
13
  writeFilesToRoot?: boolean;
11
14
  sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
15
+ httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
12
16
  };
13
17
  declare const _default: (_: any, options: Props) => Promise<void>;
14
18
 
15
- export { _default as default };
19
+ export { type HTTP_METHOD, type HTTP_METHOD_TO_MESSAGE_TYPE, _default as default };
package/dist/index.js CHANGED
@@ -387,7 +387,7 @@ async function getSchemasByOperationId(filePath, operationId) {
387
387
  return;
388
388
  }
389
389
  }
390
- async function getOperationsByType(openApiPath) {
390
+ async function getOperationsByType(openApiPath, httpMethodsToMessages) {
391
391
  try {
392
392
  const api = await import_swagger_parser.default.validate(openApiPath);
393
393
  const operations = [];
@@ -395,7 +395,8 @@ async function getOperationsByType(openApiPath) {
395
395
  const pathItem = api.paths[path3];
396
396
  for (const method in pathItem) {
397
397
  const openAPIOperation = pathItem[method];
398
- const messageType = openAPIOperation["x-eventcatalog-message-type"] || DEFAULT_MESSAGE_TYPE;
398
+ const defaultMessageType = httpMethodsToMessages?.[method.toUpperCase()] || DEFAULT_MESSAGE_TYPE;
399
+ const messageType = openAPIOperation["x-eventcatalog-message-type"] || defaultMessageType;
399
400
  const messageAction = openAPIOperation["x-eventcatalog-message-action"] === "sends" ? "sends" : "receives";
400
401
  const extensions = Object.keys(openAPIOperation).reduce((acc, key) => {
401
402
  if (key.startsWith("x-eventcatalog-")) {
@@ -623,7 +624,7 @@ var import_chalk = __toESM(require("chalk"));
623
624
  // package.json
624
625
  var package_default = {
625
626
  name: "@eventcatalog/generator-openapi",
626
- version: "5.0.1",
627
+ version: "5.0.3",
627
628
  description: "OpenAPI generator for EventCatalog",
628
629
  scripts: {
629
630
  build: "tsup",
@@ -659,7 +660,7 @@ var package_default = {
659
660
  dependencies: {
660
661
  "@apidevtools/swagger-parser": "^10.1.0",
661
662
  "@changesets/cli": "^2.27.7",
662
- "@eventcatalog/sdk": "^2.0.1",
663
+ "@eventcatalog/sdk": "^2.2.4",
663
664
  chalk: "^4",
664
665
  "js-yaml": "^4.1.0",
665
666
  "openapi-types": "^12.1.3",
@@ -1640,6 +1641,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
1640
1641
  });
1641
1642
  let owners = service.owners || [];
1642
1643
  let repository = null;
1644
+ let styles2 = null;
1643
1645
  const latestServiceInCatalog = await getService(service.id, "latest");
1644
1646
  console.log(import_chalk3.default.blue(`Processing service: ${document.info.title} (v${version})`));
1645
1647
  if (latestServiceInCatalog) {
@@ -1648,6 +1650,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
1648
1650
  sends = latestServiceInCatalog.sends || [];
1649
1651
  owners = latestServiceInCatalog.owners || [];
1650
1652
  repository = latestServiceInCatalog.repository || null;
1653
+ styles2 = latestServiceInCatalog.styles || null;
1651
1654
  serviceSpecifications = {
1652
1655
  ...serviceSpecifications,
1653
1656
  ...latestServiceInCatalog.specifications
@@ -1668,7 +1671,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
1668
1671
  sends,
1669
1672
  receives,
1670
1673
  ...owners ? { owners } : {},
1671
- ...repository ? { repository } : {}
1674
+ ...repository ? { repository } : {},
1675
+ ...styles2 ? { styles: styles2 } : {}
1672
1676
  },
1673
1677
  { path: (0, import_node_path.join)(servicePath), override: true }
1674
1678
  );
@@ -1694,7 +1698,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
1694
1698
  }
1695
1699
  };
1696
1700
  var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, options) => {
1697
- const operations = await getOperationsByType(pathToSpec);
1701
+ const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
1698
1702
  const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
1699
1703
  const version = document.info.version;
1700
1704
  let receives = [], sends = [];