跳至主要内容

API 參考

<OasDocument /> — 屬性​

屬性型別預設值說明
inputOpenApiInput | OpenApiDocument | null必填OpenAPI/Swagger 文件(物件、JSON 字串或 YAML 字串)
autoUpgradebooleantrue透過 @powerduck/openapi-parser 驗證並升級為 OAS 3.2
defaultOperationIdstring—初次渲染時選取的操作 ID
onOperationChange(operation) => void—使用者主動變更選取項目時觸發的回呼
classNamestring—根元素的附加 CSS 類別
styleReact.CSSProperties—根元素的行內樣式
theme"light" | "dark""light"初始佈景主題。儲存於 localStorage。
headerOasDocumentHeaderConfig—頁首設定(標誌、標題、導覽連結)
showTreebooleantrue顯示側邊欄樹
treeWidthnumber340側邊欄寬度,以像素為單位(範圍 240–480)

頁首設定​

欄位型別預設值
logostring | ReactNode—
titlestring"API Documentation"
navItemsArray<{ label, href?, onClick? }>[]
showThemeTogglebooleantrue

useOasDocument(input, options?)​

const {
document, // Oas32Document | null
loading, // boolean
error, // Error | null
operations, // OasOperation[]
navigationGroups, // OasNavigationGroup[]
tree, // TreeNode[]
selectedOperation, // OasOperation | undefined
setSelectedOperation,
theme, // "light" | "dark"
setTheme,
} = useOasDocument(spec, { autoUpgrade: true });

核心函式​

函式說明
loadOasDocument(input, options?)載入並升級文件,回傳 { document, operations, navigationGroups, tree, warnings, error }
parseOperations(document)從 OAS 文件擷取操作
buildNavigationGroups(document)建立分組導覽結構