@tea-agent/loop-agent 0.53.0-next.1 → 0.53.0-next.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/CHANGELOG.md +18 -52
- package/dist/build-stamp.json +3 -3
- package/dist/shared/pi-context-pressure/compaction-policy.js +22 -34
- package/dist/shared/pi-context-pressure/index.js +1 -1
- package/dist/worker/console/automation-actions.js +62 -7
- package/dist/worker/console/chat/api-workbench-core.js +131 -4
- package/dist/worker/console/chat/api-workbench-schema.js +278 -0
- package/dist/worker/console/chat/api-workbench-spring.js +333 -0
- package/dist/worker/console/chat/api-workbench.js +88 -2
- package/dist/worker/console/chat/human-gate-card.js +16 -1
- package/dist/worker/console/chat/image-cache.js +39 -8
- package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +120 -5
- package/dist/worker/console/chat/pi-runtime.js +2 -3
- package/dist/worker/console/chat/provider-error.js +12 -2
- package/dist/worker/console/chat/repo-walk.js +8 -0
- package/dist/worker/console/chat/routes.js +125 -13
- package/dist/worker/console/chat/todo-diff.js +90 -0
- package/dist/worker/console/chat/turn-process.js +3 -0
- package/dist/worker/console/network-proxy-settings.js +67 -1
- package/dist/worker/console/operator-actions.js +25 -0
- package/dist/worker/console/pi-compaction-settings.js +16 -13
- package/dist/worker/console/server.js +20 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-CR1jj_rz.js → abnfDiagram-N423BO3Z-9YdcTSkA.js} +1 -1
- package/dist/worker/console/static/assets/{arc-CjxcQfEu.js → arc-5o9a24RM.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-D-3u2qFL.js → architectureDiagram-T3A2C74G-kk-Y4K8w.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Bdr7gWVo.js → blockDiagram-VBNYF7ZC-BuMyp-i-.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-hQHNe5T3.js → c4Diagram-5PPSVZJV-BnAbUXQM.js} +1 -1
- package/dist/worker/console/static/assets/channel-DzpJs7JM.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BEg_su6q.js → chunk-2GRJ4B5K-sQ2VjuFx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-DZnV6VTC.js → chunk-2Q5K7J3B-CbkqzTV8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-Dg0LzAqO.js → chunk-5RXB4S5H-CaP8JTC3.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-D2vqr52W.js → chunk-5VM5RSS4-D7yUFtwu.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-D8We_g6R.js → chunk-6Q2QTUOP-zowLlgmO.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DbEU8drD.js → chunk-GF5L2VYU-KGzLFdSC.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Boi8TJYN.js → chunk-JWPE2WC7-DuVIxg_I.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CjJmKa9f.js → chunk-KBJHAD2P-CXP8iZrQ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-C-KV-ag7.js → chunk-RYQCIY6F-DASfOCYV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DZlTonsZ.js → chunk-XXDRQBXY-DFwLDf-r.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-ClK7LSSv.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-ClK7LSSv.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BIvFe3yn.js → cose-bilkent-JH36ORCC-CIrJSuNM.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-BOBPfv8u.js → cynefinDiagram-MW4NZA55-BrI5M-XP.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BF54orLO.js → dagre-VZM6K2ZE-BEJlUQi2.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CxjAP2AP.js → diagram-7IWD3JNH-Buw7nAqS.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BXYkuNGt.js → diagram-B4RE2ZJO-DHURLBbb.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-DQTu-2Iy.js → diagram-LBJQPF4R-CEFuptxk.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-DNURuIYc.js → diagram-Q27KOJAE-Cejgl71p.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-D69uANY8.js → diagram-UB23O5K3-Bwxq3Xoa.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-C658EcrV.js → ebnfDiagram-BXEA7PRR-i4NNenm0.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-BRccYtAl.js → erDiagram-JOGREHBK-BaSp03BR.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-DnIR4sLs.js → flowDiagram-UKHOOZJN-CQtgCCPg.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Bo3eWFVC.js → ganttDiagram-PKOTCBZU-DkS9Vbt8.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-EyWDCNU_.js → gitGraphDiagram-DS77QQ5N-Dm64UQgY.js} +1 -1
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-B0Eld9u0.js → infoDiagram-6WML65LV-BpcLrRRV.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DsJQiJ27.js → ishikawaDiagram-WSZJBQD7-DFjxaE3Q.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-fpE0yqjC.js → journeyDiagram-NVQOT4AX-G6kuLGYK.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Dq9IrDdT.js → kanban-definition-27J2QSJJ-DistDdnp.js} +1 -1
- package/dist/worker/console/static/assets/{linear-CFV4BDyf.js → linear-Cadcj4Jf.js} +1 -1
- package/dist/worker/console/static/assets/main-CKu0wCrM.js +654 -0
- package/dist/worker/console/static/assets/main-DpBoCiky.css +1 -0
- package/dist/worker/console/static/assets/{mermaid.core-BMMXqtrB.js → mermaid.core-CVqQBsGx.js} +4 -4
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-DurrK_Gi.js → mindmap-definition-FAOFIHXS-oIAAXLn3.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-CzZayNy2.js → pegDiagram-VL7TDLO6-BgBPFLA0.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-B1W7Y0cE.js → pieDiagram-7S7Q4E2Y-RTyZdL9S.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BdbL83CU.js → quadrantDiagram-CIZ2JOQS-BHEYQMZx.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-W-bQpd18.js → railroadDiagram-AXF67PYL-B2JIrks2.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-C9bi4tQJ.js → requirementDiagram-LRYGKXZP-TJ5_MWbY.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-D4kO56Wd.js → sankeyDiagram-W5VNT64P-BzjUsr0j.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CIbesK1e.js → sequenceDiagram-SI44F4Z6-DrmrPPVE.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-kFN3yUBr.js → sheet-workbook-DCQgjy0Q.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-Dk4XAK7C.js → sizeCapture-X5ZJPWSS-BLp8F5fC.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-Bz9B6UZ7.js → stateDiagram-OKZ733FA-5MNm447q.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-gP-t-MQJ.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-qLEds93n.js → swimlanes-SLNWSIFB-Cs2RUkNq.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-D6MJJUTV.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-C9rVFC0h.js → timeline-definition-Z64GVDOM-BoeTHoWc.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-CoKJ9hU0.js → vennDiagram-T6HMQDX7-DFWej-Mm.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-tHz_S7-L.js → wardleyDiagram-T6FBY63Y-BcD0_2m5.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-DKzKYnvG.js → xychartDiagram-ELKLHX3M-y4PQYZiq.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/markdown-incremental.js +138 -0
- package/dist/worker/console/static-src/operator-chat/automation-catalog-model.js +43 -0
- package/dist/worker/console/static-src/operator-chat/composer-drop.js +138 -0
- package/dist/worker/console/static-src/operator-chat/composer-image-paths.js +25 -5
- package/dist/worker/console/static-src/operator-chat/composer-image-preview.js +115 -0
- package/dist/worker/console/static-src/operator-chat/composer-session-ledger.js +44 -2
- package/dist/worker/console/static-src/operator-chat/composer-upload.js +115 -0
- package/dist/worker/console/static-src/operator-chat/gate-expiry.js +43 -0
- package/dist/worker/console/static-src/operator-chat/process-label.js +15 -2
- package/dist/worker/console/static-src/operator-chat/schedule-relative-time.js +54 -0
- package/dist/worker/console/static-src/operator-chat/schedule-rule-summary.js +213 -0
- package/dist/worker/console/static-src/operator-chat/tasks-model.js +4 -0
- package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +8 -0
- package/dist/worker/console/static-src/operator-chat/turn-process-disclosure.js +12 -0
- package/dist/worker/console/static-src/operator-chat/turn-state-projection.js +51 -0
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +22 -2
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +15 -1
- package/dist/worker/console/static-src/operator-chat/useComposer.js +290 -21
- package/dist/worker/console/static-src/operator-chat/useSessionAutomationCounts.js +98 -0
- package/dist/worker/console/static-src/pages/api-request-template.js +144 -0
- package/dist/worker/console/static-src/session-search-shortcut.js +38 -0
- package/dist/worker/console/version-notes-comparison.js +52 -0
- package/dist/worker/console/version-notes.js +16 -1
- package/dist/worker/console/workspace-context.js +10 -0
- package/dist/worker/observe/static/console-theme.css +50 -3
- package/dist/worker/observe/static/console-theme.js +86 -1
- package/dist/worker/scheduler/automation-across-workspaces.js +120 -0
- package/docs/README.md +1 -0
- package/docs/operations/README.md +1 -0
- package/package.json +3 -3
- package/dist/worker/console/static/assets/channel-CBlJfald.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-mNUYCdDo.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-mNUYCdDo.js +0 -1
- package/dist/worker/console/static/assets/main-D-ZQ4gLb.css +0 -1
- package/dist/worker/console/static/assets/main-Dwhb3ZRq.js +0 -645
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BBRlxIq8.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CRBvOMCQ.js +0 -8
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning an OpenAPI operation's `requestBody` and `responses` into field tables.
|
|
3
|
+
*
|
|
4
|
+
* The workbench used to read only paths and parameters, so a generated document's
|
|
5
|
+
* most valuable half — what the endpoint accepts and returns — was parsed away.
|
|
6
|
+
* For a Spring project that half cannot be recovered by reading source: field
|
|
7
|
+
* types, required flags, descriptions, examples and ranges all come from springdoc
|
|
8
|
+
* reflecting over the Java type system.
|
|
9
|
+
*
|
|
10
|
+
* Kept a pure module so the `$ref` walking, `allOf` merging and array flattening
|
|
11
|
+
* can be tested without a filesystem or an HTTP call.
|
|
12
|
+
*/
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
/** Component name from a local `$ref`, or undefined for anything else. */
|
|
17
|
+
export function refName(ref) {
|
|
18
|
+
if (typeof ref !== "string")
|
|
19
|
+
return undefined;
|
|
20
|
+
const match = /^#\/(?:components\/schemas|definitions)\/([^/]+)$/.exec(ref);
|
|
21
|
+
return match ? decodeURIComponent(match[1]) : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Follow one `$ref` into the document's components, when it resolves. */
|
|
24
|
+
function deref(value, components, depth) {
|
|
25
|
+
if (depth > 12)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (!isRecord(value))
|
|
28
|
+
return value;
|
|
29
|
+
const name = refName(value.$ref);
|
|
30
|
+
if (name === undefined)
|
|
31
|
+
return value;
|
|
32
|
+
const target = components?.[name];
|
|
33
|
+
return target === undefined ? undefined : deref(target, components, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
/** A readable type for one schema node. */
|
|
36
|
+
function typeOf(schema) {
|
|
37
|
+
const ref = refName(schema.$ref);
|
|
38
|
+
if (ref !== undefined)
|
|
39
|
+
return ref;
|
|
40
|
+
if (typeof schema.type === "string") {
|
|
41
|
+
if (schema.type === "array") {
|
|
42
|
+
const items = isRecord(schema.items) ? typeOf(schema.items) : "unknown";
|
|
43
|
+
return `${items}[]`;
|
|
44
|
+
}
|
|
45
|
+
if (typeof schema.format === "string" && schema.format !== "")
|
|
46
|
+
return `${schema.type}(${schema.format})`;
|
|
47
|
+
return schema.type;
|
|
48
|
+
}
|
|
49
|
+
// springdoc emits `allOf` for a wrapper around one component.
|
|
50
|
+
if (Array.isArray(schema.allOf) && schema.allOf.length === 1) {
|
|
51
|
+
const first = schema.allOf[0];
|
|
52
|
+
return isRecord(first) ? typeOf(first) : "object";
|
|
53
|
+
}
|
|
54
|
+
return "object";
|
|
55
|
+
}
|
|
56
|
+
/** Example rendered as text, from any of the three places OpenAPI allows it. */
|
|
57
|
+
function exampleOf(schema) {
|
|
58
|
+
const direct = schema.example;
|
|
59
|
+
if (direct !== undefined)
|
|
60
|
+
return typeof direct === "string" ? direct : JSON.stringify(direct);
|
|
61
|
+
// springdoc folds `@Schema(example = …)` into `examples` for parameters.
|
|
62
|
+
if (Array.isArray(schema.examples) && schema.examples.length > 0) {
|
|
63
|
+
const first = schema.examples[0];
|
|
64
|
+
return typeof first === "string" ? first : first === undefined ? undefined : JSON.stringify(first);
|
|
65
|
+
}
|
|
66
|
+
if (schema.default !== undefined) {
|
|
67
|
+
return typeof schema.default === "string" ? schema.default : JSON.stringify(schema.default);
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
/** Enum members as text, when the schema restricts the value. */
|
|
72
|
+
function allowedOf(schema) {
|
|
73
|
+
if (!Array.isArray(schema.enum))
|
|
74
|
+
return undefined;
|
|
75
|
+
const values = schema.enum.map((item) => typeof item === "string" ? item : JSON.stringify(item)).filter((item) => typeof item === "string");
|
|
76
|
+
return values.length > 0 ? values : undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Merge `allOf` branches into one object schema.
|
|
80
|
+
*
|
|
81
|
+
* springdoc emits `allOf` when a class extends another or is wrapped; ignoring it
|
|
82
|
+
* loses the inherited fields, which is precisely the information a caller needs.
|
|
83
|
+
*
|
|
84
|
+
* @param schema - a possibly-`allOf` schema.
|
|
85
|
+
* @param components - the document's component map.
|
|
86
|
+
* @param depth - recursion guard for nested references.
|
|
87
|
+
* @returns an object schema with `properties` merged across branches.
|
|
88
|
+
*/
|
|
89
|
+
function mergeAllOf(schema, components, depth = 0) {
|
|
90
|
+
if (!Array.isArray(schema.allOf) || depth > 12)
|
|
91
|
+
return schema;
|
|
92
|
+
const merged = { ...schema };
|
|
93
|
+
const properties = { ...(isRecord(schema.properties) ? schema.properties : {}) };
|
|
94
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required.filter((item) => typeof item === "string") : []);
|
|
95
|
+
for (const branch of schema.allOf) {
|
|
96
|
+
const resolved = deref(branch, components, depth + 1);
|
|
97
|
+
if (!isRecord(resolved))
|
|
98
|
+
continue;
|
|
99
|
+
const inner = mergeAllOf(resolved, components, depth + 1);
|
|
100
|
+
if (isRecord(inner.properties))
|
|
101
|
+
Object.assign(properties, inner.properties);
|
|
102
|
+
if (Array.isArray(inner.required)) {
|
|
103
|
+
for (const item of inner.required)
|
|
104
|
+
if (typeof item === "string")
|
|
105
|
+
required.add(item);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
merged.properties = properties;
|
|
109
|
+
merged.required = [...required];
|
|
110
|
+
delete merged.allOf;
|
|
111
|
+
return merged;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Flatten one schema into leaf rows.
|
|
115
|
+
*
|
|
116
|
+
* Nested objects become dotted paths and arrays get a `[]` suffix on the element,
|
|
117
|
+
* which is what a table can show and what a tester types into a path parameter.
|
|
118
|
+
*
|
|
119
|
+
* @param schema - the schema to flatten.
|
|
120
|
+
* @param components - the document's component map.
|
|
121
|
+
* @param prefix - path prefix for nested calls.
|
|
122
|
+
* @param required - whether the owning field is required.
|
|
123
|
+
* @param depth - recursion guard.
|
|
124
|
+
* @returns flattened rows.
|
|
125
|
+
*/
|
|
126
|
+
function flatten(schema, components, prefix, required, depth = 0) {
|
|
127
|
+
if (depth > 8 || !isRecord(schema))
|
|
128
|
+
return [];
|
|
129
|
+
const resolved = mergeAllOf(schema, components, depth);
|
|
130
|
+
const rows = [];
|
|
131
|
+
// An array contributes one row for its element shape, not a row per item.
|
|
132
|
+
if (resolved.type === "array") {
|
|
133
|
+
if (isRecord(resolved.items)) {
|
|
134
|
+
const itemRequired = Array.isArray(resolved.required)
|
|
135
|
+
? resolved.required.includes("items")
|
|
136
|
+
: required;
|
|
137
|
+
return flatten(resolved.items, components, `${prefix}[]`, itemRequired, depth + 1);
|
|
138
|
+
}
|
|
139
|
+
return prefix === ""
|
|
140
|
+
? []
|
|
141
|
+
: [{ path: prefix, type: "array", required }];
|
|
142
|
+
}
|
|
143
|
+
const properties = isRecord(resolved.properties) ? resolved.properties : undefined;
|
|
144
|
+
if (properties === undefined) {
|
|
145
|
+
if (prefix === "")
|
|
146
|
+
return [];
|
|
147
|
+
const row = { path: prefix, type: typeOf(resolved), required };
|
|
148
|
+
const description = typeof resolved.description === "string" ? resolved.description : undefined;
|
|
149
|
+
const example = exampleOf(resolved);
|
|
150
|
+
const allowed = allowedOf(resolved);
|
|
151
|
+
if (description !== undefined)
|
|
152
|
+
row.description = description;
|
|
153
|
+
if (example !== undefined)
|
|
154
|
+
row.example = example;
|
|
155
|
+
if (allowed !== undefined)
|
|
156
|
+
row.allowed = allowed;
|
|
157
|
+
return [row];
|
|
158
|
+
}
|
|
159
|
+
const requiredNames = new Set(Array.isArray(resolved.required) ? resolved.required.filter((item) => typeof item === "string") : []);
|
|
160
|
+
for (const [name, child] of Object.entries(properties)) {
|
|
161
|
+
const childPath = prefix === "" ? name : `${prefix}.${name}`;
|
|
162
|
+
const childRequired = requiredNames.has(name);
|
|
163
|
+
const childRecord = isRecord(child) ? child : {};
|
|
164
|
+
// A nested object or array of objects expands; a leaf stays one row.
|
|
165
|
+
const childResolved = mergeAllOf(childRecord, components, depth + 1);
|
|
166
|
+
const nested = isRecord(childResolved.properties)
|
|
167
|
+
|| (childResolved.type === "array" && isRecord(childResolved.items));
|
|
168
|
+
if (nested) {
|
|
169
|
+
rows.push(...flatten(child, components, childPath, childRequired, depth + 1));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const row = { path: childPath, type: typeOf(childResolved), required: childRequired };
|
|
173
|
+
const description = typeof childResolved.description === "string" ? childResolved.description : undefined;
|
|
174
|
+
const example = exampleOf(childResolved);
|
|
175
|
+
const allowed = allowedOf(childResolved);
|
|
176
|
+
if (description !== undefined)
|
|
177
|
+
row.description = description;
|
|
178
|
+
if (example !== undefined)
|
|
179
|
+
row.example = example;
|
|
180
|
+
if (allowed !== undefined)
|
|
181
|
+
row.allowed = allowed;
|
|
182
|
+
rows.push(row);
|
|
183
|
+
}
|
|
184
|
+
return rows;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolve a schema node into a named, flattened shape.
|
|
188
|
+
*
|
|
189
|
+
* @param schema - the node, possibly a `$ref`.
|
|
190
|
+
* @param components - the document's component map.
|
|
191
|
+
* @returns the component name when there is one, and its rows.
|
|
192
|
+
*/
|
|
193
|
+
export function resolveSchema(schema, components) {
|
|
194
|
+
if (!isRecord(schema))
|
|
195
|
+
return { fields: [] };
|
|
196
|
+
const name = refName(schema.$ref);
|
|
197
|
+
const target = deref(schema, components, 0);
|
|
198
|
+
if (target === undefined)
|
|
199
|
+
return { ...(name !== undefined ? { schemaName: name } : {}), fields: [], unresolved: true };
|
|
200
|
+
// The root is the body itself, not a named field: its members carry their own
|
|
201
|
+
// required flags from the schema. Passing `true` here marked every leaf required.
|
|
202
|
+
const fields = flatten(target, components, "", false);
|
|
203
|
+
return { ...(name !== undefined ? { schemaName: name } : {}), fields };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Read one operation's request body.
|
|
207
|
+
*
|
|
208
|
+
* @param operation - the OpenAPI operation object.
|
|
209
|
+
* @param components - the document's component map.
|
|
210
|
+
* @returns the body, or undefined when the operation takes none.
|
|
211
|
+
*/
|
|
212
|
+
export function projectRequestBody(operation, components) {
|
|
213
|
+
const body = operation.requestBody;
|
|
214
|
+
const resolvedBody = deref(body, components, 0);
|
|
215
|
+
if (!isRecord(resolvedBody))
|
|
216
|
+
return undefined;
|
|
217
|
+
const content = isRecord(resolvedBody.content) ? resolvedBody.content : undefined;
|
|
218
|
+
if (content === undefined)
|
|
219
|
+
return undefined;
|
|
220
|
+
// Prefer JSON: it is what the panel can prefill and send.
|
|
221
|
+
const types = Object.keys(content);
|
|
222
|
+
if (types.length === 0)
|
|
223
|
+
return undefined;
|
|
224
|
+
const preferred = types.find((type) => type.includes("json")) ?? types[0];
|
|
225
|
+
const media = content[preferred];
|
|
226
|
+
if (!isRecord(media) || !isRecord(media.schema))
|
|
227
|
+
return undefined;
|
|
228
|
+
const resolved = resolveSchema(media.schema, components);
|
|
229
|
+
return {
|
|
230
|
+
contentType: preferred,
|
|
231
|
+
...(resolved.schemaName !== undefined ? { schemaName: resolved.schemaName } : {}),
|
|
232
|
+
fields: resolved.fields,
|
|
233
|
+
...(resolved.unresolved ? { unresolved: true } : {}),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Read one operation's declared responses.
|
|
238
|
+
*
|
|
239
|
+
* @param operation - the OpenAPI operation object.
|
|
240
|
+
* @param components - the document's component map.
|
|
241
|
+
* @returns responses ordered numerically with `default` last.
|
|
242
|
+
*/
|
|
243
|
+
export function projectResponses(operation, components) {
|
|
244
|
+
const responses = operation.responses;
|
|
245
|
+
if (!isRecord(responses))
|
|
246
|
+
return [];
|
|
247
|
+
const out = [];
|
|
248
|
+
for (const [status, raw] of Object.entries(responses)) {
|
|
249
|
+
const resolved = deref(raw, components, 0);
|
|
250
|
+
if (!isRecord(resolved))
|
|
251
|
+
continue;
|
|
252
|
+
const description = typeof resolved.description === "string" && resolved.description !== "" ? resolved.description : undefined;
|
|
253
|
+
const content = isRecord(resolved.content) ? resolved.content : undefined;
|
|
254
|
+
if (content === undefined || Object.keys(content).length === 0) {
|
|
255
|
+
// A bodyless response is common (204, or `@Content` with no schema).
|
|
256
|
+
out.push({ status, ...(description !== undefined ? { description } : {}), fields: [] });
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const types = Object.keys(content);
|
|
260
|
+
const preferred = types.find((type) => type.includes("json")) ?? types[0];
|
|
261
|
+
const media = content[preferred];
|
|
262
|
+
if (!isRecord(media) || !isRecord(media.schema)) {
|
|
263
|
+
out.push({ status, ...(description !== undefined ? { description } : {}), fields: [] });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const schema = resolveSchema(media.schema, components);
|
|
267
|
+
out.push({
|
|
268
|
+
status,
|
|
269
|
+
...(description !== undefined ? { description } : {}),
|
|
270
|
+
contentType: preferred,
|
|
271
|
+
...(schema.schemaName !== undefined ? { schemaName: schema.schemaName } : {}),
|
|
272
|
+
fields: schema.fields,
|
|
273
|
+
...(schema.unresolved ? { unresolved: true } : {}),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const rank = (status) => (status === "default" ? Number.MAX_SAFE_INTEGER : Number(status) || Number.MAX_SAFE_INTEGER - 1);
|
|
277
|
+
return out.sort((left, right) => rank(left.status) - rank(right.status));
|
|
278
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
/**
|
|
6
|
+
* Generate an OpenAPI document from a Spring Boot project by running it.
|
|
7
|
+
*
|
|
8
|
+
* A Spring controller's real shape — parameter types, required flags, request body
|
|
9
|
+
* fields, response schemas, examples, ranges — lives in the Java type system and is
|
|
10
|
+
* only resolved at runtime by springdoc. A source scan can find `@PostMapping("/x")`
|
|
11
|
+
* and nothing else; worse, it mis-reads the constant expressions that real projects
|
|
12
|
+
* use for prefixes and emits paths that look plausible and are wrong.
|
|
13
|
+
*
|
|
14
|
+
* So for a Spring project the workbench asks the project itself. The output is an
|
|
15
|
+
* ordinary OpenAPI document, which the existing spec pipeline already knows how to
|
|
16
|
+
* read — no bespoke Java parsing to keep in sync with Spring.
|
|
17
|
+
*
|
|
18
|
+
* Everything here is bounded and non-destructive: a fixed set of commands with no
|
|
19
|
+
* shell, no arguments from the request, a timeout per step, and a temp directory
|
|
20
|
+
* outside the repository for the document.
|
|
21
|
+
*/
|
|
22
|
+
const execFileAsync = promisify(execFile);
|
|
23
|
+
/**
|
|
24
|
+
* Run one command with its arguments, on either platform.
|
|
25
|
+
*
|
|
26
|
+
* On Windows `mvn` and `gradlew` are batch files, and `execFile` cannot start a
|
|
27
|
+
* `.cmd` — it fails with ENOENT even though the tool is on PATH. `cmd.exe /d /s /c`
|
|
28
|
+
* is the documented way to run a batch file, and it is used with a fixed argument
|
|
29
|
+
* list built here, never with anything from a request.
|
|
30
|
+
*
|
|
31
|
+
* @param command - executable name.
|
|
32
|
+
* @param args - fixed argument list.
|
|
33
|
+
* @param options - cwd and timeout.
|
|
34
|
+
* @returns the child process result.
|
|
35
|
+
*/
|
|
36
|
+
async function runCommand(command, args, options) {
|
|
37
|
+
const isWindowsBatch = process.platform === "win32" && !command.endsWith(".exe");
|
|
38
|
+
if (!isWindowsBatch) {
|
|
39
|
+
const result = await execFileAsync(command, [...args], {
|
|
40
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
41
|
+
timeout: options.timeout,
|
|
42
|
+
windowsHide: true,
|
|
43
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
44
|
+
});
|
|
45
|
+
return { stdout: String(result.stdout ?? ""), stderr: String(result.stderr ?? "") };
|
|
46
|
+
}
|
|
47
|
+
// Quote each argument for cmd.exe; none of them come from a request.
|
|
48
|
+
const quoted = args.map((arg) => (/[\s"]/.test(arg) ? `"${arg.replaceAll('"', '\\"')}"` : arg)).join(" ");
|
|
49
|
+
const result = await execFileAsync("cmd.exe", ["/d", "/s", "/c", `${command} ${quoted}`], {
|
|
50
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
51
|
+
timeout: options.timeout,
|
|
52
|
+
windowsHide: true,
|
|
53
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
54
|
+
});
|
|
55
|
+
return { stdout: String(result.stdout ?? ""), stderr: String(result.stderr ?? "") };
|
|
56
|
+
}
|
|
57
|
+
/** Nothing here should take minutes silently; each step reports its own failure. */
|
|
58
|
+
const BUILD_TIMEOUT_MS = 240_000;
|
|
59
|
+
const BOOT_TIMEOUT_MS = 90_000;
|
|
60
|
+
const FETCH_TIMEOUT_MS = 15_000;
|
|
61
|
+
/** How long to keep polling the app's api-docs endpoint before giving up. */
|
|
62
|
+
const READY_POLL_MS = 1_000;
|
|
63
|
+
const READY_DEADLINE_MS = 45_000;
|
|
64
|
+
/** Files whose presence marks a directory as a Maven or Gradle project. */
|
|
65
|
+
const BUILD_FILES = [
|
|
66
|
+
{ file: "pom.xml", buildTool: "maven" },
|
|
67
|
+
{ file: "build.gradle", buildTool: "gradle" },
|
|
68
|
+
{ file: "build.gradle.kts", buildTool: "gradle" },
|
|
69
|
+
];
|
|
70
|
+
/** Dependencies that make a project able to serve an OpenAPI document. */
|
|
71
|
+
const OPENAPI_DEPENDENCY = /springdoc|springfox|swagger-ui|openapi/i;
|
|
72
|
+
/** Directories never worth descending into when looking for modules. */
|
|
73
|
+
const SEARCH_SKIP = new Set(["target", "build", ".git", "node_modules", "out", ".gradle", ".mvn"]);
|
|
74
|
+
async function exists(target) {
|
|
75
|
+
try {
|
|
76
|
+
await access(target);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Find every Spring project in a workspace.
|
|
85
|
+
*
|
|
86
|
+
* A workspace often holds several Maven modules (the layout this was written for:
|
|
87
|
+
* `service/service` and `service/remote-api-service`), so the search descends a
|
|
88
|
+
* bounded number of levels instead of only checking the root.
|
|
89
|
+
*
|
|
90
|
+
* @param repoRoot - the workspace root.
|
|
91
|
+
* @param maxDepth - how many directory levels to inspect.
|
|
92
|
+
* @returns each project root with its build tool and OpenAPI dependency status.
|
|
93
|
+
*/
|
|
94
|
+
export async function findSpringProjects(repoRoot, maxDepth = 3) {
|
|
95
|
+
const found = [];
|
|
96
|
+
const walk = async (dir, depth) => {
|
|
97
|
+
if (depth > maxDepth || found.length >= 12)
|
|
98
|
+
return;
|
|
99
|
+
for (const candidate of BUILD_FILES) {
|
|
100
|
+
const buildFile = path.join(dir, candidate.file);
|
|
101
|
+
if (!(await exists(buildFile)))
|
|
102
|
+
continue;
|
|
103
|
+
let text = "";
|
|
104
|
+
try {
|
|
105
|
+
text = await readFile(buildFile, "utf8");
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const relative = path.relative(repoRoot, dir).replace(/\\/g, "/");
|
|
111
|
+
found.push({
|
|
112
|
+
dir: relative === "" ? "." : relative,
|
|
113
|
+
absolute: dir,
|
|
114
|
+
buildTool: candidate.buildTool,
|
|
115
|
+
hasOpenApiDependency: OPENAPI_DEPENDENCY.test(text),
|
|
116
|
+
});
|
|
117
|
+
// A module's own build file ends the descent: nested builds are separate.
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let entries;
|
|
121
|
+
try {
|
|
122
|
+
entries = await (await import("node:fs/promises")).readdir(dir, { withFileTypes: true });
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (const entry of entries) {
|
|
128
|
+
if (!entry.isDirectory() || SEARCH_SKIP.has(entry.name))
|
|
129
|
+
continue;
|
|
130
|
+
await walk(path.join(dir, entry.name), depth + 1);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
await walk(repoRoot, 0);
|
|
134
|
+
return found;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Whether a JDK and the project's build tool are on PATH.
|
|
138
|
+
*
|
|
139
|
+
* Checked before a build so a missing toolchain is reported as such instead of
|
|
140
|
+
* surfacing as an opaque build failure.
|
|
141
|
+
*
|
|
142
|
+
* @returns the missing tools, empty when everything needed is present.
|
|
143
|
+
*/
|
|
144
|
+
export async function missingToolchain() {
|
|
145
|
+
const missing = [];
|
|
146
|
+
for (const [name, args] of [["java", ["-version"]], ["mvn", ["-v"]]]) {
|
|
147
|
+
try {
|
|
148
|
+
await runCommand(name, args, { timeout: 15_000 });
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
missing.push(name);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return missing;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Run one build command in the project directory.
|
|
158
|
+
*
|
|
159
|
+
* `execFile` rather than a shell: every argument is fixed here, so nothing from a
|
|
160
|
+
* request can reach a command line.
|
|
161
|
+
*
|
|
162
|
+
* @param project - the project to build.
|
|
163
|
+
* @returns nothing on success; the failure message otherwise.
|
|
164
|
+
*/
|
|
165
|
+
async function build(project) {
|
|
166
|
+
const [command, args] = project.buildTool === "maven"
|
|
167
|
+
? ["mvn", ["-q", "-DskipTests", "package", "spring-boot:repackage"]]
|
|
168
|
+
: [process.platform === "win32" ? "gradlew.bat" : "./gradlew", ["bootJar", "-x", "test", "--quiet"]];
|
|
169
|
+
try {
|
|
170
|
+
await runCommand(command, args, { cwd: project.absolute, timeout: BUILD_TIMEOUT_MS });
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
const detail = error;
|
|
175
|
+
return (detail.stderr || detail.stdout || detail.message || "构建失败").slice(-4_000);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Pick a port that is very unlikely to collide, per project.
|
|
180
|
+
*
|
|
181
|
+
* Derived from the directory name so two modules in one workspace do not fight for
|
|
182
|
+
* the same one; the application is started with this port explicitly, overriding
|
|
183
|
+
* whatever the project configured.
|
|
184
|
+
*
|
|
185
|
+
* @param seed - text to derive from.
|
|
186
|
+
* @returns a port in a high, private range.
|
|
187
|
+
*/
|
|
188
|
+
export function probePort(seed) {
|
|
189
|
+
let hash = 0;
|
|
190
|
+
for (const char of seed)
|
|
191
|
+
hash = (hash * 31 + char.charCodeAt(0)) % 20_000;
|
|
192
|
+
return 18_100 + hash;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Locate the runnable jar the build produced.
|
|
196
|
+
*
|
|
197
|
+
* @param project - the project whose build output to inspect.
|
|
198
|
+
* @returns the jar path, or undefined when the build left none.
|
|
199
|
+
*/
|
|
200
|
+
async function findJar(project) {
|
|
201
|
+
const libs = path.join(project.absolute, "build", "libs");
|
|
202
|
+
const target = path.join(project.absolute, "target");
|
|
203
|
+
const dirs = project.buildTool === "maven" ? [target] : [libs, target];
|
|
204
|
+
for (const dir of dirs) {
|
|
205
|
+
let names;
|
|
206
|
+
try {
|
|
207
|
+
names = await (await import("node:fs/promises")).readdir(dir);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
// Prefer a repackaged (fat) jar; `-plain` and `-sources` are never runnable.
|
|
213
|
+
const candidates = names
|
|
214
|
+
.filter((name) => name.endsWith(".jar") && !/-plain\.jar$|-sources\.jar$|-javadoc\.jar$/.test(name))
|
|
215
|
+
.sort((a, b) => (a.includes("SNAPSHOT") ? -1 : 0) - (b.includes("SNAPSHOT") ? -1 : 0));
|
|
216
|
+
if (candidates.length > 0)
|
|
217
|
+
return path.join(dir, candidates[0]);
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Start the application and fetch its OpenAPI document, then stop it.
|
|
223
|
+
*
|
|
224
|
+
* The document is returned as text rather than a path: it belongs in the workbench's
|
|
225
|
+
* spec list, not in the user's repository, and writing it into their tree would be a
|
|
226
|
+
* side effect this feature has no business having.
|
|
227
|
+
*
|
|
228
|
+
* @param project - the project to run.
|
|
229
|
+
* @returns the document, or a coded failure with an operator-facing message.
|
|
230
|
+
*/
|
|
231
|
+
async function runAndFetch(project) {
|
|
232
|
+
const jar = await findJar(project);
|
|
233
|
+
if (jar === undefined) {
|
|
234
|
+
return { ok: false, code: "BUILD_FAILED", message: "构建完成但没有找到可运行的 jar,请确认是 Spring Boot 项目。" };
|
|
235
|
+
}
|
|
236
|
+
const port = probePort(project.dir);
|
|
237
|
+
const child = (await import("node:child_process")).spawn("java", ["-jar", jar, `--server.port=${port}`, "--springdoc.api-docs.enabled=true"], { cwd: project.absolute, windowsHide: true, stdio: "ignore", detached: false });
|
|
238
|
+
let exited = false;
|
|
239
|
+
child.on("exit", () => { exited = true; });
|
|
240
|
+
const stop = () => {
|
|
241
|
+
if (!exited) {
|
|
242
|
+
try {
|
|
243
|
+
child.kill();
|
|
244
|
+
}
|
|
245
|
+
catch { /* already gone */ }
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const started = Date.now();
|
|
249
|
+
try {
|
|
250
|
+
const deadline = started + READY_DEADLINE_MS;
|
|
251
|
+
while (Date.now() < deadline && !exited) {
|
|
252
|
+
await new Promise((resolve) => setTimeout(resolve, READY_POLL_MS));
|
|
253
|
+
for (const candidate of ["/v3/api-docs", "/v3/api-docs/swagger-config"]) {
|
|
254
|
+
const controller = new AbortController();
|
|
255
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
256
|
+
try {
|
|
257
|
+
const response = await fetch(`http://127.0.0.1:${port}${candidate}`, { signal: controller.signal });
|
|
258
|
+
if (!response.ok)
|
|
259
|
+
continue;
|
|
260
|
+
const text = await response.text();
|
|
261
|
+
// swagger-config is a pointer, not a document.
|
|
262
|
+
if (candidate.endsWith("swagger-config"))
|
|
263
|
+
continue;
|
|
264
|
+
const parsed = JSON.parse(text);
|
|
265
|
+
if (!parsed || typeof parsed.paths !== "object")
|
|
266
|
+
continue;
|
|
267
|
+
return { ok: true, document: text, buildTool: project.buildTool, elapsedMs: Date.now() - started, warnings: [] };
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// Not up yet, or not this route; keep polling.
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
clearTimeout(timer);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
ok: false, code: exited ? "BOOT_FAILED" : "DOCS_UNAVAILABLE",
|
|
279
|
+
message: exited
|
|
280
|
+
? "应用启动后立即退出,无法读取接口文档。请确认它能独立启动(不依赖外部数据库等)。"
|
|
281
|
+
: "应用已启动,但在 45 秒内没有提供 OpenAPI 文档。请确认已引入 springdoc-openapi 依赖。",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
stop();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Generate an OpenAPI document for one Spring project.
|
|
290
|
+
*
|
|
291
|
+
* @param project - the project to run.
|
|
292
|
+
* @returns the document text or a coded failure.
|
|
293
|
+
*/
|
|
294
|
+
export async function generateSpringDocument(project) {
|
|
295
|
+
if (!project.hasOpenApiDependency) {
|
|
296
|
+
return {
|
|
297
|
+
ok: false, code: "NOT_SPRING",
|
|
298
|
+
message: "该项目没有引入 springdoc-openapi 依赖,无法生成接口文档。可添加依赖后重试,或继续使用代码扫描结果。",
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const missing = await missingToolchain();
|
|
302
|
+
if (missing.length > 0) {
|
|
303
|
+
return {
|
|
304
|
+
ok: false, code: "TOOLCHAIN_MISSING",
|
|
305
|
+
message: `缺少 ${missing.join(" 和 ")},无法构建项目。安装后重试,或继续使用代码扫描结果。`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const buildError = await build(project);
|
|
309
|
+
if (buildError !== undefined) {
|
|
310
|
+
return { ok: false, code: "BUILD_FAILED", message: "项目构建失败。", detail: buildError };
|
|
311
|
+
}
|
|
312
|
+
return runAndFetch(project);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Persist a generated document into the workbench's own storage.
|
|
316
|
+
*
|
|
317
|
+
* Kept out of the repository on purpose: the file is derived, regenerable, and
|
|
318
|
+
* writing into someone's source tree is not this feature's call to make.
|
|
319
|
+
*
|
|
320
|
+
* @param appDataRoot - the Console data root.
|
|
321
|
+
* @param workspaceId - owning workspace.
|
|
322
|
+
* @param projectDir - the project the document came from.
|
|
323
|
+
* @param document - the raw JSON text.
|
|
324
|
+
* @returns the absolute path written.
|
|
325
|
+
*/
|
|
326
|
+
export async function writeGeneratedSpec(appDataRoot, workspaceId, projectDir, document) {
|
|
327
|
+
const slug = projectDir === "." ? "root" : projectDir.replace(/[^a-z0-9]+/gi, "-");
|
|
328
|
+
const dir = path.join(appDataRoot, "api-workbench", "generated", workspaceId);
|
|
329
|
+
await mkdir(dir, { recursive: true });
|
|
330
|
+
const file = path.join(dir, `${slug}.openapi.json`);
|
|
331
|
+
await writeFile(file, document, "utf8");
|
|
332
|
+
return file;
|
|
333
|
+
}
|