docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

Can't run clean demo project from doc steps

Open beastdrc opened this issue 2 years ago • 5 comments

Documentation link

https://github.com/PaloAltoNetworks/docusaurus-openapi-docs

Describe the problem

  1. run all steps from Installing from Template
  2. run yarn add docusaurus-plugin-openapi-docs
  3. run yarn add docusaurus-theme-openapi-docs
  4. pasted config from Configuring docusaurus.config.js (Plugin and theme usage)
  5. pasted swagger file to the project

got following:

` alex@Ubuntu-x64:~/Projects/docusaurus/openapi_example/test$ yarn docusaurus gen-api-docs all yarn run v1.22.19 warning package.json: "test" is also the name of a node core module $ docusaurus gen-api-docs all

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Update available 2.1.0 → 2.4.1 │ │ │ │ To upgrade Docusaurus packages with the latest version, run the following command: │ │ yarn upgrade @docusaurus/core@latest @docusaurus/preset-classic@latest @docusaurus/module-type-aliases@latest │ │ │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0 Successfully created "api/petstore" Loading of api failed for "/home/alex/Projects/plateam/platim.ru/src_docusaurus/openapi_example/test/openapi/swagger.yaml" [ERROR] TypeError: Cannot read properties of undefined (reading 'replace') at groupByTags (/home/alex/Projects/plateam/platim.ru/src_docusaurus/openapi_example/test/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:53:38) at generateSidebarSlice (/home/alex/Projects/plateam/platim.ru/src_docusaurus/openapi_example/test/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:160:24) at generateApiDocs (/home/alex/Projects/plateam/platim.ru/src_docusaurus/openapi_example/test/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:106:61) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async /home/alex/Projects/plateam/platim.ru/src_docusaurus/openapi_example/test/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:374:29 [INFO] Docusaurus version: 2.1.0 Node version: v16.17.1 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. `

Suggested fix

beastdrc avatar Aug 14 '23 10:08 beastdrc

:tada: Thanks for opening your first issue here! Welcome to the community!

Same problem here ✋

With cmd yarn docusaurus gen-api-docs all :

Loading of api failed for "/Users/guillaume/github/noticia/documentation/specs/petstore.yaml"
[ERROR] TypeError: Cannot read properties of undefined (reading 'replace')
    at groupByTags (/Users/guillaume/github/noticia/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:53:38)
    at generateSidebarSlice (/Users/guillaume/github/noticia/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js:160:24)
    at generateApiDocs (/Users/guillaume/github/noticia/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:106:61)
    at async /Users/guillaume/github/noticia/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:374:29
[INFO] Docusaurus version: 2.4.1
Node version: v18.17.0

It works when I remove this section from plugins.config :

// sidebarOptions: {
//   groupPathsBy: "tag",
// },

glarivie avatar Aug 17 '23 06:08 glarivie

I had the same. It turned out that this was because of the outputDir being set to an incorrect location.

This is what I had.

      {
        id: "openapi",
        docsPluginId: "classic", // e.g. "classic" or the plugin-content-docs id
        config: {
          secrets: { // "secrets" is considered the <id> that you will reference in the CLI
            specPath: "openapi/configuration.yaml", // path or URL to the OpenAPI spec
            outputDir: "api/configuration", // output directory for generated *.mdx and sidebar.js files
            sidebarOptions: {
              groupPathsBy: "tag", // generate a sidebar.js slice that groups operations by tag
            },
          }
        }
      },

But after making sure the outputDir was set to a subfolder of the docs folder it worked like a charm.

      {
        id: "openapi",
        docsPluginId: "classic", // e.g. "classic" or the plugin-content-docs id
        config: {
          secrets: { // "secrets" is considered the <id> that you will reference in the CLI
            specPath: "openapi/configuration.yaml", // path or URL to the OpenAPI spec
            outputDir: "docs/api/configuration", // output directory for generated *.mdx and sidebar.js files
            sidebarOptions: {
              groupPathsBy: "tag", // generate a sidebar.js slice that groups operations by tag
            },
          }
        }
      },

Tjeerd-menno avatar Jan 19 '24 06:01 Tjeerd-menno

@Tjeerd-menno what is your original folder structure. I can see changes, but its not clear how it correlates with filesystem

beastdrc avatar Jan 19 '24 07:01 beastdrc

Regarding the error message it seems failed at https://yarnpkg.com/package?q=docusaurus-plugin-openapi-docs&name=docusaurus-plugin-openapi-docs&version=2.1.0&file=/lib/sidebars/index.js Line 57:

    const basePath = docPath
        ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
        : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");

It appears docPath here is always "docs".

reilee avatar May 15 '24 06:05 reilee