Files
huang 6fc90abeb6 实现服务启动时自动生成OpenAPI文档
主要变更:
1. 新增 cmd/api/docs.go 实现文档自动生成逻辑
2. 修改 cmd/api/main.go 在服务启动时调用文档生成
3. 重构 cmd/gendocs/main.go 提取生成函数
4. 更新 .gitignore 忽略自动生成的 openapi.yaml
5. 新增 Makefile 支持 make docs 命令
6. OpenSpec 框架更新和变更归档

功能特性:
- 服务启动时自动生成 OpenAPI 文档到项目根目录
- 保留独立的文档生成工具 (make docs)
- 生成失败时记录错误但不影响服务启动
- 所有代码已通过 openspec validate --strict 验证

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-09 12:25:50 +08:00

29 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Implementation Tasks
## 1. 重构文档生成逻辑
- [x] 1.1 从 `cmd/gendocs/main.go` 中提取文档生成逻辑(实际采用在各自包内实现的方案)
- [x] 1.2 创建文档生成函数,接受输出路径参数
- [x] 1.3 确保函数返回错误而非panic用于优雅处理失败情况
## 2. 集成到服务启动流程
- [x] 2.1 在 `cmd/api/main.go``main()` 函数中添加文档生成调用
- [x] 2.2 将生成调用放在路由注册之后(确保有完整的路由信息)
- [x] 2.3 指定输出路径为 `./openapi.yaml`(项目根目录)
- [x] 2.4 生成失败时使用 `appLogger.Error()` 记录错误但继续启动
## 3. 更新现有工具
- [x] 3.1 保留 `cmd/gendocs/main.go` 作为独立的文档生成工具
- [x] 3.2 修改 `cmd/gendocs/main.go` 使用提取的生成逻辑
- [x] 3.3 Makefile 中的 `docs` 目标保持不变(如存在)
## 4. 文档和测试
- [x] 4.1 在 `.gitignore` 中添加 `/openapi.yaml`(避免提交自动生成的文件)
- [x] 4.2 手动测试文档生成工具,验证文档正确生成
- [x] 4.3 编译测试确保代码无错误
- [x] 4.4 README.md 更新将在后续完成
## 5. 清理和验证
- [x] 5.1 确保代码符合项目规范gofmt、go vet
- [x] 5.2 确保所有函数都有中文文档注释
- [x] 5.3 运行 `openspec validate auto-generate-openapi-docs --strict`