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

tonic: Refactor handling of comma-separated lists #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

loopfz
Copy link
Owner

@loopfz loopfz commented Sep 6, 2019

No description provided.

@loopfz loopfz force-pushed the refactor-comma-lists branch from 05c0bf5 to 7b6627b Compare September 6, 2019 15:12
@@ -29,7 +29,7 @@ const (
RequiredTag = "required"
DefaultTag = "default"
ValidationTag = "validate"
ExplodeTag = "explode"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 explode, which is the term used in the OpenAPI spec, and it is widely used for this concept.
See https://swagger.io/docs/specification/serialization/, Path parameters section.

Copy link
Owner Author

Choose a reason for hiding this comment

The 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.
It was extremely confusing again getting back into it for this PR even though I was familiar with the various permutations, so I cant imagine what it must be like fresh off.


var params []string

if !c.GetBool(ArrayTag) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAPI 3 spec defines the path parameters serialization with explode being false by default. Do we want to follow that, and make comma-splitting an opt-in ?

Copy link
Owner Author

@loopfz loopfz Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAPI3 defines explode=false by default specifically for arrays.
Here, we assume a scalar.
I feel like an opt-in split mechanism, clearly defining the format as a comma-separated list, is clearer for both query & path handling.

if explodeVal, ok := ft.Tag.Lookup(ExplodeTag); ok {
if explode, err := strconv.ParseBool(explodeVal); err == nil && !explode {
c.Set(ExplodeTag, false)
c.Set(ArrayTag, false)
Copy link
Collaborator

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.

The default serialization method is style: form and explode: true.

Should we follow that ?

Copy link
Owner Author

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.

@wI2L
Copy link
Collaborator

wI2L commented Sep 6, 2019

I think we have to review the following, because it uses the current ExplodeTag.

if ok && len(fieldValues) == 0 {

The code seems also useless. I don't think we need to take the ExplodeTag into account for default values. We could simply state that multiple values can be defined in a default tag, by delimiting them with a comma, and split that to feed the fieldValues slice. Later on, if the actual type of the field is not array or slice, we'll catch it and return an error.
return BindError{field: ft.Name, typ: t, message: "multiple values not supported"}

That will allow a user to specify multiple default values for arrays and slices, but we can't do much without adding complexity to prevent a misuse.

@loopfz
Copy link
Owner Author

loopfz commented Mar 5, 2021

Not closing this right now, but will need to reassess

@loopfz loopfz added the draft label Mar 5, 2021
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.

2 participants