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.
Import Schema Model in Docs
The pointer
prop is passed on to Redoc.
import ApiSchema from '@theme/ApiSchema';
<ApiSchema pointer="#/components/schemas/Pet" />;
Results
Import Schema Model (with example) in Docs
import ApiSchema from '@theme/ApiSchema';
<ApiSchema example pointer="#/components/schemas/Pet" />;
Results
id | integer <int64> |
object (Category) | |
name required | string |
photoUrls required | Array of strings |
Array of objects (Tag) | |
status | string Enum: "available" "pending" "sold" pet status in the store |
{- "id": 0,
- "category": {
- "id": 0,
- "name": "string"
}, - "name": "doggie",
- "photoUrls": [
- "string"
], - "tags": [
- {
- "id": 0,
- "name": "string"
}
], - "status": "available"
}
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.
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',
};
import ApiSchema from '@theme/ApiSchema';
<ApiSchema id="using-single-yaml" pointer="#/components/schemas/Pet" />;
<ApiSchema id="using-remote-url" pointer="#/components/schemas/Pet" />;