Skip to content

[FEATURE] Prettify enum names #21

@Dogacel

Description

@Dogacel

Is your feature request related to a problem? Please describe.
Enum names are always prefixed by ENUM_NAME_ and this is not very intuitive for kotlin code. This is a limitation to support C++ generated code.

Describe the solution you'd like
Add an option to automatically remove ENUM_NAME_ prefix from generated enums.

Describe alternatives you've considered
None

Additional context

I think we can include an option to remove the ENUM_NAME_ prefix from the actual enum names in the generated code. Such as

enum State {
  STATE_UNKNOWN = 0
  STATE_KNOWN = 1
}

will be converted to

@Serializable
public enum class State {
    @ProtoNumber(number = 0)
    UNKNOWN,
    @ProtoNumber(number = 1)
    KNOWN,
}

And this can be toggled via an option

    generateProtoTasks {
        all().forEach {
            it.plugins {
                id("kotlinx-protobuf-gen") {
                    option("remove_enum_prefix") // <-- this
                }
            }
        }
    }

Based on conversation with @tamnguyenhuy from #14

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions