Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
adapt to pydantic xml
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jan 11, 2024
1 parent a350424 commit c86c151
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
18 changes: 13 additions & 5 deletions sdRDM/generator/templates/attribute_template.jinja2
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{{name}}: {{dtype}} = Field(
{{name}}: {{dtype}} = {% if wrapped %}wrapped("{{xml_alias}}",{% endif %}{{ field_type }}(
tag="{{tag}}",
{% if required is true and 'default' not in metadata.keys() and 'default_factory' not in metadata.keys() %}...,{% endif %}
{% for key, value in metadata.items() %}
{{key}}={{value}},
{% endfor %}
)
{% if "description" in metadata %}description={{metadata["description"]}},{% endif %}
{% if "default" in metadata %}default={{metadata["default"]}},{% endif %}
{% if "default_factory" in metadata %}default_factory={{metadata["default_factory"]}},{% endif %}
json_schema_extra=dict(
{% for key, value in metadata.items() %}
{% if not key in ["default", "description", "default_factory"]%}
{{key}}={{value}},
{% endif %}
{% endfor %}
),
){% if wrapped %}){% endif %}

9 changes: 5 additions & 4 deletions sdRDM/generator/templates/class_template.jinja2
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
@forge_signature
class {{name}}({% if inherit is not none %}
{{inherit}}
{% else %}sdRDM.DataModel{% endif %}):
{% else %}sdRDM.DataModel{% endif %}, {% if repo %}nsmap={"": "{{ repo }}@{{ commit }}#{{ name }}"},{% endif %}):


{% if docstring is not none %}"""{{ docstring }}"""{% endif %}

id: Optional[str] = Field(
id: Optional[str] = attr(
name="id",
description="Unique identifier of the given object.",
default_factory=IDGenerator("{{name.lower()}}INDEX"),
xml="@id"
)

{% for attribute in attributes -%}
{% for attribute in attributes %}
{{ attribute }}
{% endfor -%}
{% endfor %}

{% if repo is not none %}_repo: Optional[str] = PrivateAttr(default="{{repo}}"){% endif %}
{% if commit is not none %}_commit: Optional[str] = PrivateAttr(default="{{commit}}"){% endif %}
3 changes: 2 additions & 1 deletion sdRDM/generator/templates/import_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import sdRDM
{% endfor %}

from typing import Optional, Union, List
from pydantic import PrivateAttr, Field, field_validator
from pydantic import PrivateAttr, field_validator
from pydantic_xml import attr, element, wrapped
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature, IDGenerator
{% for import in from_imports %}
Expand Down

0 comments on commit c86c151

Please sign in to comment.