GRPC fallback to Rest API with custom field names

When you generate JSON for Rest API from proto-file, protoc-gen-gofast generates field names for JSON in lowerCamelCase format while most of the Rest APIs use snake_case for that.
And if you want to replace some legacy API with your new implementation without breaking backward compatibility, you need to fix it.
There could be different ways to fix it (it is really simple to implement for response fields while it’s much harder for request fields and I found only a hacky way to fix swagger’s definitions).
But the most flexible and simple way is to use field option on proto field:
string global_entity_id = 2; will become
string global_entity_id = 2 [json_name="global_entity_id"];.
And this option will affect the field name for JSON (in request or response) and swagger definitions as well.
More details here —
And special thanks to this comment on stackoverflow —
A lot more options available can be found here —

Similar Posts