Skip to content

Commit

Permalink
Honor @http annotation for query parameters
Browse files Browse the repository at this point in the history
Currently the `@http` annotation is ignored for query parameters. We are
using `@json` instead. That is a bug, and this patch fixes it.

Signed-off-by: Juan Hernandez <[email protected]>
  • Loading branch information
jhernand committed Jun 22, 2023
1 parent f8356e2 commit 5cf844b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/http/binding_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,17 @@ func (c *BindingCalculator) AttributeName(attribute *concepts.Attribute) string
// ParameterName returns the name of the field or query parameter corresponding to the given model
// method parameter.
func (c *BindingCalculator) ParameterName(parameter *concepts.Parameter) string {
name := annotations.JSONName(parameter)
name := annotations.HTTPName(parameter)
if name == "" {
name = parameter.Name().Snake()
// We check also the JSON annotation here for "bug compatibility". In the past we
// used to check only the JSON name, but that is incorrect because this about HTTP
// query parameters, not JSON field names. But some models (the 'dryRun' parameter
// of the accounts management service, for example) are already using that bug as it
// was a feature.
name = annotations.JSONName(parameter)
if name == "" {
name = parameter.Name().Snake()
}
}
return name
}
Expand Down

0 comments on commit 5cf844b

Please sign in to comment.