e29f27e2eb
通过 vitepress-openapi 插件,在 VitePress 文档中实现基于 openapi.json 的 API 文档。 这样实现的 API 文档可以从最新版本的代码库中提取路由信息,继而实现自动集成。 --- 同时,通过 Kimi 和 Deepseek 实现并审查了一个对 Google 风格 docstring 的解析函数。 该函数可以从 Google 风格的 docstring 中提取参数文档并按 openapi 规范重新整理它们。 --- 增加了 nyahome openapi 命令用来导出 openapi.json。 增加了 task openapi-docs 命令用来准备未来的持续集成。
27 lines
589 B
TypeScript
27 lines
589 B
TypeScript
import DefaultTheme from 'vitepress/theme'
|
|
import { theme, useOpenapi } from 'vitepress-openapi/client'
|
|
import 'vitepress-openapi/dist/style.css'
|
|
// @ts-ignore
|
|
import './custom.css'
|
|
import { Theme } from 'vitepress'
|
|
|
|
import spec from './openapi.json' with { type: 'json' }
|
|
|
|
export default {
|
|
extends: DefaultTheme,
|
|
async enhanceApp({ app }) {
|
|
useOpenapi({
|
|
spec,
|
|
config: {
|
|
codeSamples: {
|
|
defaultLang: 'python',
|
|
},
|
|
server: {
|
|
allowCustomServer: true,
|
|
},
|
|
}
|
|
})
|
|
theme.enhanceApp({ app })
|
|
}
|
|
} satisfies Theme
|