cloud-annotations / docusaurus-openapi

πŸ¦• OpenAPI plugin for generating API reference docs in Docusaurus v2.
https://docusaurus-openapi.netlify.app
MIT License
498 stars 82 forks source link
api-documentation documentation-generator docusaurus hacktoberfest openapi openapi3 plugin react swagger

Docusaurus OpenAPI (beta)

OpenAPI plugin for generating API reference docs in Docusaurus v2. [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cloud-annotations/docusaurus-plugin-openapi/blob/HEAD/LICENSE) [![npm latest package](https://img.shields.io/npm/v/docusaurus-preset-openapi/latest.svg)](https://www.npmjs.com/package/docusaurus-preset-openapi) [![npm downloads](https://img.shields.io/npm/dm/docusaurus-plugin-openapi.svg)](https://www.npmjs.com/package/docusaurus-preset-openapi) [![build](https://github.com/cloud-annotations/docusaurus-plugin-openapi/actions/workflows/validate.yaml/badge.svg)](https://github.com/cloud-annotations/docusaurus-plugin-openapi/actions/workflows/validate.yaml)
[![prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/) [![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/cloud-annotations/docusaurus-plugin-openapi/blob/HEAD/CONTRIBUTING.md#pull-requests)

![](https://user-images.githubusercontent.com/4212769/85324376-b9e3d900-b497-11ea-9765-c42a8ad1ff61.png)

Quick Overview

npx create-docusaurus-openapi my-website
cd my-website
npm start

Coming from v0.1.0? See the migration guide.

(npx comes with npm 5.2+ and higher)

Then open http://localhost:3000/ to see your site.
When you’re ready to deploy to production, create a minified bundle with npm run build.

Creating a new Site

You’ll need to have Node 14.0.0 or later version on your local development machine (but it’s not required on the server). We recommend using the latest LTS version. You can use nvm (macOS/Linux) or nvm-windows to switch Node versions between different projects.

To create a new site, you may choose one of the following methods:

It will create a directory called my-website inside the current folder.
Inside that directory, it will generate the initial project structure and install the transitive dependencies:

my-website
β”œβ”€β”€ blog
β”‚   β”œβ”€β”€ 2019-05-28-hola.md
β”‚   β”œβ”€β”€ 2019-05-29-hello-world.md
β”‚   └── 2020-05-30-welcome.md
β”œβ”€β”€ docs
β”‚   β”œβ”€β”€ doc1.md
β”‚   β”œβ”€β”€ doc2.md
β”‚   β”œβ”€β”€ doc3.md
β”‚   └── mdx.md
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ css
β”‚   β”‚   └── custom.css
β”‚   └── pages
β”‚       β”œβ”€β”€ styles.module.css
β”‚       └── index.js
β”œβ”€β”€ static
β”‚   └── img
β”œβ”€β”€ .gitignore
β”œβ”€β”€ openapi.json
β”œβ”€β”€ docusaurus.config.js
β”œβ”€β”€ babel.config.js
β”œβ”€β”€ package.json
β”œβ”€β”€ sidebars.js
└── README.md

For more info see project structure rundown.

Once the installation is done, you can open your project folder:

cd my-website

Inside the newly created project, you can run some built-in commands:

npm start or yarn start

Runs the site in development mode.
Open http://localhost:3000 to view it in the browser.

The page will automatically reload if you make changes to the code.

npm run build or yarn build

Builds the site for production to the build folder.

Docusaurus is a modern static website generator that will build the website into a directory of static contents, which can be copied to any static file hosting service like GitHub pages, Vercel or Netlify.

Add to an existing Site

  1. Install the dependency

    npm install docusaurus-preset-openapi
  2. Edit your docusaurus.config.js file to use this preset

    presets: [
     [
       "docusaurus-preset-openapi",
       /** @type {import('docusaurus-preset-openapi').Options} */
       {
         api: {
           path: "<PATH_TO_YOUR_OPENAPI_DOCUMENT>",
           routeBasePath: "/api",
         },
         docs: {
           sidebarPath: require.resolve("./sidebars.js"),
           routeBasePath: "/",
         },
         theme: {
           customCss: require.resolve("./src/css/custom.css"),
         },
       },
     ],
    ];

Popular Alternatives

Docusaurus OpenAPI is great for:

Here are a few common cases where you might want to try something else:

Contributing

We encourage you to contribute to Docusaurus OpenAPI! Please check out the Contributing to Docusaurus OpenAPI guide for guidelines about how to proceed.

License

Docusaurus OpenAPI is released under the MIT License.