@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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +20 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -8,7 +11,9 @@ type Props = {
|
|
|
8
11
|
saveParsedSpecFile?: boolean;
|
|
9
12
|
licenseKey?: string;
|
|
10
13
|
writeFilesToRoot?: boolean;
|
|
14
|
+
sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
|
|
15
|
+
httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
|
|
11
16
|
};
|
|
12
17
|
declare const _default: (_: any, options: Props) => Promise<void>;
|
|
13
18
|
|
|
14
|
-
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;
|
|
@@ -8,7 +11,9 @@ type Props = {
|
|
|
8
11
|
saveParsedSpecFile?: boolean;
|
|
9
12
|
licenseKey?: string;
|
|
10
13
|
writeFilesToRoot?: boolean;
|
|
14
|
+
sidebarBadgeType?: 'HTTP_METHOD' | 'MESSAGE_TYPE';
|
|
15
|
+
httpMethodsToMessages?: HTTP_METHOD_TO_MESSAGE_TYPE;
|
|
11
16
|
};
|
|
12
17
|
declare const _default: (_: any, options: Props) => Promise<void>;
|
|
13
18
|
|
|
14
|
-
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
|
|
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-")) {
|
|
@@ -552,6 +553,7 @@ var buildMessage = async (pathToFile, document, operation) => {
|
|
|
552
553
|
if (!operation.operationId && path3) {
|
|
553
554
|
uniqueIdentifier = uniqueIdentifier.concat(`_${path3}`);
|
|
554
555
|
}
|
|
556
|
+
const httpVerb = operation.method.toUpperCase() || "";
|
|
555
557
|
return {
|
|
556
558
|
id: extensions["x-eventcatalog-message-id"] || uniqueIdentifier,
|
|
557
559
|
version: extensions["x-eventcatalog-message-version"] || document.info.version,
|
|
@@ -560,7 +562,10 @@ var buildMessage = async (pathToFile, document, operation) => {
|
|
|
560
562
|
markdown: defaultMarkdown3(operation, requestBodiesAndResponses),
|
|
561
563
|
schemaPath: requestBodiesAndResponses?.requestBody ? "request-body.json" : "",
|
|
562
564
|
badges,
|
|
563
|
-
requestBodiesAndResponses
|
|
565
|
+
requestBodiesAndResponses,
|
|
566
|
+
sidebar: {
|
|
567
|
+
badge: httpVerb
|
|
568
|
+
}
|
|
564
569
|
};
|
|
565
570
|
};
|
|
566
571
|
|
|
@@ -619,7 +624,7 @@ var import_chalk = __toESM(require("chalk"));
|
|
|
619
624
|
// package.json
|
|
620
625
|
var package_default = {
|
|
621
626
|
name: "@eventcatalog/generator-openapi",
|
|
622
|
-
version: "5.0.
|
|
627
|
+
version: "5.0.2",
|
|
623
628
|
description: "OpenAPI generator for EventCatalog",
|
|
624
629
|
scripts: {
|
|
625
630
|
build: "tsup",
|
|
@@ -655,7 +660,7 @@ var package_default = {
|
|
|
655
660
|
dependencies: {
|
|
656
661
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
657
662
|
"@changesets/cli": "^2.27.7",
|
|
658
|
-
"@eventcatalog/sdk": "^2.0.
|
|
663
|
+
"@eventcatalog/sdk": "^2.0.1",
|
|
659
664
|
chalk: "^4",
|
|
660
665
|
"js-yaml": "^4.1.0",
|
|
661
666
|
"openapi-types": "^12.1.3",
|
|
@@ -1690,11 +1695,12 @@ Processing domain: ${domainName} (v${domainVersion})`));
|
|
|
1690
1695
|
}
|
|
1691
1696
|
};
|
|
1692
1697
|
var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, options) => {
|
|
1693
|
-
const operations = await getOperationsByType(pathToSpec);
|
|
1698
|
+
const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
|
|
1699
|
+
const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
|
|
1694
1700
|
const version = document.info.version;
|
|
1695
1701
|
let receives = [], sends = [];
|
|
1696
1702
|
for (const operation of operations) {
|
|
1697
|
-
const { requestBodiesAndResponses, ...message } = await buildMessage(pathToSpec, document, operation);
|
|
1703
|
+
const { requestBodiesAndResponses, sidebar, ...message } = await buildMessage(pathToSpec, document, operation);
|
|
1698
1704
|
let messageMarkdown = message.markdown;
|
|
1699
1705
|
const messageType = operation.type;
|
|
1700
1706
|
const messageAction = operation.action;
|
|
@@ -1719,7 +1725,13 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document, servicePath, op
|
|
|
1719
1725
|
messagePath = message.id;
|
|
1720
1726
|
}
|
|
1721
1727
|
await writeMessage(
|
|
1722
|
-
{
|
|
1728
|
+
{
|
|
1729
|
+
...message,
|
|
1730
|
+
markdown: messageMarkdown,
|
|
1731
|
+
...options.owners ? { owners: options.owners } : {},
|
|
1732
|
+
// only if its defined add it to the sidebar
|
|
1733
|
+
...sidebarBadgeType === "HTTP_METHOD" ? { sidebar } : {}
|
|
1734
|
+
},
|
|
1723
1735
|
{ path: messagePath, override: true }
|
|
1724
1736
|
);
|
|
1725
1737
|
if (messageAction === "sends") {
|