If I have a service like this:
service MyService { rpc GetThings(GetThingsRequest) returns (GetThingsResponse); }
How would I mark GetThings
as deprecated?
I know how to mark fields or messages as deprecated but I can't find any information about rpcs.
This is for proto3.
Introduction. As of Oct 31, 2017, RPC over HTTP will no longer be a supported protocol for accessing mail data from Exchange Online. Microsoft will no longer provide support or updates for Outlook clients that connect through RPC over HTTP, and the quality of the mail experience will decrease over time.
Protobuf has an option for marking a “field” as deprecated. optional int32 old_field = 6 [deprecated=true]; Full snipped from their documentation: deprecated (field option): If set to true , indicates that the field is deprecated and should not be used by new code.
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
A . proto file is similar to a JSON file in that it represents structured data, but you can run a compiler on the . proto file to generate code that can read and write the data in the programming language of your choice. For more information about protocol buffers, see Protocol Buffer Developer Guide on Google's site.
TL;DR: It's possible, but it does not generate a compiler warning. Consider to use field-level deprecation.
It looks like it's possible to add a deprecated option to a service, just like on a message and enum like:
service MyService { rpc GetThings(GetThingsRequest) returns (GetThingsResponse) { option deprecated = true; }; }
Found this in: https://github.com/google/protobuf/issues/1734
Even though it does compile, it does not seem to generate a compiler warning when used. I tried in Java, with the HelloWorld service from the Java quick start guide. Inspecting the generated java file further, HelloWorldProto.java, it shows that the class has not added a @Deprecated
java annotation, but there are some differences in the file, most likely the proto annotation in the proto description:
$ diff HelloWorldProto-{control,method}.java 38c38 < "ssage\030\001 \001(\t2I\n\007Greeter\022>\n\010SayHello\022\030.hel" + --- > "ssage\030\001 \001(\t2L\n\007Greeter\022A\n\010SayHello\022\030.hel" + 40,41c40,41 < "eply\"\000B6\n\033io.grpc.examples.helloworldB\017H" + < "elloWorldProtoP\001\242\002\003HLWb\006proto3" --- > "eply\"\003\210\002\001B6\n\033io.grpc.examples.helloworld" + > "B\017HelloWorldProtoP\001\242\002\003HLWb\006proto3"
I got similar result when trying the option on request message, service and file level as well. My hunch is that this is a missing feature in the java code generator. When adding the deprecated option to a field, I did however get the wanted compiler warning:
$ ./gradlew installDist ... Note: Some input files use or override a deprecated API. ...
Your options as I see it:
Mark all fields in the request message as deprecated. Then you are going to show compiler warnings as soon as anybody uses it. Like:
message HelloRequest { string name = 1 [deprecated=true]; }
Use option deprecated on the grpc method (as shown above) No compiler warnings are shown, and rely on users to just see this documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With