Skip to content

Array collection format in form binding#2750

Closed
Simon-Saaw wants to merge 2 commits into
gin-gonic:masterfrom
Simon-Saaw:master
Closed

Array collection format in form binding#2750
Simon-Saaw wants to merge 2 commits into
gin-gonic:masterfrom
Simon-Saaw:master

Conversation

@Simon-Saaw

Copy link
Copy Markdown
  • 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

MIcQo commented Oct 28, 2021

Copy link
Copy Markdown

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

@slowhigh

slowhigh commented Feb 7, 2024

Copy link
Copy Markdown
Contributor

When will there be an update?

@appleboy

appleboy commented Feb 7, 2024

Copy link
Copy Markdown
Member

please fix the conflicts @Simon-Saaw

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

codecov Bot commented Feb 7, 2024

Copy link
Copy Markdown

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

pasquale95 commented Mar 13, 2024

Copy link
Copy Markdown

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

@appleboy

Copy link
Copy Markdown
Member

move the feature to next milestone v1.11

@appleboy appleboy modified the milestones: v1.10, v1.x, v1.11 Mar 14, 2024
Comment thread binding/binding_test.go

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
Copy Markdown
Contributor

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…

Comment thread binding/binding_test.go
err := b.Bind(req, &obj)
assert.NoError(t, err)

assert.Equal(t, []int{1, 2}, obj.SliceMulti)

Copy link
Copy Markdown
Contributor

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.

Comment thread binding/binding_test.go
}

func TestBindingFormCollectionFormat(t *testing.T) {
testFormBindingForCollectionFormat(t, "POST",

Copy link
Copy Markdown
Contributor

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.

Comment thread binding/form_mapping.go

func split(vals []string, field reflect.StructField) []string {
if cfTag := field.Tag.Get("collection_format"); cfTag != "" {
sep := "multi"

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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