DEV Community

Rohit Gohri
Rohit Gohri

Posted on • Originally published at rohit.page on

OpenAPI for Docusaurus! πŸ“˜

Introducing "Redocusaurus": Redoc for Docusaurus

Redocusaurus

npm downloads

What is it?

It is a preset that allows you to easily integrate OpenAPI documentation into your docs site made with docusaurus. It has 2 main components:

Using Redoc as a React component, this provides 2 theme components, @theme/ApiDoc and @theme/Redoc. You can use them directly in js pages in Docusaurus.

This creates routes from your OpenAPI files or URLs and renders with the components provided by the theme.

How to set it up?

Install the preset



npm i --save redocusaurus



Enter fullscreen mode Exit fullscreen mode

Add it to your docusaurus.config.js:



module.exports = {
 // ...
 presets: [
   // ... Other preset configs
   [
     'redocusaurus',
     {
       specs: [{
         route: '/api/',
         spec: 'https://redocly.github.io/redoc/openapi.yaml',
       }],
     }
   ],
 ],
 // ...
};



Enter fullscreen mode Exit fullscreen mode
  1. Rebuild your site and you will have your OpenAPI docs available at the /api/ route.

Extra features over directly using Redoc

The theme includes redoc settings and some custom css to make it match the @docusaurus/classic theme. Along with support for Dark Mode and Server Side Rendering.

Docs

Find the docs and examples at the website : https://redocusaurus.vercel.app/

Github Repo

Find the source and know more on Github.

github badge

Top comments (4)

Collapse
 
rohit_gohri profile image
Rohit Gohri • Edited

Feel free to open an issue on Github if you are having issues. I have fixed a lot of issues with the builds in the last few releases.

Collapse
 
radsatjob profile image
Radhika

I happen to help a developer set up this integration of existing Swagger API documentation with Docusaurus.

After following the instructions on the ReadMe to the T, seems like he is facing this issue that Andrew pointed out. No amount of downgrade worked.

What should he be doing?

Collapse
 
andrewpierno profile image
Andrew Pierno

Does this still work? Just tried installing it. nothing happens. no routes on /api available.

Collapse
 
christopherhsieh profile image
Christopher Hsieh

Works well on my end, especially with the last few releases. Make sure all dependencies are updated.

One method of troubleshooting that worked well for me was to pull down redocusaurus’ source, and try running the project nested in the β€œexample” folder. If the example works then you could work backwards to find differences in your project.