Skip to content

Commit

Permalink
Merge pull request #47 from finbourne/feature/CTOOLS-445
Browse files Browse the repository at this point in the history
Feature/ctools 445
  • Loading branch information
JasonMayoFinbourne authored Dec 13, 2024
2 parents b3144be + 9ad7c0b commit 73b9d12
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
12 changes: 10 additions & 2 deletions generate/default_templates/model_anyof.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,17 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
else:
return json.dumps(self.actual_instance)

def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the actual instance"""
return pprint.pformat(self.dict())
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))

{{#vendorExtensions.x-py-postponed-model-imports.size}}
{{#vendorExtensions.x-py-postponed-model-imports}}
Expand Down
8 changes: 8 additions & 0 deletions generate/default_templates/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}

{{/discriminator}}
{{/hasChildren}}
def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
Expand Down
13 changes: 11 additions & 2 deletions generate/default_templates/model_oneof.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,18 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
# primitive type
return self.actual_instance

def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the actual instance"""
return pprint.pformat(self.dict())
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))


{{#vendorExtensions.x-py-postponed-model-imports.size}}
{{#vendorExtensions.x-py-postponed-model-imports}}
Expand Down
15 changes: 12 additions & 3 deletions generate/templates/model_anyof.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
else:
return instance

def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
if self.actual_instance is None:
Expand All @@ -168,9 +180,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
else:
return json.dumps(self.actual_instance)

def to_str(self) -> str:
"""Returns the string representation of the actual instance"""
return pprint.pformat(self.dict())

{{#vendorExtensions.x-py-postponed-model-imports.size}}
{{#vendorExtensions.x-py-postponed-model-imports}}
Expand Down
8 changes: 8 additions & 0 deletions generate/templates/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}

{{/discriminator}}
{{/hasChildren}}
def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
Expand Down
14 changes: 11 additions & 3 deletions generate/templates/model_oneof.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,17 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
# primitive type
return self.actual_instance

def to_str(self) -> str:
"""Returns the string representation of the actual instance"""
return pprint.pformat(self.dict())
def __str__(self):
"""For `print` and `pprint`"""
return pprint.pformat(self.dict(by_alias=False))

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))

{{#vendorExtensions.x-py-postponed-model-imports.size}}
{{#vendorExtensions.x-py-postponed-model-imports}}
Expand Down

0 comments on commit 73b9d12

Please sign in to comment.