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: add note about required write-only field #609

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

danielgtaylor
Copy link
Owner

@danielgtaylor danielgtaylor commented Oct 15, 2024

This adds one additional note about the use of omitempty with required for write-only fields that are in a struct that gets re-used for both a request/response.

Fixes #604.

Summary by CodeRabbit

  • Documentation
    • Updated request validation documentation for clarity on Go struct tags and JSON Schema generation.
    • Expanded sections on nullable fields, validation tags, and strict vs. loose field validation.
    • Added examples and explanations for advanced validation features.

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The pull request updates the documentation for request validation, specifically regarding the use of Go struct tags for JSON Schema generation. It clarifies the handling of optional and required fields, expands on nullability, and introduces new sections on validation tags and advanced validation. The documentation now also addresses the behavior of readOnly and writeOnly fields, as well as the distinction between strict and loose field validation.

Changes

File Path Change Summary
docs/docs/features/request-validation.md Updated documentation to clarify Go struct tags, added sections on validation tags, nullability, and advanced validation, and explained behavior of readOnly and writeOnly fields.

Assessment against linked issues

Objective Addressed Explanation
Address the behavior of writeOnly fields in responses (604)

Possibly related PRs

  • docs: add info about read/write only behavior #608: The changes in this PR also focus on enhancing the documentation for request validation, specifically regarding the behavior of read-only and write-only fields, which is directly related to the updates made in the main PR.

Poem

In fields of code where rabbits play,
We validate requests in a clever way.
With tags and rules, we hop along,
Making sure our structs are never wrong.
So here’s to docs, both clear and bright,
Guiding our paths in the coding night! 🐇✨


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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.83%. Comparing base (f398d76) to head (041433b).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #609   +/-   ##
=======================================
  Coverage   92.83%   92.83%           
=======================================
  Files          22       22           
  Lines        3923     3923           
=======================================
  Hits         3642     3642           
  Misses        236      236           
  Partials       45       45           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
docs/docs/features/request-validation.md (4)

Line range hint 78-138: Great addition of validation tags and formats!

The new tables provide a comprehensive list of validation tags and built-in string formats, which will be extremely helpful for users implementing request validation.

Consider adding a brief introductory sentence before each table to improve readability. For example:
"The following table lists the additional tags supported on model fields, along with their descriptions and examples:"

🧰 Tools
🪛 Markdownlint

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)


Line range hint 140-151: Valuable clarification on readOnly and writeOnly fields!

This new section provides important information about the behavior of readOnly and writeOnly fields, which is crucial for proper API design and implementation.

To further improve clarity, consider adding a brief example demonstrating the use of omitempty with required:"true" for a write-only field. This would help illustrate the note at the end of the section.

🧰 Tools
🪛 Markdownlint

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)


Line range hint 153-176: Excellent explanation of strict vs. loose field validation!

This new section clearly explains the default behavior of field validation and provides guidance on how to implement loose validation when needed. The example is helpful for understanding the concept.

Consider adding a brief note about the potential security implications of using additionalProperties:"true", as it may introduce unexpected data into the system. This would help developers make informed decisions about when to use loose validation.

🧰 Tools
🪛 Markdownlint

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)


Line range hint 178-189: Good introduction to advanced validation options!

This new section provides valuable information about additional validation rules available for custom JSON Schemas.

To enhance this section:

  1. Consider adding brief examples for each of the listed schema fields (not, oneOf, anyOf, allOf) to illustrate their usage.
  2. Expand on the note about using custom resolvers, perhaps providing a link to the relevant documentation section.
    These additions would give developers a better starting point for implementing advanced validation rules.
🧰 Tools
🪛 Markdownlint

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f398d76 and 041433b.

📒 Files selected for processing (1)
  • docs/docs/features/request-validation.md (1 hunks)
🧰 Additional context used
🪛 Markdownlint
docs/docs/features/request-validation.md

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)

🔇 Additional comments (1)
docs/docs/features/request-validation.md (1)

Line range hint 31-76: Excellent clarification on nullability!

The expanded "Nullable" section provides clear and detailed information about how nullability is determined for different field types. The step-by-step logic and examples greatly enhance understanding of this complex topic.

🧰 Tools
🪛 Markdownlint

150-150: Expected: fenced; Actual: indented
Code block style

(MD046, code-block-style)

docs/docs/features/request-validation.md Show resolved Hide resolved
@danielgtaylor danielgtaylor merged commit 1c7affe into main Oct 15, 2024
7 checks passed
@danielgtaylor danielgtaylor deleted the docs-writeonly-required-reuse branch October 15, 2024 18:18
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.

Somehow writeOnly seems to have broken? Bug?
1 participant