60 lines
2.7 KiB
JavaScript
60 lines
2.7 KiB
JavaScript
(() => {
|
|
let operations = {};
|
|
|
|
function operationKey(method, path) {
|
|
return `${method.toLowerCase()} ${path}`;
|
|
}
|
|
|
|
function decorate() {
|
|
document.querySelectorAll(".swagger-ui .opblock").forEach((block) => {
|
|
const method = block.querySelector(".opblock-summary-method")?.textContent?.trim();
|
|
const path = block.querySelector(".opblock-summary-path")?.getAttribute("data-path")
|
|
|| block.querySelector(".opblock-summary-path")?.textContent?.trim();
|
|
if (!method || !path) return;
|
|
const operation = operations[operationKey(method, path)];
|
|
if (!operation) return;
|
|
const status = operation["x-implementation-status"] || "implemented";
|
|
const label = operation["x-implementation-label"] || (status === "implemented" ? "已实现" : "未完成");
|
|
block.dataset.implementationStatus = status;
|
|
const summary = block.querySelector(".opblock-summary-description");
|
|
if (summary && !summary.querySelector(".implementation-badge")) {
|
|
const badge = document.createElement("span");
|
|
badge.className = `implementation-badge ${status}`;
|
|
badge.textContent = label;
|
|
summary.appendChild(badge);
|
|
}
|
|
});
|
|
|
|
const info = document.querySelector(".swagger-ui .information-container .info");
|
|
if (info && !info.querySelector(".implementation-legend")) {
|
|
const implemented = Object.values(operations).filter(
|
|
(item) => item["x-implementation-status"] === "implemented",
|
|
).length;
|
|
const pending = Object.values(operations).filter(
|
|
(item) => item["x-implementation-status"] === "verification_pending",
|
|
).length;
|
|
const placeholder = Object.keys(operations).length - implemented - pending;
|
|
const legend = document.createElement("div");
|
|
legend.className = "implementation-legend";
|
|
legend.innerHTML = `<strong>接口状态</strong>
|
|
<span class="implementation-badge implemented">已实现 ${implemented}</span>
|
|
<span class="implementation-badge verification_pending">待真机验证 ${pending}</span>
|
|
<span class="implementation-badge placeholder">未完成 ${placeholder}</span>
|
|
<span>仅真机验证通过的接口亮显,其余保持灰色。</span>`;
|
|
info.appendChild(legend);
|
|
}
|
|
}
|
|
|
|
fetch("/openapi.json")
|
|
.then((response) => response.json())
|
|
.then((schema) => {
|
|
Object.entries(schema.paths || {}).forEach(([path, pathItem]) => {
|
|
Object.entries(pathItem).forEach(([method, operation]) => {
|
|
operations[operationKey(method, path)] = operation;
|
|
});
|
|
});
|
|
decorate();
|
|
new MutationObserver(decorate).observe(document.body, { childList: true, subtree: true });
|
|
});
|
|
})();
|