Skip to content

Commit ef25e5e

Browse files
authored
Add a README to the preset package (#80)
1 parent c1346d3 commit ef25e5e

3 files changed

Lines changed: 116 additions & 6 deletions

File tree

packages/docusaurus-plugin-openapi/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
},
99
"types": "src/plugin-openapi.d.ts",
1010
"main": "dist/index.js",
11-
"files": [
12-
"/dist"
13-
],
1411
"scripts": {
1512
"build": "scripts/build.ts",
1613
"watch": "scripts/build.ts --watch"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<h1 align="center">Docusaurus OpenAPI</h1>
2+
3+
<div align="center">
4+
5+
OpenAPI plugin for generating API reference docs in Docusaurus v2.
6+
7+
</div>
8+
9+
<p align="center">
10+
11+
![](https://user-images.githubusercontent.com/4212769/85324376-b9e3d900-b497-11ea-9765-c42a8ad1ff61.png)
12+
13+
</p>
14+
15+
## Installation
16+
17+
Install the preset in your docusaurus project by running:
18+
19+
```sh
20+
// with npm
21+
npm install docusaurus-preset-openapi
22+
23+
// with yarn
24+
yarn add docusaurus-preset-openapi
25+
```
26+
27+
## Usage
28+
29+
1. Add your OpenAPI definition to the root of your site dir as `openapi.json` (See [Configuration](#Configuration) options below).
30+
31+
2. The OpenAPI preset can be used as a drop-in replacement for `@docusaurus/preset-classic`, replace it as follows:
32+
33+
```js
34+
/* docusaurus.config.js */
35+
36+
{
37+
presets: [
38+
[
39+
"docusaurus-preset-openapi",
40+
{
41+
// docs: { ... },
42+
// blogs: { ... },
43+
// theme: { ... },
44+
},
45+
],
46+
],
47+
}
48+
```
49+
50+
3. Add a link to the API section of your site by updating `themeConfig.navbar.items`:
51+
52+
```js
53+
/* docusaurus.config.js */
54+
55+
{
56+
themeConfig: {
57+
navbar: {
58+
items: [
59+
// ... other items
60+
{ to: "/api", label: "API", position: "left" },
61+
// ... other items
62+
],
63+
},
64+
},
65+
}
66+
```
67+
68+
## Configuration
69+
70+
The OpenAPI plugin can be configured with the following options:
71+
72+
| Name | Type | Default | Description |
73+
| ---------------------------- | --------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
74+
| `path` | `string` | `'openapi.json'` | Path to OpenAPI definition (`json` or `yaml`) on filesystem relative to site dir. |
75+
| `routeBasePath` | `string` | `'api'` | URL route for the API section of your site. **DO NOT** include a trailing slash. Use `/` for shipping API without base path. |
76+
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
77+
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
78+
| `apiLayoutComponent` | `string` | `'@theme/ApiPage'` | Root Layout component of each API page. |
79+
| `apiItemComponent` | `string` | `'@theme/ApiItem'` | Main API container, with demo panel, pagination, etc. |
80+
| `remarkPlugins` | `any[]` | `[]` | Remark plugins passed to MDX. |
81+
| `rehypePlugins` | `any[]` | `[]` | Rehype plugins passed to MDX. |
82+
| `beforeDefaultRemarkPlugins` | `any[]` | `[]` | Custom Remark plugins passed to MDX before the default Docusaurus Remark plugins. |
83+
| `beforeDefaultRehypePlugins` | `any[]` | `[]` | Custom Rehype plugins passed to MDX before the default Docusaurus Rehype plugins. |
84+
85+
Example:
86+
87+
```js
88+
/* docusaurus.config.js */
89+
90+
{
91+
presets: [
92+
[
93+
"docusaurus-preset-openapi",
94+
{
95+
api: {
96+
path: "api/cars.yaml"
97+
routeBasePath: "cars",
98+
// ... other options
99+
}
100+
},
101+
],
102+
],
103+
}
104+
```

packages/docusaurus-preset-openapi/package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
"description": "OpenAPI preset for Docusaurus.",
44
"version": "0.2.2",
55
"license": "MIT",
6+
"keywords": [
7+
"openapi",
8+
"swagger",
9+
"docusaurus",
10+
"documentation",
11+
"react"
12+
],
613
"publishConfig": {
714
"access": "public"
815
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/cloud-annotations/docusaurus-plugin-openapi.git",
19+
"directory": "packages/docusaurus-preset-openapi"
20+
},
921
"types": "src/preset-openapi.d.ts",
1022
"main": "dist/index.js",
11-
"files": [
12-
"/dist"
13-
],
1423
"scripts": {
1524
"build": "scripts/build.ts",
1625
"watch": "scripts/build.ts --watch"

0 commit comments

Comments
 (0)