Skip to content

docs(gateway): 补齐第三方接入文档体系并接入 API 示例自动生成校验#404

Merged
phantom5099 merged 2 commits into1024XEngineer:mainfrom
pionxe:main
Apr 23, 2026
Merged

docs(gateway): 补齐第三方接入文档体系并接入 API 示例自动生成校验#404
phantom5099 merged 2 commits into1024XEngineer:mainfrom
pionxe:main

Conversation

@pionxe
Copy link
Copy Markdown
Collaborator

@pionxe pionxe commented Apr 22, 2026

关联 Issue

变更摘要

  • 建立 Gateway 双文档与参考文档体系,明确内部/外部读者边界。
  • 细化 gateway.rungateway.bindStream 双向交互规范。
  • 新增错误字典与兼容性规范,统一第三方异常处理与升级策略。
  • 引入“基于 Go 结构体自动生成 JSON 示例”机制,并在 CI 强制校验,避免文实不符。

主要改动

  • 新增第三方接入文档:
    • docs/guides/gateway-integration-guide.md
  • 新增参考文档:
    • docs/reference/gateway-rpc-api.md
    • docs/reference/gateway-error-catalog.md
    • docs/reference/gateway-compatibility.md
  • 新增自动生成脚本:
    • scripts/generate_gateway_rpc_examples/main.go
  • 新增构建命令:
    • Makefile 增加 docs-gatewaydocs-gateway-check
  • 新增 CI 校验:
    • .github/workflows/ci.yml 增加 make docs-gateway-check
  • 更新文档导航与本地自检:
    • README.md

重点说明

  • gateway-rpc-api.md 采用 XGO 风格模板化描述每个方法:Method / Stability / Auth Required / Request Schema / Response Schema / Observation
  • gateway-rpc-api.mdgateway.rungateway.bindStream 增补了 ACK 与异步事件回流的细节、终态判定与取消路径。
  • gateway-error-catalog.md 以表格统一 HTTPJSON-RPC codegateway_code,并补充 Reasoning 便于第三方编写 try-catch。
  • gateway-compatibility.md 给出字段优雅废弃机制与版本节奏示例(v1.2 Deprecated -> v1.4 Removed)。

验证结果

  • go run ./scripts/generate_gateway_rpc_examples
  • go test ./scripts/...
  • make docs-gateway-check

影响范围

  • 文档与 CI 流程变更为主,不修改运行时业务逻辑。
  • PR 合并后,Gateway API 示例将受 CI 约束,结构体变更需要同步更新文档生成结果。

Checklist

  • 文档语言与术语统一为中文工程表达
  • 关键行为与当前实现对齐(方法、错误码、状态码映射)
  • 自动生成示例具备幂等性
  • CI 已接入一致性校验

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 96.17834% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
scripts/generate_gateway_rpc_examples/main.go 96.17% 12 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完成四轮审查(代码质量、性能、安全、文档一致性)后,发现 2 个值得处理的问题,主要集中在生成脚本的健壮性与回归保障。

if startIndex < 0 {
return "", fmt.Errorf("未找到自动生成起始标记 %q", beginMarker)
}
endIndex := strings.Index(documentContent, endMarker)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceGeneratedBlock 使用 strings.Index(documentContent, endMarker) 查找结束标记,会匹配到文档中第一个 endMarker。如果未来文档前半段出现同名字符串(例如示例代码块或说明文本),这里会与 beginMarker 错配并替换错误区间。建议从 contentStart 之后开始查找结束标记(例如对子串查找再回偏移),确保总是匹配到同一段自动生成块。

)
}

// replaceGeneratedBlock 将文档中标记区块替换为新生成的文本内容。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这次新增了较多生成逻辑和字符串替换分支(缺失标记、顺序非法、内容不变、正常替换),但当前没有对应 *_test.go 覆盖。建议补一组最小单测,至少覆盖 replaceGeneratedBlock 的成功路径与错误分支,避免后续文档模板调整时静默回归。

@pionxe
Copy link
Copy Markdown
Collaborator Author

pionxe commented Apr 22, 2026

@xgopilot 请你将review的问题解决,并且也将codecov/patch的覆盖率提至百分之九十五以上!

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 22, 2026

处理结果

已按本次触发要求完成两项工作,并推送到当前 PR 分支:pionxe:main(commit: 4f877c4)。

  1. 已修复 review 指出的问题
  • 修复文件:scripts/generate_gateway_rpc_examples/main.go
  • 修复点:replaceGeneratedBlock 现在从 beginMarker 之后查找 endMarker,避免误匹配文档前部同名结束标记。
  1. 已补齐测试并提升覆盖率
  • 新增测试:scripts/generate_gateway_rpc_examples/main_test.go
  • 覆盖内容:
    • replaceGeneratedBlock 成功路径与关键错误分支(缺失起始/结束标记)
    • 生成主流程(buildMethodExamplesrenderGeneratedBlockmain 幂等更新)
    • 工具函数与 panic 分支(含 exitWithError 子进程退出路径)
  1. 本地验证
  • go test ./scripts/...
  • go test -coverprofile=/tmp/scripts-cover.out ./scripts/generate_gateway_rpc_examples
  • go tool cover -func=/tmp/scripts-cover.out 结果:total: 95.2%

未做事项:未改动运行时业务逻辑与文档内容,仅修复脚本逻辑并补测试。

View job run

…r tests

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: pionxe <148670367+pionxe@users.noreply.github.com>
@phantom5099 phantom5099 merged commit 74eb862 into 1024XEngineer:main Apr 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway 对外契约文档缺失与示例漂移风险:导致第三方接入成本高且文实易不符

3 participants