feat: 从 FastAPI 导出 openapi.json 并渲染为 API 文档

通过 vitepress-openapi 插件,在 VitePress 文档中实现基于 openapi.json 的 API 文档。
这样实现的 API 文档可以从最新版本的代码库中提取路由信息,继而实现自动集成。
---
同时,通过 Kimi 和 Deepseek 实现并审查了一个对 Google 风格 docstring 的解析函数。
该函数可以从 Google 风格的 docstring 中提取参数文档并按 openapi 规范重新整理它们。
---
增加了 nyahome openapi 命令用来导出 openapi.json。
增加了 task openapi-docs 命令用来准备未来的持续集成。
This commit is contained in:
2026-05-25 14:56:36 +08:00
parent 3117af670b
commit e29f27e2eb
12 changed files with 755 additions and 19 deletions
+41 -16
View File
@@ -1,4 +1,12 @@
import {defineConfig} from 'vitepress'
import { defineConfig } from 'vitepress'
import { useSidebar } from 'vitepress-openapi'
import spec from './theme/openapi.json' with { type: 'json' }
const sidebar = useSidebar({
spec,
linkPrefix: '/dev/api-docs/'
})
// https://vitepress.dev/reference/site-config
export default defineConfig({
@@ -7,29 +15,46 @@ export default defineConfig({
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{text: '主页', link: '/'},
{text: '使用', link: '/use/start'}
{ text: '主页', link: '/' },
{ text: '使用', link: '/use/start' },
{ text: '开发', link: '/dev/start' },
],
sidebar: [
{
sidebar: {
'use': [{
text: '使用',
items: [
{text: '开始', link: '/use/start'},
{text: '默认行为', link: '/use/default-action'},
{text: '用户系统', link: '/use/user-system'},
{ text: '开始', link: '/use/start' },
{ text: '默认行为', link: '/use/default_action' },
{ text: '用户系统', link: '/use/user_system' },
]
},
{
text: '开发',
items: [
{text: '后端响应', link: '/dev/backend-response'},
]
},
],
],
'dev': [
{
text: '开发',
items: [
{ text: '开始', link: '/dev/start' },
{ text: '后端响应', link: '/dev/backend_response' },
{ text: '邮件模板', link: '/dev/email_templates' },
]
},
{
text: 'API 文档',
items: [
{ text: 'API', link: '/dev/api-docs/api' },
...sidebar.generateSidebarGroups({}),
]
},]
},
socialLinks: [
{icon: 'github', link: 'https://github.com/vuejs/vitepress'}
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
]
},
sitemap: {
hostname: 'https://docs.nyahome.cn'
}
})