Skip to content

Conversation

stevenceuppens
Copy link

@stevenceuppens stevenceuppens commented Jul 19, 2019

protoc-gen-gogo-gateway

This plugin fixes an issue where gogoproto.customname is not compatible with
protoc-gen-grpc-gateway, when this field is also referenced as a path parameter.
This happens frequently with id field of an object. Generator by default uses
CamelCase (Id) while go advises to ID to be used. gogoproto.customname helps
the generator to adjust the fieldname, but protoc-gen-grpc-gateway does not know
the field is altered and keep using CamelCase version (Id).

How it works:

This new plugin is just a wrapper around protoc-gen-grpc-gateway.

  • CodeGeneratorRequest is forwarded to protoc-gen-grpc-gateway as is.
  • CodeGeneratorResponse is inspected and updated to fix the fieldname issue.

protoc -> protoc-gen-gogo-gateway -> protoc-gen-grpc-gateway

Usage:

Use protoc-gen-gogo-gateway instead of protoc-gen-grpc-gateway

protoc -I=. -I=$(GOPATH)/src/github.com/gogo/protobuf/protobuf \
		-I=$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
		-I=$(GOPATH)/src --gogo-gateway_out=logtostderr=true:. example.proto

@stevenceuppens stevenceuppens force-pushed the protoc-gen-gogogateway branch 8 times, most recently from 4880a7f to f19776c Compare July 19, 2019 17:43
@stevenceuppens stevenceuppens changed the title Adding new plugin protoc-gen-gogogateway Adding new plugin protoc-gen-gogo-gateway Jul 19, 2019
@dominiklessel
Copy link

This would be great! Right now we're just not using the gogoproto.customname option in service specs because of this missing feature …

@stevenceuppens
Copy link
Author

@awalterschulze @jmarais Can you provide initial feedback, and guide me what needs to be done in order to get this merged.

@stevenceuppens
Copy link
Author

@jmarais can you review?

This plugin fixes an issue where gogoproto.customname is not compatible with
protoc-gen-grpc-gateway, when this field is also referenced as a path parameter.
This happens frequently with id field of an object. Generator by default uses
CamelCase (Id) while go advises to ID to be used. gogoproto.customname helps
the generator to adjust the fieldname, but protoc-gen-grpc-gateway does not know
the field is altered and keep using CamelCase version (Id).
@stevenceuppens stevenceuppens force-pushed the protoc-gen-gogogateway branch from f19776c to 30b419d Compare August 1, 2019 15:09
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

Successfully merging this pull request may close these issues.

2 participants