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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-grpc-gateway: Error if identical annotations are provided #1865

Closed
guodongq opened this issue Dec 8, 2020 · 6 comments 路 Fixed by #2246
Closed

protoc-gen-grpc-gateway: Error if identical annotations are provided #1865

guodongq opened this issue Dec 8, 2020 · 6 comments 路 Fixed by #2246

Comments

@guodongq
Copy link

guodongq commented Dec 8, 2020

馃摎 Documentation/Question

Is there any detection mechanism to check for duplicates of the corresponding RESTful URIs when I generate the Grpc-gateway files?

@guodongq guodongq changed the title Is there any detection mechanism to check for duplicates of the corresponding RESTful URIs when I generate the Grpc-gateway files? Is there any detection mechanism to check for duplicates of the corresponding RESTful URIs? Dec 8, 2020
@johanbrandhorst
Copy link
Collaborator

I think the generator should error if you have two endpoints with identical annotations, though I'm not sure if we have a test for this. Have you tried it?

@guodongq
Copy link
Author

guodongq commented Dec 9, 2020

I tried it, and it didn't give an error

@johanbrandhorst johanbrandhorst changed the title Is there any detection mechanism to check for duplicates of the corresponding RESTful URIs? protoc-gen-grpc-gateway: Error if identical annotations are provided Dec 9, 2020
@johanbrandhorst
Copy link
Collaborator

Alright, we should probably make the generator error in that case. If you'd like to contribute, the first step would be to add a new test that fails under the existing behavior. It should be possible to copy and adapt one of the tests in https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-grpc-gateway/internal/gengateway/template_test.go to reproduce this bug. Once we have a failing test, it should be easy to add some logic to check for duplicates and confirm that it works by running the test. Let me know if I can do anything more to help get you started.

@danedavid
Copy link
Contributor

Hi @johanbrandhorst I'd like to tackle this issue, and I'd looked into it. I added a failing test to template_test.go by using the same Binding twice. Now, to make Generate fail, we need to check if HTTP method-URI combos are recurring across files, right? My intuition was to use a map to store HTTP method-URI as keys and set them to true once seen. But the method and URI are available only inside applyTemplate. So does that mean we need to pass the map down from generate? Or use a global map in template.go? Or is there any better, elegant way to do it?

@johanbrandhorst
Copy link
Collaborator

Hi Dane, thank you so much for picking up this issue! If you could create a pull request with your proposed changes it would be easier for me to review, but preliminarily your suggestion sounds OK, that we'll need some way to check duplicate annotations across all input files. Passing in using explicit parameters is almost always better than using a global.

@danedavid
Copy link
Contributor

Raised a PR here for fixing this.
Have added a map and a method to the exported descriptor.Registry; not sure if that is the right place to add it. Otherwise would have had to change the API of applyTemplate.

Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants