-
Notifications
You must be signed in to change notification settings - Fork 50
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
tonic: Refactor handling of comma-separated lists #63
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
language: go | ||
|
||
go: | ||
- "1.8.x" | ||
- "1.9.x" | ||
- "1.10.x" | ||
- "1.11.x" | ||
- "1.12.x" | ||
- "master" | ||
|
||
jobs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ const ( | |
RequiredTag = "required" | ||
DefaultTag = "default" | ||
ValidationTag = "validate" | ||
ExplodeTag = "explode" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you make a change on the tag value ? I think we can keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is open for debate, I just felt the explode semantics are really unclear. |
||
ArrayTag = "commalist" | ||
) | ||
|
||
const ( | ||
|
@@ -264,7 +264,7 @@ func extractQuery(c *gin.Context, tag string) (string, []string, error) { | |
var params []string | ||
query := c.Request.URL.Query()[name] | ||
|
||
if c.GetBool(ExplodeTag) { | ||
if !c.GetBool(ArrayTag) { | ||
// Delete empty elements so default and required arguments | ||
// will play nice together. Append to a new collection to | ||
// preserve order without too much copying. | ||
|
@@ -303,18 +303,28 @@ func extractPath(c *gin.Context, tag string) (string, []string, error) { | |
if err != nil { | ||
return "", nil, err | ||
} | ||
p := c.Param(name) | ||
|
||
var params []string | ||
|
||
if !c.GetBool(ArrayTag) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenAPI 3 spec defines the path parameters serialization with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenAPI3 defines explode=false by default specifically for arrays. |
||
params = []string{c.Param(name)} | ||
} else { | ||
splitFn := func(c rune) bool { | ||
return c == ',' | ||
} | ||
params = strings.FieldsFunc(c.Param(name), splitFn) | ||
} | ||
|
||
// XXX: deprecated, use of "default" tag is preferred | ||
if p == "" && defaultVal != "" { | ||
if len(params) == 0 && defaultVal != "" { | ||
return name, []string{defaultVal}, nil | ||
} | ||
// XXX: deprecated, use of "validate" tag is preferred | ||
if p == "" && required { | ||
if len(params) == 0 && required { | ||
return "", nil, fmt.Errorf("missing path parameter: %s", name) | ||
} | ||
|
||
return name, []string{p}, nil | ||
return name, params, nil | ||
} | ||
|
||
// extractHeader is an extractor that operates on the headers | ||
|
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 OpenAPI 3 spec defines the default serialization to be true by default for
explode
.Should we follow that ?
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.
That's actually the case here. The whole explode true/false semantics are insanely confusing.
But having the comma-separated list split logic off by default ends up meaning the same thing as explode=true by default.