-
Notifications
You must be signed in to change notification settings - Fork 65
[TCGC] generate names for anonymous models in LRO #3611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
commit: |
|
All changed packages have been documented.
Show changes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #2325 by implementing name generation for anonymous models that appear in Long Running Operation (LRO) metadata. The fix ensures that anonymous models in LRO contexts receive proper generated names (like "UpdateFinalResult") instead of remaining unnamed, which improves code readability and ensures the linter rule no-unnamed-types can properly detect and warn about these cases.
Key Changes:
- Extended the
getContextPathfunction to handle LRO metadata fields (finalResult,logicalResult,envelopeResult,finalEnvelopeResult) - Added comprehensive test coverage for both data plane and ARM LRO scenarios with anonymous models
- Added changelog entry documenting the fix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/typespec-client-generator-core/src/public-utils.ts | Added logic to iterate through LRO metadata fields and generate names for anonymous models found within them |
| packages/typespec-client-generator-core/test/methods/lro.test.ts | Added test case validating that anonymous models in LRO final results receive proper generated names |
| packages/typespec-client-generator-core/test/rules/no-unnamed-types.test.ts | Added test case verifying the linter rule correctly detects anonymous models created by LRO metadata in ARM scenarios |
| .chronus/changes/tcgc_fix_lro_anonymous_models-2025-11-3-17-24-7.md | Added changelog entry documenting the fix for anonymous model name generation in LRO metadata |
packages/typespec-client-generator-core/test/methods/lro.test.ts
Outdated
Show resolved
Hide resolved
|
You can try these changes here
|
Co-authored-by: Copilot <[email protected]>
packages/typespec-client-generator-core/test/rules/no-unnamed-types.test.ts
Show resolved
Hide resolved
| @doc("Operation Status") | ||
| @lroStatus | ||
| union OperationStatusValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed to be defined for this test? Can we use the Foundations.OperationState in Core?
Or OperationResultQuery itself can be replaced by some model in Core?
Feel that both of them is not relevant to the test case. Only the definition of Instruction model matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, let me try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After using the standard ResourceOperationStatus, there seems no anonymous any more:

See playground.
I seem to get why the anonymous model is generated.. It seems to me that it's trying generate a model to conform to the standard ResourceOperationStatus...
Ideally, when this model is generated, it should be given a name by compiler. Guess a protection here is acceptable as well.
getAllModelsreturns models with empty names for Azure Core types #2325Extended the getContextPath function to handle LRO metadata fields (finalResult, logicalResult, envelopeResult, finalEnvelopeResult).
Let me know if I should also handle polling models. Currently I can't reproduce anonymous models for them.