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 parameter in path #34

Closed
ghost opened this issue Sep 6, 2019 · 5 comments
Closed

Array parameter in path #34

ghost opened this issue Sep 6, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 6, 2019

Prerequisites:

type args struct {
    Id   []int64 `path:"id" validate:"dive,required" explode:"1"`
}

fizz.GET("/:id", []fizz.OperationOption{/*...*//}, tonic.Handler(func(ctx *gin.Context, args *args) error {
  fmt.Println(args)
  return nil
}, 200))

Then, when I make a request: curl "http://localhost:8080/1,2,3", I get error: binding error on field 'Id' of type 'args': strconv.ParseInt: parsing "1,2,3": invalid syntax.

@wI2L
Copy link
Owner

wI2L commented Sep 6, 2019

This is a question related to https://github.com/loopfz/gadgeto

See https://swagger.io/docs/specification/serialization/ Query parameters section, and https://github.com/loopfz/gadgeto/blob/66acbcfcb7e86d7d226e759d3609866a3dd11365/tonic/tonic_test.go#L90 for reference.

You are using the explode flag the wrong way.
The issue, specifically with your example is that you are trying to explode a value of a path parameter, but this isn't supported, it is only for query parameters.
Also, the meaning of explode:"true" is to indicate that the query parameters are represented as ?a=1&a=2&a=3, where a is your query parameter, and 1,2,3 the values. If explode is false, then the query sent should look like this: ?a=1,2,3.

@ghost
Copy link
Author

ghost commented Sep 6, 2019

It also not work with explode:"false". In specification array in path allowed.
So, I write an issue in https://github.com/loopfz/gadgeto

@wI2L
Copy link
Owner

wI2L commented Sep 6, 2019 via email

@wI2L
Copy link
Owner

wI2L commented Sep 6, 2019

For reference, the path parameters extraction function can be found here.
It doesn't support the ExplodeTag tag, as the extractQuery function does.

@wI2L
Copy link
Owner

wI2L commented Sep 6, 2019

@ViktorPegy see loopfz/gadgeto#63, a PR has started to address what we talked about.

@wI2L wI2L closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant