-
Notifications
You must be signed in to change notification settings - Fork 86
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: [#452] slice in request cannot be bind #539
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 (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 theBind
method.
24-24
: Struct update: Verify correct usage of thedata
field.The
Validator
struct now includes adata
field of typevalidate.DataFace
. Ensure that this field is utilized correctly in the methods of theValidator
struct.
27-30
: Method update: Verify correct initialization ofdata
parameter.The
NewValidator
function now includes an additional parameter,data validate.DataFace
, to initialize thedata
field in theValidator
struct. Ensure that this parameter is passed correctly and utilized in theBind
method.
34-53
: Method update: Ensure correct handling of various data sources.The
Bind
method 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 ofdataFace
parameter.The
Make
function in theValidation
struct now includes an additional argument,dataFace
, which is passed to theNewValidator
function. Ensure that this parameter is passed correctly and utilized in theNewValidator
function.validation/validator_test.go (2)
22-28
: Struct update: Verify correct usage of new fields in test cases.The
Data
struct now includes new fieldsAges
andNames
. 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
TestBind
method has been updated to include test cases for the new fieldsAges
andNames
. 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.2
tov1.14.3
.✅ Checks