grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

protoc-gen-swagger doesn't output to specified --swagger_out directory

Open boosh opened this issue 7 years ago • 7 comments

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 avatar May 11 '17 14:05 boosh

@boosh thank you for the issue report!

tmc avatar May 11 '17 16:05 tmc

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.

narqo avatar Jun 14 '17 22:06 narqo

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.

uynap avatar Aug 15 '18 06:08 uynap

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

vaishali-ntnx avatar Nov 22 '18 14:11 vaishali-ntnx

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.

johanbrandhorst avatar Nov 22 '18 14:11 johanbrandhorst

swagger out should support the same options as protoc-gen-go

drewwells avatar May 03 '19 16:05 drewwells

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.

inge4pres avatar Jan 17 '20 14:01 inge4pres