x-openapi-flow 1.3.0 → 1.3.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.
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { loadApi } = require("../../lib/validator");
6
+ const { buildIntermediateModel } = require("../../lib/sdk-generator");
7
+
8
+ function buildRedocHtml(model, specFileName) {
9
+ const modelPayload = JSON.stringify(model);
10
+ return `<!doctype html>
11
+ <html lang="en">
12
+ <head>
13
+ <meta charset="utf-8" />
14
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
15
+ <title>x-openapi-flow Redoc</title>
16
+ <style>
17
+ body { margin: 0; background: #ffffff; color: #111827; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }
18
+ #x-openapi-flow-panel { max-width: 1200px; margin: 0 auto; padding: 16px; border-bottom: 1px solid #e5e7eb; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <div id="x-openapi-flow-panel"></div>
23
+ <redoc spec-url="./${specFileName}"></redoc>
24
+ <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
25
+ <script src="./x-openapi-flow-redoc-plugin.js"></script>
26
+ <script>
27
+ window.XOpenApiFlowRedocPlugin.mount({
28
+ model: ${modelPayload},
29
+ targetSelector: "#x-openapi-flow-panel"
30
+ });
31
+ </script>
32
+ </body>
33
+ </html>
34
+ `;
35
+ }
36
+
37
+ function generateRedocPackage(options) {
38
+ const apiPath = path.resolve(options.apiPath);
39
+ const outputDir = path.resolve(options.outputDir || path.join(process.cwd(), "redoc-flow"));
40
+
41
+ const api = loadApi(apiPath);
42
+ const model = buildIntermediateModel(api);
43
+ const specFileName = path.extname(apiPath).toLowerCase() === ".json" ? "openapi.json" : "openapi.yaml";
44
+
45
+ fs.mkdirSync(outputDir, { recursive: true });
46
+
47
+ const sourceSpec = fs.readFileSync(apiPath, "utf8");
48
+ fs.writeFileSync(path.join(outputDir, specFileName), sourceSpec, "utf8");
49
+
50
+ // Plugin lives at adapters/ui/redoc/ — __dirname is adapters/ui
51
+ const pluginSourcePath = path.join(__dirname, "redoc", "x-openapi-flow-redoc-plugin.js");
52
+ const pluginTargetPath = path.join(outputDir, "x-openapi-flow-redoc-plugin.js");
53
+ fs.copyFileSync(pluginSourcePath, pluginTargetPath);
54
+
55
+ fs.writeFileSync(
56
+ path.join(outputDir, "flow-model.json"),
57
+ `${JSON.stringify(model, null, 2)}\n`,
58
+ "utf8"
59
+ );
60
+
61
+ fs.writeFileSync(
62
+ path.join(outputDir, "index.html"),
63
+ buildRedocHtml(model, specFileName),
64
+ "utf8"
65
+ );
66
+
67
+ return {
68
+ outputDir,
69
+ indexPath: path.join(outputDir, "index.html"),
70
+ resources: model.resources.length,
71
+ flowCount: model.flowCount,
72
+ };
73
+ }
74
+
75
+ module.exports = { generateRedocPackage };