跳到主要内容

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)构建分组导航结构