@eventcatalog/generator-openapi 5.0.0 → 5.0.2

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.mjs CHANGED
@@ -376,7 +376,7 @@ async function getSchemasByOperationId(filePath, operationId) {
376
376
  return;
377
377
  }
378
378
  }
379
- async function getOperationsByType(openApiPath) {
379
+ async function getOperationsByType(openApiPath, httpMethodsToMessages) {
380
380
  try {
381
381
  const api = await SwaggerParser.validate(openApiPath);
382
382
  const operations = [];
@@ -384,7 +384,8 @@ async function getOperationsByType(openApiPath) {
384
384
  const pathItem = api.paths[path3];
385
385
  for (const method in pathItem) {
386
386
  const openAPIOperation = pathItem[method];
387
- const messageType = openAPIOperation["x-eventcatalog-message-type"] || DEFAULT_MESSAGE_TYPE;
387
+ const defaultMessageType = httpMethodsToMessages?.[method.toUpperCase()] || DEFAULT_MESSAGE_TYPE;
388
+ const messageType = openAPIOperation["x-eventcatalog-message-type"] || defaultMessageType;
388
389
  const messageAction = openAPIOperation["x-eventcatalog-message-action"] === "sends" ? "sends" : "receives";
389
390
  const extensions = Object.keys(openAPIOperation).reduce((acc, key) => {
390
391
  if (key.startsWith("x-eventcatalog-")) {
@@ -541,6 +542,7 @@ var buildMessage = async (pathToFile, document, operation) => {
541
542
  if (!operation.operationId && path3) {
542
543
  uniqueIdentifier = uniqueIdentifier.concat(`_${path3}`);
543
544
  }
545
+ const httpVerb = operation.method.toUpperCase() || "";
544
546
  return {
545
547
  id: extensions["x-eventcatalog-message-id"] || uniqueIdentifier,
546
548
  version: extensions["x-eventcatalog-message-version"] || document.info.version,
@@ -549,7 +551,10 @@ var buildMessage = async (pathToFile, document, operation) => {
549
551
  markdown: defaultMarkdown3(operation, requestBodiesAndResponses),
550
552
  schemaPath: requestBodiesAndResponses?.requestBody ? "request-body.json" : "",
551
553
  badges,
552
- requestBodiesAndResponses
554
+ requestBodiesAndResponses,
555
+ sidebar: {
556
+ badge: httpVerb
557
+ }
553
558
  };
554
559
  };
555
560
 
@@ -608,7 +613,7 @@ import chalk from "chalk";
608
613
  // package.json
609
614
  var package_default = {
610
615
  name: "@eventcatalog/generator-openapi",
611
- version: "5.0.0",
616
+ version: "5.0.2",
612
617
  description: "OpenAPI generator for EventCatalog",
613
618
  scripts: {
614
619
  build: "tsup",
@@ -644,7 +649,7 @@ var package_default = {
644
649
  dependencies: {
645
650
  "@apidevtools/swagger-parser": "^10.1.0",
646
651
  "@changesets/cli": "^2.27.7",
647
- "@eventcatalog/sdk": "^2.0.0",
652
+ "@eventcatalog/sdk": "^2.0.1",
648
653
  chalk: "^4",
649
654
  "js-yaml": "^4.1.0",
650
655
  "openapi-types": "^12.1.3",
@@ -1679,11 +1684,12 @@ Processing domain: ${domainName} (v${domainVersion})`));
1679
1684
  }
1680
1685
  };
1681
1686
  var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, options) => {
1682
- const operations = await getOperationsByType(pathToSpec);
1687
+ const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
1688
+ const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
1683
1689
  const version = document.info.version;
1684
1690
  let receives = [], sends = [];
1685
1691
  for (const operation of operations) {
1686
- const { requestBodiesAndResponses, ...message } = await buildMessage(pathToSpec, document, operation);
1692
+ const { requestBodiesAndResponses, sidebar, ...message } = await buildMessage(pathToSpec, document, operation);
1687
1693
  let messageMarkdown = message.markdown;
1688
1694
  const messageType = operation.type;
1689
1695
  const messageAction = operation.action;
@@ -1708,7 +1714,13 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
1708
1714
  messagePath = message.id;
1709
1715
  }
1710
1716
  await writeMessage(
1711
- { ...message, markdown: messageMarkdown, ...options.owners ? { owners: options.owners } : {} },
1717
+ {
1718
+ ...message,
1719
+ markdown: messageMarkdown,
1720
+ ...options.owners ? { owners: options.owners } : {},
1721
+ // only if its defined add it to the sidebar
1722
+ ...sidebarBadgeType === "HTTP_METHOD" ? { sidebar } : {}
1723
+ },
1712
1724
  { path: messagePath, override: true }
1713
1725
  );
1714
1726
  if (messageAction === "sends") {