Chuyển tới nội dung chính

Tài liệu tham khảo API

<OasDocument /> — Thuộc tính​

Thuộc tínhKiểuMặc địnhMô tả
inputOpenApiInput | OpenApiDocument | nullbắt buộcTài liệu OpenAPI/Swagger (đối tượng, chuỗi JSON hoặc chuỗi YAML)
autoUpgradebooleantrueKiểm tra và chuyển sang OAS 3.2 qua @powerduck/openapi-parser
defaultOperationIdstring—ID thao tác được chọn khi hiển thị lần đầu
onOperationChange(operation) => void—Hàm gọi lại khi người dùng thay đổi lựa chọn
classNamestring—Lớp CSS bổ sung cho phần tử gốc
styleReact.CSSProperties—Kiểu nội dòng cho phần tử gốc
theme"light" | "dark""light"Giao diện ban đầu. Được lưu vào localStorage.
headerOasDocumentHeaderConfig—Cấu hình đầu trang (logo, tiêu đề, liên kết điều hướng)
showTreebooleantrueHiện cây ở thanh bên
treeWidthnumber340Chiều rộng thanh bên tính bằng pixel (240–480)

Cấu hình đầu trang​

TrườngKiểuMặc định
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 });

Hàm lõi​

HàmMô tả
loadOasDocument(input, options?)Tải và chuyển đổi tài liệu. Trả về { document, operations, navigationGroups, tree, warnings, error }
parseOperations(document)Trích xuất thao tác từ tài liệu OAS
buildNavigationGroups(document)Tạo cấu trúc điều hướng theo nhóm