-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ebe794
commit 487644f
Showing
10 changed files
with
310 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
title: Migrating to V1 | ||
title: Migrating from v0 | ||
sidebar_position: 4 | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
slug: / | ||
title: Introduction | ||
sidebar_position: 0 | ||
author: Rohit Gohri | ||
author_url: https://rohit.page | ||
--- | ||
|
||
Redocusaurus is a preset for Docusaurus to help you integrate OpenAPI documentation via [Redoc](https://github.com/redocly/redoc/). It was created to make it easy to have API docs that live with your other documentation and look and feel like a part of it. | ||
|
||
## Features | ||
|
||
- Built with 💚 and Typescript | ||
- In built types | ||
- Easy to setup and already themed | ||
- Just add the preset and pass it your YAML | ||
- Dark Mode support | ||
- Customizable | ||
- Change Redoc Options | ||
- [Swizzle](https://docusaurus.io/docs/using-themes#swizzling-theme-components) components to your needs |
101 changes: 101 additions & 0 deletions
101
website/versioned_docs/version-0.x/getting-started/Installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
title: Installation | ||
sidebar_position: 0 | ||
author: Rohit Gohri | ||
author_url: https://rohit.page | ||
--- | ||
|
||
1. Install redocusaurus: | ||
|
||
![npm](https://img.shields.io/npm/v/redocusaurus?style=flat-square) | ||
|
||
```sh | ||
npm i --save redocusaurus | ||
``` | ||
|
||
1. Add it as a preset to your docusaurus config and pass options: | ||
|
||
- Pass it a OpenAPI spec URL | ||
|
||
```js | ||
// docusaurus.config.js | ||
|
||
module.exports = { | ||
// ... | ||
presets: [ | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
specUrl: 'https://redocly.github.io/redoc/openapi.yaml', | ||
}, | ||
], | ||
}, | ||
], | ||
], | ||
// ... | ||
}; | ||
``` | ||
|
||
- Pass it a OpenAPI spec local path | ||
|
||
```js | ||
// docusaurus.config.js | ||
module.exports = { | ||
// ... | ||
presets: [ | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
spec: 'openapi.yaml', | ||
}, | ||
], | ||
}, | ||
], | ||
], | ||
// ... | ||
}; | ||
``` | ||
|
||
The API Doc will be available by default at `/api/` path. If you wish to | ||
override this path, you may set the `routePath` option. To skip adding a | ||
route altogether, set the `addRoute` option to false. You will still be | ||
able to reference schema elements manually using [Schema Imports](/docs/guides/schema-imports). | ||
|
||
```js | ||
// docusaurus.config.js | ||
module.exports = { | ||
// ... | ||
presets: [ | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
id: 'default-route', | ||
// routePath: '/api/', | ||
// addRoute: true, | ||
}, | ||
{ | ||
id: 'route-overridden', | ||
routePath: '/different-path/', | ||
// addRoute: true, | ||
}, | ||
{ | ||
id: 'no-route', | ||
addRoute: false, | ||
}, | ||
], | ||
}, | ||
], | ||
], | ||
// ... | ||
}; | ||
``` | ||
|
||
To customize it see [full plugin options](#options). |
2 changes: 2 additions & 0 deletions
2
website/versioned_docs/version-0.x/getting-started/_category_.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label: 'Getting Started' | ||
position: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label: 'Guides' | ||
position: 2 |
91 changes: 91 additions & 0 deletions
91
website/versioned_docs/version-0.x/guides/schema-imports.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
title: Schema Imports | ||
--- | ||
|
||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
You can import model definitions from your API schema and render them in your Docusaurus Docs. You'll need to create an `.mdx` file and import the React Component. Read more [here about MDX in Docusaurus](https://docusaurus.io/docs/markdown-features/react). | ||
|
||
# Import Schema Model in Docs | ||
|
||
The `pointer` prop is passed on to [Redoc](https://redoc.ly/docs/resources/ref-guide/#pointer). | ||
|
||
```tsx | ||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
<ApiSchema pointer="#/components/schemas/Pet" />; | ||
``` | ||
|
||
### Results | ||
|
||
<ApiSchema pointer="#/components/schemas/Pet" /> | ||
|
||
## Import Schema Model (with example) in Docs | ||
|
||
```tsx | ||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
<ApiSchema example pointer="#/components/schemas/Pet" />; | ||
``` | ||
|
||
### Results | ||
|
||
<ApiSchema example pointer="#/components/schemas/Pet" /> | ||
|
||
## Importing Schema Model with multiple OpenAPI schemas | ||
|
||
If you have multiple APIs loaded with redocusaurus, then it is recommended to add `id`s to the config so that you can refer them when loading schema models. | ||
|
||
```js title="docusaurus.config.js" | ||
const config = { | ||
presets: [ | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
id: 'using-spec-url', | ||
specUrl: 'https://redocly.github.io/redoc/openapi.yaml', | ||
routePath: '/examples/using-spec-url/', | ||
}, | ||
{ | ||
id: 'using-relative-url', | ||
specUrl: `${process.env.DEPLOY_BASE_URL || '/'}openapi-page.yaml`, | ||
routePath: '/examples/using-relative-url/', | ||
}, | ||
], | ||
theme: { | ||
/** | ||
* Highlight color for docs | ||
*/ | ||
primaryColor: '#1890ff', | ||
/** | ||
* Options to pass to redoc | ||
* @see https://github.com/redocly/redoc#redoc-options-object | ||
*/ | ||
redocOptions: { hideDownloadButton: false, disableSearch: true }, | ||
}, | ||
}, | ||
], | ||
'@docusaurus/preset-classic', | ||
], | ||
title: 'Redocusaurus', | ||
}; | ||
``` | ||
|
||
```tsx | ||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
<ApiSchema id="using-single-yaml" pointer="#/components/schemas/Pet" />; | ||
<ApiSchema id="using-remote-url" pointer="#/components/schemas/Pet" />; | ||
``` | ||
|
||
### Results | ||
|
||
#### For ID `id="using-single-yaml"` | ||
|
||
<ApiSchema id="using-single-yaml" pointer="#/components/schemas/Pet" /> | ||
|
||
#### For ID `id="using-remote-url"` | ||
|
||
<ApiSchema id="using-remote-url" pointer="#/components/schemas/Pet" /> |
72 changes: 72 additions & 0 deletions
72
website/versioned_docs/version-0.x/guides/server-side-rendering.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
title: Server Side Rendering | ||
--- | ||
|
||
:::caution | ||
**NOTE:** This is in Beta. Please [add your feedback here](https://github.com/rohit-gohri/redocusaurus/discussions/88) | ||
::: | ||
|
||
## Prerequisites | ||
|
||
To enable SSR you have to do 2 things: | ||
|
||
### Updating your Root theme component | ||
|
||
Use the custom ServerStyle component in your [Theme Root](https://docusaurus.io/docs/using-themes#wrapper-your-site-with-root) (as mentioned [here](https://github.com/facebook/docusaurus/issues/3236#issuecomment-788953743)) for SSR like below: | ||
|
||
```tsx title="src/theme/Root/index.tsx" | ||
import React from 'react'; | ||
|
||
import ServerStyle from '@theme/ServerStyle'; | ||
|
||
function Root({ children }: { children: React.Component }): JSX.Element { | ||
return ( | ||
<> | ||
// TODO: Remove when docusaurus adds proper css-in-js support | ||
<ServerStyle from={children} /> | ||
{children} | ||
</> | ||
); | ||
} | ||
|
||
export default Root; | ||
``` | ||
|
||
### Use yaml files rather than urls to load OpenAPI files | ||
|
||
To enable SSR we need to parse the schema at build time so it needs to passed on as a yaml and it will be processed to JSON. This has a side-effect of the download button pointing to the JSON, to fix this you can also provide a `specUrl` to the original url that will be used as the download link. | ||
|
||
```js title="docusaurs.config.js" | ||
const config = { | ||
presets: [ | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
spec: 'openapi.yaml', | ||
/** | ||
* This becomes the Download URL in this case, while docs are generated from `spec` | ||
*/ | ||
specUrl: `${process.env.DEPLOY_BASE_URL || '/'}openapi-page.yaml`, | ||
routePath: '/examples/using-spec-yaml/', | ||
}, | ||
], | ||
theme: { | ||
/** | ||
* Highlight color for docs | ||
*/ | ||
primaryColor: '#1890ff', | ||
/** | ||
* Options to pass to redoc | ||
* @see https://github.com/redocly/redoc#redoc-options-object | ||
*/ | ||
redocOptions: { hideDownloadButton: false, disableSearch: true }, | ||
}, | ||
}, | ||
], | ||
'@docusaurus/preset-classic', | ||
], | ||
title: 'Redocusaurus', | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"defaultSidebar": [ | ||
{ | ||
"type": "autogenerated", | ||
"dirName": "." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"0.x" | ||
] |