Closed dhdevdk closed 1 year ago
@dhdevdk does that mean you were able to get your sample building and working?
@abe545 No, I was able to generate the code via
docker run -v `pwd`:/defs namely/gen-grpc-gateway -f hello_world.proto --generate-unbound-methods -s Service
Then I have the output:
/tmp/tmp$ tree gen/
gen/
└── grpc-gateway
├── cmd
│ └── gateway
│ └── main.go
├── config.yaml
├── Dockerfile
├── gen
│ ├── github.com
│ │ └── yourorg
│ │ └── yourprotos
│ │ └── gen
│ │ └── go
│ │ └── your
│ │ └── service
│ │ ├── helloworld_grpc.pb.go
│ │ ├── helloworld.pb.go
│ │ └── helloworld.pb.gw.go
│ └── helloworld.swagger.json
└── go.mod
Here is the related code so you are able to reproduce the error (https://gist.github.com/dhdevdk/32c94651d7f590a8ff94d537a4e44555) (I had to replace "/" with "--" in the paths.)
Then this command
docker build -t my-grpc-gateway gen/grpc-gateway/
fails with the reported error.
Ah, ok @dhdevdk. So I'm not a golang dev myself, but as far as that error with internal
, I believe that is a golang convention. If you just delete that word from the package path, you'll be able to bypass that error. I pulled down the example protofile, and put it in a directory named greeter
because that is how we structure our protos. Then from the directory that contains the greeter folder, this command generates the gateway from the proto unmodified (I used Greeter
as the service name because that is the name of the service in the proto):
docker run -v `pwd`:/defs namely/gen-grpc-gateway -f greeter/greeter.proto -s Greeter
When I tried to build the generated code, it gave the golang internal package error you described. I then removed internal
from the proto's go_package
option, and then ran into an error from docker with the swagger file being in the wrong spot. I think this might actually be a bug in this generator. I'll look into that. But I was able to correct the swagger file location in the dockerfile manually, and that was the only other change I had to make to get this to build.
@abe545 Ah ok, I missed that the -s option should match the service name. I was also getting an error with the json file and fixed the paths.
So it's working now. Thanks!
One more question: I can access the swagger json at /swagger.json, but is there a way to generate an openapi 3.0 compatible json/yaml file?
@dhdevdk - glad you got it working. This is a thin wrapper around https://github.com/grpc-ecosystem/grpc-gateway, so if they have an option to do so, it might just work to pass it in. If they don't have that option, there is nothing we can do. If they do have an option, and there is no way to pass it down, we'd be happy to accept a PR that adds support for it.
@abe545 Okay, I will have a look at it. I need openapi 3.0, since I am using enums, which are not supported in 2.0. I think I will try to generate an openapi 3.0 spec via https://github.com/google/gnostic/tree/main/cmd/protoc-gen-openapi and try out whether it is working properly.
So shall I close this issue?
@dhdevdk yeah, I'll close this as it seems like you are able to codegen & build it.
Hello, basically I want to set up a minimal working example and test it. I have a single file in a directory
hello_world.proto
, which content is copied fromhttps://github.com/grpc-ecosystem/grpc-gateway/blob/main/examples/internal/helloworld/helloworld.proto
.Then I run
and get this error:
I am not sure if I am doing something wrong or if this is a real bug. From the docs it says, that one should provide at least one http binding or add the option
--generate-unbound-methods
. I have done both and still get this error.I would really appreciate any help to get this working. Thanks in advance.
Edit:
I had to change the line
to something else like
because otherwise I get this error