-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
fix: automatically precompute schema validation messages #545
Conversation
WalkthroughThe recent changes enhance the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Huma
participant SchemaProvider
Client->>Huma: POST / with custom RequestBody
Huma->>SchemaProvider: Get Schema
SchemaProvider->>Huma: Return Schema
Huma->>Schema: Call PrecomputeMessages()
Schema-->>Huma: Precomputed Messages
Huma->>Huma: Validate input against Schema
Huma-->>Client: Return Response
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #545 +/- ##
==========================================
+ Coverage 92.75% 92.76% +0.01%
==========================================
Files 22 22
Lines 3876 3883 +7
==========================================
+ Hits 3595 3602 +7
Misses 236 236
Partials 45 45 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- huma.go (2 hunks)
- huma_test.go (2 hunks)
- schema.go (1 hunks)
Additional comments not posted (4)
schema.go (1)
684-686
: EnsurePrecomputeMessages()
is called on custom schemas.The addition of
PrecomputeMessages()
ensures that any necessary validation messages are precomputed for custom schemas, aligning with the PR's goal of automating schema validation. This change enhances performance and correctness when dealing with custom schemas.huma.go (2)
695-703
: Precompute schema messages for request bodies.This block ensures that all schemas in
RequestBody.Content
have their validation messages precomputed, which aligns with the PR's objective to automate schema validation setup. This change enhances the robustness of schema handling.
707-707
: Expanded check forhasInputBody
.The condition now checks that
inputBodyIndex
has elements, ensuring that the input body is not only defined but also populated. This enhances the control flow and reliability of the function.huma_test.go (1)
2162-2198
: New test for custom schema error handling.The
TestCustomSchemaErrors
function verifies that schema validation errors are correctly reported without manual calls toPrecomputeMessages()
. This test is crucial for ensuring the robustness of the automated schema validation enhancements introduced in this PR.
This fix makes it easier to use custom schemas by removing the need to manually call
schema.PrecomputeMessages()
before the server starts up.Fixes #454.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation