-
Notifications
You must be signed in to change notification settings - Fork 293
Description
Describe the bug
Setting an outputDir of docs/... fails consistently with the following error:
`outputDir: docs/business/accounts/business-wallet/Topups, docPath: ./docs
Loading of api failed for "[...]/docusaurus-home/bucket/business/accounts/business-wallet/business-wallet-app/topups.yaml"
[ERROR] TypeError: Cannot read properties of undefined (reading 'replace')
at groupByTags ([...]/docusaurus-home/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:86:38)
at generateSidebarSlice ([...]/docusaurus-home/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:224:24)
at generateApiDocs ([...]/docusaurus-home/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:107:53)
at async [...]/docusaurus-home/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:503:15
[INFO] Docusaurus version: 3.8.1
Node version: v22.14.0`
However, if I change the API config section to use ./docs/... instead, it works fine.
This may be related to the fact that my docusaurus project is configured with baseUrl: '/', and not `baseUrl: '/docs'.
Expected behavior
Given the online doc example for the outputPath gives a string of docs/... the build should work fine instead of throwing this .replace error.
It actually shouldn't matter whether the outputPath starts with ./ or not.
Current behavior
The build stops with the error reported above.
Possible solution
This is where it fails:
const basePath = docPath ? outputDir.split(docPath!)[1].replace(/^\/+/g, "") : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
See https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/main/packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts#L128
The issue is that [outputDir.split(docPath)[1]] will be undefined if [docPath] doesn't contain the exact string from docPath: in my case, it's set to ./docs -- which IS NOT something I set, but probably (wrongly) assumed given I'm using basePath / for my project.
Steps to reproduce
- Configure docusaurus project with basePath: '/'
- Add an API in the config section with outputPath: 'docs/....`
- Run the
gen-api-docs allcommand to see it fail. - Change the api config to use outputPath: './docs/...'
- Run the
gen-api-docs allcommand again to see it succeed.
Context
As described above:
- Using a docusaurus project with
basePath: '/' - Adding API docs as usual fails.
Your Environment
- Version used: Docusaurus 3.8.1 -- docusaurus-plugin-openapi-docs@^4.5.1
- Environment name and version (e.g. node v22.14.0):
- Operating System and version (desktop or mobile): OS X Sequoia 15.6.1