Path parameter names for fields with JSON name overrides are inconsistently handled by go-endpoints. In apiconfig.go, fieldNames will honor JSON name overrides, including ignoring fields with JSON name -. This affects the exported parameters field for a given function. Additionally, parseTag only recognizes the endpoints tag, "req".
On the other hand, when exporting path parameters from a service struct, service.go's requiredParamNames directly exports the field name as the path parameter and only recognizes the endpoints tag, "required".
Example code follows:
package frontend
import (
"github.com/GoogleCloudPlatform/go-endpoints/endpoints"
"golang.org/x/net/context"
)
type Request struct {
Path string `json:"myPath" endpoints:"required"`
}
type Service struct{}
func (s *Service) DoThing(c context.Context, r *Request) error { return nil }
func init() {
_, err := endpoints.RegisterService(&Service{}, "service", "v1", "Test Service", true)
if err != nil {
panic(err)
}
endpoints.HandleHTTP()
}
Note that the parameter name is "Path", but the parameter specification is for "myPath". Additionally, "myPath" is exported as a query parameter b/c of the inconsistent "req[uired]" handling.
Path parameter names for fields with JSON name overrides are inconsistently handled by
go-endpoints
. In apiconfig.go,fieldNames
will honor JSON name overrides, including ignoring fields with JSON name-
. This affects the exportedparameters
field for a given function. Additionally, parseTag only recognizes the endpoints tag,"req"
.On the other hand, when exporting path parameters from a service struct, service.go's requiredParamNames directly exports the field name as the path parameter and only recognizes the endpoints tag,
"required"
.Example code follows:
The resulting backend JSON:
Which generates the invalid discovery JSON:
Note that the parameter name is "Path", but the parameter specification is for "myPath". Additionally, "myPath" is exported as a
query
parameter b/c of the inconsistent "req[uired]" handling.