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

fix: improve type handing of query param parsing #711

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

wesbillman
Copy link
Collaborator

When building the requestMap from the supplied query params, we will set the correct type for the given value.

Previously if we received a param like a=10 it would set the type in the request map to string. However, if the field for the request was a []String this would fail the validation step.

We now use the Request data fields to determine how to set the map value.

Basically this:

switch field.Type.(type) {
case *schema.Int, *schema.Float, *schema.String, *schema.Bool:
	queryMap[key] = value[0]
case *schema.Array:
	queryMap[key] = value
default:
	return nil, fmt.Errorf("unsupported type %T for field %q", field.Type, key)
}


return validateRequestMap(dataRef, []string{dataRef.String()}, requestMap, sch)
return validateRequestMap(verb.Request, []string{verb.String()}, requestMap, sch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want verb.String() here? Won't that be like add(AddRequest) AddResponse type thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LOL 🤦 yeah :)

}
}
if field == nil {
return nil, fmt.Errorf("unknown query parameter %q", key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice.

@wesbillman wesbillman force-pushed the build-request-map-based-on-schema branch from eca59f0 to 1948df7 Compare December 7, 2023 01:13
@wesbillman wesbillman merged commit 050b6a3 into main Dec 7, 2023
11 checks passed
@wesbillman wesbillman deleted the build-request-map-based-on-schema branch December 7, 2023 01:18
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

Successfully merging this pull request may close these issues.

2 participants