Skip to content

Commit

Permalink
Merged config and client objects
Browse files Browse the repository at this point in the history
  • Loading branch information
annatisch committed May 17, 2016
1 parent fae2d8a commit 42219a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ public virtual string RequiredConstructorParameters
}
}

public virtual string ConfigConstructorParameters
{
get
{
var configParams = new List<string>();
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
{
Expand All @@ -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)(
Expand Down

0 comments on commit 42219a6

Please sign in to comment.