Skip to content

Commit

Permalink
Fixes #78
Browse files Browse the repository at this point in the history
  • Loading branch information
Semprini committed May 18, 2024
1 parent 7a6b83c commit 21b64a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mdg/templates/Python/dataclass_avro.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import typing
from datetime import date

from dataclasses_avroschema import AvroModel

{% macro do_enum(current_enum) -%}
{% set enums_done = [] %}{% set classes_done = [] %}
{% macro do_enum(current_enum) -%}{% if current_enum.id not in enums_done %}{{ enums_done.append( current_enum.id ) | default("", True) }}
class {{ current_enum.name | case_class }}(enum.Enum):{% for attr in current_enum.values %}
{{ attr | case_class | replace("/", "_") | replace("-", "_")}} = '{{ attr }}'{% endfor -%}
{% endmacro -%}
{% endif %}{% endmacro -%}

{% macro do_class(current_class, root=False) -%}
{% macro do_class(current_class, root=False) -%}{% if current_class.id not in classes_done %}{{ classes_done.append( current_class.id ) | default("", True) }}
@dataclass
class {{ current_class.name | case_class }}({% if current_class.generalization %}{{ current_class.generalization.name | case_class }}{% else %}AvroModel{% endif %}):{% if current_class.id_attribute.parent == current_class %}
{{ current_class.id_attribute.name | snakecase }}: {{current_class.id_attribute.dest_type}}{% endif %}
Expand All @@ -24,7 +24,7 @@ class {{ current_class.name | case_class }}({% if current_class.generalization %
class Meta:
namespace = "{{ current_class.package.name | snakecase }}"

{% endmacro -%}
{% endif %}{% endmacro -%}

{% for cls in package.classes %}{% for attr in cls.attributes %}{% if attr.classification %}
{{ do_enum(attr.classification) }}
Expand Down
3 changes: 2 additions & 1 deletion sample_recipes/sparxdb/config-sparxdb-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source: sqlite:///./sample_recipes/sparxdb/sample.qea
parser: sparxdb
dest_root: ./build/sample_sparxdb_schema
templates_folder: ./mdg/templates
default_dialect: default
default_dialect: python
generation_artifacts:
# Avro Schema
- dest: "avro/{{cls.package.name}}.{{ cls.name }}.avsc"
Expand All @@ -20,6 +20,7 @@ generation_artifacts:
- dest: "python/{{package.name}}_dataclasses.py"
level: package
source: "Python/dataclass_avro.py.jinja"
filter: "{% if package.classes %}True{% else %}False{% endif %}"
test_templates:
- dest: ./build/json{{ins.package.path}}/{{ins.stereotype}}.json
format: json

0 comments on commit 21b64a3

Please sign in to comment.