diff --git a/docs/features/service_client_constructors.md b/docs/features/service_client_constructors.md new file mode 100644 index 00000000000..eec88608b82 --- /dev/null +++ b/docs/features/service_client_constructors.md @@ -0,0 +1,68 @@ +## Service Client Constrctors + +Scope: This document only applies to DPG libraries. + +There will be two **public** client constructors in a generated service client: + +**One primary public constructor with:** +- An `endpoint` parameter (no matter it is required or optional). +- All the **required** client parameters. +- A `ClientOptions` parameter. + +**One secondary public constructor with:** +- All the **required** client parameters (without the `ClientOptions` parameter and **optional** paramters). + +The secondary public constructor calls the primary public constructor underneath with default values of `endpoint` (if any) and `ClientOptions`. + +For example, required parameters `Uri endpoint` and `AzureKeyCredential credential` are defined, then the generated public constructors are: + +```C# +public ServiceClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new ServiceClientOptions()) {} + +public ServiceClient(Uri endpoint, AzureKeyCredential credential, ServiceClientOptions options) {} +``` + +Usually, all the client parameters are required. But if some additional optional client parameters are defined, all the optional client parameters will go to `ClientOptions`, except for the `endpoint` parameter. + +For example, if an optional parameter `string optional` is defined, the `ClientOptions` will have a new property as + +```C# +public partial class ServiceClientOptions : ClientOptions +{ + /* Other irrelevant lines*/ + + public string Optional { get; set; } +} +``` + +The signature of the public constructors will not change, but its implementation will change to +```C# +public ServiceClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new ServiceClientOptions()) {} + +public ServiceClient(Uri endpoint, AzureKeyCredential credential, ServiceClientOptions options) +{ + /* Other irrelevant lines*/ + + _optional = options.Optional; +} +``` + +If the optional client parameters contain `endpoint`, it will still be in the client constructor, not going to `ClientOptions`. For example, if an optional parameter `string optional` is defined, an optional `endpoint` with default value `"http://localhost:3000"`, and a required parameter `AzureKeyCredential credential`, the generated public constructors are: + +```C# +public ServiceClient(AzureKeyCredential credential) : this(new Uri("http://localhost:3000"), credential, new ServiceClientOptions()) {} + +public ServiceClient(Uri endpoint, AzureKeyCredential credential, ServiceClientOptions options) +{ + /* Other irrelevant lines*/ + + _optional = options.Optional; +} + +public partial class ServiceClientOptions : ClientOptions +{ + /* Other irrelevant lines*/ + + public string Optional { get; set; } +} +``` \ No newline at end of file diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/ClientOptionsWriter.cs b/src/AutoRest.CSharp/Common/Generation/Writers/ClientOptionsWriter.cs index e3acfa49c58..68554aafc6c 100644 --- a/src/AutoRest.CSharp/Common/Generation/Writers/ClientOptionsWriter.cs +++ b/src/AutoRest.CSharp/Common/Generation/Writers/ClientOptionsWriter.cs @@ -5,6 +5,7 @@ using System.Linq; using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Output.Models.Types; +using AutoRest.CSharp.Utilities; namespace AutoRest.CSharp.Generation.Writers { @@ -49,6 +50,15 @@ public static void WriteClientOptions(CodeWriter writer, ClientOptionsTypeProvid writer.Line($"_ => throw new {typeof(NotSupportedException)}()"); } } + + writer.Line(); + } + + foreach (var parameter in clientOptions.AdditionalParameters) + { + writer.WriteXmlDocumentationSummary(parameter.Description); + writer.Line($"public {parameter.Type} {parameter.Name.ToCleanName()} {{ get; set; }}"); + writer.Line(); } } } diff --git a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs index ac759a8c00f..5f9f060814f 100644 --- a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs @@ -452,6 +452,11 @@ private static InputLiteralType CreateLiteralType(ConstantSchema constantSchema, { if (parameter.ClientDefaultValue != null) { + if (parameter.Origin == "modelerfour:synthesized/host" && (string)parameter.ClientDefaultValue == "") + { + return null; + } + return new InputConstant(Value: parameter.ClientDefaultValue, Type: CreateType(parameter.Schema, _modelsCache, parameter.IsNullable)); } diff --git a/src/AutoRest.CSharp/Common/Output/Models/Shared/KnownParameters.cs b/src/AutoRest.CSharp/Common/Output/Models/Shared/KnownParameters.cs index 7ea3d0be133..a0835550df0 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Shared/KnownParameters.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Shared/KnownParameters.cs @@ -26,7 +26,7 @@ internal static class KnownParameters public static readonly Parameter Pipeline = new("pipeline", $"The HTTP pipeline for sending and receiving REST requests and responses", new CSharpType(Configuration.ApiTypes.HttpPipelineType), null, ValidationType.AssertNotNull, null); public static readonly Parameter KeyAuth = new("keyCredential", $"The key credential to copy", new CSharpType(Configuration.ApiTypes.KeyCredentialType), null, ValidationType.None, null); public static readonly Parameter TokenAuth = new("tokenCredential", $"The token credential to copy", new CSharpType(typeof(TokenCredential)), null, ValidationType.None, null); - public static readonly Parameter Endpoint = new("endpoint", $"Service endpoint", new CSharpType(typeof(Uri)), null, ValidationType.None, null, RequestLocation: RequestLocation.Uri); + public static readonly Parameter Endpoint = new("endpoint", $"Service endpoint", new CSharpType(typeof(Uri)), null, ValidationType.None, null, RequestLocation: RequestLocation.Uri, IsEndpoint: true); public static readonly Parameter PageSizeHint = new("pageSizeHint", $"The number of items per {typeof(Page<>):C} that should be requested (from service operations that support it). It's not guaranteed that the value will be respected.", new CSharpType(typeof(int), true), null, ValidationType.None, null); public static readonly Parameter NextLink = new("nextLink", $"Continuation token", typeof(string), null, ValidationType.None, null); diff --git a/src/AutoRest.CSharp/Common/Output/Models/Shared/Parameter.cs b/src/AutoRest.CSharp/Common/Output/Models/Shared/Parameter.cs index 1c0373fcd18..23f5524e80d 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Shared/Parameter.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Shared/Parameter.cs @@ -16,7 +16,7 @@ namespace AutoRest.CSharp.Output.Models.Shared { - internal record Parameter(string Name, FormattableString? Description, CSharpType Type, Constant? DefaultValue, ValidationType Validation, FormattableString? Initializer, bool IsApiVersionParameter = false, bool IsResourceIdentifier = false, bool SkipUrlEncoding = false, RequestLocation RequestLocation = RequestLocation.None, SerializationFormat SerializationFormat = SerializationFormat.Default, bool IsPropertyBag = false) + internal record Parameter(string Name, FormattableString? Description, CSharpType Type, Constant? DefaultValue, ValidationType Validation, FormattableString? Initializer, bool IsApiVersionParameter = false, bool IsEndpoint = false, bool IsResourceIdentifier = false, bool SkipUrlEncoding = false, RequestLocation RequestLocation = RequestLocation.None, SerializationFormat SerializationFormat = SerializationFormat.Default, bool IsPropertyBag = false) { public CSharpAttribute[] Attributes { get; init; } = Array.Empty(); public bool IsOptionalInSignature => DefaultValue != null; @@ -74,6 +74,7 @@ public static Parameter FromInputParameter(in InputParameter operationParameter, validation, initializer, IsApiVersionParameter: operationParameter.IsApiVersion, + IsEndpoint: operationParameter.IsEndpoint, IsResourceIdentifier: operationParameter.IsResourceParameter, SkipUrlEncoding: skipUrlEncoding, RequestLocation: requestLocation, @@ -167,6 +168,7 @@ public static Parameter FromRequestParameter(in RequestParameter requestParamete validation, initializer, IsApiVersionParameter: requestParameter.Origin == "modelerfour:synthesized/api-version", + IsEndpoint: IsEndpointParameter(requestParameter), IsResourceIdentifier: requestParameter.IsResourceParameter, SkipUrlEncoding: skipUrlEncoding, RequestLocation: requestLocation); diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/ClientOptionsTypeProvider.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/ClientOptionsTypeProvider.cs index f75a1f599a3..384b0afccfb 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/ClientOptionsTypeProvider.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/ClientOptionsTypeProvider.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using AutoRest.CSharp.Input.Source; +using AutoRest.CSharp.Output.Models.Shared; namespace AutoRest.CSharp.Output.Models.Types { @@ -16,6 +17,7 @@ internal sealed class ClientOptionsTypeProvider : TypeProvider public FormattableString Description { get; } public IReadOnlyList? ApiVersions { get; } + public IReadOnlyList AdditionalParameters { get; init; } protected override string DefaultName { get; } protected override string DefaultAccessibility { get; } @@ -27,6 +29,8 @@ public ClientOptionsTypeProvider(IReadOnlyList? versions, string name, s if (versions is not null) ApiVersions = ConvertApiVersions(versions); + + AdditionalParameters = Array.Empty(); } private static ApiVersion[] ConvertApiVersions(IReadOnlyList versions) => diff --git a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs index 7796fd1042c..34c1d91aa88 100644 --- a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs +++ b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs @@ -259,6 +259,10 @@ private void WritePrimaryPublicConstructor(ConstructorSignature signature) { _writer.Line($"{field.Name:I} = {clientOptionsParameter.Name:I}.Version;"); } + else if (_client.ClientOptions.AdditionalParameters.Contains(parameter)) + { + _writer.Line($"{field.Name:I} = {clientOptionsParameter.Name:I}.{parameter.Name.ToCleanName()};"); + } else { _writer.Line($"{field.Name:I} = {parameter.Name:I};"); diff --git a/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs b/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs index 3408e712da8..54408c80912 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs @@ -11,6 +11,7 @@ using AutoRest.CSharp.Generation.Types; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Output.Builders; +using AutoRest.CSharp.Output.Models.Shared; using AutoRest.CSharp.Output.Models.Types; using AutoRest.CSharp.Utilities; using Microsoft.CodeAnalysis; @@ -44,7 +45,8 @@ public DpgOutputLibrary Build(bool isTspInput) .ToDictionary(ci => ci.Name); AssignParentClients(inputClients, clientInfosByName); var topLevelClientInfos = SetHierarchy(clientInfosByName); - var clientOptions = CreateClientOptions(topLevelClientInfos); + var parametersInClientOptions = new List(); + var clientOptions = CreateClientOptions(topLevelClientInfos, parametersInClientOptions); SetRequestsToClients(clientInfosByName.Values); @@ -59,7 +61,7 @@ public DpgOutputLibrary Build(bool isTspInput) CreateModels(models, library.TypeFactory); CreateEnums(enums, models, library.TypeFactory); } - CreateClients(clients, topLevelClientInfos, library.TypeFactory, clientOptions); + CreateClients(clients, topLevelClientInfos, library.TypeFactory, clientOptions, parametersInClientOptions); return library; } @@ -459,7 +461,7 @@ private static IReadOnlyList UpdateOperationParameters(IReadOnly return parameters; } - private ClientOptionsTypeProvider CreateClientOptions(IReadOnlyList topLevelClientInfos) + private ClientOptionsTypeProvider CreateClientOptions(IReadOnlyList topLevelClientInfos, List parametersInClientOptions) { var clientName = topLevelClientInfos.Count == 1 ? topLevelClientInfos[0].Name @@ -477,7 +479,10 @@ private ClientOptionsTypeProvider CreateClientOptions(IReadOnlyList throw new InvalidOperationException("Multiple API versions are not supported in the unbranded path."); apiVersions = null; } - return new ClientOptionsTypeProvider(apiVersions, clientOptionsName, _defaultNamespace, description, _sourceInputModel); + return new ClientOptionsTypeProvider(apiVersions, clientOptionsName, _defaultNamespace, description, _sourceInputModel) + { + AdditionalParameters = parametersInClientOptions + }; } private static ClientInfo CreateClientInfo(InputClient ns, SourceInputModel? sourceInputModel, string rootNamespaceName) @@ -626,9 +631,9 @@ private static void SetRequestToClient(ClientInfo clientInfo, InputOperation ope clientInfo.Requests.Add(operation); } - private void CreateClients(List allClients, IEnumerable topLevelClientInfos, TypeFactory typeFactory, ClientOptionsTypeProvider clientOptions) + private void CreateClients(List allClients, IEnumerable topLevelClientInfos, TypeFactory typeFactory, ClientOptionsTypeProvider clientOptions, List parametersInClientOptions) { - var topLevelClients = CreateClients(topLevelClientInfos, typeFactory, clientOptions, null); + var topLevelClients = CreateClients(topLevelClientInfos, typeFactory, clientOptions, null, parametersInClientOptions); // Simple implementation of breadth first traversal allClients.AddRange(topLevelClients); @@ -638,7 +643,7 @@ private void CreateClients(List allClients, IEnumerable CreateClients(IEnumerable clientInfos, TypeFactory typeFactory, ClientOptionsTypeProvider clientOptions, LowLevelClient? parentClient) + private IEnumerable CreateClients(IEnumerable clientInfos, TypeFactory typeFactory, ClientOptionsTypeProvider clientOptions, LowLevelClient? parentClient, List parametersInClientOptions) { foreach (var clientInfo in clientInfos) { @@ -673,7 +678,9 @@ private IEnumerable CreateClients(IEnumerable client SubClients = subClients }; - subClients.AddRange(CreateClients(clientInfo.Children, typeFactory, clientOptions, client)); + subClients.AddRange(CreateClients(clientInfo.Children, typeFactory, clientOptions, client, parametersInClientOptions)); + // parametersInClientOptions is assigned to ClientOptionsTypeProvider.AdditionalProperties before, which makes sure AdditionalProperties is readonly and won't change after ClientOptionsTypeProvider is built. + parametersInClientOptions.AddRange(client.GetOptionalParametersInOptions()); yield return client; } diff --git a/src/AutoRest.CSharp/LowLevel/Output/LowLevelClient.cs b/src/AutoRest.CSharp/LowLevel/Output/LowLevelClient.cs index 10a6249d4f1..1c6f9921570 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/LowLevelClient.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/LowLevelClient.cs @@ -140,7 +140,7 @@ public static IEnumerable BuildMethods(LowLevelClient? cli if (!IsSubClient) { var requiredParameters = RestClientBuilder.GetRequiredParameters(orderedParameters).ToArray(); - var optionalParameters = RestClientBuilder.GetOptionalParameters(orderedParameters).Append(CreateOptionsParameter()).ToArray(); + var optionalParameters = GetOptionalParametersInConstructor(RestClientBuilder.GetOptionalParameters(orderedParameters).Append(CreateOptionsParameter())).ToArray(); return ( BuildPrimaryConstructors(requiredParameters, optionalParameters).ToArray(), @@ -153,6 +153,17 @@ public static IEnumerable BuildMethods(LowLevelClient? cli } } + private IEnumerable GetOptionalParametersInConstructor(IEnumerable optionalParameters) + { + return optionalParameters.Where( + p => ClientOptions.Type.EqualsIgnoreNullable(p.Type) || p.IsEndpoint); // Endpoint is an exception, even it is optional, still need to be the parameter of constructor + } + + public IEnumerable GetOptionalParametersInOptions() + { + return RestClientBuilder.GetOptionalParameters(Parameters).Where(p => !p.IsEndpoint); + } + private IEnumerable BuildPrimaryConstructors(IReadOnlyList requiredParameters, IReadOnlyList optionalParameters) { var optionalToRequired = optionalParameters diff --git a/test/AutoRest.TestServerLowLevel.Tests/url-path-items.cs b/test/AutoRest.TestServerLowLevel.Tests/url-path-items.cs index 386833e238e..3f351aef763 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/url-path-items.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/url-path-items.cs @@ -12,55 +12,76 @@ public class UrlPathItemsTests : TestServerLowLevelTestBase { [Test] public Task UrlPathItemGetAll() => TestStatus(async (host) => - await new PathItemsClient(globalStringPath: "globalStringPath", - globalStringQuery: "globalStringQuery", + { + var options = new AutoRestUrlTestServiceClientOptions() + { + GlobalStringQuery = "globalStringQuery" + }; + return await new PathItemsClient(globalStringPath: "globalStringPath", credential: Key, endpoint: host, - options: null) + options: options) .GetAllWithValuesAsync( pathItemStringPath: "pathItemStringPath", pathItemStringQuery: "pathItemStringQuery", localStringPath: "localStringPath", - localStringQuery: "localStringQuery")); + localStringQuery: "localStringQuery"); + }); [Test] public Task UrlPathItemGetPathItemAndLocalNull() => TestStatus(async (host) => - await new PathItemsClient(globalStringPath: "globalStringPath", - globalStringQuery: "globalStringQuery", + { + var options = new AutoRestUrlTestServiceClientOptions() + { + GlobalStringQuery = "globalStringQuery" + }; + return await new PathItemsClient(globalStringPath: "globalStringPath", credential: Key, endpoint: host, - options: null) + options: options) .GetLocalPathItemQueryNullAsync( pathItemStringPath: "pathItemStringPath", pathItemStringQuery: null, localStringPath: "localStringPath", - localStringQuery: null)); + localStringQuery: null); + }); + [Test] public Task UrlPathItemGetGlobalNull() => TestStatus(async (host) => - await new PathItemsClient(globalStringPath: "globalStringPath", - endpoint: host, - credential: Key, - globalStringQuery: null, - options: null) - .GetGlobalQueryNullAsync( - pathItemStringPath: "pathItemStringPath", - pathItemStringQuery: "pathItemStringQuery", - localStringPath: "localStringPath", - localStringQuery: "localStringQuery")); + { + var options = new AutoRestUrlTestServiceClientOptions() + { + GlobalStringQuery = null + }; + return await new PathItemsClient(globalStringPath: "globalStringPath", + endpoint: host, + credential: Key, + options: options) + .GetGlobalQueryNullAsync( + pathItemStringPath: "pathItemStringPath", + pathItemStringQuery: "pathItemStringQuery", + localStringPath: "localStringPath", + localStringQuery: "localStringQuery"); + }); [Test] public Task UrlPathItemGetGlobalAndLocalNull() => TestStatus(async (host) => - await new PathItemsClient( - globalStringPath: "globalStringPath", - endpoint: host, - credential: Key, - globalStringQuery: null, - options: null) - .GetGlobalAndLocalQueryNullAsync( - pathItemStringPath: "pathItemStringPath", - pathItemStringQuery: "pathItemStringQuery", - localStringPath: "localStringPath", - localStringQuery: null)); + { + var options = new AutoRestUrlTestServiceClientOptions() + { + GlobalStringQuery = null + }; + return await new PathItemsClient( + globalStringPath: "globalStringPath", + endpoint: host, + credential: Key, + options: options) + .GetGlobalAndLocalQueryNullAsync( + pathItemStringPath: "pathItemStringPath", + pathItemStringQuery: "pathItemStringQuery", + localStringPath: "localStringPath", + localStringQuery: null); + }); } } diff --git a/test/TestProjects/ApiVersion/Generated/ApiVersionClient.cs b/test/TestProjects/ApiVersion/Generated/ApiVersionClient.cs index a868168e8c8..f28e010cec7 100644 --- a/test/TestProjects/ApiVersion/Generated/ApiVersionClient.cs +++ b/test/TestProjects/ApiVersion/Generated/ApiVersionClient.cs @@ -31,8 +31,8 @@ protected ApiVersionClient() /// The HTTP pipeline for sending and receiving REST requests and responses. /// server parameter. /// Api Version. - /// , or is null. - internal ApiVersionClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string apiVersion = "1.0.0") + /// , , or is null. + internal ApiVersionClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint, string apiVersion = "1.0.0") { RestClient = new ApiVersionRestClient(clientDiagnostics, pipeline, endpoint, apiVersion); _clientDiagnostics = clientDiagnostics; diff --git a/test/TestProjects/ApiVersion/Generated/ApiVersionRestClient.cs b/test/TestProjects/ApiVersion/Generated/ApiVersionRestClient.cs index 9a4fb271dc2..6182cf91813 100644 --- a/test/TestProjects/ApiVersion/Generated/ApiVersionRestClient.cs +++ b/test/TestProjects/ApiVersion/Generated/ApiVersionRestClient.cs @@ -29,12 +29,12 @@ internal partial class ApiVersionRestClient /// The HTTP pipeline for sending and receiving REST requests and responses. /// server parameter. /// Api Version. - /// , or is null. - public ApiVersionRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string apiVersion = "1.0.0") + /// , , or is null. + public ApiVersionRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint, string apiVersion = "1.0.0") { ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics)); _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); - _endpoint = endpoint ?? new Uri(""); + _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint)); _apiVersion = apiVersion ?? throw new ArgumentNullException(nameof(apiVersion)); } diff --git a/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageClient.cs b/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageClient.cs index 824bb9030d5..6f558ec5521 100644 --- a/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageClient.cs +++ b/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageClient.cs @@ -30,8 +30,8 @@ protected ModelWithConverterUsageClient() /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// server parameter. - /// or is null. - internal ModelWithConverterUsageClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + /// , or is null. + internal ModelWithConverterUsageClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint) { RestClient = new ModelWithConverterUsageRestClient(clientDiagnostics, pipeline, endpoint); _clientDiagnostics = clientDiagnostics; diff --git a/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageRestClient.cs b/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageRestClient.cs index b4efb5ab5cf..921beb077fa 100644 --- a/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageRestClient.cs +++ b/test/TestProjects/ModelWithConverterUsage/Generated/ModelWithConverterUsageRestClient.cs @@ -28,12 +28,12 @@ internal partial class ModelWithConverterUsageRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// server parameter. - /// or is null. - public ModelWithConverterUsageRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + /// , or is null. + public ModelWithConverterUsageRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint) { ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics)); _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); - _endpoint = endpoint ?? new Uri(""); + _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint)); } internal HttpMessage CreateOperationModelRequest(ModelClass value) diff --git a/test/TestProjects/Parameters-LowLevel/src/Generated/ParametersLowlevelClientBuilderExtensions.cs b/test/TestProjects/Parameters-LowLevel/src/Generated/ParametersLowlevelClientBuilderExtensions.cs deleted file mode 100644 index abea8b1d794..00000000000 --- a/test/TestProjects/Parameters-LowLevel/src/Generated/ParametersLowlevelClientBuilderExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using Azure; -using Azure.Core.Extensions; -using Parameters_LowLevel; - -namespace Microsoft.Extensions.Azure -{ - /// Extension methods to add to client builder. - public static partial class ParametersLowLevelClientBuilderExtensions - { - /// Registers a instance. - /// The builder to register with. - /// server parameter. - /// A credential used to authenticate to an Azure Service. - public static IAzureClientBuilder AddParametersLowlevelClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) - where TBuilder : IAzureClientFactoryBuilder - { - return builder.RegisterClientFactory((options) => new ParametersLowlevelClient(endpoint, credential, options)); - } - - /// Registers a instance. - /// The builder to register with. - /// The configuration values. - public static IAzureClientBuilder AddParametersLowlevelClient(this TBuilder builder, TConfiguration configuration) - where TBuilder : IAzureClientFactoryBuilderWithConfiguration - { - return builder.RegisterClientFactory(configuration); - } - } -} diff --git a/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/Docs/ServiceVersionOverrideClient.xml b/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/Docs/ServiceVersionOverrideClient.xml index 755ed41e6c9..1c6748e4e2e 100644 --- a/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/Docs/ServiceVersionOverrideClient.xml +++ b/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/Docs/ServiceVersionOverrideClient.xml @@ -5,7 +5,8 @@ This sample shows how to call OperationAsync. "); +ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = await client.OperationAsync("2.0"); @@ -13,7 +14,8 @@ Console.WriteLine(response.Status); ]]> This sample shows how to call OperationAsync with all parameters. "); +ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = await client.OperationAsync("2.0"); @@ -24,7 +26,8 @@ Console.WriteLine(response.Status); This sample shows how to call Operation. "); +ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = client.Operation("2.0"); @@ -32,7 +35,8 @@ Console.WriteLine(response.Status); ]]> This sample shows how to call Operation with all parameters. "); +ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = client.Operation("2.0"); diff --git a/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/ServiceVersionOverrideClient.cs b/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/ServiceVersionOverrideClient.cs index 278348087c8..0fc923b24d0 100644 --- a/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/ServiceVersionOverrideClient.cs +++ b/test/TestProjects/ServiceVersionOverride-LowLevel/src/Generated/ServiceVersionOverrideClient.cs @@ -27,8 +27,15 @@ public partial class ServiceVersionOverrideClient /// The HTTP pipeline for sending and receiving REST requests and responses. public virtual HttpPipeline Pipeline => _pipeline; + /// Initializes a new instance of ServiceVersionOverrideClient for mocking. + protected ServiceVersionOverrideClient() + { + } + /// Initializes a new instance of ServiceVersionOverrideClient. - public ServiceVersionOverrideClient() : this(new Uri(""), new ServiceVersionOverrideClientOptions()) + /// server parameter. + /// is null. + public ServiceVersionOverrideClient(Uri endpoint) : this(endpoint, new ServiceVersionOverrideClientOptions()) { } diff --git a/test/TestProjects/ServiceVersionOverride-LowLevel/tests/Generated/Samples/Samples_ServiceVersionOverrideClient.cs b/test/TestProjects/ServiceVersionOverride-LowLevel/tests/Generated/Samples/Samples_ServiceVersionOverrideClient.cs index 58014d6548b..8ba0d09edcc 100644 --- a/test/TestProjects/ServiceVersionOverride-LowLevel/tests/Generated/Samples/Samples_ServiceVersionOverrideClient.cs +++ b/test/TestProjects/ServiceVersionOverride-LowLevel/tests/Generated/Samples/Samples_ServiceVersionOverrideClient.cs @@ -20,7 +20,8 @@ public partial class Samples_ServiceVersionOverrideClient [Ignore("Only validating compilation of examples")] public void Example_Operation_ShortVersion() { - ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(); + Uri endpoint = new Uri(""); + ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = client.Operation("2.0"); @@ -31,7 +32,8 @@ public void Example_Operation_ShortVersion() [Ignore("Only validating compilation of examples")] public async Task Example_Operation_ShortVersion_Async() { - ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(); + Uri endpoint = new Uri(""); + ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = await client.OperationAsync("2.0"); @@ -42,7 +44,8 @@ public async Task Example_Operation_ShortVersion_Async() [Ignore("Only validating compilation of examples")] public void Example_Operation_AllParameters() { - ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(); + Uri endpoint = new Uri(""); + ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = client.Operation("2.0"); @@ -53,7 +56,8 @@ public void Example_Operation_AllParameters() [Ignore("Only validating compilation of examples")] public async Task Example_Operation_AllParameters_Async() { - ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(); + Uri endpoint = new Uri(""); + ServiceVersionOverrideClient client = new ServiceVersionOverrideClient(endpoint); Response response = await client.OperationAsync("2.0"); diff --git a/test/TestServerProjectsLowLevel/url/src/Generated/AutoRestUrlTestServiceClientOptions.cs b/test/TestServerProjectsLowLevel/url/src/Generated/AutoRestUrlTestServiceClientOptions.cs index 26ab885d6bb..435af050aae 100644 --- a/test/TestServerProjectsLowLevel/url/src/Generated/AutoRestUrlTestServiceClientOptions.cs +++ b/test/TestServerProjectsLowLevel/url/src/Generated/AutoRestUrlTestServiceClientOptions.cs @@ -33,5 +33,8 @@ public AutoRestUrlTestServiceClientOptions(ServiceVersion version = LatestVersio _ => throw new NotSupportedException() }; } + + /// should contain value null. + public string GlobalStringQuery { get; set; } } } diff --git a/test/TestServerProjectsLowLevel/url/src/Generated/PathItemsClient.cs b/test/TestServerProjectsLowLevel/url/src/Generated/PathItemsClient.cs index c645a5a7093..ff7724440d1 100644 --- a/test/TestServerProjectsLowLevel/url/src/Generated/PathItemsClient.cs +++ b/test/TestServerProjectsLowLevel/url/src/Generated/PathItemsClient.cs @@ -40,7 +40,7 @@ protected PathItemsClient() /// A credential used to authenticate to an Azure Service. /// or is null. /// is an empty string, and was expected to be non-empty. - public PathItemsClient(string globalStringPath, AzureKeyCredential credential) : this(new Uri("http://localhost:3000"), globalStringPath, credential, null, new AutoRestUrlTestServiceClientOptions()) + public PathItemsClient(string globalStringPath, AzureKeyCredential credential) : this(new Uri("http://localhost:3000"), globalStringPath, credential, new AutoRestUrlTestServiceClientOptions()) { } @@ -48,11 +48,10 @@ protected PathItemsClient() /// server parameter. /// A string value 'globalItemStringPath' that appears in the path. /// A credential used to authenticate to an Azure Service. - /// should contain value null. /// The options for configuring the client. /// , or is null. /// is an empty string, and was expected to be non-empty. - public PathItemsClient(Uri endpoint, string globalStringPath, AzureKeyCredential credential, string globalStringQuery, AutoRestUrlTestServiceClientOptions options) + public PathItemsClient(Uri endpoint, string globalStringPath, AzureKeyCredential credential, AutoRestUrlTestServiceClientOptions options) { Argument.AssertNotNull(endpoint, nameof(endpoint)); Argument.AssertNotNullOrEmpty(globalStringPath, nameof(globalStringPath)); @@ -64,7 +63,7 @@ public PathItemsClient(Uri endpoint, string globalStringPath, AzureKeyCredential _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier()); _globalStringPath = globalStringPath; _endpoint = endpoint; - _globalStringQuery = globalStringQuery; + _globalStringQuery = options.GlobalStringQuery; } /// diff --git a/test/TestServerProjectsLowLevel/url/src/Generated/UrlLowLevelClientBuilderExtensions.cs b/test/TestServerProjectsLowLevel/url/src/Generated/UrlLowLevelClientBuilderExtensions.cs index faabbf859fd..4b92e9a718f 100644 --- a/test/TestServerProjectsLowLevel/url/src/Generated/UrlLowLevelClientBuilderExtensions.cs +++ b/test/TestServerProjectsLowLevel/url/src/Generated/UrlLowLevelClientBuilderExtensions.cs @@ -40,11 +40,10 @@ public static IAzureClientBuilder server parameter. /// A string value 'globalItemStringPath' that appears in the path. /// A credential used to authenticate to an Azure Service. - /// should contain value null. - public static IAzureClientBuilder AddPathItemsClient(this TBuilder builder, Uri endpoint, string globalStringPath, AzureKeyCredential credential, string globalStringQuery) + public static IAzureClientBuilder AddPathItemsClient(this TBuilder builder, Uri endpoint, string globalStringPath, AzureKeyCredential credential) where TBuilder : IAzureClientFactoryBuilder { - return builder.RegisterClientFactory((options) => new PathItemsClient(endpoint, globalStringPath, credential, globalStringQuery, options)); + return builder.RegisterClientFactory((options) => new PathItemsClient(endpoint, globalStringPath, credential, options)); } /// Registers a instance.