Nhận diện giấy phép SPDX API
Nhận diện giấy phép từ văn bản (SPDX ID + độ tương đồng), phân tích và sửa biểu thức SPDX, kiểm tra giấy phép của thư viện với dự án và tạo file NOTICES.
op=detect (hoặc chỉ gửi text): dán file LICENSE / COPYING hoặc phần đầu file mã nguồn. Văn bản được chuẩn hoá theo hướng dẫn so khớp của SPDX (chữ hoa thường, dấu câu, gạch đầu dòng, dòng copyright, cách viết Anh / Mỹ) rồi so với mọi giấy phép trong SPDX License List (~700 văn bản) bằng độ tương đồng Dice của bộ 3 từ: trả về kết quả best kèm độ tin cậy (exact ≥ 0,95, high, medium, low), danh sách candidates với tỷ lệ văn bản và giấy phép được bao phủ, multiple_licences khi một file chứa nhiều giấy phép (ví dụ MIT + Apache-2.0), các thẻ SPDX-License-Identifier và thông báo chuẩn như phần đầu file Apache-2.0 hay GPL "or any later version".
op=parse với expression: "MIT OR (Apache-2.0 AND BSD-3-Clause)" được chuyển thành cây kèm nhóm của từng giấy phép, cờ OSI / ngừng dùng và ngoại lệ (WITH Classpath-exception-2.0); tên sai được sửa ("Apache 2" → Apache-2.0, "GPLv3" → GPL-3.0-or-later). op=check nhận dependencies ([{name, license}] hoặc {tên: biểu thức}), project_license của bạn (SPDX ID hoặc proprietary), distribution (binary, source, saas, internal) và policy tuỳ chọn (allow, deny, deny_categories): mỗi thư viện nhận ok, conditions (ghi công, NOTICE, copyleft theo file), warning, conflict, denied hoặc unknown kèm lý do — ví dụ GPL trong phần mềm đóng phát hành nhị phân, AGPL trong SaaS, Apache-2.0 với GPL-2.0-only; với OR, lựa chọn dễ dãi nhất được dùng.
op=notice biến packages ([{name, version, license, copyright, url}]) thành văn bản THIRD-PARTY-NOTICES, mỗi văn bản giấy phép xuất hiện một lần (format=text để tải file). op=info với id trả về một giấy phép (kèm văn bản khi include_text=true); không có id thì liệt kê giấy phép SPDX (q, category). Kết quả tương thích chỉ để tham khảo, không phải tư vấn pháp lý.
Markdown · OpenAPI · Postman · llms.txt
Tham số
| Tên | Vị trí | Kiểu | Bắt buộc | Mặc định | |
|---|---|---|---|---|---|
op | body|query | string | không | detect, parse, check, notice hoặc info (tự đoán từ các trường khác nếu bỏ trống). | |
text | body | string | không | detect: văn bản giấy phép hoặc phần đầu file (tối đa 500 000 ký tự; hoặc body text/plain). | |
top | body|query | number | không | 5 | detect: số ứng viên (1-20). |
expression | body|query | string | không | parse: biểu thức giấy phép SPDX. | |
dependencies | body | array | không | check: [{name, license}] hoặc {tên: biểu thức} (tối đa 2000). | |
project_license | body | string | không | check: giấy phép của bạn (SPDX ID) hoặc proprietary (mặc định). | |
distribution | body | string | không | binary | check: binary, source, saas hoặc internal. |
policy | body | object | không | check: {allow: [id], deny: [id], deny_categories: ["strong-copyleft", "network-copyleft", …]}. | |
packages | body | array | không | notice: [{name, version, license, copyright, url, text}] (tối đa 2000). | |
id | body|query | string | không | info: SPDX ID (không phân biệt hoa thường); thêm include_text=true để lấy văn bản. |
Ví dụ
curl -X POST "https://apibox.io.vn/v1/spdx-license" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"op":"check","project_license":"proprietary","distribution":"binary","dependencies":[{"name":"react","license":"MIT"},{"name":"readline-sync","license":"GPL-3.0-only"},{"name":"sharp","license":"Apache-2.0"},{"name":"dual-lib","license":"GPL-2.0-only OR MIT"}]}'const res = await fetch('https://apibox.io.vn/v1/spdx-license', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"op": "check",
"project_license": "proprietary",
"distribution": "binary",
"dependencies": [
{
"name": "react",
"license": "MIT"
},
{
"name": "readline-sync",
"license": "GPL-3.0-only"
},
{
"name": "sharp",
"license": "Apache-2.0"
},
{
"name": "dual-lib",
"license": "GPL-2.0-only OR MIT"
}
]
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/spdx-license",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"op": "check", "project_license": "proprietary", "distribution": "binary", "dependencies": [{"name": "react", "license": "MIT"}, {"name": "readline-sync", "license": "GPL-3.0-only"}, {"name": "sharp", "license": "Apache-2.0"}, {"name": "dual-lib", "license": "GPL-2.0-only OR MIT"}]},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/spdx-license');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"op":"check","project_license":"proprietary","distribution":"binary","dependencies":[{"name":"react","license":"MIT"},{"name":"readline-sync","license":"GPL-3.0-only"},{"name":"sharp","license":"Apache-2.0"},{"name":"dual-lib","license":"GPL-2.0-only OR MIT"}]}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Kết quả trả về
{
"project_license": "proprietary",
"distribution": "binary",
"overall": "conflict",
"summary": {
"conditions": 3,
"conflict": 1
},
"results": [
{
"name": "react",
"license": "MIT",
"status": "conditions",
"chosen": "MIT",
"category": "permissive",
"reasons": [
"Keep the copyright notice and licence text (attribution)"
]
},
{
"name": "readline-sync",
"license": "GPL-3.0-only",
"status": "conflict",
"chosen": "GPL-3.0-only",
"category": "strong-copyleft",
"reasons": [
"GPL-3.0-only: distributing a combined work requires releasing it under the GPL — incompatible with a proprietary project"
]
},
{
"name": "sharp",
"license": "Apache-2.0",
"status": "conditions",
"chosen": "Apache-2.0",
"category": "permissive",
"reasons": [
"Keep the copyright notice and licence text (attribution)",
"Apache-2.0: also keep its NOTICE file and mark modified files"
]
},
{
"name": "dual-lib",
"license": "GPL-2.0-only OR MIT",
"status": "conditions",
"chosen": "MIT",
"reasons": [
"Keep the copyright notice and licence text (attribution)"
]
}
],
"disclaimer": "Reference only, not legal advice; licence compatibility depends on how the code is used and distributed. Check the licence texts or ask a lawyer.",
"spdx_list_version": "3.29.0"
}
Ứng dụng
- Xác định giấy phép của thư viện chép vào dự án hoặc repo không có manifest
- Cho CI báo lỗi khi giấy phép thư viện xung đột với cách phân phối sản phẩm
- Lập báo cáo giấy phép mã nguồn mở và file NOTICE khi khách hàng yêu cầu
- Chuẩn hoá trường giấy phép lộn xộn ("Apache 2", "GPLv2+") thành SPDX ID
Hỏi đáp
Vì sao GPL-3.0-only và GPL-3.0-or-later đều giống 100 %?
Hai giấy phép dùng chung văn bản: lựa chọn "only" hay "or later" nằm ở phần đầu file. Hãy xem standard_notices hoặc SPDX-License-Identifier.
Kết quả kiểm tra tương thích có phải tư vấn pháp lý không?
Không. API áp dụng cách hiểu phổ biến (ví dụ danh sách tương thích của FSF) và đánh dấu các trường hợp cần xem lại; quyết định quan trọng hãy hỏi luật sư.
Dùng phiên bản danh sách giấy phép nào?
Bản phát hành mới nhất của SPDX License List, cập nhật hằng tuần; spdx_list_version có trong mọi kết quả.
API liên quan
Tạo UUID
Sinh tối đa 1.000 UUID v4, UUID v7 theo thời gian, ULID, Nano ID hoặc mã hex ngẫu nhiên mỗi request. Ngẫu nhiên an toàn, hỗ trợ chữ in hoa.
⏱Phân tích biểu thức cron
Kiểm tra biểu thức cron và xem các lần chạy tiếp theo theo múi giờ bất kỳ, kèm mô tả dễ hiểu. Hỗ trợ cú pháp cron 5, 6 và 7 trường.
🕒Giờ & múi giờ
Lấy giờ hiện tại ở mọi múi giờ, đổi giữa các múi giờ và Unix timestamp (giây hoặc mili giây), kèm độ lệch UTC và thứ trong tuần cho tối đa 30 múi giờ.