Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions avro_to_python/templates/fields/mapField.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{%- block map %}
def set_{{name}}(self, values: list) -> None:

def set_{{name}}(self, values) -> None:
if isinstance(values, dict):
self.{{name}} = values
return

self.{{name}} = []
if isinstance(values, list):
for item in values:
Expand Down Expand Up @@ -60,6 +63,6 @@
else:
raise TypeError("Field '{{name}}' should be type list")

def get_{{name}}(self) -> list:
def get_{{name}}(self):
return self.{{name}}
{%- endblock -%}
{%- endblock -%}
9 changes: 6 additions & 3 deletions avro_to_python/templates/files/record.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
class {{file.name}}(object):

{% include 'partials/avroSchema.j2'|indent(-4) %}
def __init__(self, obj: Union[str, dict, '{{file.name}}']) -> None:
if isinstance(obj, str):
def __init__(self, obj: Union[str, dict, '{{file.name}}'] = None) -> None:
if obj is None:
return

elif isinstance(obj, str):
obj = json.loads(obj)

elif isinstance(obj, type(self)):
Expand All @@ -22,4 +25,4 @@ class {{file.name}}(object):
{% for name, field in file.fields.items() -%}
{% include 'fields/fieldFactory.j2' %}
{% endfor -%}
{%- endblock -%}
{%- endblock -%}