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

single file with grpc annotations for multiple services don't work

Open gvencadze opened this issue 1 year ago β€’ 2 comments

πŸ› Bug Report

If you have yaml file with grpc annotations which contains selectors for multiple services, it'll raise an error if you try to generate code.

Previously discussed at slack: https://gophers.slack.com/archives/CBATURP1D/p1670838671867599

File structure scheme:

project
└───proto
    └───api
        └───first_svc
        β”‚     └───v1
        β”‚          └───first_svc.proto
        └───second_svc
        β”‚     └───v1
        β”‚          └───second_svc.proto
        β”‚
        β”‚
        └─── grpc_annotations.yaml

grpc_annotations.yaml content:

type: google.api.Service
config_version: 3

http:
  rules:
      ### First service ###
    - selector: api.first_svc.v1.FirstService.Get
      get: /api/v1/first/get

      ### Second service ###
    - selector: api.second_svc.v1.SecondService.Get
      get: /api/v2/second/get

To Reproduce

  1. Create multiple proto services
  2. Add yaml file with grpc configuration which contains selectors for this services
  3. Try to generate (I'm using buf)

Expected behavior

I'm expecting to see generated code without errors

Actual Behavior

I'm getting error:

Failure: plugin grpc-gateway: HTTP rules without a matching selector:

But If there will be single service and file with annotations will be located at the same path - everything will be okay

Your Environment

instrument version
OS macOS 12
Go 1.19.3 darwin/arm64
protoc-gen-grpc-gateway v2.16.0
protoc-gen-openapiv2 v2.16.0
buf v1.9.0

gvencadze avatar Dec 12 '22 19:12 gvencadze

Thanks for the issue. As discussed on Slack, I would expect our generator to be able to find the messages you are trying to select, since the selectors are using the global namespace. Would you be interested in fixing this? I think the first step would be to create a reproduction scenario in our examples protos. We already have an example file for external API configuration, maybe we could extend that? Or maybe a whole new folder would make sense.

johanbrandhorst avatar Dec 13 '22 01:12 johanbrandhorst

@johanbrandhorst yeah, I'm interested in contributing to open source :)

I've created MR which contains reproducible example

gvencadze avatar Dec 13 '22 10:12 gvencadze