Skip to content

Conversation

@XiaofeiCao
Copy link
Contributor

@XiaofeiCao XiaofeiCao commented Dec 3, 2025

Extended 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-client-generator-core@3611

commit: 6eff8bb

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 3, 2025

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - fix ✏️

Generate names for anonymous models in LroMetadata.

Copy link
Contributor

Copilot AI left a 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 getContextPath function 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

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 3, 2025

You can try these changes here

🛝 Playground 🌐 Website

@doc("Operation Status")
@lroStatus
union OperationStatusValue {
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 5, 2025

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, let me try.

Copy link
Contributor Author

@XiaofeiCao XiaofeiCao Dec 5, 2025

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:
image

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.

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.

[Bug]: getAllModels returns models with empty names for Azure Core types

3 participants