diff --git a/AutoRest/Generators/Python/Azure.Python/Templates/AzureServiceClientTemplate.cshtml b/AutoRest/Generators/Python/Azure.Python/Templates/AzureServiceClientTemplate.cshtml index 1bd45c95a8d80..383db9e00700c 100644 --- a/AutoRest/Generators/Python/Azure.Python/Templates/AzureServiceClientTemplate.cshtml +++ b/AutoRest/Generators/Python/Azure.Python/Templates/AzureServiceClientTemplate.cshtml @@ -92,23 +92,37 @@ else @EmptyLine class @(Model.Name)(object): """@Model.ServiceDocument -@EmptyLine - :param config: Configuration for client. - :type config: @(Model.Name)Configuration + @EmptyLine + :ivar config: Configuration for client. + :vartype config: @(Model.Name)Configuration @if (Model.MethodGroupModels.Any()) { -@EmptyLine - foreach (var methodGroup in Model.MethodGroupModels) - { + @EmptyLine + foreach (var methodGroup in Model.MethodGroupModels) + { @: :ivar @(methodGroup.MethodGroupName.ToPythonCase()): @(methodGroup.MethodGroupName) operations @: :vartype @(methodGroup.MethodGroupName.ToPythonCase()): .operations.@(methodGroup.MethodGroupType) - } + } +} +@EmptyLine +@foreach (var property in Model.Properties) +{ +@: @ParameterWrapComment(string.Empty, ServiceClientTemplateModel.GetPropertyDocumentationString(property)) +@: @ParameterWrapComment(string.Empty, ":type " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type)) } + +@if (!Model.IsCustomBaseUri) +{ +@: :param str base_url: Service URL +} + :param str filepath: Existing config """ @EmptyLine - def __init__(self, config): + def __init__( + self, @(Model.RequiredConstructorParameters)@(Model.IsCustomBaseUri ? "" : "base_url=None, ")filepath=None): @EmptyLine - self._client = ServiceClient(@(Model.Properties.Any(p => p.Type.IsPrimaryType(KnownPrimaryType.Credentials)) ? "config.credentials" : PythonConstants.None), config) + self.config = @(Model.Name)Configuration(@(Model.ConfigConstructorParameters)@(Model.IsCustomBaseUri ? "" : "base_url, ")filepath) + self._client = ServiceClient(@(Model.Properties.Any(p => p.Type.IsPrimaryType(KnownPrimaryType.Credentials)) ? "self.config.credentials" : PythonConstants.None), self.config) @EmptyLine @if (Model.ModelTemplateModels.Any()) { @@ -121,7 +135,6 @@ else self._serialize = Serializer() self._deserialize = Deserializer(client_models) @EmptyLine - self.config = config @foreach (var methodGroup in Model.MethodGroupModels) { @:self.@(methodGroup.MethodGroupName.ToPythonCase()) = @(methodGroup.MethodGroupType)( diff --git a/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs b/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs index 60629ea26ca28..24317c08c1faa 100644 --- a/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs +++ b/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs @@ -105,6 +105,24 @@ public virtual string RequiredConstructorParameters } } + public virtual string ConfigConstructorParameters + { + get + { + var configParams = new List(); + foreach (var property in this.Properties) + { + configParams.Add(property.Name.ToPythonCase()); + } + var param = string.Join(", ", configParams); + if (!param.IsNullOrEmpty()) + { + param += ", "; + } + return param; + } + } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ValueError"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "TypeError"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "str"), diff --git a/AutoRest/Generators/Python/Python/Templates/ServiceClientInitTemplate.cshtml b/AutoRest/Generators/Python/Python/Templates/ServiceClientInitTemplate.cshtml index fa51a54aafb30..d2bce3c67bd79 100644 --- a/AutoRest/Generators/Python/Python/Templates/ServiceClientInitTemplate.cshtml +++ b/AutoRest/Generators/Python/Python/Templates/ServiceClientInitTemplate.cshtml @@ -9,13 +9,10 @@ @Header("# ").TrimMultilineHeader() # -------------------------------------------------------------------------- @EmptyLine -from .@(Model.Name.ToPythonCase()) import @(Model.Name), @(Model.Name)Configuration +from .@(Model.Name.ToPythonCase()) import @(Model.Name) from .version import VERSION @EmptyLine -__all__ = [ - '@(Model.Name)', - '@(Model.Name)Configuration' -] +__all__ = ['@(Model.Name)'] @EmptyLine __version__ = VERSION @EmptyLine \ No newline at end of file diff --git a/AutoRest/Generators/Python/Python/Templates/ServiceClientTemplate.cshtml b/AutoRest/Generators/Python/Python/Templates/ServiceClientTemplate.cshtml index 9172b54791c76..e6ba317b1e190 100644 --- a/AutoRest/Generators/Python/Python/Templates/ServiceClientTemplate.cshtml +++ b/AutoRest/Generators/Python/Python/Templates/ServiceClientTemplate.cshtml @@ -86,8 +86,8 @@ else class @(Model.Name)(object): """@Model.ServiceDocument @EmptyLine - :param config: Configuration for client. - :type config: @(Model.Name)Configuration + :ivar config: Configuration for client. + :vartype config: @(Model.Name)Configuration @if (Model.MethodGroupModels.Any()) { @EmptyLine @@ -97,11 +97,25 @@ class @(Model.Name)(object): @: :vartype @(methodGroup.MethodGroupName.ToPythonCase()): .operations.@(methodGroup.MethodGroupType) } } +@EmptyLine +@foreach (var property in Model.Properties) +{ +@: @ParameterWrapComment(string.Empty, ServiceClientTemplateModel.GetPropertyDocumentationString(property)) +@: @ParameterWrapComment(string.Empty, ":type " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type)) +} + +@if (!Model.IsCustomBaseUri) +{ +@: :param str base_url: Service URL +} + :param str filepath: Existing config """ @EmptyLine - def __init__(self, config): + def __init__( + self, @(Model.RequiredConstructorParameters)@(Model.IsCustomBaseUri ? "" : "base_url=None, ")filepath=None): @EmptyLine - self._client = ServiceClient(@(Model.Properties.Any(p => p.Type.IsPrimaryType(KnownPrimaryType.Credentials)) ? "config.credentials" : PythonConstants.None), config) + self.config = @(Model.Name)Configuration(@(Model.ConfigConstructorParameters)@(Model.IsCustomBaseUri ? "" : "base_url, ")filepath) + self._client = ServiceClient(@(Model.Properties.Any(p => p.Type.IsPrimaryType(KnownPrimaryType.Credentials)) ? "self.config.credentials" : PythonConstants.None), self.config) @EmptyLine @if (Model.ModelTemplateModels.Any()) { @@ -114,7 +128,6 @@ else self._serialize = Serializer() self._deserialize = Deserializer(client_models) @EmptyLine - self.config = config @foreach (var methodGroup in Model.MethodGroupModels) { @:self.@(methodGroup.MethodGroupName.ToPythonCase()) = @(methodGroup.MethodGroupType)(