-
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
Showing
4 changed files
with
161 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: 從 v0 升級 | ||
sidebar_position: 4 | ||
--- | ||
|
||
## 選項變更 | ||
|
||
1. `spec` - 現在可以是本地文件的路徑或絕對 URL。您現在也可以指向多文件 OpenAPI 定義的入口點,我們將為您打包。 | ||
|
||
1. `routePath` -> `route`(可選) - 現在仍然有效,但現在是可選的。 | ||
|
||
1. `redocOptions` -> `options`(可選) - 我們已經刪除了一些默認值(`downloadUrl` 曾經默認隱藏),現在將自定義留給用戶。 | ||
|
||
## 已移除的選項 | ||
|
||
1. `specUrl` - 根據傳遞的 spec 類型,現在由包自動處理。我們將把您的定義打包成單個可下載的 YAML,並在構建時將其作為靜態資產添加。 | ||
|
||
1. `addRoute` - 現在不再需要,因為 `route` 現在是可選的,因此如果不需要路由,請不要傳遞它。 | ||
|
||
1. `apiDocComponent` - 現在不再需要,因為我們提供了一個 react-hook `useSpecData` 來加載插件數據,可以與 `@theme/Redoc` 組件一起使用。 | ||
|
||
## 組件變更 | ||
|
||
### 已移除實驗性 `@theme/ServerStyle` | ||
|
||
現在,構建時/服務器端渲染對所有人默認有效,無需進行任何操作。 | ||
|
||
### `@theme/Redoc` 和 `@theme/ApiDoc` prop 變更 | ||
|
||
我們現在提供了一個新的 hook `@theme/useSpecData` 來加載 YAML 文件,您可以直接將結果傳遞給 `@theme/Redoc`,而無需自己解析 API 文件。 | ||
|
||
```jsx | ||
import React from 'react'; | ||
import Layout from '@theme/Layout'; | ||
import Redoc from '@theme/Redoc'; | ||
import useSpecData from '@theme/useSpecData'; | ||
|
||
function CustomPage() { | ||
const specData = useSpecData('using-custom-layout'); | ||
return ( | ||
<Layout | ||
title="Custom Layout Docs" | ||
description="Example showing custom layout" | ||
> | ||
<Redoc {...specData} /> | ||
</Layout> | ||
); | ||
} | ||
|
||
export default CustomPage; | ||
``` |
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,94 @@ | ||
--- | ||
title: Schema 匯入 | ||
sidebar_position: 1 | ||
--- | ||
|
||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
# Schema 匯入 | ||
|
||
您可以從 API schema 中匯入模型定義並在 Docusaurus 文檔中渲染它們。您需要創建一個 `.mdx` 文件並導入 React 組件。更多信息請參見 [Docusaurus 中的 MDX](https://docusaurus.io/docs/markdown-features/react)。 | ||
|
||
# 在文檔中匯入 Schema 模型 | ||
|
||
`pointer` prop 傳遞給 [Redoc](https://redoc.ly/docs/resources/ref-guide/#pointer)。 | ||
|
||
```tsx | ||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
<ApiSchema pointer="#/components/schemas/Pet" />; | ||
``` | ||
|
||
### 結果 | ||
|
||
<ApiSchema pointer="#/components/schemas/Pet" /> | ||
|
||
## 在文檔中匯入 Schema 模型(含範例) | ||
|
||
```tsx | ||
import ApiSchema from '@theme/ApiSchema'; | ||
|
||
<ApiSchema example pointer="#/components/schemas/Pet" />; | ||
``` | ||
|
||
### 結果 | ||
|
||
<ApiSchema example pointer="#/components/schemas/Pet" /> | ||
|
||
## 匯入多個 OpenAPI schema 的 Schema 模型 | ||
|
||
如果您已經使用 redocusaurus 載入了多個 API,則建議在配置中添加 `id`,以便在載入 schema 模型時可以引用它們。 | ||
|
||
```js title="docusaurus.config.js" | ||
const config = { | ||
presets: [ | ||
'@docusaurus/preset-classic', | ||
[ | ||
'redocusaurus', | ||
{ | ||
specs: [ | ||
{ | ||
id: 'using-single-yaml', | ||
spec: 'openapi/single-file/openapi.yaml', | ||
route: '/examples/using-single-yaml/', | ||
}, | ||
{ | ||
id: 'using-remote-url', | ||
spec: 'https://redocly.github.io/redoc/openapi.yaml', | ||
route: '/examples/using-remote-url/', | ||
}, | ||
], | ||
theme: { | ||
/** | ||
* 文檔的高亮顏色 | ||
*/ | ||
primaryColor: '#1890ff', | ||
/** | ||
* 傳遞給 redoc 的選項 | ||
* @see https://github.com/redocly/redoc#redoc-options-object | ||
*/ | ||
options: { disableSearch: true }, | ||
}, | ||
}, | ||
], | ||
], | ||
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" />; | ||
``` | ||
|
||
### 結果 | ||
|
||
#### 對於 ID `id="using-single-yaml"` | ||
|
||
<ApiSchema id="using-single-yaml" pointer="#/components/schemas/Pet" /> | ||
|
||
#### 對於 ID `id="using-remote-url"` | ||
|
||
<ApiSchema id="using-remote-url" pointer="#/components/schemas/Pet" /> |
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 @@ | ||
--- | ||
title: API 1 - Swagger Petstore | ||
hide_table_of_contents: true | ||
--- | ||
|
||
import ApiDocMdx from '@theme/ApiDocMdx'; | ||
|
||
<ApiDocMdx id="using-single-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,8 @@ | ||
--- | ||
title: API 2 - Swagger Petstore | ||
hide_table_of_contents: true | ||
--- | ||
|
||
import ApiDocMdx from '@theme/ApiDocMdx'; | ||
|
||
<ApiDocMdx id="using-swagger-json" /> |