namely / docker-protoc

Docker images for generating protocol buffer definitions
BSD 3-Clause "New" or "Revised" License
707 stars 225 forks source link

ts_option is not reliable, while using useOptionals=none #369

Open johan44co opened 1 year ago

johan44co commented 1 year ago

left code generated using; namely/protoc:1.42_2 right code generated using; namely/protoc-all:1.51_1 Screenshot 2023-02-08 at 14 29 49

I have tried passing the option --ts_opt useOptionals=none but it does not have any effect

Proto definition for reference

Screenshot 2023-02-08 at 14 34 12

abe545 commented 1 year ago

Hi @johan44co - I'm wondering if this is an issue with your enum definitions. I know for the C# generation, to get the expected output, the enum items must all be prefixed with the enum name. For instance, the Groups enum should be

enum Groups {
    GROUPS_UNKNOWN = 0;
    GROUPS_TEST_0 = 1;
    GROUPS_TEST_1 = 2;
}

The C# enum for the above would be generated as

public enum Groups {
    Unknown,
    Test0,
    Test1
}

With your current proto definition, the C# code that gets generated would be:

public enum Groups {
    UnknownGroups,
    Test0,
    Test1
}

For your Unlisted enum, since they are not all prefixed with UNLISTED_, the code generation would fail to recognize the prefix, and each item would simply be converted to pascal case in c#. I'm assuming the ts protobuf generator will do something similar with the naming conventions.