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

protoc-gen-swagger: Add prefix to all paths #1567

Closed
amaury1093 opened this issue Aug 4, 2020 · 1 comment
Closed

protoc-gen-swagger: Add prefix to all paths #1567

amaury1093 opened this issue Aug 4, 2020 · 1 comment

Comments

@amaury1093
Copy link

🚀 Feature

I have the following simple service

service MyService {
  rpc MyEndpoint(MyReq) returns (MyRes) {
    option (google.api.http).get = "/myservice";
  }
}

However, I'm mounting the entire gRPC gateway on a prefixed router: /grpc/*, so that I access the above endpoint at /grpc/myservice. In the generated swagger jsons, the prefix /grpc/* does not appear.

I can of course, in the protobuf annotations, add option (google.api.http).get = "/grpc/myservice", but since I have 100+ services, I was wondering if there was an option in protoc-gen-swagger to add a prefix to all paths.

@johanbrandhorst
Copy link
Collaborator

johanbrandhorst commented Aug 4, 2020

You can specify a base_path per-file like so:

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
   base_path = "/grpc"
};

Ref: https://github.com/grpc-ecosystem/grpc-gateway/blob/v2/protoc-gen-openapiv2/options/openapiv2.proto#L59-L68 (v2 link)

For v1 it would be

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
   base_path = "/grpc"
};

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

2 participants