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

Array collection format in form binding #2750

Closed
wants to merge 2 commits into from

Conversation

Simon-Saaw
Copy link

  • With pull requests:
    • Open your pull request against master ✔️
    • Your pull request should have no more than two commits, if not you should squash them. ✔️
    • It should pass all tests in the available continuous integration systems such as TravisCI. ❓
    • You should add/modify tests to cover your proposed code changes. ✔️
    • If your pull request contains a new feature, please document it on the README. ✔️

Enables the possibility to collect array data from queries or form-data by specifying collection_format tag in structs.

@MIcQo
Copy link

MIcQo commented Oct 28, 2021

@Doa86 Can you please fix issues? I really need this feature.

@slowhigh
Copy link
Contributor

slowhigh commented Feb 7, 2024

When will there be an update?

@appleboy
Copy link
Member

appleboy commented Feb 7, 2024

please fix the conflicts @Simon-Saaw

@appleboy appleboy added this to the v1.10 milestone Feb 7, 2024
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1c2aa59) 98.73% compared to head (ddcc2ed) 98.70%.
Report is 207 commits behind head on master.

❗ Current head ddcc2ed differs from pull request most recent head e3f19a5. Consider uploading reports for the commit e3f19a5 to get more accurate results

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              
Flag Coverage Δ
go-1.13 ?
go-1.14 ?
go-1.15 ?
go-1.16 ?
go-1.17 ?
macos-latest ?
nomsgpack ?
ubuntu-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@pasquale95
Copy link

pasquale95 commented Mar 13, 2024

Does somebody know if this functionality is now available for Gin?
It would be very useful.

@appleboy
Copy link
Member

move the feature to next milestone v1.11

@appleboy appleboy modified the milestones: v1.10, v1.x, v1.11 Mar 14, 2024
@@ -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", "/",
Copy link

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)
Copy link

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",
Copy link

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"
Copy link

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.

@appleboy
Copy link
Member

Move to #3986

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants