Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

subscriptionId and apiVersion parameters were not being added to the top-level client's ClientInitialization when these parameters only existed in nested (non-direct-child) operation groups.

Root Cause

In addDefaultClientParameters, listOperationGroups(context, client.__raw) only returns direct children. Parameters in deeply nested operation groups were missed.

Changes

  • clients.ts: Pass ignoreHierarchy=true to listOperationGroups when searching for apiVersionParam and subId parameters, enabling recursive search through all nested operation groups
  • client-location.test.ts: Added test case for ARM spec with @@clientLocation moving subscriptionId to method level while verifying it remains on the client

Example

@armResourceOperations
interface Employees {
  createOrUpdate is ArmResourceCreateOrReplaceAsync<Employee, BaseParameters = EmployeeBaseParameter>;
  get is ArmResourceRead<Employee>;
}
@@clientLocation(EmployeeBaseParameter.subscriptionId, Employees.createOrUpdate);

Previously, subscriptionId was missing from the client. Now it correctly appears in client.clientInitialization.parameters.

Original prompt

This section details on the original issue you should resolve

<issue_title>[TCGC] ClientInitialization should have the subscriptionId parameter when subscriptionId is used at both the method and client levels</issue_title>
<issue_description>TypeSpec:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ClientGenerator.Core;

/** Microsoft.Contoso Resource Provider management API. */
@armProviderNamespace
@service(#{
  title: "Microsoft.Contoso management service",
})
@versioned(Microsoft.Contoso.Versions)
namespace Microsoft.Contoso;

/** The available API versions. */
enum Versions {
  /** 2021-10-01-preview version */
  @armCommonTypesVersion(CommonTypes.Versions.v5)
  v2021_10_01_preview: "2021-10-01-preview",
}

/** Employee resource */
model Employee is TrackedResource<EmployeeProperties> {
  ...ResourceNameParameter<Employee>;
}

/** Employee properties */
model EmployeeProperties {
  /** Age of employee */
  age?: int32;
  /** The status of the last operation. */
  @visibility(Lifecycle.Read)
  provisioningState?: ProvisioningState;
}

model EmployeeBaseParameter
    is Azure.ResourceManager.Foundations.DefaultBaseParameters<Employee>;

/** The resource provisioning state. */
@lroStatus
union ProvisioningState {
  ResourceProvisioningState,

  /** The resource is being provisioned */
  Provisioning: "Provisioning",

  string,
}

@armResourceOperations
interface Employees {
  createOrUpdate is ArmResourceCreateOrReplaceAsync<
    Employee,
    BaseParameters = EmployeeBaseParameter
  >;
  get is ArmResourceRead<Employee>;
}
@@clientLocation(EmployeeBaseParameter.subscriptionId, Employees.createOrUpdate);

The SubscriptionId should exist at the client.</issue_description>

<agent_instructions>In this PR: #3820, I removed the ignore hierarchy option of listOperationGroups when finding api version and subscription client parameter, which cause this regression. The reason should be when adding api version and subscription client parameter, it has not been added to __clientParametersCache which cause the missing client parameter when there are multiple layer clients. You need to fix the problem and add related test. Make sure to get all TCGC tests pass and changeset is added by pnpm -w change add.</agent_instructions>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…on groups

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copilot AI changed the title [WIP] Add subscriptionId parameter to ClientInitialization [TCGC] Fix subscriptionId/apiVersion client parameters for nested operation groups Jan 26, 2026
Copilot AI requested a review from tadelesh January 26, 2026 03:05
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 26, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/azure-http-specs@3843
npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-autorest@3843
npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-azure-resource-manager@3843
npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-client-generator-core@3843

commit: 506e73c

@tadelesh tadelesh marked this pull request as ready for review January 26, 2026 06:08
@tadelesh tadelesh merged commit 61553de into release/january-2026 Jan 26, 2026
23 checks passed
@tadelesh tadelesh deleted the copilot/add-subscription-id-parameter-again branch January 26, 2026 06:08
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.

3 participants