diff --git a/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts b/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts index 5575393928..ccb9f405be 100644 --- a/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts +++ b/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts @@ -73,7 +73,12 @@ function transformApiVersion( const queryVersionDetail = getOperationQueryApiVersion(model); const pathVersionDetail = extractPathApiVersion(urlInfo); const isCrossedVersion = - pathVersionDetail?.isCrossedVersion || queryVersionDetail?.isCrossedVersion; + queryVersionDetail || pathVersionDetail + ? Boolean( + pathVersionDetail?.isCrossedVersion || + queryVersionDetail?.isCrossedVersion + ) + : undefined; let defaultValue = pathVersionDetail?.defaultValue ?? queryVersionDetail?.defaultValue; @@ -88,7 +93,8 @@ function transformApiVersion( pathVersionDetail ), isCrossedVersion, - defaultValue + defaultValue, + required: pathVersionDetail?.required ?? queryVersionDetail?.required }; } @@ -112,9 +118,10 @@ function getOperationQueryApiVersion( if (apiVersionParam && isConstantSchema(apiVersionParam.schema)) { return { - definedPosition: "path", + definedPosition: "query", isCrossedVersion: false, - defaultValue: apiVersionParam.schema.value.value.toString() + defaultValue: apiVersionParam.schema.value.value.toString(), + required: apiVersionParam.required }; } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyComplexRest/src/bodyComplexRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyComplexRest/src/bodyComplexRestClient.ts index a653ff2e2f..a107e4e26c 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyComplexRest/src/bodyComplexRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyComplexRest/src/bodyComplexRestClient.ts @@ -5,13 +5,20 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { BodyComplexRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface BodyComplexRestClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `BodyComplexRestClient` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): BodyComplexRestClient { +export default function createClient({ + apiVersion = "2016-02-29", + ...options +}: BodyComplexRestClientOptions = {}): BodyComplexRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-body-complex-rest/1.0.0-preview1`; @@ -28,15 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyComplexRestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + return next(req); + }, + }); return client; } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyFileRest/src/bodyFile.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyFileRest/src/bodyFile.ts index 5f8ae26338..cbb106f736 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyFileRest/src/bodyFile.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyFileRest/src/bodyFile.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { BodyFileClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface BodyFileClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BodyFileClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BodyFileClientOptions = {}, ): BodyFileClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyFileClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyFormDataRest/src/bodyFormData.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyFormDataRest/src/bodyFormData.ts index 6fe12c9c97..2c61375d9f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyFormDataRest/src/bodyFormData.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyFormDataRest/src/bodyFormData.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { BodyFormDataClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface BodyFormDataClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BodyFormDataClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BodyFormDataClientOptions = {}, ): BodyFormDataClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyFormDataClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/src/bodyStringRest.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/src/bodyStringRest.ts index 523efd18f1..08ffb2321e 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/src/bodyStringRest.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/src/bodyStringRest.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { BodyStringRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface BodyStringRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BodyStringRestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BodyStringRestClientOptions = {}, ): BodyStringRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyStringRestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/customUrlRest/src/customUrlRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/customUrlRest/src/customUrlRestClient.ts index 6a362f44e0..4d8b1e6acf 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/customUrlRest/src/customUrlRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/customUrlRest/src/customUrlRestClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { CustomUrlRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface CustomUrlRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `CustomUrlRestClient` * @param host - A string value that is used as a global part of the parameterized host @@ -12,7 +15,7 @@ import { CustomUrlRestClient } from "./clientDefinitions"; */ export default function createClient( host: string, - options: ClientOptions = {}, + options: CustomUrlRestClientOptions = {}, ): CustomUrlRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://{accountName}${host}`; @@ -30,7 +33,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as CustomUrlRestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/src/dPGCustomizationClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/src/dPGCustomizationClient.ts index 15e3230f9b..0682cca5e2 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/src/dPGCustomizationClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/src/dPGCustomizationClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { DPGCustomizationClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface DPGCustomizationClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DPGCustomizationClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: DPGCustomizationClientOptions = {}, ): DPGCustomizationClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DPGCustomizationClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/src/headerRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/src/headerRestClient.ts index 2cecd7470d..3365bb8153 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/src/headerRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/src/headerRestClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { HeaderRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface HeaderRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `HeaderRestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: HeaderRestClientOptions = {}, ): HeaderRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as HeaderRestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/httpInfrastructureRest/src/httpInfrastructureRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/httpInfrastructureRest/src/httpInfrastructureRestClient.ts index 42e4a3a234..b52df866b5 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/httpInfrastructureRest/src/httpInfrastructureRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/httpInfrastructureRest/src/httpInfrastructureRestClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { HttpInfrastructureRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface HttpInfrastructureRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `HttpInfrastructureRestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: HttpInfrastructureRestClientOptions = {}, ): HttpInfrastructureRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/lroRest/src/lRORestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/lroRest/src/lRORestClient.ts index 85f9deb371..29d7a071ee 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/lroRest/src/lRORestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/lroRest/src/lRORestClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { LRORestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface LRORestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `LRORestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: LRORestClientOptions = {}, ): LRORestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as LRORestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/src/mediaTypes.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/src/mediaTypes.ts index 3560050abc..579d9c3e27 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/src/mediaTypes.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/src/mediaTypes.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { MediaTypesClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface MediaTypesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MediaTypesClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: MediaTypesClientOptions = {}, ): MediaTypesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MediaTypesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/src/multipleInheritanceRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/src/multipleInheritanceRestClient.ts index 3c9c118b84..1a86c5716e 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/src/multipleInheritanceRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/src/multipleInheritanceRestClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { MultipleInheritanceRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface MultipleInheritanceRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MultipleInheritanceRestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: MultipleInheritanceRestClientOptions = {}, ): MultipleInheritanceRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleUrlParameters/src/multipleUrlParameterRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleUrlParameters/src/multipleUrlParameterRestClient.ts index 7fed537b3c..3eea867a0f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/multipleUrlParameters/src/multipleUrlParameterRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleUrlParameters/src/multipleUrlParameterRestClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger"; import { TokenCredential } from "@azure/core-auth"; import { MultipleUrlParameterRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface MultipleUrlParameterRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MultipleUrlParameterRestClient` * @param endpoint - The catalog endpoint of your Purview account. Example: https://{accountName}.purview.azure.com @@ -17,13 +20,12 @@ export default function createClient( endpoint: string, serviceVersion: "v2" | "v1", credentials: TokenCredential, - options: ClientOptions = {}, + options: MultipleUrlParameterRestClientOptions = {}, ): MultipleUrlParameterRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}/catalog/api/atlas/${serviceVersion}/{accountName}`; - const userAgentInfo = `azsdk-js-multiple-url-parameter-rest/1.0.0-preview1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -41,7 +43,6 @@ export default function createClient( scopes: options.credentials?.scopes ?? ["user_impersonation"], }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/pagingRest/src/paging.ts b/packages/autorest.typescript/test/rlcIntegration/generated/pagingRest/src/paging.ts index 374dfc29ed..56ef8bea8f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/pagingRest/src/paging.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/pagingRest/src/paging.ts @@ -5,13 +5,20 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { PagingClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface PagingClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `PagingClient` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): PagingClient { +export default function createClient({ + apiVersion = "1.0.0", + ...options +}: PagingClientOptions = {}): PagingClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-paging-service-rest/1.0.0-preview1`; @@ -28,15 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as PagingClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + return next(req); + }, + }); return client; } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/securityAADRest/src/securityAADRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/securityAADRest/src/securityAADRestClient.ts index ff1499fcfe..84773514ba 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/securityAADRest/src/securityAADRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/securityAADRest/src/securityAADRestClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger"; import { TokenCredential } from "@azure/core-auth"; import { SecurityAADRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface SecurityAADRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SecurityAADRestClient` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { SecurityAADRestClient } from "./clientDefinitions"; */ export default function createClient( credentials: TokenCredential, - options: ClientOptions = {}, + options: SecurityAADRestClientOptions = {}, ): SecurityAADRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -36,7 +39,6 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/securityKeyRest/src/securityKeyRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/securityKeyRest/src/securityKeyRestClient.ts index 5c90259926..0ffa39eeee 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/securityKeyRest/src/securityKeyRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/securityKeyRest/src/securityKeyRestClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger"; import { KeyCredential } from "@azure/core-auth"; import { SecurityKeyRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface SecurityKeyRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SecurityKeyRestClient` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { SecurityKeyRestClient } from "./clientDefinitions"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: SecurityKeyRestClientOptions = {}, ): SecurityKeyRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -34,7 +37,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "security-key", }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/urlRest/src/urlRestClient.ts b/packages/autorest.typescript/test/rlcIntegration/generated/urlRest/src/urlRestClient.ts index 50ebb102de..44b98cebe5 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/urlRest/src/urlRestClient.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/urlRest/src/urlRestClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { UrlRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface UrlRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UrlRestClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UrlRestClientOptions = {}, ): UrlRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UrlRestClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/review/agrifood-data-plane.api.md b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/review/agrifood-data-plane.api.md index f8e414032e..bda8af90c2 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/review/agrifood-data-plane.api.md +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/review/agrifood-data-plane.api.md @@ -478,6 +478,11 @@ export type AzureAgriFoodPlatformDataPlaneServiceClient = Client & { path: Routes; }; +// @public +export interface AzureAgriFoodPlatformDataPlaneServiceClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface BoundariesCreateCascadeDeleteJob202Response extends HttpResponse { // (undocumented) @@ -876,7 +881,7 @@ export interface CascadeDeleteJobOutput { } // @public -function createClient(endpoint: string, credentials: KeyCredential, options?: ClientOptions): AzureAgriFoodPlatformDataPlaneServiceClient; +function createClient(endpoint: string, credentials: KeyCredential, { apiVersion, ...options }?: AzureAgriFoodPlatformDataPlaneServiceClientOptions): AzureAgriFoodPlatformDataPlaneServiceClient; export default createClient; // @public diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/src/azureAgriFoodPlatformDataPlaneService.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/src/azureAgriFoodPlatformDataPlaneService.ts index 829925cd5d..e8c6cae610 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/src/azureAgriFoodPlatformDataPlaneService.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/src/azureAgriFoodPlatformDataPlaneService.ts @@ -6,6 +6,13 @@ import { logger } from "./logger"; import { KeyCredential } from "@azure/core-auth"; import { AzureAgriFoodPlatformDataPlaneServiceClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface AzureAgriFoodPlatformDataPlaneServiceClientOptions + extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureAgriFoodPlatformDataPlaneServiceClient` * @param endpoint - The endpoint of your FarmBeats resource (protocol and hostname, for example: https://{resourceName}.farmbeats.azure.net). @@ -15,10 +22,12 @@ import { AzureAgriFoodPlatformDataPlaneServiceClient } from "./clientDefinitions export default function createClient( endpoint: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2021-03-31-preview", + ...options + }: AzureAgriFoodPlatformDataPlaneServiceClientOptions = {}, ): AzureAgriFoodPlatformDataPlaneServiceClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`; - const userAgentInfo = `azsdk-js-agrifood-data-plane-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -37,7 +46,6 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Authorization", }, }; - const client = getClient( endpointUrl, credentials, @@ -45,11 +53,21 @@ export default function createClient( ) as AzureAgriFoodPlatformDataPlaneServiceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/review/anomaly-detector-mv-rest.api.md b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/review/anomaly-detector-mv-rest.api.md index 337a14c4c2..3d97279e5c 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/review/anomaly-detector-mv-rest.api.md +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/review/anomaly-detector-mv-rest.api.md @@ -33,9 +33,8 @@ export type AnomalyDetectorMVClient = Client & { path: Routes; }; -// @public (undocumented) +// @public export interface AnomalyDetectorMVClientOptions extends ClientOptions { - // (undocumented) apiVersion?: "v1.1"; } @@ -123,7 +122,7 @@ export interface CreateAndTrainMultivariateModelMediaTypesParam { export type CreateAndTrainMultivariateModelParameters = CreateAndTrainMultivariateModelMediaTypesParam & CreateAndTrainMultivariateModelBodyParam & RequestParameters; // @public -function createClient(endpoint: string, credentials: KeyCredential, options?: AnomalyDetectorMVClientOptions): AnomalyDetectorMVClient; +function createClient(endpoint: string, credentials: KeyCredential, { apiVersion, ...options }?: AnomalyDetectorMVClientOptions): AnomalyDetectorMVClient; export default createClient; // @public (undocumented) diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/src/anomalyDetectorMV.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/src/anomalyDetectorMV.ts index e8965d140a..ae836e0894 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/src/anomalyDetectorMV.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-mv-rest/src/anomalyDetectorMV.ts @@ -6,7 +6,9 @@ import { logger } from "./logger"; import { KeyCredential } from "@azure/core-auth"; import { AnomalyDetectorMVClient } from "./clientDefinitions"; +/** The optional parameters for the client */ export interface AnomalyDetectorMVClientOptions extends ClientOptions { + /** Api Version */ apiVersion?: "v1.1"; } @@ -19,14 +21,12 @@ export interface AnomalyDetectorMVClientOptions extends ClientOptions { export default function createClient( endpoint: string, credentials: KeyCredential, - options: AnomalyDetectorMVClientOptions = {}, + { apiVersion = "v1.1", ...options }: AnomalyDetectorMVClientOptions = {}, ): AnomalyDetectorMVClient { - const apiVersion = options.apiVersion ?? "v1.1"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}/anomalydetector/${apiVersion}`; - const userAgentInfo = `azsdk-js-anomaly-detector-mv-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -45,7 +45,6 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, @@ -53,11 +52,6 @@ export default function createClient( ) as AnomalyDetectorMVClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/review/anomaly-detector-rest.api.md b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/review/anomaly-detector-rest.api.md index a52afd13f1..afdf6a0751 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/review/anomaly-detector-rest.api.md +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/review/anomaly-detector-rest.api.md @@ -43,6 +43,10 @@ export type AnomalyDetectorRestClient = Client & { path: Routes; }; +// @public +export interface AnomalyDetectorRestClientOptions extends ClientOptions { +} + // @public (undocumented) export interface AnomalyInterpretationOutput { contributionScore?: number; @@ -144,7 +148,7 @@ export interface CorrelationChangesOutput { } // @public -function createClient(endpoint: string, apiVersion: string, credentials: KeyCredential, options?: ClientOptions): AnomalyDetectorRestClient; +function createClient(endpoint: string, apiVersion: string, credentials: KeyCredential, options?: AnomalyDetectorRestClientOptions): AnomalyDetectorRestClient; export default createClient; // @public (undocumented) diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/src/anomalyDetectorRest.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/src/anomalyDetectorRest.ts index b5e251bded..565925195a 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/src/anomalyDetectorRest.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/src/anomalyDetectorRest.ts @@ -6,6 +6,9 @@ import { logger } from "./logger"; import { KeyCredential } from "@azure/core-auth"; import { AnomalyDetectorRestClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface AnomalyDetectorRestClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AnomalyDetectorRestClient` * @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com). @@ -17,13 +20,12 @@ export default function createClient( endpoint: string, apiVersion: string, credentials: KeyCredential, - options: ClientOptions = {}, + options: AnomalyDetectorRestClientOptions = {}, ): AnomalyDetectorRestClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}/anomalydetector/${apiVersion}`; - const userAgentInfo = `azsdk-js-anomaly-detector-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -42,7 +44,6 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, @@ -52,7 +53,7 @@ export default function createClient( client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); if (options.apiVersion) { logger.warning( - "This client does not support client api-version, please change it at the operation level", + "This client does not support to set api-version in options, please change it at positional argument", ); } diff --git a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/review/purview-administration-rest.api.md b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/review/purview-administration-rest.api.md index 5767e18e35..69a6597507 100644 --- a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/review/purview-administration-rest.api.md +++ b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/review/purview-administration-rest.api.md @@ -558,10 +558,10 @@ interface ComplexReplacerConfigOutput { } // @public -function createClient(endpoint: string, credentials: KeyCredential, options?: ClientOptions): PurviewMetadataPoliciesClient; +function createClient(endpoint: string, credentials: KeyCredential, { apiVersion, ...options }?: PurviewMetadataPoliciesClientOptions): PurviewMetadataPoliciesClient; // @public -function createClient_2(endpoint: string, credentials: TokenCredential, options?: ClientOptions): PurviewAccountClient; +function createClient_2(endpoint: string, credentials: TokenCredential, { apiVersion, ...options }?: PurviewAccountClientOptions): PurviewAccountClient; // @public interface DataPlaneAccountUpdateParameters { @@ -1312,6 +1312,7 @@ interface PrivateLinkServiceConnectionStateOutput { declare namespace PurviewAccount { export { createClient_2 as createClient, + PurviewAccountClientOptions, Parameters_3 as Parameters, Responses_2 as Responses, Client_3 as Client, @@ -1328,9 +1329,15 @@ type PurviewAccountClient = Client & { path: Routes_2; }; +// @public +interface PurviewAccountClientOptions extends ClientOptions { + apiVersion?: string; +} + declare namespace PurviewMetadataPolicies { export { createClient, + PurviewMetadataPoliciesClientOptions, Parameters_2 as Parameters, Responses, Client_2 as Client, @@ -1347,6 +1354,11 @@ type PurviewMetadataPoliciesClient = Client & { path: Routes; }; +// @public +interface PurviewMetadataPoliciesClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public (undocumented) interface RegexReplacer { // (undocumented) diff --git a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/index.ts b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/index.ts index e315b5ec2c..49748bd693 100644 --- a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/index.ts +++ b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/index.ts @@ -9,7 +9,7 @@ import * as OutputModels from "./outputModels"; import * as PaginateHelper from "./paginateHelper"; import * as UnexpectedHelper from "./isUnexpected"; -export { createClient } from "./purviewAccount"; +export { createClient, PurviewAccountClientOptions } from "./purviewAccount"; export { Parameters, Responses, diff --git a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/purviewAccount.ts b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/purviewAccount.ts index 6b054e46fa..32bcd702d2 100644 --- a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/purviewAccount.ts +++ b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/account/purviewAccount.ts @@ -6,6 +6,12 @@ import { logger } from "../logger"; import { TokenCredential } from "@azure/core-auth"; import { PurviewAccountClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface PurviewAccountClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `PurviewAccountClient` * @param endpoint - The account endpoint of your Purview account. Example: https://{accountName}.purview.azure.com/account/ @@ -15,10 +21,12 @@ import { PurviewAccountClient } from "./clientDefinitions"; export function createClient( endpoint: string, credentials: TokenCredential, - options: ClientOptions = {}, + { + apiVersion = "2019-11-01-preview", + ...options + }: PurviewAccountClientOptions = {}, ): PurviewAccountClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`; - const userAgentInfo = `azsdk-js-purview-administration-rest/1.0.0-beta.2`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,7 +46,6 @@ export function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, @@ -46,11 +53,21 @@ export function createClient( ) as PurviewAccountClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/index.ts b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/index.ts index e48f7b95cb..2d351a33cf 100644 --- a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/index.ts +++ b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/index.ts @@ -9,7 +9,10 @@ import * as OutputModels from "./outputModels"; import * as PaginateHelper from "./paginateHelper"; import * as UnexpectedHelper from "./isUnexpected"; -export { createClient } from "./purviewMetadataPolicies"; +export { + createClient, + PurviewMetadataPoliciesClientOptions, +} from "./purviewMetadataPolicies"; export { Parameters, Responses, diff --git a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/purviewMetadataPolicies.ts b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/purviewMetadataPolicies.ts index a47ab506eb..fad9e9131f 100644 --- a/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/purviewMetadataPolicies.ts +++ b/packages/autorest.typescript/test/smoke/generated/purview-administration-rest/src/metadataPolicies/purviewMetadataPolicies.ts @@ -6,6 +6,12 @@ import { logger } from "../logger"; import { KeyCredential } from "@azure/core-auth"; import { PurviewMetadataPoliciesClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface PurviewMetadataPoliciesClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `PurviewMetadataPoliciesClient` * @param endpoint - The endpoint of your Purview account. Example: https://{accountName}.purview.azure.com. @@ -15,11 +21,13 @@ import { PurviewMetadataPoliciesClient } from "./clientDefinitions"; export function createClient( endpoint: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2021-07-01-preview", + ...options + }: PurviewMetadataPoliciesClientOptions = {}, ): PurviewMetadataPoliciesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}/policyStore`; - const userAgentInfo = `azsdk-js-purview-administration-rest/1.0.0-beta.2`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -37,7 +45,6 @@ export function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "CustomAuth", }, }; - const client = getClient( endpointUrl, credentials, @@ -45,11 +52,21 @@ export function createClient( ) as PurviewMetadataPoliciesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/autorest.typescript/test/smoke/generated/synapse-artifacts-rest/src/synapseArtifacts.ts b/packages/autorest.typescript/test/smoke/generated/synapse-artifacts-rest/src/synapseArtifacts.ts index 562202e1bd..4e7dcb8838 100644 --- a/packages/autorest.typescript/test/smoke/generated/synapse-artifacts-rest/src/synapseArtifacts.ts +++ b/packages/autorest.typescript/test/smoke/generated/synapse-artifacts-rest/src/synapseArtifacts.ts @@ -6,6 +6,12 @@ import { logger } from "./logger"; import { TokenCredential } from "@azure/core-auth"; import { SynapseArtifactsClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface SynapseArtifactsClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `SynapseArtifactsClient` * @param endpoint - The workspace development endpoint, for example https://myworkspace.dev.azuresynapse.net. @@ -15,10 +21,12 @@ import { SynapseArtifactsClient } from "./clientDefinitions"; export default function createClient( endpoint: string, credentials: TokenCredential, - options: ClientOptions = {}, + { + apiVersion = "2021-11-01-preview", + ...options + }: SynapseArtifactsClientOptions = {}, ): SynapseArtifactsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`; - const userAgentInfo = `azsdk-js-synapse-artifacts-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,7 +46,6 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, @@ -46,11 +53,21 @@ export default function createClient( ) as SynapseArtifactsClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return { ...client, diff --git a/packages/autorest.typescript/test/version-tolerance/generated/rlc-initial/src/dPGClient.ts b/packages/autorest.typescript/test/version-tolerance/generated/rlc-initial/src/dPGClient.ts index 11ace438d0..225e38e135 100644 --- a/packages/autorest.typescript/test/version-tolerance/generated/rlc-initial/src/dPGClient.ts +++ b/packages/autorest.typescript/test/version-tolerance/generated/rlc-initial/src/dPGClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { DPGClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface DPGClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DPGClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): DPGClient { +export default function createClient( + options: DPGClientOptions = {}, +): DPGClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-rlcClient-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): DPGClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DPGClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/autorest.typescript/test/version-tolerance/generated/rlc-updated/src/dPGClient.ts b/packages/autorest.typescript/test/version-tolerance/generated/rlc-updated/src/dPGClient.ts index 9052ebef60..04d9357cab 100644 --- a/packages/autorest.typescript/test/version-tolerance/generated/rlc-updated/src/dPGClient.ts +++ b/packages/autorest.typescript/test/version-tolerance/generated/rlc-updated/src/dPGClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { DPGClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface DPGClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DPGClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): DPGClient { +export default function createClient( + options: DPGClientOptions = {}, +): DPGClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-rlcClient-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): DPGClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DPGClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/rlc-common/src/buildClient.ts b/packages/rlc-common/src/buildClient.ts index 3719f1e954..0cf5b2249f 100644 --- a/packages/rlc-common/src/buildClient.ts +++ b/packages/rlc-common/src/buildClient.ts @@ -22,26 +22,47 @@ import { import { getImportSpecifier } from "./helpers/importsUtil.js"; function getClientOptionsInterface( + model: RLCModel, clientName: string, optionalUrlParameters?: PathParameter[] ): OptionalKind | undefined { - if (!optionalUrlParameters || optionalUrlParameters.length === 0) { + if ( + (!optionalUrlParameters || optionalUrlParameters.length === 0) && + !model.apiVersionInfo + ) { return undefined; } - const properties = optionalUrlParameters.map((param) => { - return { - name: param.name, - type: param.type, - hasQuestionToken: true - }; - }); + const properties = + optionalUrlParameters?.map((param) => { + return { + name: param.name, + type: param.type, + hasQuestionToken: true, + docs: [ + param.description ?? "client level optional parameter " + param.name + ] + }; + }) ?? []; + if ( + model.apiVersionInfo?.isCrossedVersion === false && + !model.urlInfo?.urlParameters?.find((p) => p.name === "apiVersion") && + (model.apiVersionInfo.defaultValue || !model.apiVersionInfo?.required) + ) { + properties.push({ + name: "apiVersion", + type: "string", + hasQuestionToken: true, + docs: ["The api version option of the client"] + }); + } return { name: `${clientName}Options`, extends: ["ClientOptions"], isExported: true, - properties + properties, + docs: ["The optional parameters for the client"] }; } @@ -69,6 +90,7 @@ export function buildClient(model: RLCModel): File | undefined { ); const clientOptionsInterface = getClientOptionsInterface( + model, clientInterfaceName, optionalUrlParameters ); @@ -113,10 +135,30 @@ export function buildClient(model: RLCModel): File | undefined { ]) ]; + let apiVersionStatement: string = ""; + // Set the default api-version when we have a default AND its position is query + if ( + model.apiVersionInfo?.isCrossedVersion === false && + !!model.apiVersionInfo?.defaultValue + ) { + apiVersionStatement = ` + apiVersion = "${model.apiVersionInfo?.defaultValue}"`; + } else if ( + model.apiVersionInfo?.isCrossedVersion === false && + !model.apiVersionInfo.required + ) { + apiVersionStatement = ` + apiVersion`; + } + const allClientParams = [ ...commonClientParams, { - name: "options", + name: + apiVersionStatement === "" + ? "options" + : `{${apiVersionStatement}, ...options}`, + documentName: "options", type: `${clientOptionsInterface?.name ?? "ClientOptions"} = {}`, description: "the parameter for all optional parameters" } @@ -128,10 +170,10 @@ export function buildClient(model: RLCModel): File | undefined { docs: [ { description: - `Initialize a new instance of \`${clientInterfaceName}\` \n` + + `Initialize a new instance of \`${clientInterfaceName}\`\n` + allClientParams .map((param) => { - return `@param ${param.name} - ${ + return `@param ${param.documentName ?? param.name} - ${ param.description ?? "The parameter " + param.name }`; }) @@ -277,11 +319,14 @@ export function getClientFactoryBody( const optionalUrlParameters: string[] = []; for (const param of urlParameters ?? []) { + if (param.name === "apiVersion") { + continue; + } if (param.value) { const value = typeof param.value === "string" ? `"${param.value}"` : param.value; optionalUrlParameters.push( - `const ${param.name} = options.${param.name} ?? ${value}` + `const ${param.name} = options.${param.name} ?? ${value};` ); } } @@ -300,17 +345,6 @@ export function getClientFactoryBody( } else { endpointUrl = `options.endpoint ?? options.baseUrl ?? "${endpoint}"`; } - - let apiVersionStatement: string = ""; - // Set the default api-version when we have a default AND its position is query - if ( - model.apiVersionInfo?.definedPosition === "query" && - !!model.apiVersionInfo?.defaultValue - ) { - apiVersionStatement = `options.apiVersion = options.apiVersion ?? "${model.apiVersionInfo?.defaultValue}"`; - } else if (model.apiVersionInfo?.definedPosition === "query") { - apiVersionStatement = `options.apiVersion = options.apiVersion ?? apiVersion`; - } if (!clientPackageName.endsWith("-rest")) { clientPackageName = clientPackageName + "-rest"; } @@ -376,8 +410,7 @@ export function getClientFactoryBody( userAgentOptions: { userAgentPrefix }${loggerOptions}${customHeaderOptions}${credentialsOptions} - }`; - + };`; const getClient = `const client = getClient( endpointUrl, ${credentialsOptions ? "credentials," : ""} options ) as ${clientTypeName}; @@ -408,15 +441,42 @@ export function getClientFactoryBody( } } - let apiVersionPolicyStatement = ""; - if (model.apiVersionInfo?.definedPosition !== "query") { - apiVersionPolicyStatement = `client.pipeline.removePolicy({name: 'ApiVersionPolicy'});`; - if (flavor === "azure") { - apiVersionPolicyStatement += ` + let apiVersionPolicyStatement = `client.pipeline.removePolicy({ name: "ApiVersionPolicy" });`; + if (flavor === "azure" && model.apiVersionInfo?.isCrossedVersion !== false) { + apiVersionPolicyStatement += ` if (options.apiVersion) { logger.warning("This client does not support client api-version, please change it at the operation level"); }`; - } + } else if ( + flavor === "azure" && + !model.apiVersionInfo?.defaultValue && + model.apiVersionInfo?.required + ) { + apiVersionPolicyStatement += ` + if (options.apiVersion) { + logger.warning("This client does not support to set api-version in options, please change it at positional argument"); + }`; + } + if ( + model.apiVersionInfo?.isCrossedVersion === false && + model.apiVersionInfo?.definedPosition === "query" + ) { + apiVersionPolicyStatement += ` + client.pipeline.addPolicy({ + name: 'ClientApiVersionPolicy', + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = \`\${req.url}\${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=\${apiVersion}\`; + } + + return next(req); + }, + });`; } let returnStatement = `return client;`; @@ -438,7 +498,6 @@ export function getClientFactoryBody( return [ ...optionalUrlParameters, endpointUrlStatement, - apiVersionStatement, userAgentInfoStatement, userAgentStatement, overrideOptionsStatement, diff --git a/packages/rlc-common/src/buildIndexFile.ts b/packages/rlc-common/src/buildIndexFile.ts index ecda36757b..0e773cba36 100644 --- a/packages/rlc-common/src/buildIndexFile.ts +++ b/packages/rlc-common/src/buildIndexFile.ts @@ -174,7 +174,7 @@ function generateRLCIndexForMultiClient(file: SourceFile, model: RLCModel) { }, model ), - namedExports: [`${createClientFuncName}`] + namedExports: [`${createClientFuncName}`, `${clientName}ClientOptions`] }, { namedExports: [...exports] diff --git a/packages/rlc-common/src/helpers/apiVersionUtil.ts b/packages/rlc-common/src/helpers/apiVersionUtil.ts index ac831c63a4..8171c14a16 100644 --- a/packages/rlc-common/src/helpers/apiVersionUtil.ts +++ b/packages/rlc-common/src/helpers/apiVersionUtil.ts @@ -23,7 +23,8 @@ export function extractPathApiVersion( definedPosition: "path", isCrossedVersion: Boolean(param?.length > 1), defaultValue: - param.length === 1 ? (param[0].value as string | undefined) : undefined + param.length === 1 ? (param[0].value as string | undefined) : undefined, + required: true }; return detail; } diff --git a/packages/rlc-common/src/helpers/nameUtils.ts b/packages/rlc-common/src/helpers/nameUtils.ts index 57ecb6b17a..66d94e5e63 100644 --- a/packages/rlc-common/src/helpers/nameUtils.ts +++ b/packages/rlc-common/src/helpers/nameUtils.ts @@ -89,7 +89,8 @@ export const ReservedModelNames: ReservedName[] = [ { name: "arguments", reservedFor: [NameType.Parameter] }, // reserve client for codegen { name: "client", reservedFor: [NameType.Parameter] }, - { name: "endpoint", reservedFor: [NameType.Parameter] } + { name: "endpoint", reservedFor: [NameType.Parameter] }, + { name: "apiVersion", reservedFor: [NameType.Parameter] } ]; export enum CasingConvention { diff --git a/packages/rlc-common/src/interfaces.ts b/packages/rlc-common/src/interfaces.ts index 80cccaae75..98b82502ae 100644 --- a/packages/rlc-common/src/interfaces.ts +++ b/packages/rlc-common/src/interfaces.ts @@ -109,6 +109,7 @@ export interface ApiVersionInfo { definedPosition?: ApiVersionPosition; defaultValue?: string; isCrossedVersion?: boolean; + required?: boolean; } export type ApiVersionPosition = @@ -168,6 +169,7 @@ export type Paths = Record; export type PathParameter = { oriName?: string; name: string; + documentName?: string; type: string; description?: string; value?: string | number | boolean; diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/review/arm-networkanalytics.api.md b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/review/arm-networkanalytics.api.md index bee08ce45c..ca96399964 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/review/arm-networkanalytics.api.md +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/review/arm-networkanalytics.api.md @@ -656,7 +656,7 @@ export interface UserAssignedIdentity { principalId?: string; } -// @public (undocumented) +// @public export type Versions = "2023-11-15"; // @public diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/models/models.ts index 507241b014..918a3ad71d 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/models/models.ts @@ -30,7 +30,6 @@ export interface SystemData { } /** The kind of entity that created the resource. */ -/** "User", "Application", "ManagedIdentity", "Key" */ export type CreatedByType = string; export enum KnownCreatedByType { @@ -101,7 +100,6 @@ export interface DataProductProperties { } /** The status of the current operation. */ -/** "Succeeded", "Failed", "Canceled", "Provisioning", "Updating", "Deleting", "Accepted" */ export type ProvisioningState = string; export enum KnownProvisioningState { @@ -115,7 +113,6 @@ export enum KnownProvisioningState { } /** The data type state */ -/** "Enabled", "Disabled" */ export type ControlState = string; export enum KnownControlState { @@ -164,7 +161,6 @@ export interface IPRules { } /** Specifies the default action of allow or deny when no other rules match. */ -/** "Allow", "Deny" */ export type DefaultAction = string; export enum KnownDefaultAction { @@ -209,7 +205,6 @@ export interface ManagedServiceIdentity { } /** The kind of managed identity assigned to this resource. */ -/** "None", "SystemAssigned", "UserAssigned", "SystemAssigned, UserAssigned" */ export type ManagedServiceIdentityType = string; export enum KnownManagedServiceIdentityType { @@ -299,7 +294,6 @@ export interface ArmOperationStatus { } /** The provisioning state of a resource type. */ -/** "Succeeded", "Failed", "Canceled" */ export type ResourceProvisioningState = string; export enum KnownResourceProvisioningState { @@ -347,7 +341,6 @@ export interface RoleAssignmentCommonProperties { } /** The data type state */ -/** "Reader", "SensitiveReader" */ export type DataProductUserRole = string; export enum KnownDataProductUserRole { @@ -417,7 +410,6 @@ export interface DataTypeProperties { } /** The data type state */ -/** "Stopped", "Running" */ export type DataTypeState = string; export enum KnownDataTypeState { @@ -547,7 +539,6 @@ export interface OperationDisplay { } /** The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" */ -/** "user", "system", "user,system" */ export type Origin = string; export enum KnownOrigin { @@ -557,7 +548,6 @@ export enum KnownOrigin { } /** Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. */ -/** "Internal" */ export type ActionType = string; export enum KnownActionType { @@ -565,5 +555,4 @@ export enum KnownActionType { } /** The available API versions for the Microsoft.NetworkAnalytics RP. */ -/** */ export type Versions = "2023-11-15"; diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/rest/networkAnalyticsClient.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/rest/networkAnalyticsClient.ts index 18f17548d5..51f673ab7e 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/rest/networkAnalyticsClient.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/rest/networkAnalyticsClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { NetworkAnalyticsContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NetworkAnalyticsContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `NetworkAnalyticsContext` * @param credentials - uniquely identify client credential @@ -13,11 +19,13 @@ import { NetworkAnalyticsContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: TokenCredential, - options: ClientOptions = {}, + { + apiVersion = "2023-11-15", + ...options + }: NetworkAnalyticsContextOptions = {}, ): NetworkAnalyticsContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; - options.apiVersion = options.apiVersion ?? "2023-11-15"; const userAgentInfo = `azsdk-js-arm-networkanalytics-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -35,12 +43,27 @@ export default function createClient( scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`], }, }; - const client = getClient( endpointUrl, credentials, options, ) as NetworkAnalyticsContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/review/ai-anomaly-detector.api.md b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/review/ai-anomaly-detector.api.md index 90a9933bbb..0eaa7919e8 100644 --- a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/review/ai-anomaly-detector.api.md +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/review/ai-anomaly-detector.api.md @@ -33,10 +33,10 @@ export type ContinuablePage = TPage & { continuationToken?: string; }; -// @public (undocumented) +// @public export type DataSchema = "OneTable" | "MultiTable"; -// @public (undocumented) +// @public export type FillNAMethod = "Previous" | "Subsequent" | "Linear" | "Zero" | "Fixed"; // @public (undocumented) diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/models/models.ts index aee9e3b90a..e228f3f85a 100644 --- a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/models/models.ts @@ -26,7 +26,6 @@ export interface MultivariateMultivariateBatchDetectionResultSummary { setupInfo: MultivariateMultivariateBatchDetectionOptions; } -/** */ export type MultivariateBatchDetectionStatus = | "CREATED" | "RUNNING" @@ -179,7 +178,6 @@ export interface MultivariateModelInfo { } /** Data schema of input data source: OneTable or MultiTable. The default DataSchema is OneTable. */ -/** */ export type DataSchema = "OneTable" | "MultiTable"; /** An optional field, indicating the manner to align multiple variables. */ @@ -198,17 +196,14 @@ export interface MultivariateAlignPolicy { paddingValue?: number; } -/** */ export type AlignMode = "Inner" | "Outer"; /** An optional field, indicating how missing values will be filled. One of Previous, Subsequent, Linear, Zero, Fixed. */ -/** */ export type FillNAMethod = | "Previous" | "Subsequent" | "Linear" | "Zero" | "Fixed"; -/** */ export type ModelStatus = "CREATED" | "RUNNING" | "READY" | "FAILED"; /** Diagnostics information to help inspect the states of model or variable. */ @@ -355,7 +350,6 @@ export interface UnivariateTimeSeriesPoint { value: number; } -/** */ export type TimeGranularity = | "yearly" | "monthly" @@ -366,7 +360,6 @@ export type TimeGranularity = | "secondly" | "microsecond" | "none"; -/** */ export type ImputeMode = | "auto" | "previous" @@ -439,7 +432,6 @@ export interface UnivariateAnomalyDetectorError { message?: string; } -/** */ export type AnomalyDetectorErrorCodes = | "InvalidCustomInterval" | "BadArgument" @@ -553,5 +545,4 @@ export interface UnivariateUnivariateChangePointDetectionResult { confidenceScores?: number[]; } -/** */ export type Versions = "v1.1"; diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/rest/anomalyDetectorClient.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/rest/anomalyDetectorClient.ts index 395dca27bb..152618a043 100644 --- a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/rest/anomalyDetectorClient.ts +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/src/rest/anomalyDetectorClient.ts @@ -6,7 +6,9 @@ import { logger } from "../logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AnomalyDetectorContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ export interface AnomalyDetectorContextOptions extends ClientOptions { + /** Api Version */ apiVersion?: string; } @@ -20,14 +22,12 @@ export interface AnomalyDetectorContextOptions extends ClientOptions { export default function createClient( endpointParam: string, credentials: KeyCredential, - options: AnomalyDetectorContextOptions = {}, + { apiVersion = "v1.1", ...options }: AnomalyDetectorContextOptions = {}, ): AnomalyDetectorContext { - const apiVersion = options.apiVersion ?? "v1.1"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/anomalydetector/${apiVersion}`; - const userAgentInfo = `azsdk-js-ai-anomaly-detector-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -46,7 +46,6 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, @@ -54,11 +53,6 @@ export default function createClient( ) as AnomalyDetectorContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/review/authoring.api.md b/packages/typespec-test/test/authoring/generated/typespec-ts/review/authoring.api.md index 0bbc0cd23c..6098404b0a 100644 --- a/packages/typespec-test/test/authoring/generated/typespec-ts/review/authoring.api.md +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/review/authoring.api.md @@ -27,7 +27,12 @@ export type AuthoringClient = Client & { }; // @public -function createClient(endpointParam: string, credentials: KeyCredential, options?: ClientOptions): AuthoringClient; +export interface AuthoringClientOptions extends ClientOptions { + apiVersion?: string; +} + +// @public +function createClient(endpointParam: string, credentials: KeyCredential, { apiVersion, ...options }?: AuthoringClientOptions): AuthoringClient; export default createClient; // @public (undocumented) diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/src/authoringClient.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/src/authoringClient.ts index 5d3f80e061..98894eae89 100644 --- a/packages/typespec-test/test/authoring/generated/typespec-ts/src/authoringClient.ts +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/src/authoringClient.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AuthoringClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthoringClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AuthoringClient` * @param endpointParam - The endpoint to use. @@ -15,11 +21,13 @@ import { AuthoringClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2022-05-15-preview", + ...options + }: AuthoringClientOptions = {}, ): AuthoringClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/language`; - options.apiVersion = options.apiVersion ?? "2022-05-15-preview"; const userAgentInfo = `azsdk-js-authoring-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,12 +46,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as AuthoringClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/batch_modular/generated/typespec-ts/review/batch.api.md b/packages/typespec-test/test/batch_modular/generated/typespec-ts/review/batch.api.md index b579922d03..7e59552553 100644 --- a/packages/typespec-test/test/batch_modular/generated/typespec-ts/review/batch.api.md +++ b/packages/typespec-test/test/batch_modular/generated/typespec-ts/review/batch.api.md @@ -9,7 +9,7 @@ import { OperationOptions } from '@azure-rest/core-client'; import { Pipeline } from '@azure/core-rest-pipeline'; import { TokenCredential } from '@azure/core-auth'; -// @public (undocumented) +// @public export type AccessScope = "job"; // @public @@ -23,7 +23,7 @@ export interface AffinityInformation { affinityId: string; } -// @public (undocumented) +// @public export type AllocationState = "steady" | "resizing" | "stopping"; // @public @@ -65,7 +65,7 @@ export interface AutoScaleRunError { values?: NameValuePair[]; } -// @public (undocumented) +// @public export type AutoUserScope = "task" | "pool"; // @public @@ -367,7 +367,7 @@ export interface BatchNode { vmSize?: string; } -// @public (undocumented) +// @public export type BatchNodeDeallocationOption = "requeue" | "terminate" | "taskcompletion" | "retaineddata"; // @public @@ -382,7 +382,7 @@ export interface BatchNodeError { message?: string; } -// @public (undocumented) +// @public export type BatchNodeFillType = "spread" | "pack"; // @public @@ -406,10 +406,10 @@ export interface BatchNodeListResult { value?: BatchNode[]; } -// @public (undocumented) +// @public export type BatchNodeRebootOption = "requeue" | "terminate" | "taskcompletion" | "retaineddata"; -// @public (undocumented) +// @public export type BatchNodeReimageOption = "requeue" | "terminate" | "taskcompletion" | "retaineddata"; // @public @@ -418,7 +418,7 @@ export interface BatchNodeRemoteLoginSettingsResult { remoteLoginPort: number; } -// @public (undocumented) +// @public export type BatchNodeState = "idle" | "rebooting" | "reimaging" | "running" | "unusable" | "creating" | "starting" | "waitingforstarttask" | "starttaskfailed" | "unknown" | "leavingpool" | "offline" | "preempted"; // @public @@ -622,7 +622,7 @@ export interface BatchTaskListSubtasksResult { value?: SubtaskInformation[]; } -// @public (undocumented) +// @public export type CachingType = "none" | "readonly" | "readwrite"; // @public (undocumented) @@ -631,7 +631,7 @@ export interface CancelCertificateDeletionOptionalParams extends OperationOption timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type CertificateFormat = "pfx" | "cer"; // @public @@ -649,13 +649,13 @@ export interface CertificateReference { visibility?: CertificateVisibility[]; } -// @public (undocumented) +// @public export type CertificateState = "active" | "deleting" | "deletefailed"; -// @public (undocumented) +// @public export type CertificateStoreLocation = "currentuser" | "localmachine"; -// @public (undocumented) +// @public export type CertificateVisibility = "starttask" | "task" | "remoteuser"; // @public @@ -688,10 +688,10 @@ export interface ContainerRegistry { username?: string; } -// @public (undocumented) +// @public export type ContainerType = "dockerCompatible" | "criCompatible"; -// @public (undocumented) +// @public export type ContainerWorkingDirectory = "taskWorkingDirectory" | "containerImageDefault"; // @public @@ -829,10 +829,10 @@ export interface DeleteTaskOptionalParams extends OperationOptions { timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type DependencyAction = "satisfy" | "block"; -// @public (undocumented) +// @public export type DiffDiskPlacement = "cachedisk"; // @public @@ -840,10 +840,10 @@ export interface DiffDiskSettings { placement?: DiffDiskPlacement; } -// @public (undocumented) +// @public export type DisableBatchNodeSchedulingOption = "requeue" | "terminate" | "taskcompletion"; -// @public (undocumented) +// @public export type DisableJobOption = "requeue" | "terminate" | "wait"; // @public (undocumented) @@ -885,13 +885,13 @@ export interface DiskEncryptionConfiguration { targets?: DiskEncryptionTarget[]; } -// @public (undocumented) +// @public export type DiskEncryptionTarget = "osdisk" | "temporarydisk"; -// @public (undocumented) +// @public export type DynamicVNetAssignmentScope = "none" | "job"; -// @public (undocumented) +// @public export type ElevationLevel = "nonadmin" | "admin"; // @public (undocumented) @@ -937,7 +937,7 @@ export interface EnvironmentSetting { value?: string; } -// @public (undocumented) +// @public export type ErrorCategory = "usererror" | "servererror"; // @public @@ -1153,7 +1153,7 @@ export interface InboundEndpoint { publicIpAddress?: string; } -// @public (undocumented) +// @public export type InboundEndpointProtocol = "tcp" | "udp"; // @public @@ -1175,10 +1175,10 @@ export interface InstanceViewStatus { time?: string; } -// @public (undocumented) +// @public export type IpAddressProvisioningType = "batchmanaged" | "usermanaged" | "nopublicipaddresses"; -// @public (undocumented) +// @public export type JobAction = "none" | "disable" | "terminate"; // @public @@ -1257,7 +1257,7 @@ export interface JobPreparationTaskExecutionInformation { taskRootDirectoryUrl?: string; } -// @public (undocumented) +// @public export type JobPreparationTaskState = "running" | "completed"; // @public @@ -1285,7 +1285,7 @@ export interface JobReleaseTaskExecutionInformation { taskRootDirectoryUrl?: string; } -// @public (undocumented) +// @public export type JobReleaseTaskState = "running" | "completed"; // @public @@ -1305,7 +1305,7 @@ export interface JobScheduleExistsOptionalParams extends OperationOptions { timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type JobScheduleState = "active" | "completed" | "disabled" | "terminating" | "deleting"; // @public @@ -1353,7 +1353,7 @@ export interface JobSpecification { usesTaskDependencies?: boolean; } -// @public (undocumented) +// @public export type JobState = "active" | "disabling" | "disabled" | "enabling" | "terminating" | "completed" | "deleting"; // @public @@ -1521,7 +1521,7 @@ export interface ListTasksOptionalParams extends OperationOptions { timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type LoginMode = "batch" | "interactive"; // @public @@ -1568,7 +1568,7 @@ export interface NetworkSecurityGroupRule { sourcePortRanges?: string[]; } -// @public (undocumented) +// @public export type NetworkSecurityGroupRuleAccess = "allow" | "deny"; // @public @@ -1584,7 +1584,7 @@ export interface NodeAgentInformation { version: string; } -// @public (undocumented) +// @public export type NodeCommunicationMode = "default" | "classic" | "simplified"; // @public @@ -1629,7 +1629,7 @@ export interface NodePlacementConfiguration { policy?: NodePlacementPolicyType; } -// @public (undocumented) +// @public export type NodePlacementPolicyType = "regional" | "zonal"; // @public @@ -1662,10 +1662,10 @@ export interface NodeVMExtensionList { value?: NodeVMExtension[]; } -// @public (undocumented) +// @public export type OnAllTasksComplete = "noaction" | "terminatejob"; -// @public (undocumented) +// @public export type OnTaskFailure = "noaction" | "performexitoptionsjobaction"; // @public @@ -1673,7 +1673,7 @@ export interface OSDisk { ephemeralOSDiskSettings?: DiffDiskSettings; } -// @public (undocumented) +// @public export type OSType = "linux" | "windows"; // @public @@ -1696,7 +1696,7 @@ export interface OutputFileDestination { container?: OutputFileBlobContainerDestination; } -// @public (undocumented) +// @public export type OutputFileUploadCondition = "tasksuccess" | "taskfailure" | "taskcompletion"; // @public @@ -1731,7 +1731,7 @@ export interface PoolExistsOptionalParams extends OperationOptions { timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type PoolIdentityType = "UserAssigned" | "None"; // @public @@ -1740,7 +1740,7 @@ export interface PoolInformation { poolId?: string; } -// @public (undocumented) +// @public export type PoolLifetimeOption = "jobschedule" | "job"; // @public @@ -1788,7 +1788,7 @@ export interface PoolSpecification { vmSize: string; } -// @public (undocumented) +// @public export type PoolState = "active" | "deleting"; // @public @@ -1957,7 +1957,7 @@ export interface Schedule { startWindow?: string; } -// @public (undocumented) +// @public export type SchedulingState = "enabled" | "disabled"; // @public @@ -1984,10 +1984,10 @@ export interface StartTaskInformation { state: StartTaskState; } -// @public (undocumented) +// @public export type StartTaskState = "running" | "completed"; -// @public (undocumented) +// @public export type StatusLevelTypes = "Error" | "Info" | "Warning"; // @public (undocumented) @@ -2000,7 +2000,7 @@ export interface StopPoolResizeOptionalParams extends OperationOptions { timeOutInSeconds?: number; } -// @public (undocumented) +// @public export type StorageAccountType = "standard_lrs" | "premium_lrs"; // @public @@ -2019,7 +2019,7 @@ export interface SubtaskInformation { stateTransitionTime?: Date; } -// @public (undocumented) +// @public export type SubtaskState = "preparing" | "running" | "completed"; // @public @@ -2037,7 +2037,7 @@ export interface TaskAddResult { taskId: string; } -// @public (undocumented) +// @public export type TaskAddStatus = "Success" | "clienterror" | "servererror"; // @public @@ -2097,7 +2097,7 @@ export interface TaskExecutionInformation { startTime?: Date; } -// @public (undocumented) +// @public export type TaskExecutionResult = "success" | "failure"; // @public @@ -2138,7 +2138,7 @@ export interface TaskSlotCounts { succeeded: number; } -// @public (undocumented) +// @public export type TaskState = "active" | "preparing" | "running" | "completed"; // @public @@ -2270,10 +2270,10 @@ export interface UserIdentity { username?: string; } -// @public (undocumented) +// @public export type VerificationType = "verified" | "unverified"; -// @public (undocumented) +// @public export type Versions = "2023-05-01.17.0"; // @public diff --git a/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/models/models.ts index afe9fa4ebb..bceb271738 100644 --- a/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/models/models.ts @@ -107,7 +107,6 @@ export interface BatchNode { } /** BatchNodeState enums */ -/** */ export type BatchNodeState = | "idle" | "rebooting" @@ -123,7 +122,6 @@ export type BatchNodeState = | "offline" | "preempted"; /** SchedulingState enums */ -/** */ export type SchedulingState = "enabled" | "disabled"; /** Information about a Task running on a Compute Node. */ @@ -143,7 +141,6 @@ export interface TaskInformation { } /** TaskState enums */ -/** */ export type TaskState = "active" | "preparing" | "running" | "completed"; /** Information about the execution of a Task. */ @@ -193,7 +190,6 @@ export interface TaskFailureInformation { } /** ErrorCategory enums */ -/** */ export type ErrorCategory = "usererror" | "servererror"; /** Represents a name-value pair. */ @@ -205,7 +201,6 @@ export interface NameValuePair { } /** TaskExecutionResult enums */ -/** */ export type TaskExecutionResult = "success" | "failure"; /** @@ -274,7 +269,6 @@ export interface BatchNodeIdentityReference { } /** ContainerWorkingDirectory enums */ -/** */ export type ContainerWorkingDirectory = | "taskWorkingDirectory" | "containerImageDefault"; @@ -322,10 +316,8 @@ export interface AutoUserSpecification { } /** AutoUserScope enums */ -/** */ export type AutoUserScope = "task" | "pool"; /** ElevationLevel enums */ -/** */ export type ElevationLevel = "nonadmin" | "admin"; /** Information about a StartTask running on a Compute Node. */ @@ -351,7 +343,6 @@ export interface StartTaskInformation { } /** StartTaskState enums */ -/** */ export type StartTaskState = "running" | "completed"; /** A reference to a Certificate to be installed on Compute Nodes in a Pool. Warning: This object is deprecated and will be removed after February, 2024. Please use the [Azure KeyVault Extension](https://learn.microsoft.com/azure/batch/batch-certificate-migration-guide) instead. */ @@ -369,10 +360,8 @@ export interface CertificateReference { } /** CertificateStoreLocation enums */ -/** */ export type CertificateStoreLocation = "currentuser" | "localmachine"; /** CertificateVisibility enums */ -/** */ export type CertificateVisibility = "starttask" | "task" | "remoteuser"; /** An error encountered by a Compute Node. */ @@ -408,7 +397,6 @@ export interface InboundEndpoint { } /** InboundEndpointProtocol enums */ -/** */ export type InboundEndpointProtocol = "tcp" | "udp"; /** @@ -455,7 +443,6 @@ export interface NodeRebootOptions { } /** BatchNodeRebootOption enums */ -/** */ export type BatchNodeRebootOption = | "requeue" | "terminate" @@ -469,7 +456,6 @@ export interface NodeReimageOptions { } /** BatchNodeReimageOption enums */ -/** */ export type BatchNodeReimageOption = | "requeue" | "terminate" @@ -483,7 +469,6 @@ export interface NodeDisableSchedulingOptions { } /** DisableBatchNodeSchedulingOption enums */ -/** */ export type DisableBatchNodeSchedulingOption = | "requeue" | "terminate" @@ -582,7 +567,6 @@ export interface InstanceViewStatus { } /** Level code. */ -/** */ export type StatusLevelTypes = "Error" | "Info" | "Warning"; /** The result of listing the Compute Node extensions in a Node. */ @@ -700,10 +684,8 @@ export interface ExitOptions { } /** JobAction enums */ -/** */ export type JobAction = "none" | "disable" | "terminate"; /** DependencyAction enums */ -/** */ export type DependencyAction = "satisfy" | "block"; /** @@ -765,7 +747,6 @@ export interface OutputFileUploadOptions { } /** OutputFileUploadCondition enums */ -/** */ export type OutputFileUploadCondition = | "tasksuccess" | "taskfailure" @@ -846,7 +827,6 @@ export interface AuthenticationTokenSettings { } /** AccessScope enums */ -/** */ export type AccessScope = "job"; /** The result of listing the Tasks in a Job. */ @@ -996,7 +976,6 @@ export interface TaskAddResult { } /** TaskAddStatus enums */ -/** */ export type TaskAddStatus = "Success" | "clienterror" | "servererror"; /** The result of listing the subtasks of a Task. */ @@ -1034,7 +1013,6 @@ export interface SubtaskInformation { } /** SubtaskState enums */ -/** */ export type SubtaskState = "preparing" | "running" | "completed"; /** @@ -1075,7 +1053,6 @@ export interface BatchJobSchedule { } /** JobScheduleState enums */ -/** */ export type JobScheduleState = | "active" | "completed" @@ -1133,10 +1110,8 @@ export interface JobSpecification { } /** The action the Batch service should take when all Tasks in the Job are in the completed state. */ -/** */ export type OnAllTasksComplete = "noaction" | "terminatejob"; /** OnTaskFailure enums */ -/** */ export type OnTaskFailure = "noaction" | "performexitoptionsjobaction"; /** The network configuration for the Job. */ @@ -1330,7 +1305,6 @@ export interface AutoPoolSpecification { } /** PoolLifetimeOption enums */ -/** */ export type PoolLifetimeOption = "jobschedule" | "job"; /** Specification for creating a new Pool. */ @@ -1468,10 +1442,8 @@ export interface DataDisk { } /** CachingType enums */ -/** */ export type CachingType = "none" | "readonly" | "readwrite"; /** StorageAccountType enums */ -/** */ export type StorageAccountType = "standard_lrs" | "premium_lrs"; /** The configuration for container-enabled Pools. */ @@ -1485,7 +1457,6 @@ export interface ContainerConfiguration { } /** ContainerType enums */ -/** */ export type ContainerType = "dockerCompatible" | "criCompatible"; /** @@ -1499,7 +1470,6 @@ export interface DiskEncryptionConfiguration { } /** DiskEncryptionTarget enums */ -/** */ export type DiskEncryptionTarget = "osdisk" | "temporarydisk"; /** @@ -1513,7 +1483,6 @@ export interface NodePlacementConfiguration { } /** NodePlacementPolicyType enums */ -/** */ export type NodePlacementPolicyType = "regional" | "zonal"; /** Settings for the operating system disk of the compute node (VM). */ @@ -1532,7 +1501,6 @@ export interface DiffDiskSettings { } /** AccessDiffDiskPlacementScope enums */ -/** */ export type DiffDiskPlacement = "cachedisk"; /** Specifies how Tasks should be distributed across Compute Nodes. */ @@ -1542,7 +1510,6 @@ export interface TaskSchedulingPolicy { } /** BatchNodeFillType enums */ -/** */ export type BatchNodeFillType = "spread" | "pack"; /** The network configuration for a Pool. */ @@ -1560,7 +1527,6 @@ export interface NetworkConfiguration { } /** DynamicVNetAssignmentScope enums */ -/** */ export type DynamicVNetAssignmentScope = "none" | "job"; /** The endpoint configuration for a Pool. */ @@ -1601,7 +1567,6 @@ export interface NetworkSecurityGroupRule { } /** NetworkSecurityGroupRuleAccess enums */ -/** */ export type NetworkSecurityGroupRuleAccess = "allow" | "deny"; /** The public IP Address configuration of the networking configuration of a Pool. */ @@ -1613,7 +1578,6 @@ export interface PublicIpAddressConfiguration { } /** IPAddressProvisioningType enums */ -/** */ export type IpAddressProvisioningType = | "batchmanaged" | "usermanaged" @@ -1653,7 +1617,6 @@ export interface WindowsUserConfiguration { } /** LoginMode enums */ -/** */ export type LoginMode = "batch" | "interactive"; /** @@ -1736,7 +1699,6 @@ export interface AzureFileShareConfiguration { } /** NodeCommunicationMode enums */ -/** */ export type NodeCommunicationMode = "default" | "classic" | "simplified"; /** @@ -1856,7 +1818,6 @@ export interface BatchCertificate { } /** CertificateState enums */ -/** */ export type CertificateState = "active" | "deleting" | "deletefailed"; /** An error encountered by the Batch service when deleting a Certificate. */ @@ -1870,7 +1831,6 @@ export interface DeleteCertificateError { } /** CertificateFormat enums */ -/** */ export type CertificateFormat = "pfx" | "cer"; /** The result of listing the Certificates in the Account. */ @@ -1938,7 +1898,6 @@ export interface BatchJob { } /** JobState enums */ -/** */ export type JobState = | "active" | "disabling" @@ -2031,7 +1990,6 @@ export interface BatchJobDisableOptions { } /** DisableJobOption enums */ -/** */ export type DisableJobOption = "requeue" | "terminate" | "wait"; /** Options for terminating an Azure Batch Job. */ @@ -2139,7 +2097,6 @@ export interface JobPreparationTaskExecutionInformation { } /** JobPreparationTaskState enums */ -/** */ export type JobPreparationTaskState = "running" | "completed"; /** @@ -2168,7 +2125,6 @@ export interface JobReleaseTaskExecutionInformation { } /** JobReleaseTaskState enums */ -/** */ export type JobReleaseTaskState = "running" | "completed"; /** The Task and TaskSlot counts for a Job. */ @@ -2235,10 +2191,8 @@ export interface ImageInformation { } /** OSType enums */ -/** */ export type OSType = "linux" | "windows"; /** VerificationType enums */ -/** */ export type VerificationType = "verified" | "unverified"; /** The result of listing the Compute Node counts in the Account. */ @@ -2462,10 +2416,8 @@ export interface BatchPool { } /** PoolState enums */ -/** */ export type PoolState = "active" | "deleting"; /** AllocationState enums */ -/** */ export type AllocationState = "steady" | "resizing" | "stopping"; /** An error that occurred when resizing a Pool. */ @@ -2561,7 +2513,6 @@ export interface BatchPoolIdentity { } /** PoolIdentityType enums */ -/** */ export type PoolIdentityType = "UserAssigned" | "None"; /** The user assigned Identity */ @@ -2622,7 +2573,6 @@ export interface BatchPoolResizeOptions { } /** BatchNodeDeallocationOption enums */ -/** */ export type BatchNodeDeallocationOption = | "requeue" | "terminate" @@ -2679,5 +2629,4 @@ export interface BatchApplication { } /** The Azure Batch service version. */ -/** */ export type Versions = "2023-05-01.17.0"; diff --git a/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/rest/batchClient.ts b/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/rest/batchClient.ts index 6059823f69..6cf2f8d15d 100644 --- a/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/rest/batchClient.ts +++ b/packages/typespec-test/test/batch_modular/generated/typespec-ts/src/rest/batchClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { BatchContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BatchContextOptions extends ClientOptions {} + /** * Initialize a new instance of `BatchContext` * @param endpointParam - Batch account endpoint (for example: https://batchaccount.eastus2.batch.azure.com). @@ -15,10 +18,9 @@ import { BatchContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential, - options: ClientOptions = {}, + options: BatchContextOptions = {}, ): BatchContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-batch-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -43,7 +45,6 @@ export default function createClient( ], }, }; - const client = getClient(endpointUrl, credentials, options) as BatchContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/review/ai-chat-protocol.api.md b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/review/ai-chat-protocol.api.md index 8b4a445fc4..61236fd6a5 100644 --- a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/review/ai-chat-protocol.api.md +++ b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/review/ai-chat-protocol.api.md @@ -66,7 +66,7 @@ export class ChatProtocolClient { export interface ChatProtocolClientOptions extends ClientOptions { } -// @public (undocumented) +// @public export type ChatRole = "user" | "system" | "assistant"; // @public @@ -86,7 +86,7 @@ export interface CreateOptionalParams extends OperationOptions { export interface CreateStreamingOptionalParams extends OperationOptions { } -// @public (undocumented) +// @public export type FinishReason = "stop" | "length"; // @public diff --git a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/models/models.ts index 4c251689c5..9225f9ce2c 100644 --- a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/models/models.ts @@ -17,7 +17,6 @@ export interface ChatMessage { } /** A representation of the intended purpose of a message. */ -/** */ export type ChatRole = "user" | "system" | "assistant"; /** The configuration for a streaming chat completion request. */ @@ -84,7 +83,6 @@ export interface ChatMessageDelta { } /** Representation of the reason why a chat session has finished processing. */ -/** */ export type FinishReason = "stop" | "length"; /** The configuration for a chat completion request. */ @@ -135,5 +133,4 @@ export interface ChatChoiceRecord { finishReason: FinishReason; } -/** */ export type APIVersion = "2023-10-01-preview"; diff --git a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/rest/chatProtocolClient.ts b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/rest/chatProtocolClient.ts index 868e8649d5..839299230f 100644 --- a/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/rest/chatProtocolClient.ts +++ b/packages/typespec-test/test/chatApi_modular/generated/typespec-ts/src/rest/chatProtocolClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { ChatProtocolContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ChatProtocolContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ChatProtocolContext` * @param endpointParam - A sequence of textual characters. @@ -15,10 +18,9 @@ import { ChatProtocolContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + options: ChatProtocolContextOptions = {}, ): ChatProtocolContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-ai-chat-protocol-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -37,7 +39,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key", }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/review/confidential-ledger.api.md b/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/review/confidential-ledger.api.md index e1c3e263e5..732a49ce1f 100644 --- a/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/review/confidential-ledger.api.md +++ b/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/review/confidential-ledger.api.md @@ -26,7 +26,12 @@ export type ConfidentialLedgerClient = Client & { }; // @public -function createClient(ledgerUri: string, credentials: TokenCredential, options?: ClientOptions): ConfidentialLedgerClient; +export interface ConfidentialLedgerClientOptions extends ClientOptions { + apiVersion?: string; +} + +// @public +function createClient(ledgerUri: string, credentials: TokenCredential, { apiVersion, ...options }?: ConfidentialLedgerClientOptions): ConfidentialLedgerClient; export default createClient; // @public (undocumented) diff --git a/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/src/confidentialLedgerClient.ts b/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/src/confidentialLedgerClient.ts index 064a71ccd5..689973bac9 100644 --- a/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/src/confidentialLedgerClient.ts +++ b/packages/typespec-test/test/confidentialLedger/generated/typespec-ts/src/confidentialLedgerClient.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { TokenCredential } from "@azure/core-auth"; import { ConfidentialLedgerClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ConfidentialLedgerClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `ConfidentialLedgerClient` * @param ledgerUri - Represent a URL string as described by https://url.spec.whatwg.org/ @@ -15,10 +21,12 @@ import { ConfidentialLedgerClient } from "./clientDefinitions.js"; export default function createClient( ledgerUri: string, credentials: TokenCredential, - options: ClientOptions = {}, + { + apiVersion = "2022-05-13", + ...options + }: ConfidentialLedgerClientOptions = {}, ): ConfidentialLedgerClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${ledgerUri}`; - options.apiVersion = options.apiVersion ?? "2022-05-13"; const userAgentInfo = `azsdk-js-confidential-ledger-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,12 +46,28 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, options, ) as ConfidentialLedgerClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/review/ai-content-safety.api.md b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/review/ai-content-safety.api.md index 11c561cf57..66793bbc49 100644 --- a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/review/ai-content-safety.api.md +++ b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/review/ai-content-safety.api.md @@ -35,7 +35,7 @@ export interface AnalyzeImageOptions { outputType?: AnalyzeImageOutputType; } -// @public (undocumented) +// @public export type AnalyzeImageOutputType = "FourLevels"; // @public @@ -56,7 +56,7 @@ export interface AnalyzeTextOptions { text: string; } -// @public (undocumented) +// @public export type AnalyzeTextOutputType = "FourLevels" | "EightLevels"; // @public @@ -114,7 +114,7 @@ export interface ImageAnalyzeSeverityResult { severity?: number; } -// @public (undocumented) +// @public export type ImageCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; // @public @@ -199,7 +199,7 @@ export interface TextBlocklistMatchResult { blocklistName: string; } -// @public (undocumented) +// @public export type TextCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; // @public (undocumented) diff --git a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/models/models.ts index f5202c4eb1..13cc2ec676 100644 --- a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/models/models.ts @@ -64,10 +64,8 @@ export interface ImageData { } /** Image analyze category */ -/** */ export type ImageCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; /** The type of image analysis output. */ -/** */ export type AnalyzeImageOutputType = "FourLevels"; /** The analysis response of the image. */ @@ -99,10 +97,8 @@ export interface AnalyzeTextOptions { } /** Text analyze category */ -/** */ export type TextCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; /** The type of text analysis output. */ -/** */ export type AnalyzeTextOutputType = "FourLevels" | "EightLevels"; /** The analysis response of the text */ @@ -131,7 +127,6 @@ export interface TextAnalyzeSeverityResult { severity?: number; } -/** */ export type Versions = "2023-10-01"; /** Paged collection of TextBlocklist items */ diff --git a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/rest/contentSafetyClient.ts b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/rest/contentSafetyClient.ts index 92d2943486..c3d6bb1bb8 100644 --- a/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/rest/contentSafetyClient.ts +++ b/packages/typespec-test/test/contentsafety_modular/generated/typespec-ts/src/rest/contentSafetyClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { ContentSafetyContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ContentSafetyContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `ContentSafetyContext` * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: @@ -16,11 +22,10 @@ import { ContentSafetyContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2023-10-01", ...options }: ContentSafetyContextOptions = {}, ): ContentSafetyContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`; - options.apiVersion = options.apiVersion ?? "2023-10-01"; const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -42,12 +47,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as ContentSafetyContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/contoso/generated/typespec-ts/review/contosowidgetmanager-rest.api.md b/packages/typespec-test/test/contoso/generated/typespec-ts/review/contosowidgetmanager-rest.api.md index f118224378..444ddac818 100644 --- a/packages/typespec-test/test/contoso/generated/typespec-ts/review/contosowidgetmanager-rest.api.md +++ b/packages/typespec-test/test/contoso/generated/typespec-ts/review/contosowidgetmanager-rest.api.md @@ -21,7 +21,7 @@ import { RequestParameters } from '@azure-rest/core-client'; import { StreamableMethod } from '@azure-rest/core-client'; // @public -function createClient(endpointParam: string, options?: ClientOptions): WidgetManagerClient; +function createClient(endpointParam: string, { apiVersion, ...options }?: WidgetManagerClientOptions): WidgetManagerClient; export default createClient; // @public (undocumented) @@ -344,6 +344,11 @@ export type WidgetManagerClient = Client & { path: Routes; }; +// @public +export interface WidgetManagerClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface WidgetOutput { manufacturerId: string; diff --git a/packages/typespec-test/test/contoso/generated/typespec-ts/src/widgetManagerClient.ts b/packages/typespec-test/test/contoso/generated/typespec-ts/src/widgetManagerClient.ts index 55849a6c69..5cb9297739 100644 --- a/packages/typespec-test/test/contoso/generated/typespec-ts/src/widgetManagerClient.ts +++ b/packages/typespec-test/test/contoso/generated/typespec-ts/src/widgetManagerClient.ts @@ -5,6 +5,12 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { WidgetManagerClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface WidgetManagerClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `WidgetManagerClient` * @param endpointParam - The parameter endpointParam @@ -12,10 +18,12 @@ import { WidgetManagerClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + { + apiVersion = "2022-11-01-preview", + ...options + }: WidgetManagerClientOptions = {}, ): WidgetManagerClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - options.apiVersion = options.apiVersion ?? "2022-11-01-preview"; const userAgentInfo = `azsdk-js-contosowidgetmanager-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,8 +38,24 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as WidgetManagerClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/customWrapper/generated/typespec-ts/review/customWrapper.api.md b/packages/typespec-test/test/customWrapper/generated/typespec-ts/review/customWrapper.api.md index 9eb773bd6c..071ee43c33 100644 --- a/packages/typespec-test/test/customWrapper/generated/typespec-ts/review/customWrapper.api.md +++ b/packages/typespec-test/test/customWrapper/generated/typespec-ts/review/customWrapper.api.md @@ -19,7 +19,12 @@ export type AuthoringClient = Client & { }; // @public -function createClient(endpointParam: string, credentials: KeyCredential, options?: ClientOptions): AuthoringClient; +export interface AuthoringClientOptions extends ClientOptions { + apiVersion?: string; +} + +// @public +function createClient(endpointParam: string, credentials: KeyCredential, { apiVersion, ...options }?: AuthoringClientOptions): AuthoringClient; export default createClient; // @public diff --git a/packages/typespec-test/test/customWrapper/generated/typespec-ts/src/authoringClient.ts b/packages/typespec-test/test/customWrapper/generated/typespec-ts/src/authoringClient.ts index 996b2d22d6..0bab540534 100644 --- a/packages/typespec-test/test/customWrapper/generated/typespec-ts/src/authoringClient.ts +++ b/packages/typespec-test/test/customWrapper/generated/typespec-ts/src/authoringClient.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AuthoringClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthoringClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AuthoringClient` * @param endpointParam - The endpoint to use. @@ -15,11 +21,13 @@ import { AuthoringClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2022-05-15-preview", + ...options + }: AuthoringClientOptions = {}, ): AuthoringClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/language`; - options.apiVersion = options.apiVersion ?? "2022-05-15-preview"; const userAgentInfo = `azsdk-js-customWrapper-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,12 +46,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as AuthoringClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/models/models.ts index a49314530e..5147d86865 100644 --- a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/models/models.ts @@ -102,5 +102,4 @@ export interface RejectResult { succeededLockTokens: string[]; } -/** */ export type ServiceApiVersions = "2023-06-01-preview"; diff --git a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/rest/eventGridClient.ts b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/rest/eventGridClient.ts index 0538530f05..e80e107d08 100644 --- a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/rest/eventGridClient.ts +++ b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/rest/eventGridClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { KeyCredential } from "@azure/core-auth"; import { EventGridContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface EventGridContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `EventGridContext` * @param endpointParam - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net @@ -15,10 +21,12 @@ import { EventGridContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2023-06-01-preview", + ...options + }: EventGridContextOptions = {}, ): EventGridContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - options.apiVersion = options.apiVersion ?? "2023-06-01-preview"; const userAgentInfo = `azsdk-js-eventgrid-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -37,12 +45,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "SharedAccessKey", }, }; - const client = getClient( endpointUrl, credentials, options, ) as EventGridContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/faceai/generated/typespec-ts/review/ai-face-rest.api.md b/packages/typespec-test/test/faceai/generated/typespec-ts/review/ai-face-rest.api.md index 6f4b5591c1..83bc8beca5 100644 --- a/packages/typespec-test/test/faceai/generated/typespec-ts/review/ai-face-rest.api.md +++ b/packages/typespec-test/test/faceai/generated/typespec-ts/review/ai-face-rest.api.md @@ -591,7 +591,7 @@ export interface BlurPropertiesOutput { } // @public -function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options?: FaceClientOptions): FaceClient; +function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, { apiVersion, ...options }?: FaceClientOptions): FaceClient; export default createClient; // @public @@ -1740,9 +1740,8 @@ export type FaceClient = Client & { path: Routes; }; -// @public (undocumented) +// @public export interface FaceClientOptions extends ClientOptions { - // (undocumented) apiVersion?: Versions; } diff --git a/packages/typespec-test/test/faceai/generated/typespec-ts/src/faceClient.ts b/packages/typespec-test/test/faceai/generated/typespec-ts/src/faceClient.ts index 9c39a3f25f..1806a4e039 100644 --- a/packages/typespec-test/test/faceai/generated/typespec-ts/src/faceClient.ts +++ b/packages/typespec-test/test/faceai/generated/typespec-ts/src/faceClient.ts @@ -7,7 +7,9 @@ import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { FaceClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ export interface FaceClientOptions extends ClientOptions { + /** API Version */ apiVersion?: Versions; } @@ -21,14 +23,12 @@ export interface FaceClientOptions extends ClientOptions { export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: FaceClientOptions = {}, + { apiVersion = "v1.1-preview.1", ...options }: FaceClientOptions = {}, ): FaceClient { - const apiVersion = options.apiVersion ?? "v1.1-preview.1"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/face/${apiVersion}`; - const userAgentInfo = `azsdk-js-ai-face-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -50,15 +50,9 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient(endpointUrl, credentials, options) as FaceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/review/health-insights-radiologyinsights.api.md b/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/review/health-insights-radiologyinsights.api.md index 05a8e91528..bd62d5a3f1 100644 --- a/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/review/health-insights-radiologyinsights.api.md +++ b/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/review/health-insights-radiologyinsights.api.md @@ -48,6 +48,11 @@ export type AzureHealthInsightsClient = Client & { path: Routes; }; +// @public +export interface AzureHealthInsightsClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export type ClinicalDocumentType = "consultation" | "dischargeSummary" | "historyAndPhysical" | "radiologyReport" | "procedure" | "progress" | "laboratory" | "pathologyReport"; @@ -202,7 +207,7 @@ export type ContactPointUse = "home" | "work" | "temp" | "old" | "mobile"; export type ContactPointUseOutput = "home" | "work" | "temp" | "old" | "mobile"; // @public -function createClient(endpointParam: string, credentials: KeyCredential, options?: ClientOptions): AzureHealthInsightsClient; +function createClient(endpointParam: string, credentials: KeyCredential, { apiVersion, ...options }?: AzureHealthInsightsClientOptions): AzureHealthInsightsClient; export default createClient; // @public (undocumented) diff --git a/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/src/azureHealthInsightsClient.ts b/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/src/azureHealthInsightsClient.ts index 55338dd11c..b08db6e0c3 100644 --- a/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/src/azureHealthInsightsClient.ts +++ b/packages/typespec-test/test/healthInsights_radiologyinsights/generated/typespec-ts/src/azureHealthInsightsClient.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AzureHealthInsightsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureHealthInsightsClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureHealthInsightsClient` * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com). @@ -15,11 +21,13 @@ import { AzureHealthInsightsClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2023-09-01-preview", + ...options + }: AzureHealthInsightsClientOptions = {}, ): AzureHealthInsightsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`; - options.apiVersion = options.apiVersion ?? "2023-09-01-preview"; const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,12 +46,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as AzureHealthInsightsClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/review/health-insights-clinicalmatching.api.md b/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/review/health-insights-clinicalmatching.api.md index 47f3499f29..d3fe9ad5cd 100644 --- a/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/review/health-insights-clinicalmatching.api.md +++ b/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/review/health-insights-clinicalmatching.api.md @@ -191,7 +191,7 @@ export interface ContactDetailsOutput { } // @public -function createClient(endpointParam: string, credentials: KeyCredential, options?: ClientOptions): HealthInsightsClinicalMatchingClient; +function createClient(endpointParam: string, credentials: KeyCredential, { apiVersion, ...options }?: HealthInsightsClinicalMatchingClientOptions): HealthInsightsClinicalMatchingClient; export default createClient; // @public (undocumented) @@ -350,6 +350,11 @@ export type HealthInsightsClinicalMatchingClient = Client & { path: Routes; }; +// @public +export interface HealthInsightsClinicalMatchingClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public (undocumented) export function isUnexpected(response: GetJob200Response | GetJobDefaultResponse): response is GetJobDefaultResponse; diff --git a/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/src/healthInsightsClinicalMatching.ts b/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/src/healthInsightsClinicalMatching.ts index b7fee8d8db..39e6a8fdb0 100644 --- a/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/src/healthInsightsClinicalMatching.ts +++ b/packages/typespec-test/test/healthInsights_trialmatcher/generated/typespec-ts/src/healthInsightsClinicalMatching.ts @@ -6,6 +6,13 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { HealthInsightsClinicalMatchingClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface HealthInsightsClinicalMatchingClientOptions + extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `HealthInsightsClinicalMatchingClient` * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com). @@ -15,11 +22,13 @@ import { HealthInsightsClinicalMatchingClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + { + apiVersion = "2023-03-01-preview", + ...options + }: HealthInsightsClinicalMatchingClientOptions = {}, ): HealthInsightsClinicalMatchingClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/healthinsights`; - options.apiVersion = options.apiVersion ?? "2023-03-01-preview"; const userAgentInfo = `azsdk-js-health-insights-clinicalmatching-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -38,12 +47,28 @@ export default function createClient( options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as HealthInsightsClinicalMatchingClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/hierarchy_generic/generated/typespec-ts/src/rest/fooClient.ts b/packages/typespec-test/test/hierarchy_generic/generated/typespec-ts/src/rest/fooClient.ts index 7cc8a35cb3..d981f429bd 100644 --- a/packages/typespec-test/test/hierarchy_generic/generated/typespec-ts/src/rest/fooClient.ts +++ b/packages/typespec-test/test/hierarchy_generic/generated/typespec-ts/src/rest/fooClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { FooContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface FooContextOptions extends ClientOptions {} + /** * Initialize a new instance of `FooContext` * @param endpointParam - The parameter endpointParam @@ -12,10 +15,9 @@ import { FooContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: FooContextOptions = {}, ): FooContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-hierarchy-generic-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as FooContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/review/load-testing.api.md b/packages/typespec-test/test/loadTest/generated/typespec-ts/review/load-testing.api.md index a56496118b..c2f9e65fab 100644 --- a/packages/typespec-test/test/loadTest/generated/typespec-ts/review/load-testing.api.md +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/review/load-testing.api.md @@ -49,6 +49,11 @@ export type AzureLoadTestingClient = Client & { path: Routes; }; +// @public +export interface AzureLoadTestingClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface CertificateMetadata { name?: string; @@ -70,7 +75,7 @@ export type CertificateType = "AKV_CERT_URI"; export type CertificateTypeOutput = "AKV_CERT_URI"; // @public -function createClient(endpointParam: string, credentials: TokenCredential, options?: ClientOptions): AzureLoadTestingClient; +function createClient(endpointParam: string, credentials: TokenCredential, { apiVersion, ...options }?: AzureLoadTestingClientOptions): AzureLoadTestingClient; export default createClient; // @public diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/src/azureLoadTesting.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/src/azureLoadTesting.ts index 9d6d3b72be..4ec205eac9 100644 --- a/packages/typespec-test/test/loadTest/generated/typespec-ts/src/azureLoadTesting.ts +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/src/azureLoadTesting.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { TokenCredential } from "@azure/core-auth"; import { AzureLoadTestingClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureLoadTestingClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureLoadTestingClient` * @param endpointParam - A sequence of textual characters. @@ -15,11 +21,10 @@ import { AzureLoadTestingClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential, - options: ClientOptions = {}, + { apiVersion = "2022-11-01", ...options }: AzureLoadTestingClientOptions = {}, ): AzureLoadTestingClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`; - options.apiVersion = options.apiVersion ?? "2022-11-01"; const userAgentInfo = `azsdk-js-load-testing-rest/1.0.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -39,12 +44,27 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, options, ) as AzureLoadTestingClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/administrationOperations/models/models.ts b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/administrationOperations/models/models.ts index daab3ea449..1e24def656 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/administrationOperations/models/models.ts +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/administrationOperations/models/models.ts @@ -77,14 +77,12 @@ export interface PassFailMetric { readonly result?: PFResult; } -/** */ export type PFMetrics = | "response_time_ms" | "latency" | "error" | "requests" | "requests_per_sec"; -/** */ export type PFAgFunc = | "count" | "percentage" @@ -95,9 +93,7 @@ export type PFAgFunc = | "p99" | "min" | "max"; -/** */ export type PFAction = "continue" | "stop"; -/** */ export type PFResult = "passed" | "undetermined" | "failed"; /** Secret */ @@ -108,7 +104,6 @@ export interface Secret { type?: SecretType; } -/** */ export type SecretType = "AKV_SECRET_URI" | "SECRET_VALUE"; /** Certificates metadata */ @@ -121,7 +116,6 @@ export interface CertificateMetadata { name?: string; } -/** */ export type CertificateType = "AKV_CERT_URI"; /** The load test configuration. */ @@ -192,9 +186,7 @@ export interface FileInfo { validationFailureDetails?: string; } -/** */ export type FileType = "JMX_FILE" | "USER_PROPERTIES" | "ADDITIONAL_ARTIFACTS"; -/** */ export type FileStatus = | "NOT_VALIDATED" | "VALIDATION_SUCCESS" @@ -306,7 +298,6 @@ export interface PagedTest { nextLink?: string; } -/** */ export type APIVersions = "2022-11-01"; /** Load test run model */ @@ -437,9 +428,7 @@ export interface TestRunOutputArtifacts { logsFileInfo?: FileInfo; } -/** */ export type PFTestResult = "PASSED" | "NOT_APPLICABLE" | "FAILED"; -/** */ export type Status = | "ACCEPTED" | "NOTSTARTED" @@ -498,7 +487,6 @@ export interface TestRunServerMetricConfig { readonly lastModifiedBy?: string; } -/** */ export type Interval = "PT5S" | "PT10S" | "PT1M" | "PT5M" | "PT1H"; export interface DimensionValueList { @@ -542,7 +530,6 @@ export interface NameAndDesc { name?: string; } -/** */ export type AggregationType = | "Average" | "Count" @@ -551,7 +538,6 @@ export type AggregationType = | "Percentile90" | "Percentile95" | "Percentile99"; -/** */ export type MetricUnit = | "NotSpecified" | "Percent" @@ -571,7 +557,6 @@ export interface MetricAvailability { timeGrain?: TimeGrain; } -/** */ export type TimeGrain = "PT5S" | "PT10S" | "PT1M" | "PT5M" | "PT1H"; /** Represents collection of metric namespaces. */ diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/rest/azureLoadTestingClient.ts b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/rest/azureLoadTestingClient.ts index 5e51f0a87d..01f53c8bc8 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/rest/azureLoadTestingClient.ts +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/rest/azureLoadTestingClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { AzureLoadTestingContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureLoadTestingContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureLoadTestingContext` * @param endpointParam - A sequence of textual characters. @@ -15,11 +21,13 @@ import { AzureLoadTestingContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential, - options: ClientOptions = {}, + { + apiVersion = "2022-11-01", + ...options + }: AzureLoadTestingContextOptions = {}, ): AzureLoadTestingContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`; - options.apiVersion = options.apiVersion ?? "2022-11-01"; const userAgentInfo = `azsdk-js-load-testing-rest/1.0.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -39,12 +47,27 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, options, ) as AzureLoadTestingContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/testRunOperations/models/models.ts b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/testRunOperations/models/models.ts index daab3ea449..1e24def656 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/testRunOperations/models/models.ts +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/testRunOperations/models/models.ts @@ -77,14 +77,12 @@ export interface PassFailMetric { readonly result?: PFResult; } -/** */ export type PFMetrics = | "response_time_ms" | "latency" | "error" | "requests" | "requests_per_sec"; -/** */ export type PFAgFunc = | "count" | "percentage" @@ -95,9 +93,7 @@ export type PFAgFunc = | "p99" | "min" | "max"; -/** */ export type PFAction = "continue" | "stop"; -/** */ export type PFResult = "passed" | "undetermined" | "failed"; /** Secret */ @@ -108,7 +104,6 @@ export interface Secret { type?: SecretType; } -/** */ export type SecretType = "AKV_SECRET_URI" | "SECRET_VALUE"; /** Certificates metadata */ @@ -121,7 +116,6 @@ export interface CertificateMetadata { name?: string; } -/** */ export type CertificateType = "AKV_CERT_URI"; /** The load test configuration. */ @@ -192,9 +186,7 @@ export interface FileInfo { validationFailureDetails?: string; } -/** */ export type FileType = "JMX_FILE" | "USER_PROPERTIES" | "ADDITIONAL_ARTIFACTS"; -/** */ export type FileStatus = | "NOT_VALIDATED" | "VALIDATION_SUCCESS" @@ -306,7 +298,6 @@ export interface PagedTest { nextLink?: string; } -/** */ export type APIVersions = "2022-11-01"; /** Load test run model */ @@ -437,9 +428,7 @@ export interface TestRunOutputArtifacts { logsFileInfo?: FileInfo; } -/** */ export type PFTestResult = "PASSED" | "NOT_APPLICABLE" | "FAILED"; -/** */ export type Status = | "ACCEPTED" | "NOTSTARTED" @@ -498,7 +487,6 @@ export interface TestRunServerMetricConfig { readonly lastModifiedBy?: string; } -/** */ export type Interval = "PT5S" | "PT10S" | "PT1M" | "PT5M" | "PT1H"; export interface DimensionValueList { @@ -542,7 +530,6 @@ export interface NameAndDesc { name?: string; } -/** */ export type AggregationType = | "Average" | "Count" @@ -551,7 +538,6 @@ export type AggregationType = | "Percentile90" | "Percentile95" | "Percentile99"; -/** */ export type MetricUnit = | "NotSpecified" | "Percent" @@ -571,7 +557,6 @@ export interface MetricAvailability { timeGrain?: TimeGrain; } -/** */ export type TimeGrain = "PT5S" | "PT10S" | "PT1M" | "PT5M" | "PT1H"; /** Represents collection of metric namespaces. */ diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/review/openai.api.md b/packages/typespec-test/test/openai/generated/typespec-ts/review/openai.api.md index f588aa5c47..4ee970948e 100644 --- a/packages/typespec-test/test/openai/generated/typespec-ts/review/openai.api.md +++ b/packages/typespec-test/test/openai/generated/typespec-ts/review/openai.api.md @@ -237,7 +237,7 @@ export interface ContentFilterResultsOutput { export type ContentFilterSeverityOutput = "safe" | "low" | "medium" | "high"; // @public -function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): OpenAIClient; +function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, { apiVersion, ...options }?: OpenAIClientOptions): OpenAIClient; export default createClient; // @public @@ -528,6 +528,11 @@ export type OpenAIClient = Client & { path: Routes; }; +// @public +export interface OpenAIClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface PromptFilterResultOutput { content_filter_results?: ContentFilterResultsOutput; diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/src/openAIClient.ts b/packages/typespec-test/test/openai/generated/typespec-ts/src/openAIClient.ts index d50917702d..32fd3fd681 100644 --- a/packages/typespec-test/test/openai/generated/typespec-ts/src/openAIClient.ts +++ b/packages/typespec-test/test/openai/generated/typespec-ts/src/openAIClient.ts @@ -6,6 +6,12 @@ import { logger } from "./logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { OpenAIClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OpenAIClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `OpenAIClient` * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: @@ -16,11 +22,10 @@ import { OpenAIClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2023-08-01-preview", ...options }: OpenAIClientOptions = {}, ): OpenAIClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/openai`; - options.apiVersion = options.apiVersion ?? "2023-08-01-preview"; const userAgentInfo = `azsdk-js-openai-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -41,8 +46,24 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key", }, }; - const client = getClient(endpointUrl, credentials, options) as OpenAIClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/openai_generic/generated/typespec-ts/src/rest/openAIClient.ts b/packages/typespec-test/test/openai_generic/generated/typespec-ts/src/rest/openAIClient.ts index 4aac636178..775e475301 100644 --- a/packages/typespec-test/test/openai_generic/generated/typespec-ts/src/rest/openAIClient.ts +++ b/packages/typespec-test/test/openai_generic/generated/typespec-ts/src/rest/openAIClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { KeyCredential } from "@azure/core-auth"; import { OpenAIContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OpenAIContextOptions extends ClientOptions {} + /** * Initialize a new instance of `OpenAIContext` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { OpenAIContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: OpenAIContextOptions = {}, ): OpenAIContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://api.openai.com/v1`; @@ -31,7 +34,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as OpenAIContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-test/test/openai_modular/generated/typespec-ts/review/openai_modular.api.md b/packages/typespec-test/test/openai_modular/generated/typespec-ts/review/openai_modular.api.md index 009df1e822..c2de3981ca 100644 --- a/packages/typespec-test/test/openai_modular/generated/typespec-ts/review/openai_modular.api.md +++ b/packages/typespec-test/test/openai_modular/generated/typespec-ts/review/openai_modular.api.md @@ -19,13 +19,13 @@ export interface AudioSpeechOptions { voice: AudioSpeechVoice; } -// @public (undocumented) +// @public export type AudioSpeechOutputFormat = "mp3" | "opus" | "aac" | "flac"; -// @public (undocumented) +// @public export type AudioSpeechVoice = "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer"; -// @public (undocumented) +// @public export type AudioTaskLabel = "transcribe" | "translate"; // @public @@ -37,7 +37,7 @@ export interface AudioTranscription { text: string; } -// @public (undocumented) +// @public export type AudioTranscriptionFormat = "json" | "verbose_json" | "text" | "srt" | "vtt"; // @public @@ -74,7 +74,7 @@ export interface AudioTranslation { text: string; } -// @public (undocumented) +// @public export type AudioTranslationFormat = "json" | "verbose_json" | "text" | "srt" | "vtt"; // @public @@ -135,7 +135,7 @@ export interface AzureChatExtensionsMessageContext { intent?: string; } -// @public (undocumented) +// @public export type AzureChatExtensionType = "azure_search" | "azure_ml_index" | "azure_cosmos_db" | "elasticsearch" | "Pinecone"; // @public @@ -255,7 +255,7 @@ export interface AzureSearchIndexFieldMappingOptions { vectorFields?: string[]; } -// @public (undocumented) +// @public export type AzureSearchQueryType = "simple" | "semantic" | "vector" | "vector_simple_hybrid" | "vector_semantic_hybrid"; // @public @@ -382,7 +382,7 @@ export interface ChatCompletionsToolDefinition { // @public export type ChatCompletionsToolDefinitionUnion = ChatCompletionsFunctionToolDefinition | ChatCompletionsToolDefinition; -// @public (undocumented) +// @public export type ChatCompletionsToolSelectionPreset = "auto" | "none"; // @public @@ -407,7 +407,7 @@ export interface ChatMessageImageContentItem extends ChatMessageContentItem { type: "image_url"; } -// @public (undocumented) +// @public export type ChatMessageImageDetailLevel = "auto" | "low" | "high"; // @public @@ -476,7 +476,7 @@ export interface ChatResponseMessage { toolCalls?: ChatCompletionsToolCallUnion[]; } -// @public (undocumented) +// @public export type ChatRole = "system" | "assistant" | "user" | "function" | "tool"; // @public @@ -512,7 +512,7 @@ export interface Completions { usage: CompletionsUsage; } -// @public (undocumented) +// @public export type CompletionsFinishReason = "stop" | "length" | "content_filter" | "function_call" | "tool_calls"; // @public @@ -614,7 +614,7 @@ export interface ContentFilterResultsForPrompt { promptIndex: number; } -// @public (undocumented) +// @public export type ContentFilterSeverity = "safe" | "low" | "medium" | "high"; // @public @@ -647,7 +647,7 @@ export interface ElasticsearchIndexFieldMappingOptions { vectorFields?: string[]; } -// @public (undocumented) +// @public export type ElasticsearchQueryType = "simple" | "vector"; // @public @@ -682,7 +682,7 @@ export interface FunctionCall { name: string; } -// @public (undocumented) +// @public export type FunctionCallPreset = "auto" | "none"; // @public @@ -756,10 +756,10 @@ export interface ImageGenerationOptions { user?: string; } -// @public (undocumented) +// @public export type ImageGenerationQuality = "standard" | "hd"; -// @public (undocumented) +// @public export type ImageGenerationResponseFormat = "url" | "b64_json"; // @public @@ -768,10 +768,10 @@ export interface ImageGenerations { data: ImageGenerationData[]; } -// @public (undocumented) +// @public export type ImageGenerationStyle = "natural" | "vivid"; -// @public (undocumented) +// @public export type ImageSize = "256x256" | "512x512" | "1024x1024" | "1792x1024" | "1024x1792"; // @public @@ -799,7 +799,7 @@ export interface OnYourDataAuthenticationOptions { // @public export type OnYourDataAuthenticationOptionsUnion = OnYourDataApiKeyAuthenticationOptions | OnYourDataConnectionStringAuthenticationOptions | OnYourDataKeyAndKeyIdAuthenticationOptions | OnYourDataEncodedApiKeyAuthenticationOptions | OnYourDataAccessTokenAuthenticationOptions | OnYourDataSystemAssignedManagedIdentityAuthenticationOptions | OnYourDataUserAssignedManagedIdentityAuthenticationOptions | OnYourDataAuthenticationOptions; -// @public (undocumented) +// @public export type OnYourDataAuthenticationType = "api_key" | "connection_string" | "key_and_key_id" | "encoded_api_key" | "access_token" | "system_assigned_managed_identity" | "user_assigned_managed_identity"; // @public @@ -856,7 +856,7 @@ export interface OnYourDataVectorizationSource { type: OnYourDataVectorizationSourceType; } -// @public (undocumented) +// @public export type OnYourDataVectorizationSourceType = "endpoint" | "deployment_name" | "model_id"; // @public diff --git a/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/models/models.ts index 344fa6e520..ecbd4db006 100644 --- a/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/models/models.ts @@ -4,7 +4,6 @@ import { ErrorModel } from "@azure-rest/core-client"; /** Defines available options for the underlying response format of output transcription information. */ -/** */ export type AudioTranscriptionFormat = | "json" | "verbose_json" @@ -62,7 +61,6 @@ export interface AudioTranscription { } /** Defines the possible descriptors for available audio operation responses. */ -/** */ export type AudioTaskLabel = "transcribe" | "translate"; /** @@ -100,7 +98,6 @@ export interface AudioTranscriptionSegment { } /** Defines available options for the underlying response format of output translation information. */ -/** */ export type AudioTranslationFormat = | "json" | "verbose_json" @@ -362,7 +359,6 @@ export interface ContentFilterResult { } /** Ratings for the intensity and risk level of harmful content. */ -/** */ export type ContentFilterSeverity = "safe" | "low" | "medium" | "high"; /** Represents the outcome of a detection operation performed by content filtering. */ @@ -482,7 +478,6 @@ export interface CompletionsLogProbabilityModel { } /** Representation of the manner in which a completions response concluded. */ -/** */ export type CompletionsFinishReason = | "stop" | "length" @@ -567,7 +562,6 @@ export interface ChatMessageImageUrl { } /** A representation of the possible image detail levels for image-based chat completions message content. */ -/** */ export type ChatMessageImageDetailLevel = "auto" | "low" | "high"; /** A request chat message representing response or action from the assistant. */ @@ -647,7 +641,6 @@ export interface ChatRequestFunctionMessage extends ChatRequestMessage { } /** A description of the intended purpose of a message within a chat completions interaction. */ -/** */ export type ChatRole = "system" | "assistant" | "user" | "function" | "tool"; /** The definition of a caller-specified function that chat completions may invoke in response to matching user input. */ @@ -667,7 +660,6 @@ export interface FunctionDefinition { * The collection of predefined behaviors for handling request-provided function information in a chat completions * operation. */ -/** */ export type FunctionCallPreset = "auto" | "none"; /** @@ -808,7 +800,6 @@ export interface OnYourDataUserAssignedManagedIdentityAuthenticationOptions } /** The authentication types supported with Azure OpenAI On Your Data. */ -/** */ export type OnYourDataAuthenticationType = | "api_key" | "connection_string" @@ -837,7 +828,6 @@ export interface AzureSearchIndexFieldMappingOptions { } /** The type of Azure Search retrieval query that should be executed when using it as an Azure OpenAI chat extension. */ -/** */ export type AzureSearchQueryType = | "simple" | "semantic" @@ -893,7 +883,6 @@ export interface OnYourDataModelIdVectorizationSource * Represents the available sources Azure OpenAI On Your Data can use to configure vectorization of data for use with * vector search. */ -/** */ export type OnYourDataVectorizationSourceType = | "endpoint" | "deployment_name" @@ -1068,7 +1057,6 @@ export interface ElasticsearchIndexFieldMappingOptions { } /** The type of Elasticsearch® retrieval query that should be executed when using it as an Azure OpenAI chat extension. */ -/** */ export type ElasticsearchQueryType = "simple" | "vector"; /** @@ -1133,7 +1121,6 @@ export interface PineconeFieldMappingOptions { * completions request that should use Azure OpenAI chat extensions to augment the response behavior. * The use of this configuration is compatible only with Azure OpenAI. */ -/** */ export type AzureChatExtensionType = | "azure_search" | "azure_ml_index" @@ -1203,7 +1190,6 @@ export interface ChatCompletionsFunctionToolDefinition } /** Represents a generic policy for how a chat completions tool may be selected. */ -/** */ export type ChatCompletionsToolSelectionPreset = "auto" | "none"; /** An abstract representation of an explicit, named tool selection to use for a chat completions request. */ @@ -1569,7 +1555,6 @@ export interface AzureGroundingEnhancementCoordinatePoint { } /** The desired size of generated images. */ -/** */ export type ImageSize = | "256x256" | "512x512" @@ -1577,19 +1562,16 @@ export type ImageSize = | "1792x1024" | "1024x1792"; /** The format in which the generated images are returned. */ -/** */ export type ImageGenerationResponseFormat = "url" | "b64_json"; /** * An image generation configuration that specifies how the model should prioritize quality, cost, and speed. * Only configurable with dall-e-3 models. */ -/** */ export type ImageGenerationQuality = "standard" | "hd"; /** * An image generation configuration that specifies how the model should incorporate realism and other visual characteristics. * Only configurable with dall-e-3 models. */ -/** */ export type ImageGenerationStyle = "natural" | "vivid"; /** Represents the request data used to generate images. */ @@ -1657,7 +1639,6 @@ export interface ImageGenerationData { } /** The available voices for text-to-speech. */ -/** */ export type AudioSpeechVoice = | "alloy" | "echo" @@ -1666,7 +1647,6 @@ export type AudioSpeechVoice = | "nova" | "shimmer"; /** The supported audio output formats for text-to-speech. */ -/** */ export type AudioSpeechOutputFormat = "mp3" | "opus" | "aac" | "flac"; /** A representation of the request options that control the behavior of a text-to-speech operation. */ @@ -1741,7 +1721,6 @@ export interface EmbeddingsUsage { totalTokens: number; } -/** */ export type ServiceApiVersions = | "2022-12-01" | "2023-05-15" diff --git a/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/rest/openAIClient.ts b/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/rest/openAIClient.ts index e553197b40..ad00233515 100644 --- a/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/rest/openAIClient.ts +++ b/packages/typespec-test/test/openai_modular/generated/typespec-ts/src/rest/openAIClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { OpenAIContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OpenAIContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `OpenAIContext` * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: @@ -16,11 +22,10 @@ import { OpenAIContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2024-02-15-preview", ...options }: OpenAIContextOptions = {}, ): OpenAIContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/openai`; - options.apiVersion = options.apiVersion ?? "2024-02-15-preview"; const userAgentInfo = `azsdk-js-openai_modular-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -41,8 +46,24 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key", }, }; - const client = getClient(endpointUrl, credentials, options) as OpenAIContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/openai_non_branded/generated/typespec-ts/src/rest/openAIClient.ts b/packages/typespec-test/test/openai_non_branded/generated/typespec-ts/src/rest/openAIClient.ts index 15ab0d850e..604f21cbdf 100644 --- a/packages/typespec-test/test/openai_non_branded/generated/typespec-ts/src/rest/openAIClient.ts +++ b/packages/typespec-test/test/openai_non_branded/generated/typespec-ts/src/rest/openAIClient.ts @@ -4,6 +4,9 @@ import { getClient, ClientOptions } from "@typespec/ts-http-runtime"; import { KeyCredential } from "@typespec/ts-http-runtime"; import { OpenAIContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OpenAIContextOptions extends ClientOptions {} + /** * Initialize a new instance of `OpenAIContext` * @param credentials - uniquely identify client credential @@ -11,7 +14,7 @@ import { OpenAIContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: OpenAIContextOptions = {}, ): OpenAIContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://api.openai.com/v1`; @@ -26,7 +29,6 @@ export default function createClient( userAgentPrefix, }, }; - const client = getClient(endpointUrl, options) as OpenAIContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/review/overload_modular.api.md b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/review/overload_modular.api.md index c87e48635f..42cfa301e3 100644 --- a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/review/overload_modular.api.md +++ b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/review/overload_modular.api.md @@ -30,7 +30,7 @@ export interface FooOperationsOperations { getAvatarAsPng: (image: Uint8Array, options?: FooOperationsGetAvatarAsPngOptionalParams) => Promise; } -// @public (undocumented) +// @public export type Versions = "2022-08-30"; // @public (undocumented) diff --git a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/models/models.ts index f6a8c2c70b..81e99759bd 100644 --- a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/models/models.ts @@ -2,5 +2,4 @@ // Licensed under the MIT license. /** The Contoso Widget Manager service version. */ -/** */ export type Versions = "2022-08-30"; diff --git a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/rest/widgetManagerClient.ts b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/rest/widgetManagerClient.ts index c07467b524..f85c3d1cd6 100644 --- a/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/rest/widgetManagerClient.ts +++ b/packages/typespec-test/test/overloads_modular/generated/typespec-ts/src/rest/widgetManagerClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { WidgetManagerContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface WidgetManagerContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `WidgetManagerContext` * @param endpointParam - Supported Widget Services endpoints (protocol and hostname, for example: @@ -16,11 +22,10 @@ import { WidgetManagerContext } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2022-08-30", ...options }: WidgetManagerContextOptions = {}, ): WidgetManagerContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/widget`; - options.apiVersion = options.apiVersion ?? "2022-08-30"; const userAgentInfo = `azsdk-js-overload_modular-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -41,12 +46,28 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key", }, }; - const client = getClient( endpointUrl, credentials, options, ) as WidgetManagerContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/parametrizedHost/generated/typespec-ts/src/rest/parametrizedHostClient.ts b/packages/typespec-test/test/parametrizedHost/generated/typespec-ts/src/rest/parametrizedHostClient.ts index c903781a4a..a0eef34f33 100644 --- a/packages/typespec-test/test/parametrizedHost/generated/typespec-ts/src/rest/parametrizedHostClient.ts +++ b/packages/typespec-test/test/parametrizedHost/generated/typespec-ts/src/rest/parametrizedHostClient.ts @@ -6,10 +6,15 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { ParametrizedHostContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ export interface ParametrizedHostContextOptions extends ClientOptions { + /** A sequence of textual characters. */ host?: string; + /** A sequence of textual characters. */ subdomain?: string; + /** A sequence of textual characters. */ sufix?: string; + /** A sequence of textual characters. */ apiVersion?: string; } @@ -20,17 +25,15 @@ export interface ParametrizedHostContextOptions extends ClientOptions { */ export default function createClient( credentials: TokenCredential, - options: ParametrizedHostContextOptions = {}, + { apiVersion = "v1", ...options }: ParametrizedHostContextOptions = {}, ): ParametrizedHostContext { const host = options.host ?? "one"; const subdomain = options.subdomain ?? "two"; const sufix = options.sufix ?? "three"; - const apiVersion = options.apiVersion ?? "v1"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${host}.${subdomain}.${sufix}.com/${apiVersion}`; - const userAgentInfo = `azsdk-js-parametrized-host-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -50,7 +53,6 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, @@ -58,11 +60,6 @@ export default function createClient( ) as ParametrizedHostContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/review/schema-registry.api.md b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/review/schema-registry.api.md index 26ee3986d4..3fe51648a3 100644 --- a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/review/schema-registry.api.md +++ b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/review/schema-registry.api.md @@ -9,7 +9,7 @@ import { OperationOptions } from '@azure-rest/core-client'; import { Pipeline } from '@azure/core-rest-pipeline'; import { TokenCredential } from '@azure/core-auth'; -// @public (undocumented) +// @public export type ContentTypeEnum = "application/octet-stream" | "application/json; serialization=Avro" | "application/json; serialization=json" | "text/vnd.ms.protobuf"; // @public @@ -47,10 +47,10 @@ export interface Schema { properties: SchemaProperties; } -// @public (undocumented) +// @public export type SchemaContentTypeValues = "application/json; serialization=Avro" | "application/json; serialization=json" | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf"; -// @public (undocumented) +// @public export type SchemaFormat = "Avro" | "Json" | "Custom" | "Protobuf"; // @public @@ -124,7 +124,7 @@ export interface SchemaVersion { readonly schemaVersion: number; } -// @public (undocumented) +// @public export type ServiceApiVersions = "2021-10" | "2022-10" | "2023-07-01"; // (No @packageDocumentation comment for this package) diff --git a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/models/models.ts index c23644e09e..52ce0ea9a0 100644 --- a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/models/models.ts @@ -14,7 +14,6 @@ export interface SchemaVersion { } /** Type of SchemaContentTypeValues */ -/** */ export type SchemaContentTypeValues = | "application/json; serialization=Avro" | "application/json; serialization=json" @@ -36,7 +35,6 @@ export interface SchemaProperties { } /** Represents the format of the schema to be stored by the Schema Registry service. */ -/** */ export type SchemaFormat = "Avro" | "Json" | "Custom" | "Protobuf"; /** The schema content of a schema, along with id and meta properties. */ @@ -48,14 +46,12 @@ export interface Schema { } /** The content type for the schema. */ -/** */ export type ContentTypeEnum = | "application/octet-stream" | "application/json; serialization=Avro" | "application/json; serialization=json" | "text/vnd.ms.protobuf"; /** Represents the Schema Registry API version to use for requests. */ -/** */ export type ServiceApiVersions = "2021-10" | "2022-10" | "2023-07-01"; /** Paged collection of SchemaGroup items */ diff --git a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/rest/schemaRegistryClient.ts b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/rest/schemaRegistryClient.ts index f75b877da4..6132cd7be7 100644 --- a/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/rest/schemaRegistryClient.ts +++ b/packages/typespec-test/test/schemaRegistry/generated/typespec-ts/src/rest/schemaRegistryClient.ts @@ -6,6 +6,12 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { SchemaRegistryContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SchemaRegistryContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `SchemaRegistryContext` * @param fullyQualifiedNamespace - The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'. @@ -15,11 +21,10 @@ import { SchemaRegistryContext } from "./clientDefinitions.js"; export default function createClient( fullyQualifiedNamespace: string, credentials: TokenCredential, - options: ClientOptions = {}, + { apiVersion = "2023-07-01", ...options }: SchemaRegistryContextOptions = {}, ): SchemaRegistryContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${fullyQualifiedNamespace}`; - options.apiVersion = options.apiVersion ?? "2023-07-01"; const userAgentInfo = `azsdk-js-schema-registry-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -39,12 +44,28 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, options, ) as SchemaRegistryContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/review/todo-non-branded.api.md b/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/review/todo-non-branded.api.md index 0e7d87b088..bad1f09509 100644 --- a/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/review/todo-non-branded.api.md +++ b/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/review/todo-non-branded.api.md @@ -14,7 +14,7 @@ import { RequestParameters } from '@typespec/ts-http-runtime'; import { StreamableMethod } from '@typespec/ts-http-runtime'; // @public -function createClient(endpointParam: string, credentials: KeyCredential, options?: ClientOptions): TodoClient; +function createClient(endpointParam: string, credentials: KeyCredential, options?: TodoClientOptions): TodoClient; export default createClient; // @public (undocumented) @@ -52,6 +52,10 @@ export type TodoClient = Client & { path: Routes; }; +// @public +export interface TodoClientOptions extends ClientOptions { +} + // @public (undocumented) export interface TodoFileAttachmentOutput { filename: string; diff --git a/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/src/todoClient.ts b/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/src/todoClient.ts index b78e158915..500d24474f 100644 --- a/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/src/todoClient.ts +++ b/packages/typespec-test/test/todo_non_branded/generated/typespec-ts/src/todoClient.ts @@ -4,6 +4,9 @@ import { getClient, ClientOptions } from "@typespec/ts-http-runtime"; import { KeyCredential } from "@typespec/ts-http-runtime"; import { TodoClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface TodoClientOptions extends ClientOptions {} + /** * Initialize a new instance of `TodoClient` * @param endpointParam - The parameter endpointParam @@ -13,10 +16,9 @@ import { TodoClient } from "./clientDefinitions.js"; export default function createClient( endpointParam: string, credentials: KeyCredential, - options: ClientOptions = {}, + options: TodoClientOptions = {}, ): TodoClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-todo-non-branded-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -28,7 +30,6 @@ export default function createClient( userAgentPrefix, }, }; - const client = getClient(endpointUrl, options) as TodoClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-test/test/translator/generated/typespec-ts/review/cognitiveservices-translator.api.md b/packages/typespec-test/test/translator/generated/typespec-ts/review/cognitiveservices-translator.api.md index 32b0493e0b..8fbcf87aab 100644 --- a/packages/typespec-test/test/translator/generated/typespec-ts/review/cognitiveservices-translator.api.md +++ b/packages/typespec-test/test/translator/generated/typespec-ts/review/cognitiveservices-translator.api.md @@ -109,7 +109,7 @@ export interface CommonScriptModelOutput { } // @public -function createClient(endpointParam: string, options?: ClientOptions): TranslatorClient; +function createClient(endpointParam: string, { apiVersion, ...options }?: TranslatorClientOptions): TranslatorClient; export default createClient; // @public (undocumented) @@ -616,6 +616,11 @@ export type TranslatorClient = Client & { path: Routes; }; +// @public +export interface TranslatorClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface TransliterableScriptOutput extends CommonScriptModelOutput { toScripts: Array; diff --git a/packages/typespec-test/test/translator/generated/typespec-ts/src/translatorClient.ts b/packages/typespec-test/test/translator/generated/typespec-ts/src/translatorClient.ts index 6b7ef367d6..2072e6f398 100644 --- a/packages/typespec-test/test/translator/generated/typespec-ts/src/translatorClient.ts +++ b/packages/typespec-test/test/translator/generated/typespec-ts/src/translatorClient.ts @@ -5,6 +5,12 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { TranslatorClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface TranslatorClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `TranslatorClient` * @param endpointParam - Supported Text Translation endpoints (protocol and hostname, for example: @@ -13,10 +19,9 @@ import { TranslatorClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + { apiVersion = "3.0", ...options }: TranslatorClientOptions = {}, ): TranslatorClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - options.apiVersion = options.apiVersion ?? "3.0"; const userAgentInfo = `azsdk-js-cognitiveservices-translator-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -31,8 +36,24 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as TranslatorClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/review/widget_dpg.api.md b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/review/widget_dpg.api.md index a6fdeaade9..f0461b502c 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/review/widget_dpg.api.md +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/review/widget_dpg.api.md @@ -97,7 +97,7 @@ export interface User { role: string; } -// @public (undocumented) +// @public export type Versions = "1.0.0"; // @public (undocumented) diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/models/models.ts b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/models/models.ts index 5722c21fab..e902e45af6 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/models/models.ts +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/models/models.ts @@ -60,5 +60,4 @@ export interface NonReferencedModel { } /** The Contoso Widget Manager service version. */ -/** */ export type Versions = "1.0.0"; diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/rest/widgetServiceClient.ts b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/rest/widgetServiceClient.ts index e037192643..1a44e090fe 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/rest/widgetServiceClient.ts +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/rest/widgetServiceClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { WidgetServiceContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface WidgetServiceContextOptions extends ClientOptions {} + /** * Initialize a new instance of `WidgetServiceContext` * @param endpointParam - The parameter endpointParam @@ -12,10 +15,9 @@ import { WidgetServiceContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: WidgetServiceContextOptions = {}, ): WidgetServiceContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-widget_dpg-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as WidgetServiceContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/src/modular/emitModels.ts b/packages/typespec-ts/src/modular/emitModels.ts index 8c2cf6989a..a1f0ca5366 100644 --- a/packages/typespec-ts/src/modular/emitModels.ts +++ b/packages/typespec-ts/src/modular/emitModels.ts @@ -99,16 +99,7 @@ function buildEnumModel( return { name: model.name!, isExported: true, - docs: [ - ...getDocsFromDescription(model.description), - // If it is a fixed enum we don't need to list the known values in the docs as the - // output will be a literal union which is self documenting - model.isFixed || !model.isNonExhaustive - ? "" - : // When we generate an "extensible" enum, the type will be "string" or "number" so we list the known values - // in the docs for user reference. - getEnumValues() - ], + docs: [...getDocsFromDescription(model.description)], type: buildEnumType() }; diff --git a/packages/typespec-ts/src/transform/transform.ts b/packages/typespec-ts/src/transform/transform.ts index 46753d19c3..de0c458e27 100644 --- a/packages/typespec-ts/src/transform/transform.ts +++ b/packages/typespec-ts/src/transform/transform.ts @@ -164,11 +164,9 @@ export function transformUrlInfo( if (importedModels.size > 0) { importDetails.rlcClientFactory.importsSet = importedModels; } - let hasApiVersionInUrl = false; if (endpoint && urlParameters.length > 0) { for (const param of urlParameters) { if (param.oriName === "apiVersion") { - hasApiVersionInUrl = true; dpgContext.hasApiVersionInClient = true; } if (param.oriName) { @@ -185,9 +183,10 @@ export function transformUrlInfo( type: "string" }); } - const apiVersionInfo = !hasApiVersionInUrl - ? transformApiVersionInfo(client, dpgContext, { endpoint, urlParameters }) - : undefined; + const apiVersionInfo = transformApiVersionInfo(client, dpgContext, { + endpoint, + urlParameters + }); if ( apiVersionInfo && urlParameters && @@ -196,7 +195,8 @@ export function transformUrlInfo( !apiVersionInfo.defaultValue ) { urlParameters.push({ - name: "api-version", + oriName: "api-version", + name: "apiVersion", type: "string" }); } diff --git a/packages/typespec-ts/src/transform/transformApiVersionInfo.ts b/packages/typespec-ts/src/transform/transformApiVersionInfo.ts index a8c7225f90..dc4739a5e0 100644 --- a/packages/typespec-ts/src/transform/transformApiVersionInfo.ts +++ b/packages/typespec-ts/src/transform/transformApiVersionInfo.ts @@ -29,7 +29,12 @@ export function transformApiVersionInfo( const queryVersionDetail = getOperationApiVersion(client, dpgContext); const pathVersionDetail = extractPathApiVersion(urlInfo); const isCrossedVersion = - pathVersionDetail?.isCrossedVersion || queryVersionDetail?.isCrossedVersion; + queryVersionDetail || pathVersionDetail + ? Boolean( + pathVersionDetail?.isCrossedVersion || + queryVersionDetail?.isCrossedVersion + ) + : undefined; const defaultValue = (pathVersionDetail || queryVersionDetail) && !isCrossedVersion ? getDefaultApiVersionString(dpgContext) ?? @@ -49,7 +54,8 @@ export function transformApiVersionInfo( pathVersionDetail ), isCrossedVersion, - defaultValue + defaultValue, + required: pathVersionDetail?.required ?? queryVersionDetail?.required }; } @@ -59,6 +65,7 @@ export function getOperationApiVersion( ): ApiVersionInfo | undefined { const apiVersionTypes = new Set(); const locations = new Set(); + const required = new Set(); const clientOperations = listOperationsInOperationGroup(dpgContext, client); dpgContext.hasApiVersionInClient = true; let hasApiVersionInOperation = true; @@ -81,6 +88,7 @@ export function getOperationApiVersion( needRef: false, relevantProperty: p.param }); + required.add(!p.param.optional); if (p.type !== "header") { locations.add(p.type); } @@ -121,14 +129,18 @@ export function getOperationApiVersion( needRef: false, relevantProperty: p.param }); + required.add(!p.param.optional); if (p.type !== "header") { locations.add(p.type); } - const typeString = JSON.stringify(trimUsage(type)); apiVersionTypes.add(typeString); }); - if (apiVersionTypes.size > 1 || !dpgContext.hasApiVersionInClient) { + if ( + apiVersionTypes.size > 1 || + !dpgContext.hasApiVersionInClient || + required.size > 1 + ) { break; } if (params.length === 1) { @@ -147,7 +159,8 @@ export function getOperationApiVersion( definedPosition: locations.size > 1 ? "duplicate" : locations.values().next().value, isCrossedVersion: apiVersionTypes.size > 1, - defaultValue: undefined // We won't prompt the query versions into client one + defaultValue: undefined, // We won't prompt the query versions into client one + required: required.values().next().value }; return detail; } diff --git a/packages/typespec-ts/test/integration/generated/authentication/api-key/src/authApiKeyClient.ts b/packages/typespec-ts/test/integration/generated/authentication/api-key/src/authApiKeyClient.ts index d968378717..4ff53b2d5e 100644 --- a/packages/typespec-ts/test/integration/generated/authentication/api-key/src/authApiKeyClient.ts +++ b/packages/typespec-ts/test/integration/generated/authentication/api-key/src/authApiKeyClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AuthApiKeyClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthApiKeyClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AuthApiKeyClient` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { AuthApiKeyClient } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: AuthApiKeyClientOptions = {}, ): AuthApiKeyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -34,7 +37,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "x-ms-api-key", }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/typespec-ts/test/integration/generated/authentication/http/custom/src/authHttpCustomClient.ts b/packages/typespec-ts/test/integration/generated/authentication/http/custom/src/authHttpCustomClient.ts index c1191a3d8e..3b33a3a081 100644 --- a/packages/typespec-ts/test/integration/generated/authentication/http/custom/src/authHttpCustomClient.ts +++ b/packages/typespec-ts/test/integration/generated/authentication/http/custom/src/authHttpCustomClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; import { AuthHttpCustomClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthHttpCustomClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AuthHttpCustomClient` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { AuthHttpCustomClient } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: AuthHttpCustomClientOptions = {}, ): AuthHttpCustomClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -31,7 +34,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AuthHttpCustomClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts b/packages/typespec-ts/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts index f7089f5f79..5d8d37c131 100644 --- a/packages/typespec-ts/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts +++ b/packages/typespec-ts/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { TokenCredential } from "@azure/core-auth"; import { AuthOauth2Client } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthOauth2ClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AuthOauth2Client` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { AuthOauth2Client } from "./clientDefinitions.js"; */ export default function createClient( credentials: TokenCredential, - options: ClientOptions = {}, + options: AuthOauth2ClientOptions = {}, ): AuthOauth2Client { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -36,7 +39,6 @@ export default function createClient( ], }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/typespec-ts/test/integration/generated/authentication/union/src/authUnionClient.ts b/packages/typespec-ts/test/integration/generated/authentication/union/src/authUnionClient.ts index 575ab5dc8a..963db44fef 100644 --- a/packages/typespec-ts/test/integration/generated/authentication/union/src/authUnionClient.ts +++ b/packages/typespec-ts/test/integration/generated/authentication/union/src/authUnionClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { AuthUnionClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AuthUnionClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AuthUnionClient` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { AuthUnionClient } from "./clientDefinitions.js"; */ export default function createClient( credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + options: AuthUnionClientOptions = {}, ): AuthUnionClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -37,7 +40,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "x-ms-api-key", }, }; - const client = getClient( endpointUrl, credentials, diff --git a/packages/typespec-ts/test/integration/generated/azure/client-generator-core/access/src/accessClient.ts b/packages/typespec-ts/test/integration/generated/azure/client-generator-core/access/src/accessClient.ts index f10ba866ce..265e057143 100644 --- a/packages/typespec-ts/test/integration/generated/azure/client-generator-core/access/src/accessClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/client-generator-core/access/src/accessClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { AccessClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AccessClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AccessClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: AccessClientOptions = {}, ): AccessClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AccessClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/azure/client-generator-core/usage/src/usageClient.ts b/packages/typespec-ts/test/integration/generated/azure/client-generator-core/usage/src/usageClient.ts index 7f8b06bf14..fb6e19ac2a 100644 --- a/packages/typespec-ts/test/integration/generated/azure/client-generator-core/usage/src/usageClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/client-generator-core/usage/src/usageClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { UsageClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): UsageClient { +export default function createClient( + options: UsageClientOptions = {}, +): UsageClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-clientGeneratorCore-usage-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): UsageClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UsageClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/basic/src/azureCoreClient.ts b/packages/typespec-ts/test/integration/generated/azure/core/basic/src/azureCoreClient.ts index 3f4fd1fc5e..853a88da02 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/basic/src/azureCoreClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/core/basic/src/azureCoreClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { AzureCoreClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureCoreClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureCoreClient` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): AzureCoreClient { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: AzureCoreClientOptions = {}): AzureCoreClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-azurecore-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AzureCoreClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/integration/generated/azure/core/lro/rpc/src/rpcClient.ts b/packages/typespec-ts/test/integration/generated/azure/core/lro/rpc/src/rpcClient.ts index 93bf644f68..ba1176318b 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/lro/rpc/src/rpcClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/core/lro/rpc/src/rpcClient.ts @@ -5,14 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { RpcClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RpcClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `RpcClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): RpcClient { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: RpcClientOptions = {}): RpcClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-lro-rpc-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -27,8 +35,23 @@ export default function createClient(options: ClientOptions = {}): RpcClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RpcClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/integration/generated/azure/core/lro/standard/src/standardClient.ts b/packages/typespec-ts/test/integration/generated/azure/core/lro/standard/src/standardClient.ts index 53b470b6cb..e002545d18 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/lro/standard/src/standardClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/core/lro/standard/src/standardClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { StandardClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface StandardClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `StandardClient` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): StandardClient { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: StandardClientOptions = {}): StandardClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-lro-core-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as StandardClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/integration/generated/azure/core/scalar/src/azureCoreScalarClient.ts b/packages/typespec-ts/test/integration/generated/azure/core/scalar/src/azureCoreScalarClient.ts index e5bb4d1816..628cb9d3f8 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/scalar/src/azureCoreScalarClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/core/scalar/src/azureCoreScalarClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { AzureCoreScalarClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureCoreScalarClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AzureCoreScalarClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: AzureCoreScalarClientOptions = {}, ): AzureCoreScalarClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AzureCoreScalarClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/traits/src/azureCoreTraitsClient.ts b/packages/typespec-ts/test/integration/generated/azure/core/traits/src/azureCoreTraitsClient.ts index e5f8a4c148..5f5c9c2ba0 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/traits/src/azureCoreTraitsClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/core/traits/src/azureCoreTraitsClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { AzureCoreTraitsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AzureCoreTraitsClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `AzureCoreTraitsClient` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): AzureCoreTraitsClient { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: AzureCoreTraitsClientOptions = {}): AzureCoreTraitsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-azurecoretraits-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AzureCoreTraitsClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/integration/generated/azure/special-headers/client-request-id/src/xmsClientRequestIdClient.ts b/packages/typespec-ts/test/integration/generated/azure/special-headers/client-request-id/src/xmsClientRequestIdClient.ts index 5b42a951e5..1535fa8b0f 100644 --- a/packages/typespec-ts/test/integration/generated/azure/special-headers/client-request-id/src/xmsClientRequestIdClient.ts +++ b/packages/typespec-ts/test/integration/generated/azure/special-headers/client-request-id/src/xmsClientRequestIdClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { XmsClientRequestIdClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface XmsClientRequestIdClientOptions extends ClientOptions {} + /** * Initialize a new instance of `XmsClientRequestIdClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: XmsClientRequestIdClientOptions = {}, ): XmsClientRequestIdClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as XmsClientRequestIdClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/client/naming/src/namingClient.ts b/packages/typespec-ts/test/integration/generated/client/naming/src/namingClient.ts index e01dd4506b..7c606a6bcb 100644 --- a/packages/typespec-ts/test/integration/generated/client/naming/src/namingClient.ts +++ b/packages/typespec-ts/test/integration/generated/client/naming/src/namingClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NamingClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NamingClientOptions extends ClientOptions {} + /** * Initialize a new instance of `NamingClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NamingClientOptions = {}, ): NamingClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NamingClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/client/structure/default/src/serviceClient.ts b/packages/typespec-ts/test/integration/generated/client/structure/default/src/serviceClient.ts index 457dc5d230..1dddd3ca10 100644 --- a/packages/typespec-ts/test/integration/generated/client/structure/default/src/serviceClient.ts +++ b/packages/typespec-ts/test/integration/generated/client/structure/default/src/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { ServiceClient } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceClientOptions = {}, ): ServiceClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-default-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/client/structure/multi-client/src/serviceClient.ts b/packages/typespec-ts/test/integration/generated/client/structure/multi-client/src/serviceClient.ts index d67c6c484d..ec042329dc 100644 --- a/packages/typespec-ts/test/integration/generated/client/structure/multi-client/src/serviceClient.ts +++ b/packages/typespec-ts/test/integration/generated/client/structure/multi-client/src/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { ServiceClient } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceClientOptions = {}, ): ServiceClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-multiclient-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/client/structure/renamed-operation/src/serviceClient.ts b/packages/typespec-ts/test/integration/generated/client/structure/renamed-operation/src/serviceClient.ts index 0af7e2092b..6568d46789 100644 --- a/packages/typespec-ts/test/integration/generated/client/structure/renamed-operation/src/serviceClient.ts +++ b/packages/typespec-ts/test/integration/generated/client/structure/renamed-operation/src/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { ServiceClient } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceClientOptions = {}, ): ServiceClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-renamed-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/client/structure/two-operation-group/src/serviceClient.ts b/packages/typespec-ts/test/integration/generated/client/structure/two-operation-group/src/serviceClient.ts index 14a8ff876e..e9b1a6abfe 100644 --- a/packages/typespec-ts/test/integration/generated/client/structure/two-operation-group/src/serviceClient.ts +++ b/packages/typespec-ts/test/integration/generated/client/structure/two-operation-group/src/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { ServiceClient } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceClientOptions = {}, ): ServiceClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-twoopgroup-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/encode/bytes/src/bytesClient.ts b/packages/typespec-ts/test/integration/generated/encode/bytes/src/bytesClient.ts index b020dcf746..7ea470b45c 100644 --- a/packages/typespec-ts/test/integration/generated/encode/bytes/src/bytesClient.ts +++ b/packages/typespec-ts/test/integration/generated/encode/bytes/src/bytesClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { BytesClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BytesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BytesClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): BytesClient { +export default function createClient( + options: BytesClientOptions = {}, +): BytesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-encode-bytes-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): BytesClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BytesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/encode/datetime/src/datetimeClient.ts b/packages/typespec-ts/test/integration/generated/encode/datetime/src/datetimeClient.ts index fb735a777d..eccae1cf5e 100644 --- a/packages/typespec-ts/test/integration/generated/encode/datetime/src/datetimeClient.ts +++ b/packages/typespec-ts/test/integration/generated/encode/datetime/src/datetimeClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { DatetimeClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface DatetimeClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DatetimeClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: DatetimeClientOptions = {}, ): DatetimeClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DatetimeClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/encode/duration/src/durationClient.ts b/packages/typespec-ts/test/integration/generated/encode/duration/src/durationClient.ts index 982ef1670f..f3031c5135 100644 --- a/packages/typespec-ts/test/integration/generated/encode/duration/src/durationClient.ts +++ b/packages/typespec-ts/test/integration/generated/encode/duration/src/durationClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { DurationClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface DurationClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DurationClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: DurationClientOptions = {}, ): DurationClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DurationClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/media-types/src/mediaTypesClient.ts b/packages/typespec-ts/test/integration/generated/media-types/src/mediaTypesClient.ts index d3f418ba0b..7d1a9e8dff 100644 --- a/packages/typespec-ts/test/integration/generated/media-types/src/mediaTypesClient.ts +++ b/packages/typespec-ts/test/integration/generated/media-types/src/mediaTypesClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { MediaTypesClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface MediaTypesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MediaTypesClient` * @param $host - A sequence of textual characters. @@ -12,10 +15,9 @@ import { MediaTypesClient } from "./clientDefinitions.js"; */ export default function createClient( $host: string, - options: ClientOptions = {}, + options: MediaTypesClientOptions = {}, ): MediaTypesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${$host}`; - const userAgentInfo = `azsdk-js-media-types-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MediaTypesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/overload/src/overalodClient.ts b/packages/typespec-ts/test/integration/generated/overload/src/overalodClient.ts index 3dd5d33bdc..7b5693b016 100644 --- a/packages/typespec-ts/test/integration/generated/overload/src/overalodClient.ts +++ b/packages/typespec-ts/test/integration/generated/overload/src/overalodClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { OveralodClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OveralodClientOptions extends ClientOptions {} + /** * Initialize a new instance of `OveralodClient` * @param $host - A sequence of textual characters. @@ -12,10 +15,9 @@ import { OveralodClient } from "./clientDefinitions.js"; */ export default function createClient( $host: string, - options: ClientOptions = {}, + options: OveralodClientOptions = {}, ): OveralodClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${$host}`; - const userAgentInfo = `azsdk-js-media-types-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as OveralodClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/parameters/basic/src/basicClient.ts b/packages/typespec-ts/test/integration/generated/parameters/basic/src/basicClient.ts index e9fdedc7e8..ba530c7045 100644 --- a/packages/typespec-ts/test/integration/generated/parameters/basic/src/basicClient.ts +++ b/packages/typespec-ts/test/integration/generated/parameters/basic/src/basicClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { BasicClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BasicClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BasicClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): BasicClient { +export default function createClient( + options: BasicClientOptions = {}, +): BasicClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-parameterBasic-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): BasicClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BasicClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/parameters/body-optionality/src/bodyOptionalityClient.ts b/packages/typespec-ts/test/integration/generated/parameters/body-optionality/src/bodyOptionalityClient.ts index ee16a02afe..d7dc31a130 100644 --- a/packages/typespec-ts/test/integration/generated/parameters/body-optionality/src/bodyOptionalityClient.ts +++ b/packages/typespec-ts/test/integration/generated/parameters/body-optionality/src/bodyOptionalityClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { BodyOptionalityClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BodyOptionalityClientOptions extends ClientOptions {} + /** * Initialize a new instance of `BodyOptionalityClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BodyOptionalityClientOptions = {}, ): BodyOptionalityClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyOptionalityClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts b/packages/typespec-ts/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts index c1e272de89..fcfa226c8d 100644 --- a/packages/typespec-ts/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts +++ b/packages/typespec-ts/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { CollectionFormatClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface CollectionFormatClientOptions extends ClientOptions {} + /** * Initialize a new instance of `CollectionFormatClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: CollectionFormatClientOptions = {}, ): CollectionFormatClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as CollectionFormatClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/parameters/spread/src/spreadClient.ts b/packages/typespec-ts/test/integration/generated/parameters/spread/src/spreadClient.ts index 1b1b59ac72..6d6f3093b5 100644 --- a/packages/typespec-ts/test/integration/generated/parameters/spread/src/spreadClient.ts +++ b/packages/typespec-ts/test/integration/generated/parameters/spread/src/spreadClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SpreadClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SpreadClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SpreadClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SpreadClientOptions = {}, ): SpreadClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SpreadClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/payload/content-negotiation/src/contentNegotiationClient.ts b/packages/typespec-ts/test/integration/generated/payload/content-negotiation/src/contentNegotiationClient.ts index a516f2a226..84f55d3bce 100644 --- a/packages/typespec-ts/test/integration/generated/payload/content-negotiation/src/contentNegotiationClient.ts +++ b/packages/typespec-ts/test/integration/generated/payload/content-negotiation/src/contentNegotiationClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ContentNegotiationClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ContentNegotiationClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ContentNegotiationClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ContentNegotiationClientOptions = {}, ): ContentNegotiationClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ContentNegotiationClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/payload/media-type/src/mediaTypeClient.ts b/packages/typespec-ts/test/integration/generated/payload/media-type/src/mediaTypeClient.ts index 6fe90aabaf..18cbf36079 100644 --- a/packages/typespec-ts/test/integration/generated/payload/media-type/src/mediaTypeClient.ts +++ b/packages/typespec-ts/test/integration/generated/payload/media-type/src/mediaTypeClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { MediaTypeClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface MediaTypeClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MediaTypeClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: MediaTypeClientOptions = {}, ): MediaTypeClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MediaTypeClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/payload/multipart/src/multiPartClient.ts b/packages/typespec-ts/test/integration/generated/payload/multipart/src/multiPartClient.ts index 6b4ceeead6..5622f84d9a 100644 --- a/packages/typespec-ts/test/integration/generated/payload/multipart/src/multiPartClient.ts +++ b/packages/typespec-ts/test/integration/generated/payload/multipart/src/multiPartClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { MultiPartClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface MultiPartClientOptions extends ClientOptions {} + /** * Initialize a new instance of `MultiPartClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: MultiPartClientOptions = {}, ): MultiPartClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MultiPartClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/payload/pageable/src/pageableClient.ts b/packages/typespec-ts/test/integration/generated/payload/pageable/src/pageableClient.ts index 477ea6121b..630fb5dd40 100644 --- a/packages/typespec-ts/test/integration/generated/payload/pageable/src/pageableClient.ts +++ b/packages/typespec-ts/test/integration/generated/payload/pageable/src/pageableClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { PageableClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface PageableClientOptions extends ClientOptions {} + /** * Initialize a new instance of `PageableClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: PageableClientOptions = {}, ): PageableClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as PageableClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-main/src/serviceDrivenNewClient.ts b/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-main/src/serviceDrivenNewClient.ts index e9066ec7ca..2b86ece61d 100644 --- a/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-main/src/serviceDrivenNewClient.ts +++ b/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-main/src/serviceDrivenNewClient.ts @@ -5,7 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ServiceDrivenNewClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ export interface ServiceDrivenNewClientOptions extends ClientOptions { + /** Pass in either 'v1' or 'v2'. This represents the API version of a service. */ apiVersion?: string; } @@ -18,14 +20,12 @@ export interface ServiceDrivenNewClientOptions extends ClientOptions { export default function createClient( endpointParam: string, serviceDeploymentVersion: string, - options: ServiceDrivenNewClientOptions = {}, + { apiVersion = "v2", ...options }: ServiceDrivenNewClientOptions = {}, ): ServiceDrivenNewClient { - const apiVersion = options.apiVersion ?? "v2"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/resiliency/service-driven/client:v2/service:${serviceDeploymentVersion}/api-version:${apiVersion}`; - const userAgentInfo = `azsdk-js-srv-driven-main-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -40,15 +40,9 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceDrivenNewClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-old/src/serviceDrivenOldClient.ts b/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-old/src/serviceDrivenOldClient.ts index ec29fe5a81..6a93efb38d 100644 --- a/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-old/src/serviceDrivenOldClient.ts +++ b/packages/typespec-ts/test/integration/generated/resiliency/srv-driven-old/src/serviceDrivenOldClient.ts @@ -5,7 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ServiceDrivenOldClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ export interface ServiceDrivenOldClientOptions extends ClientOptions { + /** Pass in 'v1'. This represents the API version of the service. Will grow up in the next deployment to be both 'v1' and 'v2' */ apiVersion?: string; } @@ -18,14 +20,12 @@ export interface ServiceDrivenOldClientOptions extends ClientOptions { export default function createClient( endpointParam: string, serviceDeploymentVersion: string, - options: ServiceDrivenOldClientOptions = {}, + { apiVersion = "v1", ...options }: ServiceDrivenOldClientOptions = {}, ): ServiceDrivenOldClient { - const apiVersion = options.apiVersion ?? "v1"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/resiliency/service-driven/client:v1/service:${serviceDeploymentVersion}/api-version:${apiVersion}`; - const userAgentInfo = `azsdk-js-srv-driven-old-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -40,15 +40,9 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceDrivenOldClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-ts/test/integration/generated/serialization/encoded-name/json/src/serializationEncodedNameJsonClient.ts b/packages/typespec-ts/test/integration/generated/serialization/encoded-name/json/src/serializationEncodedNameJsonClient.ts index 1f7a5eb884..b1d77204e4 100644 --- a/packages/typespec-ts/test/integration/generated/serialization/encoded-name/json/src/serializationEncodedNameJsonClient.ts +++ b/packages/typespec-ts/test/integration/generated/serialization/encoded-name/json/src/serializationEncodedNameJsonClient.ts @@ -5,12 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SerializationEncodedNameJsonClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SerializationEncodedNameJsonClientOptions + extends ClientOptions {} + /** * Initialize a new instance of `SerializationEncodedNameJsonClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SerializationEncodedNameJsonClientOptions = {}, ): SerializationEncodedNameJsonClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/server/endpoint/not-defined/src/notDefinedParamInServerEndpointClient.ts b/packages/typespec-ts/test/integration/generated/server/endpoint/not-defined/src/notDefinedParamInServerEndpointClient.ts index 4f3444010a..bbcea117d4 100644 --- a/packages/typespec-ts/test/integration/generated/server/endpoint/not-defined/src/notDefinedParamInServerEndpointClient.ts +++ b/packages/typespec-ts/test/integration/generated/server/endpoint/not-defined/src/notDefinedParamInServerEndpointClient.ts @@ -5,6 +5,10 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NotDefinedParamInServerEndpointClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotDefinedParamInServerEndpointClientOptions + extends ClientOptions {} + /** * Initialize a new instance of `NotDefinedParamInServerEndpointClient` * @param endpointParam - The parameter endpointParam @@ -12,10 +16,9 @@ import { NotDefinedParamInServerEndpointClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: NotDefinedParamInServerEndpointClientOptions = {}, ): NotDefinedParamInServerEndpointClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-notdefinedparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +33,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts b/packages/typespec-ts/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts index 9f2ce47c31..21d2dcc99a 100644 --- a/packages/typespec-ts/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts +++ b/packages/typespec-ts/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts @@ -6,7 +6,9 @@ import { logger } from "./logger.js"; import { MultipleParamInServerPathClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ export interface MultipleParamInServerPathClientOptions extends ClientOptions { + /** Pass in v1.0 for API version. */ apiVersion?: Versions; } @@ -17,14 +19,15 @@ export interface MultipleParamInServerPathClientOptions extends ClientOptions { */ export default function createClient( endpointParam: string, - options: MultipleParamInServerPathClientOptions = {}, + { + apiVersion = "v1.0", + ...options + }: MultipleParamInServerPathClientOptions = {}, ): MultipleParamInServerPathClient { - const apiVersion = options.apiVersion ?? "v1.0"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/server/path/multiple/${apiVersion}`; - const userAgentInfo = `azsdk-js-multipleparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -39,18 +42,12 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, ) as MultipleParamInServerPathClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-ts/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts b/packages/typespec-ts/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts index 4b5a366503..a7d3d2c657 100644 --- a/packages/typespec-ts/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts +++ b/packages/typespec-ts/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SingleParamInServerPathClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SingleParamInServerPathClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SingleParamInServerPathClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +15,9 @@ import { SingleParamInServerPathClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: SingleParamInServerPathClientOptions = {}, ): SingleParamInServerPathClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-singleparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/server/versions/not-versioned/src/notVersionedParamInServerVersionsClient.ts b/packages/typespec-ts/test/integration/generated/server/versions/not-versioned/src/notVersionedParamInServerVersionsClient.ts index 3c06243829..e9df441ba0 100644 --- a/packages/typespec-ts/test/integration/generated/server/versions/not-versioned/src/notVersionedParamInServerVersionsClient.ts +++ b/packages/typespec-ts/test/integration/generated/server/versions/not-versioned/src/notVersionedParamInServerVersionsClient.ts @@ -5,6 +5,10 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NotVersionedParamInServerVersionsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotVersionedParamInServerVersionsClientOptions + extends ClientOptions {} + /** * Initialize a new instance of `NotVersionedParamInServerVersionsClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +16,9 @@ import { NotVersionedParamInServerVersionsClient } from "./clientDefinitions.js" */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: NotVersionedParamInServerVersionsClientOptions = {}, ): NotVersionedParamInServerVersionsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-not-versioned-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +33,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/server/versions/versioned/src/versionedParamInServerVersionsClient.ts b/packages/typespec-ts/test/integration/generated/server/versions/versioned/src/versionedParamInServerVersionsClient.ts index 9d560734e3..9f8dae7cac 100644 --- a/packages/typespec-ts/test/integration/generated/server/versions/versioned/src/versionedParamInServerVersionsClient.ts +++ b/packages/typespec-ts/test/integration/generated/server/versions/versioned/src/versionedParamInServerVersionsClient.ts @@ -5,6 +5,10 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { VersionedParamInServerVersionsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface VersionedParamInServerVersionsClientOptions + extends ClientOptions {} + /** * Initialize a new instance of `VersionedParamInServerVersionsClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +16,9 @@ import { VersionedParamInServerVersionsClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: VersionedParamInServerVersionsClientOptions = {}, ): VersionedParamInServerVersionsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-versioned-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +33,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/shared-route/src/sharedRouteClient.ts b/packages/typespec-ts/test/integration/generated/shared-route/src/sharedRouteClient.ts index 7eb8d7f6b5..958a1c74e1 100644 --- a/packages/typespec-ts/test/integration/generated/shared-route/src/sharedRouteClient.ts +++ b/packages/typespec-ts/test/integration/generated/shared-route/src/sharedRouteClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SharedRouteClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SharedRouteClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SharedRouteClient` * @param $host - A sequence of textual characters. @@ -12,10 +15,9 @@ import { SharedRouteClient } from "./clientDefinitions.js"; */ export default function createClient( $host: string, - options: ClientOptions = {}, + options: SharedRouteClientOptions = {}, ): SharedRouteClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${$host}`; - const userAgentInfo = `azsdk-js-media-types-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SharedRouteClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/special-headers/repeatability/src/repeatabilityClient.ts b/packages/typespec-ts/test/integration/generated/special-headers/repeatability/src/repeatabilityClient.ts index c693610ef6..37a3c08a51 100644 --- a/packages/typespec-ts/test/integration/generated/special-headers/repeatability/src/repeatabilityClient.ts +++ b/packages/typespec-ts/test/integration/generated/special-headers/repeatability/src/repeatabilityClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { RepeatabilityClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RepeatabilityClientOptions extends ClientOptions {} + /** * Initialize a new instance of `RepeatabilityClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: RepeatabilityClientOptions = {}, ): RepeatabilityClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RepeatabilityClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/special-words/src/specialWordsClient.ts b/packages/typespec-ts/test/integration/generated/special-words/src/specialWordsClient.ts index 2453710353..137f5e085f 100644 --- a/packages/typespec-ts/test/integration/generated/special-words/src/specialWordsClient.ts +++ b/packages/typespec-ts/test/integration/generated/special-words/src/specialWordsClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SpecialWordsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SpecialWordsClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SpecialWordsClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SpecialWordsClientOptions = {}, ): SpecialWordsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SpecialWordsClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/array/src/arrayItemTypesClient.ts b/packages/typespec-ts/test/integration/generated/type/array/src/arrayItemTypesClient.ts index 0836bf5828..871c3ed297 100644 --- a/packages/typespec-ts/test/integration/generated/type/array/src/arrayItemTypesClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/array/src/arrayItemTypesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ArrayItemTypesClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ArrayItemTypesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ArrayItemTypesClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ArrayItemTypesClientOptions = {}, ): ArrayItemTypesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ArrayItemTypesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/dictionary/src/dictClient.ts b/packages/typespec-ts/test/integration/generated/type/dictionary/src/dictClient.ts index a2ac343f4e..0668650e86 100644 --- a/packages/typespec-ts/test/integration/generated/type/dictionary/src/dictClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/dictionary/src/dictClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { DictClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface DictClientOptions extends ClientOptions {} + /** * Initialize a new instance of `DictClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): DictClient { +export default function createClient( + options: DictClientOptions = {}, +): DictClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-dictionary-rest/1.0.0`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): DictClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DictClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/enum/extensible/src/extensibleClient.ts b/packages/typespec-ts/test/integration/generated/type/enum/extensible/src/extensibleClient.ts index 23ec841338..b91b6bec4a 100644 --- a/packages/typespec-ts/test/integration/generated/type/enum/extensible/src/extensibleClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/enum/extensible/src/extensibleClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ExtensibleClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ExtensibleClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ExtensibleClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ExtensibleClientOptions = {}, ): ExtensibleClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ExtensibleClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/enum/fixed/src/fixedClient.ts b/packages/typespec-ts/test/integration/generated/type/enum/fixed/src/fixedClient.ts index 00c34fcbb2..aedba809be 100644 --- a/packages/typespec-ts/test/integration/generated/type/enum/fixed/src/fixedClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/enum/fixed/src/fixedClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { FixedClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface FixedClientOptions extends ClientOptions {} + /** * Initialize a new instance of `FixedClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): FixedClient { +export default function createClient( + options: FixedClientOptions = {}, +): FixedClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-extensible-fixed-rest/1.0.0`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): FixedClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as FixedClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/empty/src/emptyClient.ts b/packages/typespec-ts/test/integration/generated/type/model/empty/src/emptyClient.ts index be8a9c6419..65d1ecd4d4 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/empty/src/emptyClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/empty/src/emptyClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { EmptyClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface EmptyClientOptions extends ClientOptions {} + /** * Initialize a new instance of `EmptyClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): EmptyClient { +export default function createClient( + options: EmptyClientOptions = {}, +): EmptyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-empty-model-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): EmptyClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as EmptyClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/flatten/src/flattenClient.ts b/packages/typespec-ts/test/integration/generated/type/model/flatten/src/flattenClient.ts index f928ee06cf..d611d76f11 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/flatten/src/flattenClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/flatten/src/flattenClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { FlattenClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface FlattenClientOptions extends ClientOptions {} + /** * Initialize a new instance of `FlattenClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: FlattenClientOptions = {}, ): FlattenClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as FlattenClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/inheritance/enum-discriminator/src/enumDiscriminatorClient.ts b/packages/typespec-ts/test/integration/generated/type/model/inheritance/enum-discriminator/src/enumDiscriminatorClient.ts index dd1b60d5f8..f74f411b6a 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/inheritance/enum-discriminator/src/enumDiscriminatorClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/inheritance/enum-discriminator/src/enumDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { EnumDiscriminatorClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface EnumDiscriminatorClientOptions extends ClientOptions {} + /** * Initialize a new instance of `EnumDiscriminatorClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: EnumDiscriminatorClientOptions = {}, ): EnumDiscriminatorClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as EnumDiscriminatorClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/inheritance/nested-discriminator/src/nestedDiscriminatorClient.ts b/packages/typespec-ts/test/integration/generated/type/model/inheritance/nested-discriminator/src/nestedDiscriminatorClient.ts index 69ca55c540..c835bb5081 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/inheritance/nested-discriminator/src/nestedDiscriminatorClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/inheritance/nested-discriminator/src/nestedDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NestedDiscriminatorClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NestedDiscriminatorClientOptions extends ClientOptions {} + /** * Initialize a new instance of `NestedDiscriminatorClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NestedDiscriminatorClientOptions = {}, ): NestedDiscriminatorClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NestedDiscriminatorClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/inheritance/not-discriminated/src/notDiscriminatedClient.ts b/packages/typespec-ts/test/integration/generated/type/model/inheritance/not-discriminated/src/notDiscriminatedClient.ts index 8dad8ca81d..1464424179 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/inheritance/not-discriminated/src/notDiscriminatedClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/inheritance/not-discriminated/src/notDiscriminatedClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NotDiscriminatedClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotDiscriminatedClientOptions extends ClientOptions {} + /** * Initialize a new instance of `NotDiscriminatedClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NotDiscriminatedClientOptions = {}, ): NotDiscriminatedClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NotDiscriminatedClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/inheritance/recursive/src/recursiveClient.ts b/packages/typespec-ts/test/integration/generated/type/model/inheritance/recursive/src/recursiveClient.ts index 9a7a5076e0..0811167883 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/inheritance/recursive/src/recursiveClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/inheritance/recursive/src/recursiveClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { RecursiveClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RecursiveClientOptions extends ClientOptions {} + /** * Initialize a new instance of `RecursiveClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: RecursiveClientOptions = {}, ): RecursiveClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RecursiveClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/inheritance/single-discriminator/src/singleDiscriminatorClient.ts b/packages/typespec-ts/test/integration/generated/type/model/inheritance/single-discriminator/src/singleDiscriminatorClient.ts index 5a6402bb47..86ac38e583 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/inheritance/single-discriminator/src/singleDiscriminatorClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/inheritance/single-discriminator/src/singleDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { SingleDiscriminatorClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SingleDiscriminatorClientOptions extends ClientOptions {} + /** * Initialize a new instance of `SingleDiscriminatorClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SingleDiscriminatorClientOptions = {}, ): SingleDiscriminatorClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SingleDiscriminatorClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/usage/src/usageClient.ts b/packages/typespec-ts/test/integration/generated/type/model/usage/src/usageClient.ts index bd9bdee5d5..6ea7957b7b 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/usage/src/usageClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/usage/src/usageClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { UsageClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): UsageClient { +export default function createClient( + options: UsageClientOptions = {}, +): UsageClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-usage-rest/1.0.0`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): UsageClient { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UsageClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/model/visibility/src/visibilityClient.ts b/packages/typespec-ts/test/integration/generated/type/model/visibility/src/visibilityClient.ts index 1ceb38e3ee..2f6761f542 100644 --- a/packages/typespec-ts/test/integration/generated/type/model/visibility/src/visibilityClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/model/visibility/src/visibilityClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { VisibilityClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface VisibilityClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VisibilityClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: VisibilityClientOptions = {}, ): VisibilityClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as VisibilityClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/property/additional-properties/src/additionalPropertiesClient.ts b/packages/typespec-ts/test/integration/generated/type/property/additional-properties/src/additionalPropertiesClient.ts index 1bb6d167d0..05eaa5deb8 100644 --- a/packages/typespec-ts/test/integration/generated/type/property/additional-properties/src/additionalPropertiesClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/property/additional-properties/src/additionalPropertiesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { AdditionalPropertiesClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AdditionalPropertiesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `AdditionalPropertiesClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: AdditionalPropertiesClientOptions = {}, ): AdditionalPropertiesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AdditionalPropertiesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/property/nullable/src/nullableClient.ts b/packages/typespec-ts/test/integration/generated/type/property/nullable/src/nullableClient.ts index 207971503d..61c507b9c1 100644 --- a/packages/typespec-ts/test/integration/generated/type/property/nullable/src/nullableClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/property/nullable/src/nullableClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { NullableClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NullableClientOptions extends ClientOptions {} + /** * Initialize a new instance of `NullableClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NullableClientOptions = {}, ): NullableClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NullableClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/property/optionality/src/optionalClient.ts b/packages/typespec-ts/test/integration/generated/type/property/optionality/src/optionalClient.ts index 0cf2a2a473..579516a525 100644 --- a/packages/typespec-ts/test/integration/generated/type/property/optionality/src/optionalClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/property/optionality/src/optionalClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { OptionalClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OptionalClientOptions extends ClientOptions {} + /** * Initialize a new instance of `OptionalClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: OptionalClientOptions = {}, ): OptionalClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as OptionalClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/property/value-types/src/valueTypesClient.ts b/packages/typespec-ts/test/integration/generated/type/property/value-types/src/valueTypesClient.ts index 7c7526ab19..7017bc3875 100644 --- a/packages/typespec-ts/test/integration/generated/type/property/value-types/src/valueTypesClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/property/value-types/src/valueTypesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ValueTypesClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ValueTypesClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ValueTypesClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ValueTypesClientOptions = {}, ): ValueTypesClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ValueTypesClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/scalar/src/scalarClient.ts b/packages/typespec-ts/test/integration/generated/type/scalar/src/scalarClient.ts index 1ac1118554..d60a8fc7ef 100644 --- a/packages/typespec-ts/test/integration/generated/type/scalar/src/scalarClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/scalar/src/scalarClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { ScalarClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ScalarClientOptions extends ClientOptions {} + /** * Initialize a new instance of `ScalarClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ScalarClientOptions = {}, ): ScalarClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ScalarClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/type/union/src/unionsClient.ts b/packages/typespec-ts/test/integration/generated/type/union/src/unionsClient.ts index b36244e9a8..91a8d6c517 100644 --- a/packages/typespec-ts/test/integration/generated/type/union/src/unionsClient.ts +++ b/packages/typespec-ts/test/integration/generated/type/union/src/unionsClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { UnionsClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UnionsClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UnionsClient` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UnionsClientOptions = {}, ): UnionsClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UnionsClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/union-body/src/unionBodyClient.ts b/packages/typespec-ts/test/integration/generated/union-body/src/unionBodyClient.ts index 81096dc5f8..9394c4032b 100644 --- a/packages/typespec-ts/test/integration/generated/union-body/src/unionBodyClient.ts +++ b/packages/typespec-ts/test/integration/generated/union-body/src/unionBodyClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { UnionBodyClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UnionBodyClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UnionBodyClient` * @param endpointParam - The parameter endpointParam @@ -12,10 +15,9 @@ import { UnionBodyClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: UnionBodyClientOptions = {}, ): UnionBodyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-union-body-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UnionBodyClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/versioning/added/src/versioningAddedClient.ts b/packages/typespec-ts/test/integration/generated/versioning/added/src/versioningAddedClient.ts index a88e876f42..a1f715aebb 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/added/src/versioningAddedClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/added/src/versioningAddedClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { VersioningAddedClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningAddedClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VersioningAddedClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningAddedClientOptions = {}, ): VersioningAddedClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/added/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-added-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as VersioningAddedClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/versioning/madeOptional/src/versioningMadeOptionalClient.ts b/packages/typespec-ts/test/integration/generated/versioning/madeOptional/src/versioningMadeOptionalClient.ts index 057f3dd708..1892abf4ec 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/madeOptional/src/versioningMadeOptionalClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/madeOptional/src/versioningMadeOptionalClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { VersioningMadeOptionalClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningMadeOptionalClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VersioningMadeOptionalClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningMadeOptionalClientOptions = {}, ): VersioningMadeOptionalClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/made-optional/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-madeOptional-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/versioning/removed/src/versioningRemovedClient.ts b/packages/typespec-ts/test/integration/generated/versioning/removed/src/versioningRemovedClient.ts index 0fddcd0f51..3f25dbed4e 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/removed/src/versioningRemovedClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/removed/src/versioningRemovedClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { VersioningRemovedClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningRemovedClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VersioningRemovedClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningRemovedClientOptions = {}, ): VersioningRemovedClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/removed/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-removed-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as VersioningRemovedClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/versioning/renamedFrom/src/versioningRenamedFromClient.ts b/packages/typespec-ts/test/integration/generated/versioning/renamedFrom/src/versioningRenamedFromClient.ts index 9637103fa0..015c5c4a61 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/renamedFrom/src/versioningRenamedFromClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/renamedFrom/src/versioningRenamedFromClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { VersioningRenamedFromClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningRenamedFromClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VersioningRenamedFromClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningRenamedFromClientOptions = {}, ): VersioningRenamedFromClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/renamed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-renamedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as VersioningRenamedFromClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/integration/generated/versioning/returnTypeChangedFrom/src/versioningReturnTypeChangedFromClient.ts b/packages/typespec-ts/test/integration/generated/versioning/returnTypeChangedFrom/src/versioningReturnTypeChangedFromClient.ts index 5a5daf0ed6..6a25068d01 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/returnTypeChangedFrom/src/versioningReturnTypeChangedFromClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/returnTypeChangedFrom/src/versioningReturnTypeChangedFromClient.ts @@ -6,6 +6,10 @@ import { logger } from "./logger.js"; import { VersioningReturnTypeChangedFromClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningReturnTypeChangedFromClientOptions + extends ClientOptions {} + /** * Initialize a new instance of `VersioningReturnTypeChangedFromClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +19,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningReturnTypeChangedFromClientOptions = {}, ): VersioningReturnTypeChangedFromClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/return-type-changed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-returnTypeChangedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +39,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/integration/generated/versioning/typeChangedFrom/src/versioningTypeChangedFromClient.ts b/packages/typespec-ts/test/integration/generated/versioning/typeChangedFrom/src/versioningTypeChangedFromClient.ts index 1629fe6e1f..0523813e57 100644 --- a/packages/typespec-ts/test/integration/generated/versioning/typeChangedFrom/src/versioningTypeChangedFromClient.ts +++ b/packages/typespec-ts/test/integration/generated/versioning/typeChangedFrom/src/versioningTypeChangedFromClient.ts @@ -6,6 +6,9 @@ import { logger } from "./logger.js"; import { VersioningTypeChangedFromClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface VersioningTypeChangedFromClientOptions extends ClientOptions {} + /** * Initialize a new instance of `VersioningTypeChangedFromClient` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: VersioningTypeChangedFromClientOptions = {}, ): VersioningTypeChangedFromClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/type-changed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versioning-typeChangedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/modularIntegration/generated/authentication/api-key/src/rest/apiKeyClient.ts b/packages/typespec-ts/test/modularIntegration/generated/authentication/api-key/src/rest/apiKeyClient.ts index 027e7918ab..aab53b8639 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/authentication/api-key/src/rest/apiKeyClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/authentication/api-key/src/rest/apiKeyClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { KeyCredential } from "@azure/core-auth"; import { ApiKeyContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ApiKeyContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ApiKeyContext` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { ApiKeyContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: ApiKeyContextOptions = {}, ): ApiKeyContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -34,7 +37,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "x-ms-api-key", }, }; - const client = getClient(endpointUrl, credentials, options) as ApiKeyContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/authentication/http/custom/src/rest/customClient.ts b/packages/typespec-ts/test/modularIntegration/generated/authentication/http/custom/src/rest/customClient.ts index fcefa80f01..b5d2440cd1 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/authentication/http/custom/src/rest/customClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/authentication/http/custom/src/rest/customClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { KeyCredential } from "@azure/core-auth"; import { CustomContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface CustomContextOptions extends ClientOptions {} + /** * Initialize a new instance of `CustomContext` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { CustomContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: KeyCredential, - options: ClientOptions = {}, + options: CustomContextOptions = {}, ): CustomContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -31,7 +34,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as CustomContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/authentication/oauth2/src/rest/oAuth2Client.ts b/packages/typespec-ts/test/modularIntegration/generated/authentication/oauth2/src/rest/oAuth2Client.ts index 3e9268ba19..bebfc5ddcd 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/authentication/oauth2/src/rest/oAuth2Client.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/authentication/oauth2/src/rest/oAuth2Client.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { TokenCredential } from "@azure/core-auth"; import { OAuth2Context } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface OAuth2ContextOptions extends ClientOptions {} + /** * Initialize a new instance of `OAuth2Context` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { OAuth2Context } from "./clientDefinitions.js"; */ export default function createClient( credentials: TokenCredential, - options: ClientOptions = {}, + options: OAuth2ContextOptions = {}, ): OAuth2Context { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -36,7 +39,6 @@ export default function createClient( ], }, }; - const client = getClient(endpointUrl, credentials, options) as OAuth2Context; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/authentication/union/src/rest/unionClient.ts b/packages/typespec-ts/test/modularIntegration/generated/authentication/union/src/rest/unionClient.ts index 178d2dbd9b..0a75ba212d 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/authentication/union/src/rest/unionClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/authentication/union/src/rest/unionClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { UnionContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UnionContextOptions extends ClientOptions {} + /** * Initialize a new instance of `UnionContext` * @param credentials - uniquely identify client credential @@ -13,7 +16,7 @@ import { UnionContext } from "./clientDefinitions.js"; */ export default function createClient( credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + options: UnionContextOptions = {}, ): UnionContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -37,7 +40,6 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "x-ms-api-key", }, }; - const client = getClient(endpointUrl, credentials, options) as UnionContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/access/src/rest/accessClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/access/src/rest/accessClient.ts index b270240d42..df083101cd 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/access/src/rest/accessClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/access/src/rest/accessClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { AccessContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AccessContextOptions extends ClientOptions {} + /** * Initialize a new instance of `AccessContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: AccessContextOptions = {}, ): AccessContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AccessContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/usage/src/rest/usageClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/usage/src/rest/usageClient.ts index a4a4e94cd9..1fcc547e4c 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/usage/src/rest/usageClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/client-generator-core/usage/src/rest/usageClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { UsageContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageContextOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UsageContextOptions = {}, ): UsageContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UsageContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/models/models.ts index 22e292fb4b..d6cce12d91 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/models/models.ts @@ -30,7 +30,6 @@ export interface ListItemInputBody { } /** An extensible enum input parameter. */ -/** */ export type ListItemInputExtensibleEnum = "First" | "Second"; export interface UserListResults { @@ -53,7 +52,6 @@ export interface SecondItem { } /** The version of the API. */ -/** */ export type Versions = "2022-12-01-preview"; /** Paged collection of User items */ diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/rest/basicClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/rest/basicClient.ts index 8b68786fff..bf44790ff6 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/rest/basicClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/basic/src/rest/basicClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { BasicContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BasicContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `BasicContext` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): BasicContext { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: BasicContextOptions = {}): BasicContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-azure-core-basic-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BasicContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/models/models.ts index ad18a1d724..0ec623dfa6 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/models/models.ts @@ -29,5 +29,4 @@ export interface GenerationResult { } /** The API version. */ -/** */ export type Versions = "2022-12-01-preview"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/rest/rpcClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/rest/rpcClient.ts index 524f4e2f8a..a71cbe1770 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/rest/rpcClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/rest/rpcClient.ts @@ -5,14 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { RpcContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RpcContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `RpcContext` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): RpcContext { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: RpcContextOptions = {}): RpcContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-modular-lro-rpc-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -27,8 +35,23 @@ export default function createClient(options: ClientOptions = {}): RpcContext { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RpcContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/models/models.ts index 215937603c..994dc4699a 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/models/models.ts @@ -18,5 +18,4 @@ export interface ExportedUser { } /** The API version. */ -/** */ export type Versions = "2022-12-01-preview"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/rest/standardClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/rest/standardClient.ts index 9da7a1fd60..6733d1b3d4 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/rest/standardClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/rest/standardClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { StandardContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface StandardContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `StandardContext` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): StandardContext { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: StandardContextOptions = {}): StandardContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-modular-lro-standard-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as StandardContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/models/models.ts index a21d9029ec..b360567e49 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/models/models.ts @@ -6,5 +6,4 @@ export interface AzureLocationModel { } /** The version of the API. */ -/** */ export type Versions = "2022-12-01-preview"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/rest/scalarClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/rest/scalarClient.ts index be651d9923..2ea9b1172a 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/rest/scalarClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/scalar/src/rest/scalarClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ScalarContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ScalarContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ScalarContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ScalarContextOptions = {}, ): ScalarContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ScalarContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/models/models.ts index 842662828e..a9fb39fb5f 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/models/models.ts @@ -22,8 +22,6 @@ export interface UserActionResponse { } /** Service versions */ -/** */ export type Versions = "2022-12-01-preview"; /** Repeatability Result header options */ -/** */ export type RepeatabilityResult = "accepted" | "rejected"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/rest/traitsClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/rest/traitsClient.ts index 2706ac25ff..b91a7cd1b0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/rest/traitsClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/traits/src/rest/traitsClient.ts @@ -5,16 +5,22 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { TraitsContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface TraitsContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `TraitsContext` * @param options - the parameter for all optional parameters */ -export default function createClient( - options: ClientOptions = {}, -): TraitsContext { +export default function createClient({ + apiVersion = "2022-12-01-preview", + ...options +}: TraitsContextOptions = {}): TraitsContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; - options.apiVersion = options.apiVersion ?? "2022-12-01-preview"; const userAgentInfo = `azsdk-js-azure-core-traits-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -29,8 +35,23 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as TraitsContext; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/special-headers/client-request-id/src/rest/xmsClientRequestIdClient.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/special-headers/client-request-id/src/rest/xmsClientRequestIdClient.ts index a9c3042ccf..186f638fde 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/special-headers/client-request-id/src/rest/xmsClientRequestIdClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/special-headers/client-request-id/src/rest/xmsClientRequestIdClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { XmsRequestIdClientContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface XmsRequestIdClientContextOptions extends ClientOptions {} + /** * Initialize a new instance of `XmsRequestIdClientContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: XmsRequestIdClientContextOptions = {}, ): XmsRequestIdClientContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as XmsRequestIdClientContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/models/models.ts index 9d311db530..7e23402d14 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/models/models.ts @@ -17,10 +17,8 @@ export interface ClientNameAndJsonEncodedNameModel { } /** Type of ClientExtensibleEnum */ -/** */ export type ClientExtensibleEnum = "value1"; /** Type of ExtensibleEnum */ -/** */ export type ExtensibleEnum = "value1" | "value2"; export interface ClientModel { diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/rest/namingClient.ts b/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/rest/namingClient.ts index d623809811..0e0d4a29e7 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/rest/namingClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/naming/src/rest/namingClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { NamingContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NamingContextOptions extends ClientOptions {} + /** * Initialize a new instance of `NamingContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NamingContextOptions = {}, ): NamingContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NamingContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/models/models.ts index 67064de802..a886b317d0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/models/models.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** */ export type ClientType = | "default" | "multi-client" diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/rest/serviceClient.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/rest/serviceClient.ts index 02dd369ae6..1136c9197a 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/rest/serviceClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/src/rest/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { ServiceContext } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceContextOptions = {}, ): ServiceContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-default-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/a/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/a/models/models.ts index 67064de802..a886b317d0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/a/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/a/models/models.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** */ export type ClientType = | "default" | "multi-client" diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/b/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/b/models/models.ts index 67064de802..a886b317d0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/b/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/b/models/models.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** */ export type ClientType = | "default" | "multi-client" diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/rest/serviceClient.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/rest/serviceClient.ts index 0087a0f544..3a14c29c10 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/rest/serviceClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/src/rest/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { ServiceContext } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceContextOptions = {}, ): ServiceContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-multiclient-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/models/models.ts index 67064de802..a886b317d0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/models/models.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** */ export type ClientType = | "default" | "multi-client" diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/rest/serviceClient.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/rest/serviceClient.ts index d67652eb03..0c2ba21f01 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/rest/serviceClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/src/rest/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { ServiceContext } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceContextOptions = {}, ): ServiceContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-renamed-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/models/models.ts index 67064de802..a886b317d0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/models/models.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** */ export type ClientType = | "default" | "multi-client" diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/rest/serviceClient.ts b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/rest/serviceClient.ts index 3fdfc5ac81..acd795e96c 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/rest/serviceClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/src/rest/serviceClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { ServiceContext } from "./clientDefinitions.js"; import { ClientType } from "./models.js"; +/** The optional parameters for the client */ +export interface ServiceContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ServiceContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { ClientType } from "./models.js"; export default function createClient( endpointParam: string, clientParam: ClientType, - options: ClientOptions = {}, + options: ServiceContextOptions = {}, ): ServiceContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/client/structure/${clientParam}`; - const userAgentInfo = `azsdk-js-client-structure-twoopgroup-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ServiceContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/encode/bytes/src/rest/bytesClient.ts b/packages/typespec-ts/test/modularIntegration/generated/encode/bytes/src/rest/bytesClient.ts index 69444ee713..3206feb158 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/encode/bytes/src/rest/bytesClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/encode/bytes/src/rest/bytesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { BytesContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BytesContextOptions extends ClientOptions {} + /** * Initialize a new instance of `BytesContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BytesContextOptions = {}, ): BytesContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BytesContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/encode/datetime/src/rest/datetimeClient.ts b/packages/typespec-ts/test/modularIntegration/generated/encode/datetime/src/rest/datetimeClient.ts index 2c719ec209..be1c70c21a 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/encode/datetime/src/rest/datetimeClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/encode/datetime/src/rest/datetimeClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { DatetimeContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface DatetimeContextOptions extends ClientOptions {} + /** * Initialize a new instance of `DatetimeContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: DatetimeContextOptions = {}, ): DatetimeContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DatetimeContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/encode/duration/src/rest/durationClient.ts b/packages/typespec-ts/test/modularIntegration/generated/encode/duration/src/rest/durationClient.ts index 75aad9f553..5b9594579e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/encode/duration/src/rest/durationClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/encode/duration/src/rest/durationClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { DurationContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface DurationContextOptions extends ClientOptions {} + /** * Initialize a new instance of `DurationContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: DurationContextOptions = {}, ): DurationContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as DurationContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/parameters/basic/src/rest/basicClient.ts b/packages/typespec-ts/test/modularIntegration/generated/parameters/basic/src/rest/basicClient.ts index c1328099e1..ebfce9a8ed 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/parameters/basic/src/rest/basicClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/parameters/basic/src/rest/basicClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { BasicContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BasicContextOptions extends ClientOptions {} + /** * Initialize a new instance of `BasicContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BasicContextOptions = {}, ): BasicContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BasicContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/parameters/body-optionality/src/rest/bodyOptionalityClient.ts b/packages/typespec-ts/test/modularIntegration/generated/parameters/body-optionality/src/rest/bodyOptionalityClient.ts index c632b44427..1356f1ccc7 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/parameters/body-optionality/src/rest/bodyOptionalityClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/parameters/body-optionality/src/rest/bodyOptionalityClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { BodyOptionalityContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface BodyOptionalityContextOptions extends ClientOptions {} + /** * Initialize a new instance of `BodyOptionalityContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: BodyOptionalityContextOptions = {}, ): BodyOptionalityContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as BodyOptionalityContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/parameters/collection-format/src/rest/collectionFormatClient.ts b/packages/typespec-ts/test/modularIntegration/generated/parameters/collection-format/src/rest/collectionFormatClient.ts index 2135fca732..ddfe80c371 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/parameters/collection-format/src/rest/collectionFormatClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/parameters/collection-format/src/rest/collectionFormatClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { CollectionFormatContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface CollectionFormatContextOptions extends ClientOptions {} + /** * Initialize a new instance of `CollectionFormatContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: CollectionFormatContextOptions = {}, ): CollectionFormatContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as CollectionFormatContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/parameters/spread/src/rest/spreadClient.ts b/packages/typespec-ts/test/modularIntegration/generated/parameters/spread/src/rest/spreadClient.ts index 9b7e318e4f..14c1842cc7 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/parameters/spread/src/rest/spreadClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/parameters/spread/src/rest/spreadClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { SpreadContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SpreadContextOptions extends ClientOptions {} + /** * Initialize a new instance of `SpreadContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SpreadContextOptions = {}, ): SpreadContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SpreadContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/payload/content-negotiation/src/rest/contentNegotiationClient.ts b/packages/typespec-ts/test/modularIntegration/generated/payload/content-negotiation/src/rest/contentNegotiationClient.ts index 7d31daffea..57ebde3fb9 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/payload/content-negotiation/src/rest/contentNegotiationClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/payload/content-negotiation/src/rest/contentNegotiationClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ContentNegotiationContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ContentNegotiationContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ContentNegotiationContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ContentNegotiationContextOptions = {}, ): ContentNegotiationContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ContentNegotiationContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/payload/media-type/src/rest/mediaTypeClient.ts b/packages/typespec-ts/test/modularIntegration/generated/payload/media-type/src/rest/mediaTypeClient.ts index ca2dc9c566..b3696f0c4b 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/payload/media-type/src/rest/mediaTypeClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/payload/media-type/src/rest/mediaTypeClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { MediaTypeContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface MediaTypeContextOptions extends ClientOptions {} + /** * Initialize a new instance of `MediaTypeContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: MediaTypeContextOptions = {}, ): MediaTypeContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MediaTypeContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/payload/pageable/src/rest/pageableClient.ts b/packages/typespec-ts/test/modularIntegration/generated/payload/pageable/src/rest/pageableClient.ts index 80a1c962a9..327a332271 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/payload/pageable/src/rest/pageableClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/payload/pageable/src/rest/pageableClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { PageableContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface PageableContextOptions extends ClientOptions {} + /** * Initialize a new instance of `PageableContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: PageableContextOptions = {}, ): PageableContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as PageableContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/serialization/encoded-name/json/src/rest/jsonClient.ts b/packages/typespec-ts/test/modularIntegration/generated/serialization/encoded-name/json/src/rest/jsonClient.ts index 7496870d7c..088e219a06 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/serialization/encoded-name/json/src/rest/jsonClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/serialization/encoded-name/json/src/rest/jsonClient.ts @@ -5,11 +5,16 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { JsonContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface JsonContextOptions extends ClientOptions {} + /** * Initialize a new instance of `JsonContext` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): JsonContext { +export default function createClient( + options: JsonContextOptions = {}, +): JsonContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-serialization-encoded-name-json-rest/1.0.0-beta.1`; @@ -26,7 +31,6 @@ export default function createClient(options: ClientOptions = {}): JsonContext { logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as JsonContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/endpoint/not-defined/src/rest/notDefinedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/server/endpoint/not-defined/src/rest/notDefinedClient.ts index 2ada236a67..7c19db4972 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/endpoint/not-defined/src/rest/notDefinedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/endpoint/not-defined/src/rest/notDefinedClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { NotDefinedContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotDefinedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `NotDefinedContext` * @param endpointParam - The parameter endpointParam @@ -12,10 +15,9 @@ import { NotDefinedContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: NotDefinedContextOptions = {}, ): NotDefinedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-notdefinedparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NotDefinedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/models/models.ts index b88ebd374a..73ba43f52e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/models/models.ts @@ -2,5 +2,4 @@ // Licensed under the MIT license. /** Service versions */ -/** */ export type Versions = "v1.0"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/rest/multipleClient.ts b/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/rest/multipleClient.ts index 6d67841ff4..ebb23ff620 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/rest/multipleClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/path/multiple/src/rest/multipleClient.ts @@ -6,7 +6,9 @@ import { logger } from "../logger.js"; import { MultipleContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ export interface MultipleContextOptions extends ClientOptions { + /** Pass in v1.0 for API version. */ apiVersion?: Versions; } @@ -17,14 +19,12 @@ export interface MultipleContextOptions extends ClientOptions { */ export default function createClient( endpointParam: string, - options: MultipleContextOptions = {}, + { apiVersion = "v1.0", ...options }: MultipleContextOptions = {}, ): MultipleContext { - const apiVersion = options.apiVersion ?? "v1.0"; const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/server/path/multiple/${apiVersion}`; - const userAgentInfo = `azsdk-js-multipleparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -39,15 +39,9 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MultipleContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - } return client; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/path/single/src/rest/singleClient.ts b/packages/typespec-ts/test/modularIntegration/generated/server/path/single/src/rest/singleClient.ts index 37b2ccc3e3..75c0147aa8 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/path/single/src/rest/singleClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/path/single/src/rest/singleClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { SingleContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SingleContextOptions extends ClientOptions {} + /** * Initialize a new instance of `SingleContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +15,9 @@ import { SingleContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: SingleContextOptions = {}, ): SingleContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-singleparam-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SingleContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/versions/not-versioned/src/rest/notVersionedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/server/versions/not-versioned/src/rest/notVersionedClient.ts index 1fa116bf95..bbe4b91b84 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/versions/not-versioned/src/rest/notVersionedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/versions/not-versioned/src/rest/notVersionedClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { NotVersionedContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotVersionedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `NotVersionedContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +15,9 @@ import { NotVersionedContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: NotVersionedContextOptions = {}, ): NotVersionedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-not-versioned-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NotVersionedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/models/models.ts index b21a97d1e5..49acadb10f 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/models/models.ts @@ -2,5 +2,4 @@ // Licensed under the MIT license. /** The version of the API. */ -/** */ export type Versions = "2021-01-01-preview" | "2022-12-01-preview"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/rest/versionedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/rest/versionedClient.ts index a392232b9f..df3b5746ea 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/rest/versionedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/server/versions/versioned/src/rest/versionedClient.ts @@ -5,6 +5,9 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { VersionedContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface VersionedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `VersionedContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -12,10 +15,9 @@ import { VersionedContext } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + options: VersionedContextOptions = {}, ): VersionedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - const userAgentInfo = `azsdk-js-versioned-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -30,7 +32,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as VersionedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/special-headers/repeatability/generated/src/rest/repeatabilityClient.ts b/packages/typespec-ts/test/modularIntegration/generated/special-headers/repeatability/generated/src/rest/repeatabilityClient.ts index 8a32c2e0d6..3ba6e212be 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/special-headers/repeatability/generated/src/rest/repeatabilityClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/special-headers/repeatability/generated/src/rest/repeatabilityClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { RepeatabilityContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RepeatabilityContextOptions extends ClientOptions {} + /** * Initialize a new instance of `RepeatabilityContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: RepeatabilityContextOptions = {}, ): RepeatabilityContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RepeatabilityContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/special-words/src/rest/specialWordsClient.ts b/packages/typespec-ts/test/modularIntegration/generated/special-words/src/rest/specialWordsClient.ts index 12917de155..fcbe1a71d9 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/special-words/src/rest/specialWordsClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/special-words/src/rest/specialWordsClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { SpecialWordsContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SpecialWordsContextOptions extends ClientOptions {} + /** * Initialize a new instance of `SpecialWordsContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SpecialWordsContextOptions = {}, ): SpecialWordsContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SpecialWordsContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/array/src/rest/arrayClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/array/src/rest/arrayClient.ts index 5881eed915..c7599a5275 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/array/src/rest/arrayClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/array/src/rest/arrayClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ArrayContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ArrayContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ArrayContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ArrayContextOptions = {}, ): ArrayContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ArrayContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/models/models.ts index 571d7d50d0..c919071946 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/models/models.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. /** Days of the week */ -/** */ export type DaysOfWeekExtensibleEnum = | "Monday" | "Tuesday" diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/rest/extensibleClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/rest/extensibleClient.ts index f550822ffe..70e759b520 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/rest/extensibleClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/enum/extensible/src/rest/extensibleClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ExtensibleContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ExtensibleContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ExtensibleContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ExtensibleContextOptions = {}, ): ExtensibleContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ExtensibleContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/models/models.ts index 4b9c553be7..963fe85f9d 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/models/models.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. /** Days of the week */ -/** */ export type DaysOfWeekEnum = | "Monday" | "Tuesday" diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/rest/fixedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/rest/fixedClient.ts index 5ed1c60ff3..638ec17bc7 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/rest/fixedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/enum/fixed/src/rest/fixedClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { FixedContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface FixedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `FixedContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: FixedContextOptions = {}, ): FixedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as FixedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/empty/generated/src/rest/emptyClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/empty/generated/src/rest/emptyClient.ts index a1c7261125..99b0356b34 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/empty/generated/src/rest/emptyClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/empty/generated/src/rest/emptyClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { EmptyContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface EmptyContextOptions extends ClientOptions {} + /** * Initialize a new instance of `EmptyContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: EmptyContextOptions = {}, ): EmptyContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as EmptyContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/flatten/generated/src/rest/flattenClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/flatten/generated/src/rest/flattenClient.ts index 2393630b2a..e0716cf4a6 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/flatten/generated/src/rest/flattenClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/flatten/generated/src/rest/flattenClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { FlattenContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface FlattenContextOptions extends ClientOptions {} + /** * Initialize a new instance of `FlattenContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: FlattenContextOptions = {}, ): FlattenContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as FlattenContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/models/models.ts index 2d4d014b4b..e385b9bb2c 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/models/models.ts @@ -16,7 +16,6 @@ export interface Golden extends Dog { } /** extensible enum type for discriminator */ -/** */ export type DogKind = "golden"; /** Test fixed enum type for discriminator */ @@ -34,7 +33,6 @@ export interface Cobra extends Snake { } /** fixed enum type for discriminator */ -/** */ export type SnakeKind = "cobra"; /** Alias for DogUnion */ export type DogUnion = Golden | Dog; diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/rest/enumDiscriminatorClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/rest/enumDiscriminatorClient.ts index 482a1895a5..37ffebcb59 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/rest/enumDiscriminatorClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/enum-discriminator/src/rest/enumDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { EnumDiscriminatorContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface EnumDiscriminatorContextOptions extends ClientOptions {} + /** * Initialize a new instance of `EnumDiscriminatorContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: EnumDiscriminatorContextOptions = {}, ): EnumDiscriminatorContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as EnumDiscriminatorContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/nested-discriminator/src/rest/nestedDiscriminatorClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/nested-discriminator/src/rest/nestedDiscriminatorClient.ts index fc10fca7ef..910c36c73f 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/nested-discriminator/src/rest/nestedDiscriminatorClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/nested-discriminator/src/rest/nestedDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { NestedDiscriminatorContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NestedDiscriminatorContextOptions extends ClientOptions {} + /** * Initialize a new instance of `NestedDiscriminatorContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NestedDiscriminatorContextOptions = {}, ): NestedDiscriminatorContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NestedDiscriminatorContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/not-discriminated/src/rest/notDiscriminatedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/not-discriminated/src/rest/notDiscriminatedClient.ts index 694f703566..229cbad53e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/not-discriminated/src/rest/notDiscriminatedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/not-discriminated/src/rest/notDiscriminatedClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { NotDiscriminatedContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface NotDiscriminatedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `NotDiscriminatedContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: NotDiscriminatedContextOptions = {}, ): NotDiscriminatedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as NotDiscriminatedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/recursive/generated/src/rest/recursiveClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/recursive/generated/src/rest/recursiveClient.ts index 08b7e34145..18803ac135 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/recursive/generated/src/rest/recursiveClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/recursive/generated/src/rest/recursiveClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { RecursiveContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface RecursiveContextOptions extends ClientOptions {} + /** * Initialize a new instance of `RecursiveContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: RecursiveContextOptions = {}, ): RecursiveContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RecursiveContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/single-discriminator/src/rest/singleDiscriminatorClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/single-discriminator/src/rest/singleDiscriminatorClient.ts index 44309cb453..b1805bc255 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/single-discriminator/src/rest/singleDiscriminatorClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/inheritance/single-discriminator/src/rest/singleDiscriminatorClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { SingleDiscriminatorContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface SingleDiscriminatorContextOptions extends ClientOptions {} + /** * Initialize a new instance of `SingleDiscriminatorContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: SingleDiscriminatorContextOptions = {}, ): SingleDiscriminatorContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as SingleDiscriminatorContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/model/usage/generated/src/rest/usageClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/model/usage/generated/src/rest/usageClient.ts index 58b978b7d4..9cbde0d668 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/model/usage/generated/src/rest/usageClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/model/usage/generated/src/rest/usageClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { UsageContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageContextOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UsageContextOptions = {}, ): UsageContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UsageContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/property/additional-properties/src/rest/additionalPropertiesClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/property/additional-properties/src/rest/additionalPropertiesClient.ts index 5669419fa9..e0a8db9934 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/property/additional-properties/src/rest/additionalPropertiesClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/property/additional-properties/src/rest/additionalPropertiesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { AdditionalPropertiesContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface AdditionalPropertiesContextOptions extends ClientOptions {} + /** * Initialize a new instance of `AdditionalPropertiesContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: AdditionalPropertiesContextOptions = {}, ): AdditionalPropertiesContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AdditionalPropertiesContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/models/models.ts index dcdcc75567..a5431c4426 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/models/models.ts @@ -8,7 +8,6 @@ export interface UnionEnumValueProperty { } /** Type of ExtendedEnum */ -/** */ export type ExtendedEnum = "value2"; /** Model with a union of float literal as property. */ @@ -123,7 +122,6 @@ export interface ExtensibleEnumProperty { } /** Enum that will be used as a property for model EnumProperty. Extensible. */ -/** */ export type InnerEnum = "ValueOne" | "ValueTwo"; /** Model with enum properties */ @@ -133,7 +131,6 @@ export interface EnumProperty { } /** Enum that will be used as a property for model EnumProperty. Non-extensible. */ -/** */ export type FixedInnerEnum = "ValueOne" | "ValueTwo"; /** Model with a duration property */ diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/rest/valueTypesClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/rest/valueTypesClient.ts index 321125747f..c81e2308c4 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/rest/valueTypesClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/property/value-types/generated/src/rest/valueTypesClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ValueTypesContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ValueTypesContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ValueTypesContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ValueTypesContextOptions = {}, ): ValueTypesContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ValueTypesContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/scalar/src/rest/scalarClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/scalar/src/rest/scalarClient.ts index 9187bead27..4d12eff59b 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/scalar/src/rest/scalarClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/scalar/src/rest/scalarClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { ScalarContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface ScalarContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ScalarContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: ScalarContextOptions = {}, ): ScalarContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as ScalarContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/union/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/type/union/src/models/models.ts index d62f6cc102..deb92b3cf2 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/union/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/union/src/models/models.ts @@ -43,9 +43,7 @@ export interface EnumsOnlyCases { ud: Ud | Ud; } -/** */ export type Lr = "left" | "right"; -/** */ export type Ud = "up" | "down"; export interface Dog { @@ -53,7 +51,6 @@ export interface Dog { } /** Type of StringExtensibleNamedUnion */ -/** "b", "c" */ export type StringExtensibleNamedUnion = string; export enum KnownStringExtensibleNamedUnion { diff --git a/packages/typespec-ts/test/modularIntegration/generated/type/union/src/rest/unionClient.ts b/packages/typespec-ts/test/modularIntegration/generated/type/union/src/rest/unionClient.ts index 1062abb0fd..b9aa9e4167 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/type/union/src/rest/unionClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/type/union/src/rest/unionClient.ts @@ -5,12 +5,15 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "../logger.js"; import { UnionContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UnionContextOptions extends ClientOptions {} + /** * Initialize a new instance of `UnionContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UnionContextOptions = {}, ): UnionContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -28,7 +31,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as UnionContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/models/models.ts index b1e3abeef4..760dccc54f 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/models/models.ts @@ -7,7 +7,6 @@ export interface ModelV1 { unionProp: UnionV1; } -/** */ export type EnumV1 = "enumMemberV1" | "enumMemberV2"; export interface ModelV2 { @@ -16,10 +15,8 @@ export interface ModelV2 { unionProp: UnionV2; } -/** */ export type EnumV2 = "enumMember"; /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; /** Alias for UnionV1 */ export type UnionV1 = string | number; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/rest/addedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/rest/addedClient.ts index 8db275394f..1525400059 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/rest/addedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/added/src/rest/addedClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { AddedContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface AddedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `AddedContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: AddedContextOptions = {}, ): AddedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/added/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-added-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as AddedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/models/models.ts index ef769fdee8..3cac3997e4 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/models/models.ts @@ -7,5 +7,4 @@ export interface TestModel { } /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/rest/madeOptionalClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/rest/madeOptionalClient.ts index ef7b67c630..83da6f4c2d 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/rest/madeOptionalClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/madeOptional/src/rest/madeOptionalClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { MadeOptionalContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface MadeOptionalContextOptions extends ClientOptions {} + /** * Initialize a new instance of `MadeOptionalContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: MadeOptionalContextOptions = {}, ): MadeOptionalContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/made-optional/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-madeOptional-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as MadeOptionalContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/models/models.ts index 5c6004b837..5305dfe31e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/models/models.ts @@ -7,10 +7,8 @@ export interface ModelV2 { unionProp: UnionV2; } -/** */ export type EnumV2 = "enumMemberV2"; /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; /** Alias for UnionV2 */ export type UnionV2 = string | number; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/rest/removedClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/rest/removedClient.ts index ae7d95e7e1..c53d51cbc8 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/rest/removedClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/rest/removedClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { RemovedContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface RemovedContextOptions extends ClientOptions {} + /** * Initialize a new instance of `RemovedContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: RemovedContextOptions = {}, ): RemovedContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/removed/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-removed-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RemovedContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/models/models.ts index 1b94d2e6ba..6cf3efa501 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/models/models.ts @@ -7,10 +7,8 @@ export interface NewModel { unionProp: NewUnion; } -/** */ export type NewEnum = "newEnumMember"; /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; /** Alias for NewUnion */ export type NewUnion = string | number; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/rest/renamedFromClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/rest/renamedFromClient.ts index 1d3552bea7..fc467e2ca6 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/rest/renamedFromClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/renamedFrom/src/rest/renamedFromClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { RenamedFromContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface RenamedFromContextOptions extends ClientOptions {} + /** * Initialize a new instance of `RenamedFromContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: RenamedFromContextOptions = {}, ): RenamedFromContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/renamed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-renamedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as RenamedFromContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/models/models.ts index 04c5c24d9e..668e9f102e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/models/models.ts @@ -2,5 +2,4 @@ // Licensed under the MIT license. /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/rest/returnTypeChangedFromClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/rest/returnTypeChangedFromClient.ts index d1a0341a3f..8453d83202 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/rest/returnTypeChangedFromClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/returnTypeChangedFrom/src/rest/returnTypeChangedFromClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { ReturnTypeChangedFromContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface ReturnTypeChangedFromContextOptions extends ClientOptions {} + /** * Initialize a new instance of `ReturnTypeChangedFromContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: ReturnTypeChangedFromContextOptions = {}, ): ReturnTypeChangedFromContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/return-type-changed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-returnTypeChangedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient( endpointUrl, options, diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/models/models.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/models/models.ts index 10084535ef..1cd418002b 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/models/models.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/models/models.ts @@ -7,5 +7,4 @@ export interface TestModel { } /** The version of the API. */ -/** */ export type Versions = "v1" | "v2"; diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/rest/typeChangedFromClient.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/rest/typeChangedFromClient.ts index d3b5a622ed..64ae568a10 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/rest/typeChangedFromClient.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/typeChangedFrom/src/rest/typeChangedFromClient.ts @@ -6,6 +6,9 @@ import { logger } from "../logger.js"; import { TypeChangedFromContext } from "./clientDefinitions.js"; import { Versions } from "./models.js"; +/** The optional parameters for the client */ +export interface TypeChangedFromContextOptions extends ClientOptions {} + /** * Initialize a new instance of `TypeChangedFromContext` * @param endpointParam - Need to be set as 'http://localhost:3000' in client. @@ -15,13 +18,12 @@ import { Versions } from "./models.js"; export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {}, + options: TypeChangedFromContextOptions = {}, ): TypeChangedFromContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/versioning/type-changed-from/api-version:${version}`; - const userAgentInfo = `azsdk-js-versionning-typeChangedFrom-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -36,7 +38,6 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as TypeChangedFromContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/modularUnit/enumUnion.spec.ts b/packages/typespec-ts/test/modularUnit/enumUnion.spec.ts index 7d8f9091de..349eff8276 100644 --- a/packages/typespec-ts/test/modularUnit/enumUnion.spec.ts +++ b/packages/typespec-ts/test/modularUnit/enumUnion.spec.ts @@ -43,7 +43,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "application/json; serialization=Avro" | "application/json; serialization=json" @@ -142,7 +141,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "application/json; serialization=Avro" | "application/json; serialization=json" @@ -187,7 +185,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf"; @@ -234,7 +231,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of JsonContentType */ - /** */ export type JsonContentType = "application/json; serialization=Avro" | "application/json; serialization=json"; /** Alias for SchemaContentTypeValues */ export type SchemaContentTypeValues = JsonContentType | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf" | string; @@ -281,7 +277,6 @@ describe("header parameters", () => { await assertEqualContent( schemaOutput?.getFullText()!, ` - /** */ export type JsonContentType = "application/json; serialization=Avro" | "application/json; serialization=json"; /** Alias for SchemaContentTypeValues */ export type SchemaContentTypeValues = JsonContentType | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf" | string; @@ -325,7 +320,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf"; @@ -372,7 +366,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of JsonContentType */ - /** */ export type JsonContentType = "application/json; serialization=Avro" | "application/json; serialization=json"; /** Alias for SchemaContentTypeValues */ export type SchemaContentTypeValues = JsonContentType | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf" | string; @@ -419,7 +412,6 @@ describe("header parameters", () => { await assertEqualContent( schemaOutput?.getFullText()!, ` - /** */ export type JsonContentType = "application/json; serialization=Avro" | "application/json; serialization=json"; /** Alias for SchemaContentTypeValues */ export type SchemaContentTypeValues = JsonContentType | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf" | string; @@ -629,7 +621,6 @@ describe("header parameters", () => { await assertEqualContent( schemaOutput?.getFullText()!, ` - /** */ export type SchemaContentTypeValues = "application/json; serialization=Avro" | "application/json; serialization=json" | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf";` ); }); @@ -671,7 +662,6 @@ describe("header parameters", () => { await assertEqualContent( schemaOutput?.getFullText()!, ` - /** */ export type SchemaContentTypeValues = "application/json; serialization=Avro" | "application/json; serialization=json" | "text/plain; charset=utf-8" | "text/vnd.ms.protobuf";` ); }); @@ -717,7 +707,6 @@ describe("header parameters", () => { schemaOutput?.getFullText()!, ` /** Type of EnumTest */ - /** */ export type EnumTest = 1 | 2 | 3 | 4; ` ); @@ -770,7 +759,6 @@ describe("header parameters", () => { await assertEqualContent( schemaOutput?.getFullText()!, ` - /** */ export type EnumTest = 1 | 2 | 3 | 4; export interface Foo { @@ -822,7 +810,6 @@ describe("model type", () => { color: "red"; } - /** */ export type Color = "red" | "blue"; ` ); @@ -900,7 +887,6 @@ describe("model type", () => { color: 1; } - /** */ export type Color = 1 | 2; ` ); @@ -926,7 +912,6 @@ describe("model type", () => { } /** Type of Color */ - /** */ export type Color = 1 | 2; ` ); @@ -958,7 +943,6 @@ describe("model type", () => { } /** Type of Color */ - /** */ export type Color = 1 | 2; ` ); @@ -988,9 +972,7 @@ describe("model type", () => { color: Lr | Ud; } - /** */ export type Lr = "left" | "right"; - /** */ export type Ud = "up" | "down"; ` ); @@ -1020,9 +1002,7 @@ describe("model type", () => { } /** Type of LeftAndRight */ - /** */ export type LeftAndRight = "left" | "right"; - /** */ export type UpAndDown = "up" | "down"; ` ); diff --git a/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts b/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts index 16ded81ee7..4607c93398 100644 --- a/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts +++ b/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts @@ -96,7 +96,6 @@ describe("model property type", () => { additionalTypeSpecDefinition: tspTypeDefinition, additionalInputContent: ` /** Translation Language Values */ - /** */ export type TranslationLanguageValues = "English" | "Chinese"; ` }); @@ -1532,7 +1531,6 @@ describe("inheritance & polymorphism", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "application/json; serialization=Avro" | "application/json; serialization=json" @@ -1631,7 +1629,6 @@ describe("inheritance & polymorphism", () => { schemaOutput?.getFullText()!, ` /** Type of SchemaContentTypeValues */ - /** */ export type SchemaContentTypeValues = | "application/json; serialization=Avro" | "application/json; serialization=json" diff --git a/packages/typespec-ts/test/nonBrandedIntegration/modular/generated/models/usage/src/rest/usageClient.ts b/packages/typespec-ts/test/nonBrandedIntegration/modular/generated/models/usage/src/rest/usageClient.ts index 0587b79c5c..3a30b4dd57 100644 --- a/packages/typespec-ts/test/nonBrandedIntegration/modular/generated/models/usage/src/rest/usageClient.ts +++ b/packages/typespec-ts/test/nonBrandedIntegration/modular/generated/models/usage/src/rest/usageClient.ts @@ -3,12 +3,15 @@ import { getClient, ClientOptions } from "@typespec/ts-http-runtime"; import { UsageContext } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageContextOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageContext` * @param options - the parameter for all optional parameters */ export default function createClient( - options: ClientOptions = {}, + options: UsageContextOptions = {}, ): UsageContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; @@ -23,7 +26,6 @@ export default function createClient( userAgentPrefix, }, }; - const client = getClient(endpointUrl, options) as UsageContext; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/nonBrandedIntegration/rlc/generated/models/usage/src/usageClient.ts b/packages/typespec-ts/test/nonBrandedIntegration/rlc/generated/models/usage/src/usageClient.ts index 3d1d24375e..39dee96380 100644 --- a/packages/typespec-ts/test/nonBrandedIntegration/rlc/generated/models/usage/src/usageClient.ts +++ b/packages/typespec-ts/test/nonBrandedIntegration/rlc/generated/models/usage/src/usageClient.ts @@ -3,11 +3,16 @@ import { getClient, ClientOptions } from "@typespec/ts-http-runtime"; import { UsageClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface UsageClientOptions extends ClientOptions {} + /** * Initialize a new instance of `UsageClient` * @param options - the parameter for all optional parameters */ -export default function createClient(options: ClientOptions = {}): UsageClient { +export default function createClient( + options: UsageClientOptions = {}, +): UsageClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; const userAgentInfo = `azsdk-js-usage-rest/1.0.0`; @@ -21,7 +26,6 @@ export default function createClient(options: ClientOptions = {}): UsageClient { userAgentPrefix, }, }; - const client = getClient(endpointUrl, options) as UsageClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/unit/apiVersion.spec.ts b/packages/typespec-ts/test/unit/apiVersion.spec.ts index d7240b4ae5..67e19c9a26 100644 --- a/packages/typespec-ts/test/unit/apiVersion.spec.ts +++ b/packages/typespec-ts/test/unit/apiVersion.spec.ts @@ -118,43 +118,78 @@ const buildMixedDefinition = (options: DefinitionOptions) => { const buildDefaultReturn = ( hasDefault: boolean, hasQueryDefinition: boolean, - hasApiVersionInClient: boolean = false + hasApiVersionInClient: boolean = false, + apiVersionRequired: boolean = true ) => { - const defaultDef = !hasDefault - ? hasApiVersionInClient - ? `options.apiVersion = options.apiVersion ?? apiVersion;` - : "" - : `options.apiVersion = options.apiVersion ?? "2022-05-15-preview";`; - const apiVersionDef = !hasQueryDefinition - ? `\n client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning( - "This client does not support client api-version, please change it at the operation level", - ); - }\n \n` - : ``; + const apiVersionWarning = + apiVersionRequired && !hasDefault && hasApiVersionInClient + ? ` + if (options.apiVersion) { + logger.warning( + "This client does not support to set api-version in options, please change it at positional argument", + ); + }` + : !hasApiVersionInClient + ? ` + if (options.apiVersion) { + logger.warning("This client does not support client api-version, please change it at the operation level"); + }` + : ""; return ` import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions ${ + hasApiVersionInClient && (!apiVersionRequired || hasDefault) + ? `{ + /** The api version option of the client */ + apiVersion?: string; + }` + : "{}" + } + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The endpoint to use.${ - hasApiVersionInClient && !hasDefault - ? "\n * @param apiVersion - The parameter apiVersion" + hasApiVersionInClient && apiVersionRequired && !hasDefault + ? "\n * @param apiVersion - The parameter apiVersion" : "" } - * @param options - the parameter for all optional parameters + * @param ${ + (!hasDefault && apiVersionRequired) || hasApiVersionInClient + ? "options - the parameter for all optional parameters" + : `{ + * ${ + hasDefault && hasApiVersionInClient + ? `apiVersion = "2022-05-15-preview"` + : hasApiVersionInClient + ? "apiVersion" + : "" + }, ...options} - the parameter for all optional parameters` + } */ export default function createClient( endpointParam: string,${ - hasApiVersionInClient && !hasDefault ? "\napiVersion: string," : "" + hasApiVersionInClient && apiVersionRequired && !hasDefault + ? "apiVersion: string," + : "" } - options: ClientOptions = {} + ${ + (!hasDefault && apiVersionRequired) || !hasApiVersionInClient + ? "options" + : `{ + ${ + hasDefault && hasApiVersionInClient + ? `apiVersion = "2022-05-15-preview"` + : hasApiVersionInClient + ? "apiVersion" + : "" + }, ...options}` + }: testClientOptions = {} ): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/language\`; - ${defaultDef} const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -167,11 +202,32 @@ const buildDefaultReturn = ( }, loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info - }, + } }; - const client = getClient(endpointUrl, options) as testClient; - ${apiVersionDef} + + client.pipeline.removePolicy({ name: "ApiVersionPolicy" });${apiVersionWarning} + ${ + hasQueryDefinition + ? `client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = \`\${req.url}\${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=\${apiVersion}\`; + } + + return next(req); + }, + });` + : `` + } + + return client; }`; }; @@ -182,8 +238,9 @@ const buildPathReturn_WithDefault = () => { import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; - + /** The optional parameters for the client */ export interface testClientOptions extends ClientOptions { + /** Api Version */ apiVersion?: Versions; } @@ -194,11 +251,9 @@ const buildPathReturn_WithDefault = () => { */ export default function createClient( endpointParam: string, - options: testClientOptions = {} + { apiVersion = "2022-05-15-preview", ...options}: testClientOptions = {} ): testClient { - const apiVersion = options.apiVersion ?? "2022-05-15-preview"; const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/anomalydetector/\${apiVersion}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -211,16 +266,12 @@ const buildPathReturn_WithDefault = () => { }, loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info - }, + } }; const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); - if (options.apiVersion) { - logger.warning("This client does not support client api-version, please change it at the operation level"); - } - return client; }`; }; @@ -231,7 +282,8 @@ const buildPathReturn_WithoutDefault = () => { import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; - + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} /** * Initialize a new instance of \`testClient\` * @param endpointParam - The endpoint to use. @@ -241,10 +293,9 @@ const buildPathReturn_WithoutDefault = () => { export default function createClient( endpointParam: string, apiVersion: Versions, - options: ClientOptions = {} + options: testClientOptions = {} ): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/anomalydetector/\${apiVersion}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -257,14 +308,14 @@ const buildPathReturn_WithoutDefault = () => { }, loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info - }, + } }; const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); if (options.apiVersion) { - logger.warning("This client does not support client api-version, please change it at the operation level"); + logger.warning("This client does not support to set api-version in options, please change it at positional argument"); } return client; @@ -278,7 +329,7 @@ describe("api-version", () => { const def = buildQueryDefinition({ "@versioned": true }); - const expectedRes = buildDefaultReturn(true, true); + const expectedRes = buildDefaultReturn(true, true, true); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); await assertEqualContent(models!.content, expectedRes); @@ -305,7 +356,7 @@ describe("api-version", () => { const expectedRes = buildPathReturn_WithDefault(); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); describe("without default value", () => { @@ -316,7 +367,7 @@ describe("api-version", () => { const expectedRes = buildPathReturn_WithoutDefault(); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); }); @@ -329,7 +380,7 @@ describe("api-version", () => { const expectedRes = buildPathReturn_WithDefault(); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); describe("without default value", () => { @@ -340,7 +391,7 @@ describe("api-version", () => { const expectedRes = buildPathReturn_WithoutDefault(); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); }); @@ -354,7 +405,7 @@ describe("api-version", () => { const expectedRes = buildDefaultReturn(false, false); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); describe("without default value", () => { @@ -365,7 +416,7 @@ describe("api-version", () => { const expectedRes = buildDefaultReturn(false, false); const models = await emitClientFactoryFromTypeSpec(def); assert.ok(models); - await assertEqualContent(models!.content, expectedRes); + await assertEqualContent(models!.content, expectedRes, true); }); }); }); diff --git a/packages/typespec-ts/test/unit/armTemplate.spec.ts b/packages/typespec-ts/test/unit/armTemplate.spec.ts index e3e8915cbe..78fc6ec9fa 100644 --- a/packages/typespec-ts/test/unit/armTemplate.spec.ts +++ b/packages/typespec-ts/test/unit/armTemplate.spec.ts @@ -76,7 +76,9 @@ describe("ARM template", () => { true ); assert.ok(response); - await assertEqualContent(response!.content, ` + await assertEqualContent( + response!.content, + ` import { RawHttpHeaders } from "@azure/core-rest-pipeline"; import { HttpResponse } from "@azure-rest/core-client"; import { OnboardResponseOutput, ErrorResponseOutput } from "./outputModels.js"; @@ -109,6 +111,7 @@ describe("ARM template", () => { export interface UploadLogicalResponse extends HttpResponse { status: "200"; body: OnboardResponseOutput; - }`); + }` + ); }); }); diff --git a/packages/typespec-ts/test/unit/clientFactoryGenerator.spec.ts b/packages/typespec-ts/test/unit/clientFactoryGenerator.spec.ts index edad19d42d..21169f0f1c 100644 --- a/packages/typespec-ts/test/unit/clientFactoryGenerator.spec.ts +++ b/packages/typespec-ts/test/unit/clientFactoryGenerator.spec.ts @@ -21,14 +21,16 @@ describe("Client Factory generation", () => { import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; - + + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param options - the parameter for all optional parameters */ - export default function createClient(options: ClientOptions = {}): testClient { + export default function createClient(options: testClientOptions = {}): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`localhost\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -43,7 +45,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -77,6 +78,9 @@ describe("Client Factory generation", () => { import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; + + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} /** * Initialize a new instance of \`testClient\` @@ -85,10 +89,9 @@ describe("Client Factory generation", () => { */ export default function createClient( endpointParam: string, - options: ClientOptions = {} + options: testClientOptions = {} ): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/language\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -103,7 +106,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -151,6 +153,9 @@ describe("Client Factory generation", () => { import { testClient } from "./clientDefinitions.js"; import { Version } from "./models.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The endpoint to use. @@ -160,10 +165,9 @@ describe("Client Factory generation", () => { export default function createClient( endpointParam: string, version: Version, - options: ClientOptions = {} + options: testClientOptions = {} ): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/language/\${version}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -178,7 +182,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -224,6 +227,9 @@ describe("Client Factory generation", () => { import { testClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The endpoint to use. @@ -233,10 +239,9 @@ describe("Client Factory generation", () => { export default function createClient( endpointParam: string, version: Versions, - options: ClientOptions = {} + options: testClientOptions = {} ): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/language/\${version}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -251,7 +256,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -297,8 +301,10 @@ describe("Client Factory generation", () => { import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; import { Versions } from "./models.js"; - + + /** The optional parameters for the client */ export interface testClientOptions extends ClientOptions { + /** The endpoint to use. */ endpointParam?: string; } @@ -313,7 +319,6 @@ describe("Client Factory generation", () => { ): testClient { const endpointParam = options.endpointParam ?? "http://localhost:3000"; const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}/language/\${version}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -328,7 +333,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -357,14 +361,16 @@ describe("Client Factory generation", () => { import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The parameter endpointParam * @param options - the parameter for all optional parameters */ - export default function createClient(endpointParam: string, options: ClientOptions = {}): testClient { + export default function createClient(endpointParam: string, options: testClientOptions = {}): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -379,7 +385,6 @@ describe("Client Factory generation", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -447,6 +452,9 @@ describe("Client Factory generation", () => { import { logger } from "./logger.js"; import { TokenCredential } from "@azure/core-auth"; import { testClient } from "./clientDefinitions.js"; + + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} /** * Initialize a new instance of \`testClient\` @@ -454,9 +462,8 @@ describe("Client Factory generation", () => { * @param credentials - uniquely identify client credential * @param options - the parameter for all optional parameters */ - export default function createClient(endpointParam: string, credentials: TokenCredential, options: ClientOptions = {}): testClient { + export default function createClient(endpointParam: string, credentials: TokenCredential, options: testClientOptions = {}): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? \`\${options.userAgentOptions.userAgentPrefix} \${userAgentInfo}\`: \`\${userAgentInfo}\`;; options = { @@ -471,7 +478,6 @@ describe("Client Factory generation", () => { scopes: options.credentials?.scopes ?? [\`\${endpointUrl}/.default\`], }, }; - const client = getClient(endpointUrl, credentials, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); @@ -506,15 +512,17 @@ describe("Client Factory generation", () => { import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { testClient } from "./clientDefinitions.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The parameter endpointParam * @param credentials - uniquely identify client credential * @param options - the parameter for all optional parameters */ - export default function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options: ClientOptions = {}): testClient { + export default function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options: testClientOptions = {}): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}\`; - const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -533,7 +541,6 @@ describe("Client Factory generation", () => { apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "apiKey", }, }; - const client = getClient(endpointUrl, credentials, options) as testClient; client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); diff --git a/packages/typespec-ts/test/unit/parametersGenerator.spec.ts b/packages/typespec-ts/test/unit/parametersGenerator.spec.ts index b8ab8b4106..05e2776af8 100644 --- a/packages/typespec-ts/test/unit/parametersGenerator.spec.ts +++ b/packages/typespec-ts/test/unit/parametersGenerator.spec.ts @@ -42,15 +42,17 @@ describe("Parameters.ts", () => { import { logger } from "./logger.js"; import { testClient } from "./clientDefinitions.js"; + /** The optional parameters for the client */ + export interface testClientOptions extends ClientOptions {} + /** * Initialize a new instance of \`testClient\` * @param endpointParam - The parameter endpointParam * @param apiVersion - The parameter apiVersion * @param options - the parameter for all optional parameters */ - export default function createClient(endpointParam: string, apiVersion: string, options: ClientOptions = {}): testClient { + export default function createClient(endpointParam: string, apiVersion: string, options: testClientOptions = {}): testClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? \`\${endpointParam}\`; - options.apiVersion = options.apiVersion ?? apiVersion; const userAgentInfo = \`azsdk-js-test-rest/1.0.0-beta.1\`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -65,9 +67,30 @@ describe("Parameters.ts", () => { logger: options.loggingOptions?.logger ?? logger.info }, }; - const client = getClient(endpointUrl, options) as testClient; - + + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + if (options.apiVersion) { + logger.warning( + "This client does not support to set api-version in options, please change it at positional argument", + ); + } + client.pipeline.addPolicy({ + name: 'ClientApiVersionPolicy', + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = \`\${req.url}\${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=\${apiVersion}\`; + } + + return next(req); + }, + }); + return client; } ` diff --git a/packages/typespec-ts/test/util/testUtil.ts b/packages/typespec-ts/test/util/testUtil.ts index a9faad21af..8842271b8e 100644 --- a/packages/typespec-ts/test/util/testUtil.ts +++ b/packages/typespec-ts/test/util/testUtil.ts @@ -106,11 +106,11 @@ export async function assertEqualContent( ) { assert.strictEqual( await format( - ignoreWeirdLine ? actual.replace(/\n/g, "") : actual, + ignoreWeirdLine ? actual.replace(/$\n^/g, "").replace(/\s+/g, " ") : actual, prettierTypeScriptOptions ), await format( - ignoreWeirdLine ? expected.replace(/\n/g, "") : expected, + ignoreWeirdLine ? expected.replace(/$\n^/g, "").replace(/\s+/g, " ") : expected, prettierTypeScriptOptions ) );