grpc-gateway
grpc-gateway copied to clipboard
protoc-gen-swagger doesn't output to specified --swagger_out directory
Invoking protoc-gen-swagger
with:
protoc -I/usr/local/include -I. -I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:. \
mycorp/api/user/v1/user_service.proto
The outputted file ends up in mycorp/api/user/v1/
, not the current working directory.
@boosh thank you for the issue report!
Hey, @tmc I'd be happy to help with the issue, but it feels it'd be best to start with a brief discussion. As I can see, the mycorp/api/user/v1/
part is taken from the original proto file path and is done by the peace of code in genswagger/generator.go.
But does this really a wrong behaviour? It looks like both protoc-gen-go and protoc-gen-grpc-gateway works in the very same way.
Hi @narqo , Sorry to comment this old thread. I recently got the same issue. It's apparent that protoc-gen-swagger is not working in the same way as protoc-gen-go and protoc-gen-grpc-gateway.
Firstly, the path of the files generated by protoc-gen-grpc-gateway is indicated by the "option go_package". Secondly, when "option go_package" is missing, protoc-gen-grpc-gateway use the "-import_path" option to declare it.
To have the consistent behaviour, I think protoc-gen-swagger should be in the same way.
I am also facing the same issue. The directory structure followed is same as path of proto file and not picked from go_package option. I am not sure if there is a similar option for swagger too
I think it's questionable whether the swagger generator should really care about the go_package
option in its generator, but I see there's a need for a more explicit option to direct the output files of the generation. We could potentially support the paths=source_relative
parameter that is in protoc-gen-go
though: https://github.com/golang/protobuf/commit/6fb8a6f1c1f011b7fde2b40f72f46587180d8d25.
swagger out should support the same options as protoc-gen-go
Isn't it working as expected?
protoc -I/usr/local/include -I. --grpc-gateway_out=logtostderr=true,paths=source_relative:. --swagger_out=logtostderr=true:. path/to/service.proto
generates service.pb.gw.go
and service.swagger.json
in the current directory, while setting a different directory, it generates the expected tree under that folder.