There is currently no way of marking a whole message as deprecated.
My current workaround of doing this is to deprecate all fields.
message MyMessage {
uint32 id = 1 [deprecated=true];
string name = 2 [deprecated=true];
}
... but it does not exactly mean the same thing, right ?
It would be great to be able to either mark the message with an option (does that even exist ?)
message MyMessage [deprecated=true] {
uint32 id = 1;
string name = 2;
}
or an annotation ?
@deprecated
message MyMessage {
uint32 id = 1;
string name = 2;
}
The other nice thing about deprecating the message itself would be that one would not need to find all its usages as field and mark all of them as deprecated fields.
Drive by - Your last comment in the interesting part. It's sorta harder to say a message can be deprecated without looking at all of the uses. Deprecating it usually means there is something that should be used instead. If you can mark the message as deprecated without ensuring all uses have the alternate way, aren't you likely to create situations where the other messages are basically broken because they don't have the new way?
You can already mark a message as deprecated by doing this:
message MyMessage {
option deprecated = true;
...
}
Actually you can pretty much use the deprecation annotation on all proto constructs:
option deprecated = true; // file-level option
message MyMessage {
option deprecated = true; // message level
enum MyEnum {
option deprecated = true; // enum level
MY_ENUM_FOO = 1 [deprecated = true]; // enum-value
}
}
This doesn't do anything useful in most implementations though (i.e., nothing is generated for this deprecated annotation), but if you can file separate requests per language if there is a standard way to do deprecation in that language.
This one gives me a compile-error:
option deprecated = true; // enum level
Option "deprecated" unknown.
Does enum value deprecation:
MY_ENUM_FOO = 1 [deprecated = true]; // enum-value
actually work in any protobuf version?
I don't think so. It's also not documented explicitly anywhere.
The new reserved keyword might be of interest here (both proto2 and proto3).
(First introduced in 3.0.0-alpha-3.)
Wanted to note that option deprecated = true; works on proto messages as of latest protoc in March 2019, and when compiling to C# will apply the System.ObsoleteAttribute to the generated class.
Another note to the note above:
This, unfortunately, isn't true for rpcs.
Adding an option deprecated=true; to an rpc doesn't seem to have effect on generated C# methods.
Note for Go: adding option deprecated = true to an rpc effectively adds // Deprecated: Do not use. comment to the generated service client/server interfaces and client method implementation.