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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer.GetProto does not honor System.ObsoleteAttribute #1149

Open
mrshridhara opened this issue Apr 22, 2024 · 0 comments
Open

Serializer.GetProto does not honor System.ObsoleteAttribute #1149

mrshridhara opened this issue Apr 22, 2024 · 0 comments

Comments

@mrshridhara
Copy link

Package version used: 3.2.30

Adding System.Obsolete attribute on class, enum or property does not result in deprecated message, enum, or property in generated proto.

C# declaration

using System;
using ProtoBuf;
using ProtoBuf.Meta;

[ProtoContract]
[Obsolete]
public class SomeClass
{
    [ProtoMember(tag: 1)]
    public int SomeProperty { get; set; }
}

[ProtoContract]
public class SomeOtherClass
{
    [ProtoMember(tag: 1)]
    [Obsolete]
    public string SomeOtherProperty { get; set; }
}

[ProtoContract]
[Obsolete]
public enum SomeEnum
{
    One,
    Two,
    Three,
}

static class Program
{
    static void Main()
    {
        var proto = Serializer.GetProto(new SchemaGenerationOptions
        {
            Syntax = ProtoSyntax.Proto3,
            Package = "DefaultPackage",
            Types = { typeof(SomeClass), typeof(SomeOtherClass), typeof(SomeEnum) },
        });

        Console.WriteLine(proto);
    }
}

Expected

syntax = "proto3";
package DefaultPackage;

message SomeClass {
   option deprecated = true;
   int32 SomeProperty = 1;
}
enum SomeEnum {
   option deprecated = true;
   One = 0;
   Two = 1;
   Three = 2;
}
message SomeOtherClass {
   string SomeOtherProperty = 1 [deprecated=true];
}

Actual

syntax = "proto3";
package DefaultPackage;

message SomeClass {
   int32 SomeProperty = 1;
}
enum SomeEnum {
   One = 0;
   Two = 1;
   Three = 2;
}
message SomeOtherClass {
   string SomeOtherProperty = 1;
}
mrshridhara added a commit to mrshridhara/protobuf-net that referenced this issue Apr 23, 2024
- Updated `MetaType` to check if `System.ObsoleteAttribute` exists on type or field to add deprecated option while generating proto.
- Added unit test to reproduce the issue.
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

No branches or pull requests

1 participant