From 75f2f33773072f892ae2b2233555927696fd3604 Mon Sep 17 00:00:00 2001 From: "Jiao Di (MSFT)" <80496810+v-jiaodi@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:54:10 +0800 Subject: [PATCH 1/4] add case for apiVersion header/path/query --- ...lientGeneratorCoreApiVersionHeader.spec.ts | 26 ++++++++++++ ...eClientGeneratorCoreApiVersionPath.spec.ts | 25 ++++++++++++ ...ClientGeneratorCoreApiVersionQuery.spec.ts | 26 ++++++++++++ .../api-version/header/.gitignore | 6 +++ .../api-version/header/src/index.d.ts | 40 +++++++++++++++++++ .../api-version/header/tspconfig.yaml | 9 +++++ .../api-version/path/.gitignore | 6 +++ .../api-version/path/src/index.d.ts | 31 ++++++++++++++ .../api-version/path/tspconfig.yaml | 9 +++++ .../api-version/query/.gitignore | 6 +++ .../api-version/query/src/index.d.ts | 39 ++++++++++++++++++ .../api-version/query/tspconfig.yaml | 9 +++++ ...lientGeneratorCoreApiVersionHeader.spec.ts | 17 ++++++++ ...eClientGeneratorCoreApiVersionPath.spec.ts | 17 ++++++++ ...ClientGeneratorCoreApiVersionQuery.spec.ts | 17 ++++++++ .../api-version/header/.gitignore | 6 +++ .../api-version/header/src/index.d.ts | 23 +++++++++++ .../api-version/header/tspconfig.yaml | 10 +++++ .../api-version/path/.gitignore | 6 +++ .../api-version/path/src/index.d.ts | 23 +++++++++++ .../api-version/path/tspconfig.yaml | 10 +++++ .../api-version/query/.gitignore | 6 +++ .../api-version/query/src/index.d.ts | 23 +++++++++++ .../api-version/query/tspconfig.yaml | 10 +++++ .../test/commands/cadl-ranch-list.js | 24 +++++++++++ 25 files changed, 424 insertions(+) create mode 100644 packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts create mode 100644 packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts create mode 100644 packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/.gitignore create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/.gitignore create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/.gitignore create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml create mode 100644 packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/.gitignore create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/.gitignore create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/.gitignore create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts create mode 100644 packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts new file mode 100644 index 0000000000..21d5e8b765 --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts @@ -0,0 +1,26 @@ +import { assert } from "chai"; +import HeaderClientFactory, { + HeaderClient +} from "./generated/azure/client-generator-core/api-version/header/src/index.js"; + +describe("Azure Client Generator Core - API Version Header", () => { + let client: HeaderClient; + + beforeEach(() => { + client = HeaderClientFactory({ + allowInsecureConnection: true + }); + }); + + it("should handle API version through header parameter", async () => { + const result = await client + .path("/azure/client-generator-core/api-version/header") + .post({ + headers: { + "x-ms-version": "2025-01-01" + } + }); + + assert.strictEqual(result.status, "200"); + }); +}); diff --git a/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts new file mode 100644 index 0000000000..5101499268 --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts @@ -0,0 +1,25 @@ +import { assert } from "chai"; +import PathClientFactory, { + PathClient +} from "./generated/azure/client-generator-core/api-version/path/src/index.js"; + +describe("Azure Client Generator Core - API Version Path", () => { + let client: PathClient; + + beforeEach(() => { + client = PathClientFactory({ + allowInsecureConnection: true + }); + }); + + it("should handle API version through path parameter", async () => { + const result = await client + .path( + "/azure/client-generator-core/api-version/path/{version}", + "2025-01-01" + ) + .post(); + + assert.strictEqual(result.status, "200"); + }); +}); diff --git a/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts new file mode 100644 index 0000000000..03ec4f04be --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts @@ -0,0 +1,26 @@ +import { assert } from "chai"; +import QueryClientFactory, { + QueryClient +} from "./generated/azure/client-generator-core/api-version/query/src/index.js"; + +describe("Azure Client Generator Core - API Version Query", () => { + let client: QueryClient; + + beforeEach(() => { + client = QueryClientFactory({ + allowInsecureConnection: true + }); + }); + + it("should handle API version through query parameter", async () => { + const result = await client + .path("/azure/client-generator-core/api-version/query") + .post({ + queryParameters: { + version: "2025-01-01" + } + }); + + assert.strictEqual(result.status, "200"); + }); +}); diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/.gitignore b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts new file mode 100644 index 0000000000..6b4ae619df --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts @@ -0,0 +1,40 @@ +import type { Client } from '@azure-rest/core-client'; +import type { ClientOptions } from '@azure-rest/core-client'; +import type { HttpResponse } from '@azure-rest/core-client'; +import type { RawHttpHeadersInput } from '@azure/core-rest-pipeline'; +import type { RequestParameters } from '@azure-rest/core-client'; +import type { StreamableMethod } from '@azure-rest/core-client'; + +declare function createClient(options?: HeaderClientOptions): HeaderClient; +export default createClient; + +export declare interface HeaderApiVersion { + post(options: HeaderApiVersionParameters): StreamableMethod; +} + +export declare interface HeaderApiVersion200Response extends HttpResponse { + status: "200"; +} + +export declare interface HeaderApiVersionHeaderParam { + headers: RawHttpHeadersInput & HeaderApiVersionHeaders; +} + +export declare interface HeaderApiVersionHeaders { + "x-ms-version": string; +} + +export declare type HeaderApiVersionParameters = HeaderApiVersionHeaderParam & RequestParameters; + +export declare type HeaderClient = Client & { + path: Routes; +}; + +export declare interface HeaderClientOptions extends ClientOptions { +} + +export declare interface Routes { + (path: "/azure/client-generator-core/api-version/header"): HeaderApiVersion; +} + +export { } diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml new file mode 100644 index 0000000000..4828f86b4d --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml @@ -0,0 +1,9 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + package-details: + name: "@azure/client-generator-core-header" diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/.gitignore b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts new file mode 100644 index 0000000000..ab1f5d773e --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts @@ -0,0 +1,31 @@ +import type { Client } from '@azure-rest/core-client'; +import type { ClientOptions } from '@azure-rest/core-client'; +import type { HttpResponse } from '@azure-rest/core-client'; +import type { RequestParameters } from '@azure-rest/core-client'; +import type { StreamableMethod } from '@azure-rest/core-client'; + +declare function createClient(options?: PathClientOptions): PathClient; +export default createClient; + +export declare interface PathApiVersion { + post(options?: PathApiVersionParameters): StreamableMethod; +} + +export declare interface PathApiVersion200Response extends HttpResponse { + status: "200"; +} + +export declare type PathApiVersionParameters = RequestParameters; + +export declare type PathClient = Client & { + path: Routes; +}; + +export declare interface PathClientOptions extends ClientOptions { +} + +export declare interface Routes { + (path: "/azure/client-generator-core/api-version/path/{version}", version: string): PathApiVersion; +} + +export { } diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml new file mode 100644 index 0000000000..96c6b59ce6 --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml @@ -0,0 +1,9 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + package-details: + name: "@azure/client-generator-core-path" diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/.gitignore b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts new file mode 100644 index 0000000000..084cf5a1c9 --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts @@ -0,0 +1,39 @@ +import type { Client } from '@azure-rest/core-client'; +import type { ClientOptions } from '@azure-rest/core-client'; +import type { HttpResponse } from '@azure-rest/core-client'; +import type { RequestParameters } from '@azure-rest/core-client'; +import type { StreamableMethod } from '@azure-rest/core-client'; + +declare function createClient(options?: QueryClientOptions): QueryClient; +export default createClient; + +export declare interface QueryApiVersion { + post(options: QueryApiVersionParameters): StreamableMethod; +} + +export declare interface QueryApiVersion200Response extends HttpResponse { + status: "200"; +} + +export declare type QueryApiVersionParameters = QueryApiVersionQueryParam & RequestParameters; + +export declare interface QueryApiVersionQueryParam { + queryParameters: QueryApiVersionQueryParamProperties; +} + +export declare interface QueryApiVersionQueryParamProperties { + version: string; +} + +export declare type QueryClient = Client & { + path: Routes; +}; + +export declare interface QueryClientOptions extends ClientOptions { +} + +export declare interface Routes { + (path: "/azure/client-generator-core/api-version/query"): QueryApiVersion; +} + +export { } diff --git a/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml new file mode 100644 index 0000000000..9d542c773f --- /dev/null +++ b/packages/typespec-ts/test/azureIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml @@ -0,0 +1,9 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + package-details: + name: "@azure/client-generator-core-query" diff --git a/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts new file mode 100644 index 0000000000..cad2ee3c60 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionHeader.spec.ts @@ -0,0 +1,17 @@ +import { HeaderClient } from "./generated/azure/client-generator-core/api-version/header/src/index.js"; + +describe("Azure Client Generator Core - API Version Header (Modular)", () => { + let client: HeaderClient; + + beforeEach(() => { + client = new HeaderClient({ + endpoint: "http://localhost:3002", + allowInsecureConnection: true + }); + }); + + it("should handle API version through header parameter", async () => { + // The header API version is handled internally by the client + await client.headerApiVersion(); + }); +}); diff --git a/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts new file mode 100644 index 0000000000..7a5907b72f --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionPath.spec.ts @@ -0,0 +1,17 @@ +import { PathClient } from "./generated/azure/client-generator-core/api-version/path/src/index.js"; + +describe("Azure Client Generator Core - API Version Path (Modular)", () => { + let client: PathClient; + + beforeEach(() => { + client = new PathClient({ + endpoint: "http://localhost:3002", + allowInsecureConnection: true + }); + }); + + it("should handle API version through path parameter", async () => { + // The path API version is handled internally by the client + await client.pathApiVersion(); + }); +}); diff --git a/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts new file mode 100644 index 0000000000..b5301465c8 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/azureClientGeneratorCoreApiVersionQuery.spec.ts @@ -0,0 +1,17 @@ +import { QueryClient } from "./generated/azure/client-generator-core/api-version/query/src/index.js"; + +describe("Azure Client Generator Core - API Version Query (Modular)", () => { + let client: QueryClient; + + beforeEach(() => { + client = new QueryClient({ + endpoint: "http://localhost:3002", + allowInsecureConnection: true + }); + }); + + it("should handle API version through query parameter", async () => { + // The query API version is handled internally by the client + await client.queryApiVersion(); + }); +}); diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/.gitignore b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts new file mode 100644 index 0000000000..6e509f8d40 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/src/index.d.ts @@ -0,0 +1,23 @@ +import { ClientOptions } from '@azure-rest/core-client'; +import { OperationOptions } from '@azure-rest/core-client'; +import { Pipeline } from '@azure/core-rest-pipeline'; + +export declare interface HeaderApiVersionOptionalParams extends OperationOptions { +} + +export declare class HeaderClient { + private _client; + readonly pipeline: Pipeline; + constructor(options?: HeaderClientOptionalParams); + headerApiVersion(options?: HeaderApiVersionOptionalParams): Promise; +} + +export declare interface HeaderClientOptionalParams extends ClientOptions { + version?: string; +} + +export declare enum KnownApiVersions { + V20250101 = "2025-01-01" +} + +export { } diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml new file mode 100644 index 0000000000..c782343f35 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/header/tspconfig.yaml @@ -0,0 +1,10 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + is-modular-library: true + package-details: + name: "@azure/client-generator-core-header" diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/.gitignore b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts new file mode 100644 index 0000000000..36c1a19ddf --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/src/index.d.ts @@ -0,0 +1,23 @@ +import { ClientOptions } from '@azure-rest/core-client'; +import { OperationOptions } from '@azure-rest/core-client'; +import { Pipeline } from '@azure/core-rest-pipeline'; + +export declare enum KnownApiVersions { + V20250101 = "2025-01-01" +} + +export declare interface PathApiVersionOptionalParams extends OperationOptions { +} + +export declare class PathClient { + private _client; + readonly pipeline: Pipeline; + constructor(options?: PathClientOptionalParams); + pathApiVersion(options?: PathApiVersionOptionalParams): Promise; +} + +export declare interface PathClientOptionalParams extends ClientOptions { + version?: string; +} + +export { } diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml new file mode 100644 index 0000000000..e5f90b4412 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/path/tspconfig.yaml @@ -0,0 +1,10 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + is-modular-library: true + package-details: + name: "@azure/client-generator-core-path" diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/.gitignore b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/.gitignore new file mode 100644 index 0000000000..39220655cc --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/.gitignore @@ -0,0 +1,6 @@ +/** +!/src +/src/** +!/src/index.d.ts +!/.gitignore +!/tspconfig.yaml diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts new file mode 100644 index 0000000000..09702cd63b --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/src/index.d.ts @@ -0,0 +1,23 @@ +import { ClientOptions } from '@azure-rest/core-client'; +import { OperationOptions } from '@azure-rest/core-client'; +import { Pipeline } from '@azure/core-rest-pipeline'; + +export declare enum KnownApiVersions { + V20250101 = "2025-01-01" +} + +export declare interface QueryApiVersionOptionalParams extends OperationOptions { +} + +export declare class QueryClient { + private _client; + readonly pipeline: Pipeline; + constructor(options?: QueryClientOptionalParams); + queryApiVersion(options?: QueryApiVersionOptionalParams): Promise; +} + +export declare interface QueryClientOptionalParams extends ClientOptions { + version?: string; +} + +export { } diff --git a/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml new file mode 100644 index 0000000000..9c84595ed5 --- /dev/null +++ b/packages/typespec-ts/test/azureModularIntegration/generated/azure/client-generator-core/api-version/query/tspconfig.yaml @@ -0,0 +1,10 @@ +emit: + - "@azure-tools/typespec-ts" +options: + "@azure-tools/typespec-ts": + emitter-output-dir: "{project-root}" + add-credentials: false + azure-sdk-for-js: false + is-modular-library: true + package-details: + name: "@azure/client-generator-core-query" diff --git a/packages/typespec-ts/test/commands/cadl-ranch-list.js b/packages/typespec-ts/test/commands/cadl-ranch-list.js index cb9d24c322..916f9df314 100644 --- a/packages/typespec-ts/test/commands/cadl-ranch-list.js +++ b/packages/typespec-ts/test/commands/cadl-ranch-list.js @@ -311,6 +311,18 @@ export const azureRlcTsps = [ { outputPath: "azure/resource-manager/non-resource", inputPath: "azure/resource-manager/non-resource" + }, + { + outputPath: "azure/client-generator-core/api-version/header", + inputPath: "azure/client-generator-core/api-version/header" + }, + { + outputPath: "azure/client-generator-core/api-version/path", + inputPath: "azure/client-generator-core/api-version/path" + }, + { + outputPath: "azure/client-generator-core/api-version/query", + inputPath: "azure/client-generator-core/api-version/query" } ]; @@ -815,6 +827,18 @@ export const azureModularTsps = [ { outputPath: "azure/resource-manager/non-resource", inputPath: "azure/resource-manager/non-resource" + }, + { + outputPath: "azure/client-generator-core/api-version/header", + inputPath: "azure/client-generator-core/api-version/header" + }, + { + outputPath: "azure/client-generator-core/api-version/path", + inputPath: "azure/client-generator-core/api-version/path" + }, + { + outputPath: "azure/client-generator-core/api-version/query", + inputPath: "azure/client-generator-core/api-version/query" } ]; From 6e853f1f856693e21db8ca98ebccaf12a0b67ecc Mon Sep 17 00:00:00 2001 From: "Jiao Di (MSFT)" <80496810+v-jiaodi@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:52:26 +0800 Subject: [PATCH 2/4] fix --- packages/typespec-ts/src/modular/buildClientContext.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/typespec-ts/src/modular/buildClientContext.ts b/packages/typespec-ts/src/modular/buildClientContext.ts index d3c6339d00..5c855fb4d3 100644 --- a/packages/typespec-ts/src/modular/buildClientContext.ts +++ b/packages/typespec-ts/src/modular/buildClientContext.ts @@ -45,9 +45,8 @@ export function getClientContextPath( const { subfolder } = getModularClientOptions(clientMap); const name = getClientName(client); const srcPath = emitterOptions.modularOptions.sourceRoot; - const contentPath = `${srcPath}/${ - subfolder && subfolder !== "" ? subfolder + "/" : "" - }api/${normalizeName(name, NameType.File)}Context.ts`; + const contentPath = `${srcPath}/${subfolder && subfolder !== "" ? subfolder + "/" : "" + }api/${normalizeName(name, NameType.File)}Context.ts`; return contentPath; } @@ -195,8 +194,9 @@ export function buildClientContext( : []; const apiVersionInEndpoint = templateArguments && templateArguments.find((p) => p.isApiVersionParam); + const parameterName = getClientParameterName(apiVersionParam); if (!apiVersionInEndpoint && apiVersionParam.clientDefaultValue) { - apiVersionPolicyStatement += `const apiVersion = options.apiVersion ?? "${apiVersionParam.clientDefaultValue}";`; + apiVersionPolicyStatement += `const ${parameterName} = options.${parameterName} ?? "${apiVersionParam.clientDefaultValue}";`; } if (apiVersionParam.kind === "method") { @@ -210,7 +210,7 @@ export function buildClientContext( if (!url.searchParams.get("api-version")) { req.url = \`\${req.url}\${ Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" - }api-version=\${${getClientParameterName(apiVersionParam)}}\`; + }api-version=\${${parameterName}}\`; } return next(req); From 4a836076ab7295632f072c8e836ee2ce775c2f81 Mon Sep 17 00:00:00 2001 From: "Jiao Di (MSFT)" <80496810+v-jiaodi@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:53:14 +0800 Subject: [PATCH 3/4] format --- packages/typespec-ts/src/modular/buildClientContext.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/typespec-ts/src/modular/buildClientContext.ts b/packages/typespec-ts/src/modular/buildClientContext.ts index 5c855fb4d3..ab20516a2c 100644 --- a/packages/typespec-ts/src/modular/buildClientContext.ts +++ b/packages/typespec-ts/src/modular/buildClientContext.ts @@ -45,8 +45,9 @@ export function getClientContextPath( const { subfolder } = getModularClientOptions(clientMap); const name = getClientName(client); const srcPath = emitterOptions.modularOptions.sourceRoot; - const contentPath = `${srcPath}/${subfolder && subfolder !== "" ? subfolder + "/" : "" - }api/${normalizeName(name, NameType.File)}Context.ts`; + const contentPath = `${srcPath}/${ + subfolder && subfolder !== "" ? subfolder + "/" : "" + }api/${normalizeName(name, NameType.File)}Context.ts`; return contentPath; } From 997f8937589459743fa307f30c22b0230e8b306b Mon Sep 17 00:00:00 2001 From: "Jiao Di (MSFT)" <80496810+v-jiaodi@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:31:22 +0800 Subject: [PATCH 4/4] revert change --- packages/typespec-ts/src/modular/buildClientContext.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/typespec-ts/src/modular/buildClientContext.ts b/packages/typespec-ts/src/modular/buildClientContext.ts index ab20516a2c..d3c6339d00 100644 --- a/packages/typespec-ts/src/modular/buildClientContext.ts +++ b/packages/typespec-ts/src/modular/buildClientContext.ts @@ -195,9 +195,8 @@ export function buildClientContext( : []; const apiVersionInEndpoint = templateArguments && templateArguments.find((p) => p.isApiVersionParam); - const parameterName = getClientParameterName(apiVersionParam); if (!apiVersionInEndpoint && apiVersionParam.clientDefaultValue) { - apiVersionPolicyStatement += `const ${parameterName} = options.${parameterName} ?? "${apiVersionParam.clientDefaultValue}";`; + apiVersionPolicyStatement += `const apiVersion = options.apiVersion ?? "${apiVersionParam.clientDefaultValue}";`; } if (apiVersionParam.kind === "method") { @@ -211,7 +210,7 @@ export function buildClientContext( if (!url.searchParams.get("api-version")) { req.url = \`\${req.url}\${ Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" - }api-version=\${${parameterName}}\`; + }api-version=\${${getClientParameterName(apiVersionParam)}}\`; } return next(req);