@camunda8/docusaurus-plugin-openapi-docs 4.5.3 → 4.6.0
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.
|
@@ -16,6 +16,8 @@ interface OperationMapEntry {
|
|
|
16
16
|
file: string;
|
|
17
17
|
region: string;
|
|
18
18
|
label?: string;
|
|
19
|
+
/** Import/using statement to prepend to the code sample (e.g. "import { CamundaClient } from ..."). */
|
|
20
|
+
imports?: string;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Shape of operation-map.json: operationId -> entries[].
|
|
@@ -125,7 +125,13 @@ function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache
|
|
|
125
125
|
console.warn(`SDK examples: operation-map not found at ${mapPath}`);
|
|
126
126
|
continue;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
try {
|
|
129
|
+
operationMap = fs_extra_1.default.readJSONSync(mapPath);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
console.warn(`SDK examples: failed to parse ${mapPath}: ${err instanceof Error ? err.message : err}`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
129
135
|
mapCache.set(mapPath, operationMap);
|
|
130
136
|
}
|
|
131
137
|
// Try exact match first, then fall back to snake_case conversion
|
|
@@ -134,6 +140,7 @@ function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache
|
|
|
134
140
|
if (!entries || entries.length === 0)
|
|
135
141
|
continue;
|
|
136
142
|
const mapDir = path_1.default.dirname(mapPath);
|
|
143
|
+
const hasMultipleEntries = entries.length > 1;
|
|
137
144
|
for (const entry of entries) {
|
|
138
145
|
const filePath = path_1.default.resolve(mapDir, entry.file);
|
|
139
146
|
let fileContent = fileCache.get(filePath);
|
|
@@ -150,10 +157,13 @@ function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache
|
|
|
150
157
|
console.warn(`SDK examples: region "${entry.region}" not found in ${filePath} (${sdk.lang}, ${operationId})`);
|
|
151
158
|
continue;
|
|
152
159
|
}
|
|
160
|
+
// Use "SDK - <label>" only when there are multiple entries for the same
|
|
161
|
+
// operationId, so readers can distinguish between variants.
|
|
162
|
+
const label = hasMultipleEntries && entry.label ? `SDK - ${entry.label}` : "SDK";
|
|
153
163
|
samples.push({
|
|
154
164
|
lang: sdk.lang,
|
|
155
|
-
label
|
|
156
|
-
source: code,
|
|
165
|
+
label,
|
|
166
|
+
source: entry.imports ? `${entry.imports}\n\n${code}` : code,
|
|
157
167
|
});
|
|
158
168
|
}
|
|
159
169
|
}
|
package/package.json
CHANGED
|
@@ -28,6 +28,8 @@ interface OperationMapEntry {
|
|
|
28
28
|
file: string;
|
|
29
29
|
region: string;
|
|
30
30
|
label?: string;
|
|
31
|
+
/** Import/using statement to prepend to the code sample (e.g. "import { CamundaClient } from ..."). */
|
|
32
|
+
imports?: string;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -169,7 +171,14 @@ export function buildCodeSamples(
|
|
|
169
171
|
console.warn(`SDK examples: operation-map not found at ${mapPath}`);
|
|
170
172
|
continue;
|
|
171
173
|
}
|
|
172
|
-
|
|
174
|
+
try {
|
|
175
|
+
operationMap = fs.readJSONSync(mapPath) as OperationMap;
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.warn(
|
|
178
|
+
`SDK examples: failed to parse ${mapPath}: ${err instanceof Error ? err.message : err}`
|
|
179
|
+
);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
173
182
|
mapCache.set(mapPath, operationMap);
|
|
174
183
|
}
|
|
175
184
|
|
|
@@ -180,6 +189,7 @@ export function buildCodeSamples(
|
|
|
180
189
|
if (!entries || entries.length === 0) continue;
|
|
181
190
|
|
|
182
191
|
const mapDir = path.dirname(mapPath);
|
|
192
|
+
const hasMultipleEntries = entries.length > 1;
|
|
183
193
|
|
|
184
194
|
for (const entry of entries) {
|
|
185
195
|
const filePath = path.resolve(mapDir, entry.file);
|
|
@@ -203,10 +213,15 @@ export function buildCodeSamples(
|
|
|
203
213
|
continue;
|
|
204
214
|
}
|
|
205
215
|
|
|
216
|
+
// Use "SDK - <label>" only when there are multiple entries for the same
|
|
217
|
+
// operationId, so readers can distinguish between variants.
|
|
218
|
+
const label =
|
|
219
|
+
hasMultipleEntries && entry.label ? `SDK - ${entry.label}` : "SDK";
|
|
220
|
+
|
|
206
221
|
samples.push({
|
|
207
222
|
lang: sdk.lang,
|
|
208
|
-
label
|
|
209
|
-
source: code,
|
|
223
|
+
label,
|
|
224
|
+
source: entry.imports ? `${entry.imports}\n\n${code}` : code,
|
|
210
225
|
});
|
|
211
226
|
}
|
|
212
227
|
}
|