feat: expose API markdown doc

This commit is contained in:
ittoview
2026-05-09 17:04:22 +01:00
parent 693aa7df61
commit 1a8948761b
5 changed files with 69 additions and 3 deletions

View File

@@ -121,6 +121,15 @@ const endpoints: ApiEndpoint[] = [
description: '返回指定工具与技术出现的过程。',
fields: ['id工具 ID', 'name工具名称', 'usedIn使用该工具的过程数组'],
},
{
id: 'api-doc-markdown',
name: 'Markdown 接口文档',
method: 'GET',
path: '/apidoc',
samplePath: '/apidoc',
description: '返回接口说明 Markdown 文本字符串。',
fields: ['响应体Markdown 文本字符串', '用途:供知识库或外部系统直接读取接口说明'],
},
]
const fieldGroups = [
@@ -167,7 +176,7 @@ export function ApiDocPage() {
setResult('')
try {
const response = await fetch(requestPath, { headers: { Accept: 'application/json' } })
const response = await fetch(requestPath, { headers: { Accept: 'application/json, text/markdown, text/plain, */*' } })
const contentType = response.headers.get('content-type') ?? ''
const body = contentType.includes('application/json') ? await response.json() : await response.text()
@@ -200,8 +209,18 @@ export function ApiDocPage() {
</div>
<h1 className="text-2xl font-bold text-gray-900 dark:text-white">API </h1>
<p className="mt-2 max-w-2xl text-sm leading-6 text-gray-500 dark:text-gray-400">
JSON GET /api
GET /api JSON/apidoc Markdown
</p>
<div className="mt-4 flex flex-wrap gap-2">
<a
href="/apidoc"
target="_blank"
rel="noreferrer"
className="inline-flex items-center rounded-lg bg-gray-900 px-3 py-2 text-sm font-medium text-white transition hover:bg-gray-700 dark:bg-white dark:text-gray-900 dark:hover:bg-gray-200"
>
Markdown /apidoc
</a>
</div>
</div>
<div className="grid grid-cols-3 gap-3 text-center">
<div className="rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-900/50">
@@ -213,7 +232,7 @@ export function ApiDocPage() {
<div className="text-xs text-gray-500 dark:text-gray-400"></div>
</div>
<div className="rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-900/50">
<div className="text-lg font-bold text-gray-900 dark:text-white">JSON</div>
<div className="text-lg font-bold text-gray-900 dark:text-white">JSON/MD</div>
<div className="text-xs text-gray-500 dark:text-gray-400"></div>
</div>
</div>