docusaurus-openapi-docs
docusaurus-openapi-docs copied to clipboard
Can't run clean demo project from doc steps
Documentation link
https://github.com/PaloAltoNetworks/docusaurus-openapi-docs
Describe the problem
- run all steps from Installing from Template
- run yarn add docusaurus-plugin-openapi-docs
- run yarn add docusaurus-theme-openapi-docs
- pasted config from Configuring docusaurus.config.js (Plugin and theme usage)
- 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
: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",
// },
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 what is your original folder structure. I can see changes, but its not clear how it correlates with filesystem
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".