docusaurus-plugin-openapi-docs 0.0.0-1081 → 0.0.0-1082

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/lib/index.js CHANGED
@@ -234,6 +234,7 @@ custom_edit_url: null
234
234
  schema: schemaPageGenerator,
235
235
  };
236
236
  loadedApi.map(async (item) => {
237
+ var _a, _b;
237
238
  if (downloadUrl) {
238
239
  item.downloadUrl = downloadUrl;
239
240
  }
@@ -257,9 +258,14 @@ custom_edit_url: null
257
258
  .toString("base64"));
258
259
  let infoBasePath = `${outputDir}/${item.infoId}`;
259
260
  if (docRouteBasePath) {
260
- infoBasePath = `${docRouteBasePath}/${outputDir
261
- .split(docPath)[1]
262
- .replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
261
+ // Safely extract path segment, handling cases where docPath may not be in outputDir
262
+ const outputSegment = docPath && outputDir.includes(docPath)
263
+ ? ((_b = (_a = outputDir.split(docPath)[1]) === null || _a === void 0 ? void 0 : _a.replace(/^\/+/g, "")) !== null && _b !== void 0 ? _b : "")
264
+ : outputDir
265
+ .slice(outputDir.indexOf("/", 1))
266
+ .replace(/^\/+/g, "");
267
+ infoBasePath =
268
+ `${docRouteBasePath}/${outputSegment}/${item.infoId}`.replace(/^\/+/g, "");
263
269
  }
264
270
  if (item.infoId)
265
271
  item.infoPath = infoBasePath;
@@ -81,9 +81,18 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
81
81
  if (sidebarOptions.groupPathsBy !== "tagGroup") {
82
82
  apiTags = (0, uniq_1.default)(apiTags.concat(operationTags, schemaTags));
83
83
  }
84
- const basePath = docPath
85
- ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
86
- : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
84
+ // Extract base path from outputDir, handling cases where docPath may not be in outputDir
85
+ const getBasePathFromOutput = (output, doc) => {
86
+ var _a, _b;
87
+ if (doc && output.includes(doc)) {
88
+ return (_b = (_a = output.split(doc)[1]) === null || _a === void 0 ? void 0 : _a.replace(/^\/+/g, "")) !== null && _b !== void 0 ? _b : "";
89
+ }
90
+ const slashIndex = output.indexOf("/", 1);
91
+ return slashIndex === -1
92
+ ? ""
93
+ : output.slice(slashIndex).replace(/^\/+/g, "");
94
+ };
95
+ const basePath = getBasePathFromOutput(outputDir, docPath);
87
96
  const createDocItemFnContext = {
88
97
  sidebarOptions,
89
98
  basePath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "0.0.0-1081",
4
+ "version": "0.0.0-1082",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=14"
67
67
  },
68
- "gitHead": "2b7184703cfbed61bafb8d671bbbb61ac5f187bc"
68
+ "gitHead": "7e23eae947f6c077f3a087f2b42368dbbadcb6bb"
69
69
  }
package/src/index.ts CHANGED
@@ -353,9 +353,18 @@ custom_edit_url: null
353
353
  .toString("base64"));
354
354
  let infoBasePath = `${outputDir}/${item.infoId}`;
355
355
  if (docRouteBasePath) {
356
- infoBasePath = `${docRouteBasePath}/${outputDir
357
- .split(docPath!)[1]
358
- .replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
356
+ // Safely extract path segment, handling cases where docPath may not be in outputDir
357
+ const outputSegment =
358
+ docPath && outputDir.includes(docPath)
359
+ ? (outputDir.split(docPath)[1]?.replace(/^\/+/g, "") ?? "")
360
+ : outputDir
361
+ .slice(outputDir.indexOf("/", 1))
362
+ .replace(/^\/+/g, "");
363
+ infoBasePath =
364
+ `${docRouteBasePath}/${outputSegment}/${item.infoId}`.replace(
365
+ /^\/+/g,
366
+ ""
367
+ );
359
368
  }
360
369
  if (item.infoId) item.infoPath = infoBasePath;
361
370
  }
@@ -125,9 +125,21 @@ function groupByTags(
125
125
  apiTags = uniq(apiTags.concat(operationTags, schemaTags));
126
126
  }
127
127
 
128
- const basePath = docPath
129
- ? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
130
- : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
128
+ // Extract base path from outputDir, handling cases where docPath may not be in outputDir
129
+ const getBasePathFromOutput = (
130
+ output: string,
131
+ doc: string | undefined
132
+ ): string => {
133
+ if (doc && output.includes(doc)) {
134
+ return output.split(doc)[1]?.replace(/^\/+/g, "") ?? "";
135
+ }
136
+ const slashIndex = output.indexOf("/", 1);
137
+ return slashIndex === -1
138
+ ? ""
139
+ : output.slice(slashIndex).replace(/^\/+/g, "");
140
+ };
141
+
142
+ const basePath = getBasePathFromOutput(outputDir, docPath);
131
143
 
132
144
  const createDocItemFnContext = {
133
145
  sidebarOptions,