Commit f4969fa
feat(docs): fumadocs-openapi 自动 API 参考 + 修好 /openapi.json + Scalar 鉴权 (#48)
* feat(docs): /docs 接入 fumadocs-openapi 自动 API 参考 + 修好 /openapi.json + Scalar 鉴权
server
- 修复 /openapi.json 500:level 模块的 UnlockRuleSchema 用 z.lazy 做自递归但没注册成 component,zod-to-openapi 的 isOptionalSchema 走到它就栈溢出;加 .openapi("LevelUnlockRule") 把递归节点序列化成 $ref,文档恢复 200 (459 ops, 427 schemas)。
- 新 src/lib/openapi.ts 收拢三件事:
- validationDefaultHook 统一 Zod 校验失败的 400 响应 {error,code:"VALIDATION_ERROR",issues,requestId}
- createAdminRouter / createClientRouter / createPublicRouter 给每个模块 router 注入 defaultHook
- createAdminRoute / createClientRoute / createPublicRoute 自动派生 operationId (${tag}_${method}_${path}) 并注入 security (Session+AdminApiKey / ClientCredential / [])
- registerSecuritySchemes 在 app 层注册 Session / AdminApiKey / ClientCredential 三套 securitySchemes
- 全部 30 个 admin routes.ts + 24 个 client-routes.ts + health.ts 机械化迁到新 helper;459/459 op 拿到唯一 operationId,admin/client/public security 数组按路由类型正确落位。
- index.ts 的 doc31 补 info.description(中文鉴权说明)。
- 新 pnpm --filter=server openapi:dump 把 spec 冻结到 apps/server/openapi.json,同时注入顶层 tags 数组(fumadocs-openapi 的 fromTagName 必需,否则直接崩)。
admin
- pnpm --filter=admin gen:api-docs (bun 跑) 从 apps/server/openapi.json 生成中文 API 参考 MDX:
- 自定义 groupBy 函数按 MODULES 前缀表折叠两层目录(Lottery→pools/tiers/prizes/pity-rules/pull/client,Entity→schemas/blueprints/skins/formations/client,etc)
- 自动生成 index.mdx 落地页(Operations / Tags / Schemas 统计 + 鉴权速览 + 怎么用)
- polishLeafMetas 修 leaf meta.json title(Lottery/Pools→Pools),给父文件夹补 meta.json,改写根 meta.json pages 让 fumadocs source loader 能找到。
- 新 src/lib/openapi.tsx:TanStack Start 没有 RSC,fumadocs-openapi 默认的 createAPIPage 是 async server component 会 hydrate 报错;换 createClientAPIPage 并把 MDX 里的 document="apollokit" 逻辑 key 映射到 bundled payload,spec 通过 ../../server/openapi.json 被 Vite import 进 bundle,运行期零 fetch。
- routes/docs/$.tsx 把 APIPage 注入 MDX components 映射。
- 顶部 nav links 改成 getBaseOptions(locale) 工厂,OpenAPI 入口跟随当前 locale(英文站点击不再被甩到 /docs/zh/api);Home / Dashboard 标签按 locale 切中英。
- content/docs/{zh,en}/meta.json 各加 API 参考 / API Reference 分组;zh 挂完整 api 子树,en 为了避免 MDX 文件数翻倍(vite/cf-vite-plugin 会 hang)只放单文件 api.mdx stub,内部链到中文版,依靠 fumadocs i18n fallback 让 en sidebar 也能看到 86 个模块。
- zh 的 folder title / index title 故意用通用英文(API / API Overview),因为 fumadocs i18n fallback 会把 zh 的 meta 直接当 en 的用,写中文会漏到英文站。
日常流程
pnpm dev # wrangler 在 8787
pnpm --filter=server openapi:dump # 刷快照
pnpm --filter=admin gen:api-docs # 重跑 MDX
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(deps): refresh pnpm lockfile after fumadocs-openapi + shiki install
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent bf6f5c0 commit f4969fa
633 files changed
Lines changed: 75174 additions & 589 deletions
File tree
- apps
- admin
- content/docs
- en
- zh
- api
- activity
- client
- analytics
- announcement
- admin
- client
- assist-pool
- client
- instances
- banner
- admin
- client
- cdkey
- batches
- client
- codes
- logs
- redemption
- check-in
- client
- rewards
- client-credentials
- collection
- client
- entries
- groups
- milestones
- ops
- currency
- client
- definitions
- ledger
- wallet
- dialogue
- admin
- client
- end-user
- entity
- blueprints
- client
- formations
- schemas
- skins
- event-catalog
- exchange
- client
- configs
- execution
- options
- friend-gift
- client
- friend
- client
- guild
- client
- invite
- admin
- client
- item
- categories
- client
- definitions
- inventory
- leaderboard
- client
- level
- client
- levels
- stages
- lottery
- client
- pity-rules
- pools
- prizes
- pull
- tiers
- mail
- admin
- client
- media-library
- admin
- meta
- rank
- admin
- client
- shop
- categories
- client
- execution
- growth-stages
- products
- tags
- storage-box
- configs
- transactions
- task
- assignments
- categories
- client
- definitions
- team
- client
- scripts
- src
- lib
- routes/docs
- server
- scripts
- src
- lib
- modules
- activity
- analytics
- announcement
- assist-pool
- banner
- cdkey
- check-in
- client-credentials
- collection
- currency
- dialogue
- end-user
- entity
- event-catalog
- exchange
- friend-gift
- friend
- guild
- invite
- item
- leaderboard
- level
- lottery
- mail
- media-library
- rank
- shop
- storage-box
- task
- team
- routes
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments