Skip to content

Adding enum values with a number after the prefix result in breaking change to previously generated values. #1284

@mikeder

Description

@mikeder

When adding a new enum value that contains a number after the prefix, generated enums names will change to use the full "ENUM_PREFIX_NAME" style rather than the "Prefix.Name" value style.

Observed with both buf.build/bufbuild/es:v2.2.0 and current buf.build/bufbuild/es:v2.10.0, did not test in between versions.

Example:

Start with minimum basic enum:

syntax = "proto3";

package enum.test.v1;

enum ActionType {
  ACTION_TYPE_INVALID = 0;
  ACTION_TYPE_ONE = 1;
}

Results in this being generated:

/**
 * @generated from enum enum.test.v1.ActionType
 */
export enum ActionType {
  /**
   * @generated from enum value: ACTION_TYPE_INVALID = 0;
   */
  INVALID = 0,

  /**
   * @generated from enum value: ACTION_TYPE_ONE = 1;
   */
  ONE = 1,
}

Add a new enum value containing a number:

syntax = "proto3";

package enum.test.v1;

enum ActionType {
  ACTION_TYPE_INVALID = 0;
  ACTION_TYPE_ONE = 1;
  ACTION_TYPE_2 = 2;
}

Notice all of the generated values change format:

/**
 * @generated from enum enum.test.v1.ActionType
 */
export enum ActionType {
  /**
   * @generated from enum value: ACTION_TYPE_INVALID = 0;
   */
  ACTION_TYPE_INVALID = 0,

  /**
   * @generated from enum value: ACTION_TYPE_ONE = 1;
   */
  ACTION_TYPE_ONE = 1,

  /**
   * @generated from enum value: ACTION_TYPE_2 = 2;
   */
  ACTION_TYPE_2 = 2,
}

I know this is a bad example, since you shouldn't mix enum name styles in proto to begin with, but we recently had a somewhat justified reason for doing so and were surprised by a breaking change in our generated code, despite breaking change detection on the proto itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions