Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: optimize egg-validate usage #2852

Merged
merged 2 commits into from
Aug 6, 2018
Merged

docs: optimize egg-validate usage #2852

merged 2 commits into from
Aug 6, 2018

Conversation

zoux
Copy link
Contributor

@zoux zoux commented Jul 27, 2018

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

优化在文档 restful API 章节中, egg-validate 的使用,由原来的 ctx.validate(rule) 调整为 ctx.validate(rule, ctx.request.body)。

因为自己参照文档学习使用 egg 开发 cnode 范例的时候,不知道传第二个参数(即被检测的对象),踩了这个坑。。

@codecov
Copy link

codecov bot commented Jul 27, 2018

Codecov Report

Merging #2852 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2852   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files          29       29           
  Lines         822      822           
=======================================
  Hits          819      819           
  Misses          3        3

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 422b342...a4d9c90. Read the comment docs.

@@ -156,7 +156,7 @@ class TopicController extends Controller {
const ctx = this.ctx;
// 校验 `ctx.request.body` 是否符合我们预期的格式
// 如果参数校验未通过,将会抛出一个 status = 422 的异常
ctx.validate(createRule);
ctx.validate(createRule, ctx.request.body);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

您指出的默认参数值确实正确,不过我个人觉得似乎不太好查到。

我在查看 egg-validate 的 readme.md 的时候,并没有很直观的发现这条规则,以至于在写 get 请求获取 query 参数的时候,没有很快的解决这个需求点。

也可能是因为我是 node 菜鸟的缘故吧,不过我个人觉得文档更直观具体会更具友好性。如果您觉得我的建议确实不太具有建设性,我会关闭这个 PR 的。

再次对你的解答表示感谢啦 :)

@fengmk2 fengmk2 merged commit 033fe0c into eggjs:master Aug 6, 2018
popomore pushed a commit that referenced this pull request Aug 6, 2018
docs: optimize egg-validate usage (#2852)
@zoux zoux deleted the optimize-egg-validate-usage branch August 6, 2018 11:35
@zoux zoux restored the optimize-egg-validate-usage branch August 6, 2018 11:35
@zoux zoux deleted the optimize-egg-validate-usage branch August 6, 2018 11:41
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.

4 participants