Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/docusaurus-plugin-openapi-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,18 @@ custom_edit_url: null
.toString("base64"));
let infoBasePath = `${outputDir}/${item.infoId}`;
if (docRouteBasePath) {
infoBasePath = `${docRouteBasePath}/${outputDir
.split(docPath!)[1]
.replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
// Safely extract path segment, handling cases where docPath may not be in outputDir
const outputSegment =
docPath && outputDir.includes(docPath)
? (outputDir.split(docPath)[1]?.replace(/^\/+/g, "") ?? "")
: outputDir
.slice(outputDir.indexOf("/", 1))
.replace(/^\/+/g, "");
infoBasePath =
`${docRouteBasePath}/${outputSegment}/${item.infoId}`.replace(
/^\/+/g,
""
);
}
if (item.infoId) item.infoPath = infoBasePath;
}
Expand Down
18 changes: 15 additions & 3 deletions packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,21 @@ function groupByTags(
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
}

const basePath = docPath
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
// Extract base path from outputDir, handling cases where docPath may not be in outputDir
const getBasePathFromOutput = (
output: string,
doc: string | undefined
): string => {
if (doc && output.includes(doc)) {
return output.split(doc)[1]?.replace(/^\/+/g, "") ?? "";
}
const slashIndex = output.indexOf("/", 1);
return slashIndex === -1
? ""
: output.slice(slashIndex).replace(/^\/+/g, "");
};

const basePath = getBasePathFromOutput(outputDir, docPath);

const createDocItemFnContext = {
sidebarOptions,
Expand Down
Loading