@eventcatalog/generator-openapi 5.0.3 → 5.0.5

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,6 +376,19 @@ async function getSchemasByOperationId(filePath, operationId) {
376
376
  return;
377
377
  }
378
378
  }
379
+ function getDeprecatedValues(openAPIOperation) {
380
+ const deprecatedDate = openAPIOperation["x-eventcatalog-deprecated-date"] || null;
381
+ const deprecatedMessage = openAPIOperation["x-eventcatalog-deprecated-message"] || null;
382
+ const isNativeDeprecated = openAPIOperation.deprecated;
383
+ let deprecated = isNativeDeprecated;
384
+ if (deprecatedDate) {
385
+ deprecated = {
386
+ date: deprecatedDate,
387
+ message: deprecatedMessage
388
+ };
389
+ }
390
+ return deprecated;
391
+ }
379
392
  async function getOperationsByType(openApiPath, httpMethodsToMessages) {
380
393
  try {
381
394
  const api = await SwaggerParser.validate(openApiPath);
@@ -385,6 +398,7 @@ async function getOperationsByType(openApiPath, httpMethodsToMessages) {
385
398
  for (const method in pathItem) {
386
399
  const openAPIOperation = pathItem[method];
387
400
  const defaultMessageType = httpMethodsToMessages?.[method.toUpperCase()] || DEFAULT_MESSAGE_TYPE;
401
+ const deprecated = getDeprecatedValues(openAPIOperation);
388
402
  const messageType = openAPIOperation["x-eventcatalog-message-type"] || defaultMessageType;
389
403
  const messageAction = openAPIOperation["x-eventcatalog-message-action"] === "sends" ? "sends" : "receives";
390
404
  const extensions = Object.keys(openAPIOperation).reduce((acc, key) => {
@@ -403,7 +417,8 @@ async function getOperationsByType(openApiPath, httpMethodsToMessages) {
403
417
  description: openAPIOperation.description,
404
418
  summary: openAPIOperation.summary,
405
419
  tags: openAPIOperation.tags || [],
406
- extensions
420
+ extensions,
421
+ ...deprecated ? { deprecated } : {}
407
422
  };
408
423
  operations.push(operation);
409
424
  }
@@ -554,7 +569,8 @@ var buildMessage = async (pathToFile, document, operation) => {
554
569
  requestBodiesAndResponses,
555
570
  sidebar: {
556
571
  badge: httpVerb
557
- }
572
+ },
573
+ ...operation.deprecated ? { deprecated: operation.deprecated } : {}
558
574
  };
559
575
  };
560
576
 
@@ -613,7 +629,7 @@ import chalk from "chalk";
613
629
  // package.json
614
630
  var package_default = {
615
631
  name: "@eventcatalog/generator-openapi",
616
- version: "5.0.3",
632
+ version: "5.0.5",
617
633
  description: "OpenAPI generator for EventCatalog",
618
634
  scripts: {
619
635
  build: "tsup",
@@ -649,7 +665,7 @@ var package_default = {
649
665
  dependencies: {
650
666
  "@apidevtools/swagger-parser": "^10.1.0",
651
667
  "@changesets/cli": "^2.27.7",
652
- "@eventcatalog/sdk": "^2.2.4",
668
+ "@eventcatalog/sdk": "^2.2.6",
653
669
  chalk: "^4",
654
670
  "js-yaml": "^4.1.0",
655
671
  "openapi-types": "^12.1.3",
@@ -1690,6 +1706,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
1690
1706
  const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
1691
1707
  const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
1692
1708
  const version = document.info.version;
1709
+ const preserveExistingMessages = options.preserveExistingMessages ?? true;
1693
1710
  let receives = [], sends = [];
1694
1711
  for (const operation of operations) {
1695
1712
  const { requestBodiesAndResponses, sidebar, ...message } = await buildMessage(pathToSpec, document, operation);
@@ -1706,7 +1723,9 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
1706
1723
  } = getMessageTypeUtils(process.env.PROJECT_DIR, messageType);
1707
1724
  const catalogedMessage = await getMessage(message.id, "latest");
1708
1725
  if (catalogedMessage) {
1709
- messageMarkdown = catalogedMessage.markdown;
1726
+ if (preserveExistingMessages) {
1727
+ messageMarkdown = catalogedMessage.markdown;
1728
+ }
1710
1729
  if (catalogedMessage.version !== version) {
1711
1730
  await versionMessage(message.id);
1712
1731
  console.log(chalk3.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));