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

String-values for Enums in request object are not recognized. #150

Closed
fnchooft opened this issue May 9, 2016 · 4 comments
Closed

String-values for Enums in request object are not recognized. #150

fnchooft opened this issue May 9, 2016 · 4 comments

Comments

@fnchooft
Copy link

fnchooft commented May 9, 2016

Good Morning, first off, great work! And thanks for making it available.

I seem to have a problem with enums in request-objects, passing the string-representation does not work. If I change the value to the assigned integer the curl-post-request passes.
I saw some issues about jsonpb but I am not go-proficient enough (yet) to debug more.
Any help would be greatly appreciated.

Example curl-calls to show the behavior:

FAILURE-case.

$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{

"enum_value": "UNKNOWN",
"identifier": {
"identifier": 0
}
}' 'http://localhost:8080/trial/v1/setEnumAndId'
{"error":"json: cannot unmarshal string into Go value of type protomsg.EnumValue","code":3}

PASSING-case:

$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"enum_value": 0,
"identifier": {
"identifier": 0
}
}' 'http://localhost:8080/trial/v1/setEnumAndId'
{}

PS: Tested with latest master from 9 mai 2016.

@fnchooft
Copy link
Author

Afternoon, after checking out again today (2016/05/10), the problem has been resolved.
Thank you.

PS: The only thing I had to do is CamelCase the client-calls.
In order to do that I added a small sed-statement in the Makefile I am using.

Makefile-rule:

%.pb.gw.go: %.proto
    protoc -I/usr/local/include -I. \
        -I${GOPATH}/src \
        -I${GOPATH}/src/github.com/gengo/grpc-gateway/third_party/googleapis \
        --grpc-gateway_out=logtostderr=true:. \
        $<
        sed -e "s/client\.\(.\)/client\.\u\1/g" -i $@

@igateno
Copy link

igateno commented May 11, 2016

I'm having a similar issue, as I described in #153

@fnchooft you said you were able to make this work? I just checked out the latest master (2016/05/10 @ 11:04 GMT-8) and I just get a bunch of Go errors in my *.pb.gw.go file.

@fnchooft
Copy link
Author

Evening @igateno,
I tested yesterday and all is fine, the only issue I faced was the fact that my rpc-function names are lower-case in the proto-file. The grpc-gateway_out-plugin uses the same literal-string as written in the proto-file. Since the plugin is used with the GO-language, where public functions are written in Camelcase, maybe the plugin could Camelcase those rpcs and emit a warning.

Do not forget to regenerate all go-files, to make sure that the files are consistent.

@igateno
Copy link

igateno commented May 12, 2016

So my issue was that I didn't run go build after updating grpc-gateway to the latest master. It's fixed now. Thanks!

@yugui yugui closed this as completed May 17, 2016
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

No branches or pull requests

3 participants