Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Error on .replace() in groupByTags() #1224

Open
Labels
bugSomething isn't working
@gsejourne

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

  1. Configure docusaurus project with basePath: '/'
  2. Add an API in the config section with outputPath: 'docs/....`
  3. Run the gen-api-docs all command to see it fail.
  4. Change the api config to use outputPath: './docs/...'
  5. Run the gen-api-docs all command 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /