Skip to content

Conversation

@iscai-msft
Copy link
Contributor

No description provided.

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 14, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 14, 2026

Open in StackBlitz

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

commit: fa95628

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 14, 2026

All changed packages have been documented.

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

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

Correctly detect name collisions with --namespace flag and or multi service usage

// Skip `@clientName` on versioning types
continue;
}
if (type.kind === "Operation") {
Copy link
Member

Choose a reason for hiding this comment

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

The following @clientLocation logic for operation has one legacy issue: we now allow to move to existed ns with string (@@clientLocation(op, "Test"); namespace Test {}), which is not handled in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh good catch, thanks!

movedTo,
tcgcContext.program.getGlobalNamespaceType(),
);
if (isMultiService) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think multiple service is a criteria for this check. Shall we use the criteria: whether honor TypeSpec namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to run the check only when we really need to, that's why I want with multi service. what criteria would you use to evaluate whether it honors the tsp namespace? since we don't have access to the namespace flag at this point

Copy link
Member

Choose a reason for hiding this comment

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

If we honor TypeSpec namespace in multiple services scenario, we should not do the validation. With Tim's opinion, I believe we could only do the validation in the createSDKContext.

/**
* Collect all types from a namespace and its nested namespaces recursively.
*/
function collectTypesFromNamespace(
Copy link
Member

Choose a reason for hiding this comment

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

The problem here is the check will also for the types that is not used in the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, but the problem here is that we don't have access to the sdkcontext at this point, so we still don't know whether a type will be used in the eventual client. What scenario do you have where we don't care if there's collisions?

Copy link
Member

Choose a reason for hiding this comment

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

Same with previous comment.


// Validate cross-namespace names if namespace flag is set (flattens namespaces)
// Can't validate in $onValidate bc we don't have access to the namespace flag
validateCrossNamespaceNamesWithFlag(context, diagnostics);
Copy link
Member

Choose a reason for hiding this comment

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

We always have duplicate logic because of the config for emitter could not be get when compile or validate. Could you help to confirm with TypeSpec team to see if there is any solution that we could have such info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timotheeguerin do you have any suggestions here? Basically we want to do validations in $onValidate, but that takes in the tcgc context without flags. When we want to do validation with flags, we have to rerun validation with sdk context and access to the flags. Is this the only way? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

where do those flags come from?

Copy link
Member

Choose a reason for hiding this comment

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

while missing some context I think you either needs to do the validation in onValidate for every case scenario once(Like I believe it was done for @clientName conflict validating all emitters) or you have to let that validation happen when the emitter set their flag

Copy link
Member

Choose a reason for hiding this comment

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

So, I believe if our validation is based on emitter's config, we need to do that in the createSDKContext.

const allUnions: Union[] = [];
const allScalars: Scalar[] = [];

for (const serviceNs of serviceNamespaces) {
Copy link
Member

Choose a reason for hiding this comment

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

This missed the check for imported lib: Azure.Core, Azure.ResourceManager, etc.

@tadelesh
Copy link
Member

Shall we have some discussions with TypeSpec team to see their suggestions for such kind of validation, since it will impact perf.

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

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants