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

Swagger-UI query parameters for enum types are sent as strings #320

Closed
johanbrandhorst opened this issue Mar 1, 2017 · 7 comments
Closed

Swagger-UI query parameters for enum types are sent as strings #320

johanbrandhorst opened this issue Mar 1, 2017 · 7 comments

Comments

@johanbrandhorst
Copy link
Collaborator

@johanbrandhorst johanbrandhorst commented Mar 1, 2017

When using a GET endpoint and an enum type in the query parameter, the swagger definition shows a selection of the string representation of the enum as input options, but using that representation returns an error:

enum MyEnum {
    DEFAULT = 0
    OTHER = 1
}

message Request {
    MyEnum value = 1;
}

service MyService {
    rpc Method(Request) returns (google.protobug.Empty) {
        option (google.api.http) = {
            get: "/api/method"
        };
    };
}
{
  "error": "strconv.ParseInt: parsing \"DEFAULT\": invalid syntax",
  "code": 3
}

The swagger definition needs to use the numeric representation of the enum for it to work.

@johanbrandhorst johanbrandhorst changed the title Swagger query parameters for enum types are sent as strings Swagger-UI query parameters for enum types are sent as strings Mar 1, 2017
@tmc
Copy link
Collaborator

@tmc tmc commented Mar 1, 2017

@johanbrandhorst thanks for the issue report. My preference would be to allow either representation.

@johanbrandhorst
Copy link
Collaborator Author

@johanbrandhorst johanbrandhorst commented Mar 1, 2017

Here's a stack trace (edited):

net/http.(*http2serverConn).runHandler.func1(0xc42031c010, 0xc420471faf, 0xc42034a000)
        /usr/lib/go/src/net/http/h2_bundle.go:4592 +0x190
panic(0x9b54c0, 0xc42012c8a0)
        /usr/lib/go/src/runtime/panic.go:489 +0x2cf
myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.Int32(0xc4202f45e0, 0x9, 0x0, 0x0, 0x0)
        /go/src/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go:41 +0x63
reflect.Value.call(0x9d3b60, 0xab4658, 0x13, 0xa8c513, 0x4, 0xc420471420, 0x1, 0x1, 0xc42012c870, 0x9b54c0, ...)
        /usr/lib/go/src/reflect/value.go:434 +0x91f
reflect.Value.Call(0x9d3b60, 0xab4658, 0x13, 0xc420471420, 0x1, 0x1, 0xa076fc, 0x76, 0x30)
        /usr/lib/go/src/reflect/value.go:302 +0xa4
myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.populateField(0x9e5400, 0xc4202f2fb0, 0x185, 0xc4202f45e0, 0x9, 0xc420298b40,
 0xc4202f2fb0, 0x185)
        /go/src/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:158 +0x21a
myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.populateFieldValueFromPath(0xda6f40, 0xc4202f2f80, 0xc42012c750, 0x1, 0x1, 0x
c42012c740, 0x1, 0x1, 0xc42012c740, 0x0)
        /go/src/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:87 +0x8f7
myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.PopulateQueryParameters(0xda6f40, 0xc4202f2f80, 0xc4201e4840, 0xf02160, 0xc42
00821a8, 0x433401)
        /go/src/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:24 +0x1c3
myrepo/vendor/myprotorepo/myprotoservice.request_Method_0(0x7f11586fa9a0, 0xc4201e4810, 0xdab680, 0xc420253840,
0xdade60, 0xc42000e118, 0xc420342100, 0xc4201e46c0, 0x24, 0x16, ...)
        /go/src/myrepo/vendor/myprotorepo/myprotoservice/myprotoservice.pb.gw.go:193 +0x139
myrepo/vendor/myprotorepo/myprotoservice.RegisteHandler.func7(0xda9740, 0xc42031c010, 0xc420342100, 0xc4201e46c0)
        /go/src/myrepo/vendor/myprotorepo/myprotoservice/myprotoservice.pb.gw.go:490 +0x1fd
myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.(*ServeMux).ServeHTTP(0xc42024ecf0, 0xda9740, 0xc42031c010, 0xc420342100)
        /go/src/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go:89 +0x7f4
net/http.(*ServeMux).ServeHTTP(0xc420237d40, 0xda9740, 0xc42031c010, 0xc420342100)
        /usr/lib/go/src/net/http/server.go:2238 +0x130
@tmc
Copy link
Collaborator

@tmc tmc commented Mar 1, 2017

That seems to indicate

if enumValMap := proto.EnumValueMap(props.Enum); enumValMap != nil {
is failing

@johanbrandhorst
Copy link
Collaborator Author

@johanbrandhorst johanbrandhorst commented Mar 2, 2017

Indeed EnumValueMap is returning an empty map for the enum type

@johanbrandhorst
Copy link
Collaborator Author

@johanbrandhorst johanbrandhorst commented Mar 2, 2017

AH this is because we've generated our code with gogo/proto instead of golang/proto, the enum is never registered with golang/proto which is what grpc-gateway calls to. Anything we can do about that?

@johanbrandhorst
Copy link
Collaborator Author

@johanbrandhorst johanbrandhorst commented Mar 2, 2017

This is probably not grpc-gateways fault, so I'm gonna go ahead and close it. I'm doubtful the grpc-gateway will ever allow the user to specify the protobuf backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants