Conversation
WalkthroughThis update enhances the validation logic by adding an additional Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant Validator
participant Binder
Client->>Server: Send request with data
Server->>Binder: Bind data through `Make`
Binder->>Validator: Invoke `NewValidator` with data
Validator-->>Binder: Return validated data
Binder-->>Server: Return response
Server-->>Client: Send validated response
Assessment against linked issues
Poem
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 Configration File (
|
| if formData, ok := v.data.(*validate.FormData); ok { | ||
| values := make(map[string]any) | ||
| for key, value := range v.data.Src().(url.Values) { | ||
| values[key] = value[0] |
There was a problem hiding this comment.
Only support one value in the form case, this is the default behavior of gookit/validate for now.
| { | ||
| name: "empty when data is struct and key is lowercase", | ||
| data: func() validate.DataFace { | ||
| data, err := validate.FromStruct(struct { | ||
| a string | ||
| }{ | ||
| a: "aa", | ||
| }) | ||
| assert.Nil(t, err) | ||
|
|
||
| return data | ||
| }(), | ||
| rules: map[string]string{"a": "required"}, | ||
| assert: func(data Data) { | ||
| assert.Equal(t, "", data.A) | ||
| }, | ||
| }, | ||
| { | ||
| name: "empty when data is struct and key is struct", | ||
| data: func() validate.DataFace { | ||
| data, err := validate.FromStruct(struct { | ||
| D *Data | ||
| }{ | ||
| D: &Data{ | ||
| A: "aa", | ||
| }, | ||
| }) | ||
| assert.Nil(t, err) | ||
|
|
||
| return data | ||
| }(), | ||
| rules: map[string]string{"d.a": "required"}, | ||
| assert: func(data Data) { | ||
| assert.Equal(t, "", data.A) | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Should test these cases in the Make test method, so remove them.
| assert.Equal(t, []int{1, 2}, data.Ages) | ||
| assert.Equal(t, []string{"a", "b"}, data.Names) |
There was a problem hiding this comment.
The test cases for the issue.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v1.14.x #539 +/- ##
==========================================
Coverage ? 70.10%
==========================================
Files ? 176
Lines ? 10884
Branches ? 0
==========================================
Hits ? 7630
Misses ? 2686
Partials ? 568 ☔ View full report in Codecov by Sentry. |
|
@coderabbitai review |
Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- support/constant.go (1 hunks)
- validation/validation.go (1 hunks)
- validation/validator.go (3 hunks)
- validation/validator_test.go (6 hunks)
Files skipped from review due to trivial changes (1)
- support/constant.go
Additional comments not posted (7)
validation/validator.go (4)
4-4: Import update: Ensure consistency with data handling changes.The import of
"mime/multipart"was replaced with"net/url". Ensure that this aligns with the updated data handling logic in theBindmethod.
24-24: Struct update: Verify correct usage of thedatafield.The
Validatorstruct now includes adatafield of typevalidate.DataFace. Ensure that this field is utilized correctly in the methods of theValidatorstruct.
27-30: Method update: Verify correct initialization ofdataparameter.The
NewValidatorfunction now includes an additional parameter,data validate.DataFace, to initialize thedatafield in theValidatorstruct. Ensure that this parameter is passed correctly and utilized in theBindmethod.
34-53: Method update: Ensure correct handling of various data sources.The
Bindmethod has been modified to handle various data sources and bind data accordingly. Ensure that the method correctly handles different data sources and binds them to the provided pointer.validation/validation.go (1)
63-63: Method update: Verify correct passing ofdataFaceparameter.The
Makefunction in theValidationstruct now includes an additional argument,dataFace, which is passed to theNewValidatorfunction. Ensure that this parameter is passed correctly and utilized in theNewValidatorfunction.validation/validator_test.go (2)
22-28: Struct update: Verify correct usage of new fields in test cases.The
Datastruct now includes new fieldsAgesandNames. Ensure that these fields are utilized correctly in the test cases.
Line range hint
62-145:
Test case update: Ensure comprehensive coverage for binding slice data.The
TestBindmethod has been updated to include test cases for the new fieldsAgesandNames. Ensure that the test cases cover various scenarios for binding slice data.
📑 Description
Closes goravel/goravel#452
Summary by CodeRabbit
New Features
Bug Fixes
Miscellaneous
v1.14.2tov1.14.3.✅ Checks