Bỏ qua, đến nội dung

@digiforce-nc/plugin-api-doc ​

Plugin tự động sinh tài liệu API theo chuẩn Swagger/OpenAPI — dựa trên collection schema và resource actions đã đăng ký, cung cấp giao diện Swagger UI tương tác.

Plugin này làm gì? ​

Thay vì viết tài liệu API thủ công, plugin quét toàn bộ collection và resource endpoint, sinh ra OpenAPI 3.0 spec tự động. Developer truy cập Swagger UI để xem và thử nghiệm API trực tiếp.

Ba nhiệm vụ chính ​

#Nhiệm vụChi tiết
1Quét schemaSwaggerManager duyệt tất cả collection fields, associations, resource actions
2Sinh OpenAPI specTạo paths, schemas, parameters, responses theo chuẩn OpenAPI 3.0
3Swagger UITrang Settings + route /api-documentation nhúng Swagger UI tương tác

Kiến trúc ​

Tổng quan ​

TầngVai tròThành phần
Client UIHiển thị Swagger UI, chọn namespaceSettings entry, /api-documentation route
ServerResource swagger với actions get, getUrlsPluginAPIDocServer
SwaggerManagerQuét schema, sinh OpenAPI specCore logic phía server
NamespacesPhân nhóm API theo nguồncore, plugins, collections

Namespace system ​

NamespaceMô tảVí dụ
coreAPI lõi: auth, app metadata/api/auth:signIn, /api/app:getLang
pluginsAPI do plugin đăng ký resource riêng/api/roles:list, /api/workflows:trigger
collectionsAPI CRUD tự sinh cho mỗi collection/api/posts:list, /api/posts:create

Luồng sinh tài liệu ​

Vòng đời plugin ​

ACL - Phân quyền ​

ACL snippetQuyềnMô tả
pm.api-doc.documentationAdminTruy cập trang tài liệu API trong Settings

Ví dụ sử dụng API ​

Lấy danh sách namespaces ​

typescript
const response = await agent.resource('swagger').getUrls();
// [{ name: 'core', url: '...' }, { name: 'plugins', url: '...' }, ...]

Lấy OpenAPI spec cho namespace ​

typescript
const response = await agent.resource('swagger').get({
  filter: { ns: 'collections' },
});
// spec.openapi = '3.0.0'
// spec.paths = { '/api/posts:list': { get: {...} }, ... }

Truy cập Swagger UI trên trình duyệt ​

https://your-app.com/api-documentation

Swagger UI cho phép duyệt endpoint, thử gọi API (Try it out), xem schema chi tiết, tải xuống OpenAPI spec.

Thành phần client ​

Thành phầnMô tả
APIDocSettingsEntry trong Settings → "API Documentation"
SwaggerUIPageTrang nhúng Swagger UI với namespace selector
APIDocExportNút xuất OpenAPI spec (JSON)

Dependencies ​

PackageVai trò
swagger-ui-distThư viện Swagger UI frontend
@digiforce-nc/serverServer framework — resource registration
@digiforce-nc/databaseDatabase ORM — đọc collection schema
@digiforce-nc/clientClient framework — đăng ký Settings entry

Mục lục chi tiết ​