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

Added docs for validated-dto #840

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

xuanyanwow
Copy link
Collaborator

@xuanyanwow xuanyanwow commented Feb 18, 2025

Summary by CodeRabbit

  • Documentation
    • 新增“自定义规则”章节,详细说明如何在特定场景下定制验证规则,帮助提高数据验证的灵活性与可读性。
    • 更新了类型转换指南,提供多种转换方式和错误处理示例,确保用户能清晰理解数据转换规则。

Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

该 PR 在 Validated DTO 的文档中新增了关于自定义验证规则的说明。英文文档中增加了 “Customizing Validation Rules” 部分,包括使用 afterValidatorResolving 方法注册自定义规则示例。中文文档(简体、香港繁体、台湾繁体)分别新增或扩展了 “自定义/自定義规则” 部分,其中简体中文版本还增加了 “类型转换” 部分,详细介绍了 DTO 属性的类型转换和可能抛出的异常。

Changes

文件路径 变更描述
docs/**/components/validated-dto.md (en) 新增 “Customizing Validation Rules” 部分,介绍 afterValidatorResolving 方法及 ‘diy_rule’ 自定义验证示例。
docs/**/components/validated-dto.md (zh-cn) 新增 “自定义规则” 部分(同英文示例)及 “类型转换” 部分,详细说明各种 DTO 属性的转换选项及异常情况。
docs/**/components/validated-dto.md (zh-hk, zh-tw) 分别新增 “自定義規則” 部分,展示 afterValidatorResolving 方法示例;zh-hk 文档扩展了 “類型轉換” 部分说明。

Sequence Diagram(s)

sequenceDiagram
    participant DTO as DTO实例
    participant V as Validator
    participant CR as 自定义规则

    DTO->>V: 开始验证过程
    V->>DTO: 调用 afterValidatorResolving 方法
    DTO->>V: 注册 'diy_rule' 自定义验证规则
    V->>V: 进行 'diy_rule' 规则验证
Loading

Poem

我是一只跳跃的小兔,
在代码原野中奔跑不停,
自定义规则轻轻吟唱,
命令与逻辑共舞飞扬,
点点新章闪耀如晨曦🐰✨
欢庆变更乐在心间!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46ac14a and 6d274d9.

📒 Files selected for processing (4)
  • docs/en/components/validated-dto.md (1 hunks)
  • docs/zh-cn/components/validated-dto.md (1 hunks)
  • docs/zh-hk/components/validated-dto.md (1 hunks)
  • docs/zh-tw/components/validated-dto.md (1 hunks)
🔇 Additional comments (5)
docs/zh-tw/components/validated-dto.md (1)

329-350: 新增“自定義規則”板块说明清晰且示例完整。
添加的内容详细描述了如何在 afterValidatorResolving 方法中添加专门针对 DTO 的自定义规则,并通过示例代码直观地展示了实现过程。建议在后续版本中补充说明规则验证失败时如何反馈错误信息,从而使说明更加完善。

docs/zh-hk/components/validated-dto.md (1)

329-350: 香港版本新增的“自定義規則”板块说明明确。
新增部分展示了如何通过 afterValidatorResolving 方法为 DTO 添加自定义规则,示例代码易于理解。建议考虑在示例中增加对规则验证失败时的提示说明,以帮助用户更好地理解异常处理。

docs/zh-cn/components/validated-dto.md (2)

329-350: 新增“自定义规则”部分说明具体且示例直观。
这一部分详细介绍了如何使用 afterValidatorResolving 方法为 DTO 添加自定义规则,并提供了一个检查值是否等于 'diy_rule' 的示例。建议补充对规则验证失败时异常或错误反馈的说明,以便用户能全面了解使用场景。


586-642: 新增“创建你自己的类型转换”部分为用户提供了可扩展性的示例。
该部分展示了如何通过实现 Castable 接口(例如 URLCast 类)来自定义 DTO 属性的转换逻辑,示例代码清晰且易于理解。建议在文档中进一步补充实际应用中的场景示例,以及在转换过程中可能抛出的异常信息说明,帮助用户更好地借鉴和扩展。

docs/en/components/validated-dto.md (1)

329-350: The new "Customizing Validation Rules" section is well integrated.
尽管文档主体为英文,但新增部分在示例代码中清楚地展示了如何在 DTO 内部通过 afterValidatorResolving 方法扩展自定义规则。建议在代码注释或文档描述中补充关于规则验证失败时的错误处理说明,以便用户对异常情况有更深入的了解。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@huangdijia huangdijia merged commit 20aa898 into friendsofhyperf:main Feb 18, 2025
1 check passed
huangdijia pushed a commit that referenced this pull request Feb 24, 2025
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.

2 participants