@camunda8/docusaurus-plugin-openapi-docs 4.5.4 → 4.6.1

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.
@@ -8,6 +8,9 @@ export interface SdkExampleSource {
8
8
  highlight?: string;
9
9
  /** Path to the operation-map.json file (relative to site root or absolute). */
10
10
  operationMapPath: string;
11
+ /** Default import/using statement prepended to every code sample for this language.
12
+ * Individual entries in operation-map.json can override this with their own `imports` field. */
13
+ defaultImports?: string;
11
14
  }
12
15
  /**
13
16
  * A single entry in operation-map.json for one operationId.
@@ -16,6 +19,8 @@ interface OperationMapEntry {
16
19
  file: string;
17
20
  region: string;
18
21
  label?: string;
22
+ /** Import/using statement to prepend to the code sample (e.g. "import { CamundaClient } from ..."). */
23
+ imports?: string;
19
24
  }
20
25
  /**
21
26
  * Shape of operation-map.json: operationId -> entries[].
@@ -116,6 +116,7 @@ function camelToSnake(str) {
116
116
  * @returns Array of x-codeSamples entries, or empty array if none found.
117
117
  */
118
118
  function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache) {
119
+ var _a;
119
120
  const samples = [];
120
121
  for (const sdk of sdkExamples) {
121
122
  const mapPath = path_1.default.resolve(siteDir, sdk.operationMapPath);
@@ -140,6 +141,7 @@ function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache
140
141
  if (!entries || entries.length === 0)
141
142
  continue;
142
143
  const mapDir = path_1.default.dirname(mapPath);
144
+ const hasMultipleEntries = entries.length > 1;
143
145
  for (const entry of entries) {
144
146
  const filePath = path_1.default.resolve(mapDir, entry.file);
145
147
  let fileContent = fileCache.get(filePath);
@@ -156,10 +158,14 @@ function buildCodeSamples(operationId, sdkExamples, siteDir, fileCache, mapCache
156
158
  console.warn(`SDK examples: region "${entry.region}" not found in ${filePath} (${sdk.lang}, ${operationId})`);
157
159
  continue;
158
160
  }
161
+ // Use "SDK - <label>" only when there are multiple entries for the same
162
+ // operationId, so readers can distinguish between variants.
163
+ const label = hasMultipleEntries && entry.label ? `SDK - ${entry.label}` : "SDK";
164
+ const imports = (_a = entry.imports) !== null && _a !== void 0 ? _a : sdk.defaultImports;
159
165
  samples.push({
160
166
  lang: sdk.lang,
161
- label: "SDK",
162
- source: code,
167
+ label,
168
+ source: imports ? `${imports}\n\n${code}` : code,
163
169
  });
164
170
  }
165
171
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@camunda8/docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "4.5.4",
4
+ "version": "4.6.1",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -19,6 +19,9 @@ export interface SdkExampleSource {
19
19
  highlight?: string;
20
20
  /** Path to the operation-map.json file (relative to site root or absolute). */
21
21
  operationMapPath: string;
22
+ /** Default import/using statement prepended to every code sample for this language.
23
+ * Individual entries in operation-map.json can override this with their own `imports` field. */
24
+ defaultImports?: string;
22
25
  }
23
26
 
24
27
  /**
@@ -28,6 +31,8 @@ interface OperationMapEntry {
28
31
  file: string;
29
32
  region: string;
30
33
  label?: string;
34
+ /** Import/using statement to prepend to the code sample (e.g. "import { CamundaClient } from ..."). */
35
+ imports?: string;
31
36
  }
32
37
 
33
38
  /**
@@ -187,6 +192,7 @@ export function buildCodeSamples(
187
192
  if (!entries || entries.length === 0) continue;
188
193
 
189
194
  const mapDir = path.dirname(mapPath);
195
+ const hasMultipleEntries = entries.length > 1;
190
196
 
191
197
  for (const entry of entries) {
192
198
  const filePath = path.resolve(mapDir, entry.file);
@@ -210,10 +216,16 @@ export function buildCodeSamples(
210
216
  continue;
211
217
  }
212
218
 
219
+ // Use "SDK - <label>" only when there are multiple entries for the same
220
+ // operationId, so readers can distinguish between variants.
221
+ const label =
222
+ hasMultipleEntries && entry.label ? `SDK - ${entry.label}` : "SDK";
223
+
224
+ const imports = entry.imports ?? sdk.defaultImports;
213
225
  samples.push({
214
226
  lang: sdk.lang,
215
- label: "SDK",
216
- source: code,
227
+ label,
228
+ source: imports ? `${imports}\n\n${code}` : code,
217
229
  });
218
230
  }
219
231
  }