Skip to content

feat(protobuf): add opt-in enum value prefixes - #12103

Open
Cameron Taggart (cataggar) wants to merge 2 commits into
microsoft:mainfrom
cataggar:feat/protobuf-enum-value-prefix
Open

Cameron Taggart (cataggar) wants to merge 2 commits into
microsoft:mainfrom
cataggar:feat/protobuf-enum-value-prefix

Conversation

@cataggar

@cataggar Cameron Taggart (cataggar) commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #12102.

Add the opt-in enum-value-prefix: enum-name option to @typespec/protobuf. Every enum value is prefixed with its enum name in UPPER_SNAKE_CASE, so TypeSpec can use short member names without package-scope collisions.

options:
  "@typespec/protobuf":
    enum-value-prefix: enum-name
enum OrderState {
  Unspecified: 0,
  Pending: 1,
  Shipped: 2,
}
enum OrderState {
  ORDER_STATE_UNSPECIFIED = 0;
  ORDER_STATE_PENDING = 1;
  ORDER_STATE_SHIPPED = 2;
}
  • Default output remains unchanged (enum-value-prefix: none).
  • Preserve already-prefixed names and avoid adding a second prefix after case conversion.
  • Preserve numeric values, member order, enum type names, aliases, and documentation. Members and numbers remain explicit; no Unspecified member is synthesized.
  • Validate collisions directly from each emitted file, including unnamed packages, and identify the original conflicting enum member or declaration kind/name in diagnostics.
  • Reuse the existing catalog's change-case dependency and update the lockfile's protobuf importer only.
  • Update the guide, generated option references, and feature changelog. Document generated-API and Protobuf JSON naming implications.

This follows AIP-126 and the Protobuf style guide, which recommends:

Prefix Every Value With the Enum Name (Converted to UPPER_SNAKE_CASE)

Explicit @encodedName support and automatic numbering/member synthesis are outside this change.

Validation

  • Confirmed the new tests fail before implementation.
  • pnpm build — full workspace build passed.
  • pnpm --filter @typespec/protobuf test — 63 tests passed, including 22 prefix-option cases and all existing scenarios.
  • pnpm exec oxlint packages/protobuf --type-aware --deny-warnings — passed.
  • pnpm format:check — passed.
  • Scoped CSpell — passed.
  • pnpm chronus verify --since microsoft/main — passed.
  • Compiled a standalone TypeSpec example containing two enums with Unspecified members, then compiled the emitted .proto with protoc 36.2.

Local lint limitation after a full build: pnpm lint and pnpm lint:fix fail in the unchanged compiler configuration: packages/compiler/tsconfig.json attempts to emit dist/src/server/tmlanguage.d.ts over an input declaration imported by its generation script. The protobuf package's type-aware lint passes; no unrelated compiler changes are included.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/protobuf@12103

commit: ffce982

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 3 High severity · 1 Medium severity

Open (4)
What changed in this PR

Adds an opt-in Protobuf emitter option to prefix enum value names with their enum name (UPPER_SNAKE_CASE) to avoid package-scope collisions, and documents/tests the new behavior.

Changes:

  • Add enum-value-prefix: enum-name emitter option + schema/diagnostic support.
  • Implement enum value prefixing + collision detection in the transform pipeline.
  • Add docs (guide/reference/README) and a dedicated test suite for the option.
File Description
website/​src/​content/​docs/​docs/​emitters/​protobuf/​reference/​emitter.md Documents the new enum-value-prefix option in the reference page.
website/​src/​content/​docs/​docs/​emitters/​protobuf/​guide.md Adds a guide section explaining enum emission and the new prefixing option.
packages/​protobuf/​test/​enum-prefix.test.ts Adds tests covering prefixing, normalization, and collision diagnostics.
packages/​protobuf/​src/​transform/​index.ts Implements enum value prefixing and collision checking across a Protobuf package.
packages/​protobuf/​src/​lib.ts Extends emitter options + JSON schema and introduces a new collision diagnostic.
packages/​protobuf/​package.json Adds change-case dependency for name normalization/prefixing.
packages/​protobuf/​README.md Documents the new emitter option for package consumers.
.chronus/​changes/​protobuf-enum-value-prefix-2026-10-02.md Adds a feature changelog entry describing the new option.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/protobuf/src/transform/index.ts Outdated
Comment thread packages/protobuf/src/transform/index.ts Outdated
Comment thread packages/protobuf/src/transform/index.ts Outdated
Comment thread packages/protobuf/src/lib.ts
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/protobuf
Show changes

@typespec/protobuf - feature ✏️

Add an opt-in enum-value-prefix: enum-name emitter option to prefix enum values with the enum name in UPPER_SNAKE_CASE, without repeating the prefix in TypeSpec members.,> ,> yaml,> options:,> "@typespec/protobuf":,> enum-value-prefix: enum-name,> ,> ,> For example, the Shipped: 2 member of OrderState emits ORDER_STATE_SHIPPED = 2. Already-prefixed names are preserved, and collisions in the emitted package scope are reported as errors identifying the original conflicting symbol.,> ,> Existing output remains unchanged by default. Enum members and numeric values remain explicit; this option does not add an Unspecified member or infer numbers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches the linked feature requirements and includes appropriate tests, documentation, dependency updates, and changelog coverage.

Review effort: Balanced
Findings: None

Resolved since last review (4)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:protobuf The protobuf emitter meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[protobuf] Add opt-in enum-name prefixes for enum values

2 participants