Skip to content

Đặc tả OpenAPI 3.1 và AsyncAPI 3.0 ​

LatticeDX phát sinh động cả hai tài liệu đặc tả máy đọc được ngay tại runtime từ openapi-spec.js và observability.js: OpenAPI 3.1.0 cho toàn bộ bề mặt HTTP REST/MCP và AsyncAPI 3.0.0 cho kênh MQTT IIoT, luồng SSE bề mặt UI, Redis Pub/Sub và webhook outbox NGSI-LD.

Endpoint phát hiện đặc tả ​

Cả hai endpoint đều gắn cờ ctx.withoutDataWrapping = true, trả về JSON thuần với header Content-Control / Cache-Control: no-store và mở ACL công khai để công cụ sinh mã, Swagger UI hoặc API gateway thu thập trực tiếp.

GET/api/dxos:openapi
Public (APISIX 120 req/60s)
Trả về đặc tả OpenAPI 3.1.0 đầy đủ bao gồm các thao tác cốt lõi và toàn bộ domain động latticeCustom* đang kích hoạt.
GET/api/dxos:asyncapi
Public (APISIX 120 req/60s)
Trả về đặc tả AsyncAPI 3.0.0 mô tả 3 server (MQTT, HTTP/SSE, Redis Pub/Sub) và 5 kênh thông điệp bất đồng bộ.

Quy tắc phân giải Server URL ​

Hàm resolveRequestServerUrl và normalizeServerUrl xác định trường servers[0].url theo thứ tự ưu tiên:

  1. Đọc giao thức từ x-forwarded-proto (http hoặc https, lấy phần tử đầu tiên nếu có nhiều proxy).
  2. Đọc tên máy chủ từ x-forwarded-host hoặc host sau khi kiểm tra regex an toàn ^[a-zA-Z0-9.:[\]-]{1,253}$.
  3. Loại bỏ mọi thông tin xác thực nhúng trong URL (username/password) và quay về mặc định http://localhost:13014 khi thiếu header hợp lệ.

Cấu trúc đặc tả OpenAPI 3.1.0 ​

Đặc tả OpenAPI khai báo phiên bản openapi: "3.1.0" cùng thông tin giấy phép Apache-2.0 và hai cơ chế bảo mật toàn cục trong components.securitySchemes:

Security Schemes trong OpenAPI 3.1.0
Tham sốKiểuMặc địnhMô tả
bearerAuth
http (bearer)JWT / ldx_pat_*Chấp nhận OIDC/NocoBase Bearer JWT hoặc Personal Access Token dạng Bearer ldx_pat_*.
latticeApiKey
apiKey (header)X-Lattice-API-KeyKhóa PaaS theo phạm vi truyền qua header X-Lattice-API-Key: ldx_pat_<8hex>_<32hex>.

Các nhóm đường dẫn công khai như /api/dxos:health, /api/dxos:openapi, /api/dxos:asyncapi, /api/dxosWms:publicTrack, /api/dxosBroker:deviceStatusIngest, /api/dxosBroker:orionNotify và /api/dxosForms:{meta,submit,status} được đánh dấu security: []. Toàn bộ các thao tác còn lại yêu cầu một trong hai scheme bearerAuth hoặc latticeApiKey và chuẩn hóa phản hồi lỗi 400, 401, 403.

Nhóm Tag nghiệp vụ và operationId ​

Mỗi mục trong API_OPERATIONS tự động tạo operationId duy nhất bằng makeOperationId(pathStr, method) (ví dụ get_dxosLedgerEntries, post_dxosWmsIssueStock) và gán vào nhóm tag tương ứng:

Nhóm nghiệp vụDanh sách Tag trong OpenAPI
Nền tảng & Bảo mậtObservability, PaaS API Keys, PKI & Crypto Ledger, Data Governance, Connector & Secrets Vault, Event Bus & Webhooks
Nghiệp vụ & Tự động hóaVouchers, Notifications, SLA Engine, PARA Knowledge Vault, WMS & Cold Logistics, DMN Decision Engine, Native Automation Engine, Unified Approvals, Omnichannel Notifications, Public Forms
Studio, Tích hợp & AIBlocks & IoT Telemetry, IoT Broker Control Plane, DX-OS Studio, Visual Domain Builder, Stock n8n Integration, AI Workforce & MCP, Dynamic Custom Domains

Ánh xạ Collection động (latticeCustom*) ​

Hàm collectCustomCollections(db) tự động quét mọi collection khớp /^latticeCustom[A-Za-z0-9_]+$/ đang tồn tại trong cơ sở dữ liệu runtime và ánh xạ kiểu trường sang JSON Schema:

Kiểu trường NocoBaseKiểu JSON Schema sinh raĐịnh dạng / Ràng buộc
integer, bigintinteger—
float, double, decimal, numbernumber—
booleanboolean—
json, jsonbobjectadditionalProperties: true
date, datetime, timestringformat: "date-time"
string và các kiểu còn lạistringTrích xuất mảng enum từ uiSchema.enum nếu có

Mỗi collection latticeCustom<Name> tự động sinh schema tại #/components/schemas/<Name> (gồm sẵn id, organizationId và danh sách required từ allowNull === false) cùng năm endpoint REST dưới tag Dynamic Custom Domains: list (GET), get (GET), create (POST), update (POST) và destroy (POST).

Cấu trúc đặc tả AsyncAPI 3.0.0 ​

Tài liệu asyncapi: "3.0.0" chuẩn hóa giao tiếp hướng sự kiện giữa thiết bị biên, broker, hàng đợi outbox và trình duyệt người dùng qua 3 server và 5 kênh:

Server IDGiao thứcĐịa chỉ mặc địnhVai trò
mqttBrokermqtt<host>:1883Eclipse Mosquitto nhận telemetry cảm biến và phát lệnh downlink
httpGatewayhttp / https<origin>Gateway HTTP/SSE và phân phối webhook từ latticeContextOutbox
redisPubSubredisredis:6379Valkey DB 1 Pub/Sub đồng bộ cập nhật giao diện giữa các worker

5 Kênh thông điệp và Hợp đồng Payload ​

Channel IDĐịa chỉ (address)Operation (action)Message Payload Schema
iotTelemetrylatticedx/{org}/{entity}/telemetryreceive (ingestIotTelemetry)TelemetryPoint: organizationId, entityId, metric, value, unit?, observedAt
iotDownlinkCommandlatticedx/{org}/{entity}/commandsend (dispatchIotCommand)DownlinkCommand: organizationId, entityId, command, args?, signatureBase64?, issuedAt
surfaceEventsSse/api/dxosAi:surfaceEventssend (subscribeSurfaceEvents)SurfaceUpdate: portalSlug, kind?, organizationId?, revision?
redisSurfaceUpdateslatticedx:surface-updatessend (publishSurfaceUpdates)SurfaceUpdate: portalSlug, kind?, organizationId?, revision?
contextOutboxWebhookslatticeContextOutboxsend (deliverContextOutboxWebhook)ContextOutboxWebhook: eventId, entityId, organizationId, collectionName, recordId, payload

Chi tiết các Schema thông điệp (components.messages) ​

Mỗi message trong AsyncAPI 3.0.0 dùng contentType: "application/json" và khai báo trường bắt buộc để phía thiết bị biên và consumer webhook kiểm tra lược đồ trước khi xử lý:

Các trường bắt buộc của 4 Message Schemas
Tham sốKiểuMặc địnhMô tả
TelemetryPointbắt buộc
object—Bắt buộc organizationId, entityId, metric, value (number), observedAt (date-time); tùy chọn unit.
DownlinkCommandbắt buộc
object—Bắt buộc organizationId, entityId, command, issuedAt (date-time); tùy chọn args và signatureBase64.
SurfaceUpdatebắt buộc
object—Bắt buộc portalSlug; tùy chọn kind, organizationId và revision (integer).
ContextOutboxWebhookbắt buộc
object—Bắt buộc eventId, entityId, organizationId, collectionName, recordId (integer) và payload.

Các luồng bất đồng bộ trên kết nối SSE /api/dxosAi:surfaceEvents hỗ trợ tối đa 1000 kết nối đồng thời và phát bình luận keepalive mỗi 25 giây nhằm giữ kết nối ổn định qua reverse proxy Caddy và APISIX.

Sinh SDK và Kiểm tra đặc tả ​

Các đội ngũ tích hợp có thể tải trực tiếp tài liệu JSON để sinh kiểu TypeScript, kiểm thử hợp đồng API hoặc cấu hình client MQTT/SSE.

bash
# Tải OpenAPI 3.1.0 và AsyncAPI 3.0.0
curl -fsS "https://app.example.com/api/dxos:openapi" -o openapi.json
curl -fsS "https://app.example.com/api/dxos:asyncapi" -o asyncapi.json

# Sinh TypeScript definitions từ OpenAPI 3.1.0
npx openapi-typescript ./openapi.json -o ./src/types/latticedx-api.d.ts

Tài liệu liên quan ​

Apache-2.0 · LatticeDX v0.4.2 · Powered by NocoBase · v2.2.50 · Apache-2.0 (Clause 5.2)