Skip to content

Fix enum member names: use enum type name as prefix instead of _ for leading-digit identifiers#3868

Merged
MaryGao merged 14 commits intomainfrom
copilot/fix-enum-member-names
Mar 30, 2026
Merged

Fix enum member names: use enum type name as prefix instead of _ for leading-digit identifiers#3868
MaryGao merged 14 commits intomainfrom
copilot/fix-enum-member-names

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Fixes enum member naming in the Modular SDK emitter to produce valid TypeScript identifiers when enum values start with digits or special characters.

Changes Made

  • Enum type name prefix: emitEnumMember now computes enumTypeName internally from member.enumType.name (via normalizeName) instead of receiving it as a parameter, keeping the function signature clean.
  • Deduplication of colliding names: Added deduplicateEnumMemberNames() in buildEnumTypes to handle cases where multiple enum values normalize to the same identifier (e.g. "10" and "1.0" both normalizing to ExtensibleString10). Conflicting names are disambiguated by appending _1, _2, ... suffixes (e.g. ExtensibleString10_1 and ExtensibleString10_2).
  • Diagnostic reporting: A prefix-adding-in-enum-member warning is reported when a leading-digit member name is prefixed with the enum type name.
  • Snapshot updates: Updated enumKeyNorm.md and extends.md scenario snapshots to reflect the new naming behavior.
  • Smoke test regeneration: Regenerated all TypeSpec smoke test scenarios so the check:tree CI step passes with the new enum member names.

Testing

  • All 599 modular unit tests pass.
  • Snapshot tests updated and passing for affected scenarios.
Original prompt

This section details on the original issue you should resolve

<issue_title>[emitter] Review comment with _0 to fix enum member names having a _ prefix</issue_title>
<issue_description>### Background
During the SDK release phase, we often receive review comments on public APIs that require the service team to modify the original specification and regenerate the SDK. This frequently leads to multiple rounds of back-and-forth discussions. It would be beneficial to revisit these cases and determine:

  • Whether the issue can be addressed on the emitter side, or
  • Whether the emitter or TCGC should report errors or diagnostics earlier or
  • Whether we should NOT report this comment in review phase.

Review Comment

This is a case where the AI flags enum member names having _ prefix generated, which is unexpected. The _1 prefix is auto-added before any digit numbers which is not a valid typescript symbol and would cause compile failure.

Suggestion

To give the enum member more valuable name, we plan to add enum type name as prefix not _ and also report a warning when detecting any non-valid enum member. This would only work for Modular.

</issue_description>

<agent_instructions>To give the enum member more valuable name, we plan to add enum type name as prefix not _ and also report a warning when detecting any non-valid enum member. This would only work for Modular.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 26, 2026 08:11
…core"

- Update emitEnumMember to accept enumTypeName parameter and use it as prefix instead of _ for invalid identifiers
- Update buildEnumTypes to pass normalized enum type name to emitEnumMember
- Update prefix-adding-in-enum-member diagnostic message format to include enumTypeName
- Update enumKeyNorm.md scenario snapshot to use enum type name prefix
- Update extends.md scenario snapshot with new enum member names
- Update enumUnion.spec.ts test to properly verify new diagnostic behavior

Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/99a3e736-bfc1-4400-a41d-56f4053c4638
Copilot AI changed the title [WIP] Fix enum member names with _ prefix in emitter Fix enum member names: use enum type name as prefix instead of _ for leading-digit identifiers Mar 26, 2026
Copilot AI requested a review from MaryGao March 26, 2026 08:19
@MaryGao
Copy link
Copy Markdown
Member

MaryGao commented Mar 26, 2026

@copilot Could you take a look at the pipeline failure and try to fix then?

Copilot AI and others added 2 commits March 26, 2026 09:37
Generated files updated to reflect the new enum member naming where enum type
name is used as prefix instead of underscore (e.g., Versions100 instead of _100,
Versions20240701Preview instead of _20240701Preview). This ensures the CI
check:tree step passes since it compares generated files against committed files.

Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/d16aef3a-466d-4251-a6fe-489bd3fd2549
The previous commit accidentally deleted the openai_non_branded generated
files because it uses a non-standard tspconfig.yaml path (in spec/ not root).
Re-running the smoke test properly regenerates these files.

Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/d16aef3a-466d-4251-a6fe-489bd3fd2549
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 26, 2026

@copilot Could you take a look at the pipeline failure and try to fix then?

The CI failure was in the TypeSpec_Smoke_Test stage's check:tree step. This step regenerates all TypeSpec smoke test scenarios and verifies the generated files match what's committed in git. Since my emitter changes produce different enum member names (e.g., Versions100 instead of _100), the regenerated files differed from the committed ones.

Fixed in commits 7f7ebc2 and e027d69 by:

  1. Regenerating all 30 TypeSpec smoke test scenarios with the new enum member naming
  2. Restoring the openai_non_branded scenario that was accidentally deleted (it uses a non-standard tspconfig.yaml path in spec/ rather than the root)

The check:tree now passes locally, confirming the generated files are in sync with the updated emitter behavior.

@v-jiaodi
Copy link
Copy Markdown
Member

@copilot run pnpm smoke-test to fix ci under typespec-test folder

… from main

Regenerated 6 scenarios (NetworkAnalytics.Management, healthInsights_radiologyinsights,
loadtesting_modular, nestedClient, openai_modular, schemaRegistry) that were affected
by the merge with main branch (PR #3856: model array responses fix). This ensures
the check:tree CI step passes.

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/47b50ca2-9eda-4d7f-8560-c906ba14c70f

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot run pnpm smoke-test to fix ci under typespec-test folder

Done in commit 33d2ecd. Ran pnpm smoke-test which regenerated 6 scenarios (NetworkAnalytics.Management, healthInsights_radiologyinsights, loadtesting_modular, nestedClient, openai_modular, schemaRegistry) that were affected by the merge from main. check:tree now passes cleanly.

Copilot AI requested a review from v-jiaodi March 27, 2026 06:55
@MaryGao MaryGao marked this pull request as ready for review March 30, 2026 03:21
@v-jiaodi
Copy link
Copy Markdown
Member

@copilot pull main branch and resolve conflicts.

…er-names

# Conflicts:
#	packages/typespec-ts/test/modularUnit/enumUnion.spec.ts

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 30, 2026

@copilot pull main branch and resolve conflicts.

Done in commit 485c752. Merged main branch (PR #3810 - Report TCGC diagnostics) and resolved the conflict: enumUnion.spec.ts was deleted by main and the test was moved to diagnostics.spec.ts with the old message format. Updated diagnostics.spec.ts to use our new diagnostic message format with the enum type name as prefix. All tests pass and check:tree passes cleanly.

Comment thread packages/typespec-ts/src/modular/emitModels.ts Outdated
@v-jiaodi
Copy link
Copy Markdown
Member

@copilot revert headerParamWithClientInitialization.md and storageCompatResponse.md file change.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 30, 2026

@copilot revert headerParamWithClientInitialization.md and storageCompatResponse.md file change.

Done in commit 6867008. Both files are restored to their original state — those were unrelated Prettier formatting changes that accidentally got included.

@MaryGao MaryGao enabled auto-merge (squash) March 30, 2026 09:16
@MaryGao MaryGao merged commit c8572e1 into main Mar 30, 2026
16 checks passed
@MaryGao MaryGao deleted the copilot/fix-enum-member-names branch March 30, 2026 09:44
Copilot AI added a commit that referenced this pull request Mar 30, 2026
v-jiaodi added a commit that referenced this pull request Mar 30, 2026
…script 6.0.65 (#3871)

* Initial plan

* Bump emitter versions: typespec-ts 0.51.1, rlc-common 0.51.1, autorest.typescript 6.0.65

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/a8b8af62-f460-4099-8944-43f4cb8ff6f7

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>

* Run pnpm install to update lock file with bumped version references

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/fa4b7fda-60f7-4a6f-bacf-fbd27da9e99f

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>

* Add missing #3870 (Bump TypeSpec dependencies) to all three changelogs

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/42aeb7ec-160d-4e69-9f03-f354ec0afda7

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>

* Add missing #3868 (Fix enum member names) to all three changelogs

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/d1234708-ecd8-4ce3-ab5c-5d9bfc6b69fb

Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

[emitter] Review comment with _0 to fix enum member names having a _ prefix

4 participants