-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Array collection format in form binding #2750
Conversation
@Doa86 Can you please fix issues? I really need this feature. |
When will there be an update? |
please fix the conflicts @Simon-Saaw |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2750 +/- ##
==========================================
- Coverage 98.73% 98.70% -0.03%
==========================================
Files 41 41
Lines 3080 2088 -992
==========================================
- Hits 3041 2061 -980
+ Misses 27 15 -12
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Does somebody know if this functionality is now available for Gin? |
move the feature to next milestone v1.11 |
@@ -311,6 +318,15 @@ func TestBindingFormInvalidName2(t *testing.T) { | |||
"map_foo=bar", "bar2=foo") | |||
} | |||
|
|||
func TestBindingFormCollectionFormat(t *testing.T) { | |||
testFormBindingForCollectionFormat(t, "POST", | |||
"/?slice_multi=1&slice_multi=2&slice_csv=1,2&slice_ssv=1 2&slice_pipes=1|2", "/", |
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.
Missing fuzzy tests here. Should try it with string type and see what happens if we feed pipes to csv param, csv to pipe param, csv to multi param etc…
err := b.Bind(req, &obj) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, []int{1, 2}, obj.SliceMulti) |
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.
I'd refrain from using values 1 and 2 for each one of them. It can potentially conceal misbehaviour.
@@ -311,6 +318,15 @@ func TestBindingFormInvalidName2(t *testing.T) { | |||
"map_foo=bar", "bar2=foo") | |||
} | |||
|
|||
func TestBindingFormCollectionFormat(t *testing.T) { | |||
testFormBindingForCollectionFormat(t, "POST", |
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.
Example in README.md
shows curl with GET
but test only tests POST
.
@@ -376,6 +380,25 @@ func head(str, sep string) (head string, tail string) { | |||
return str[:idx], str[idx+len(sep):] | |||
} | |||
|
|||
func split(vals []string, field reflect.StructField) []string { | |||
if cfTag := field.Tag.Get("collection_format"); cfTag != "" { | |||
sep := "multi" |
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.
It will stay as sep = "multi"
when invalid separator is defined e.g. collection_format:"foo"
Should it fail / warn instead silently doing fallback?
Should also add test case for it.
Move to #3986 |
master
✔️Enables the possibility to collect array data from queries or form-data by specifying
collection_format
tag in structs.