diff --git a/templates/python-pydantic.jinja b/templates/python-pydantic.jinja index b127d4d..6964fad 100644 --- a/templates/python-pydantic.jinja +++ b/templates/python-pydantic.jinja @@ -40,18 +40,18 @@ class {{ object.name }}(BaseModel): # JSON-LD fields ld_id: str = Field( - serialization_alias="@id", + alias="@id", default_factory=lambda: "{{ prefix }}:{{ object.name }}/" + str(uuid4()) ) ld_type: list[str] = Field( - serialization_alias="@type", + alias="@type", default_factory = lambda: [ "{{ prefix }}:{{ object.name }}", {%- if object.term -%}"{{ object.term }}"{%- endif %} ], ) ld_context: dict[str, str | dict] = Field( - serialization_alias="@context", + alias="@context", default_factory = lambda: { "{{ prefix }}": "{{ repo }}", {%- for prefix, address in prefixes %} diff --git a/tests/data/expected_pydantic.py b/tests/data/expected_pydantic.py index c470fef..5fe48fd 100644 --- a/tests/data/expected_pydantic.py +++ b/tests/data/expected_pydantic.py @@ -16,17 +16,17 @@ class Test(BaseModel): # JSON-LD fields ld_id: str = Field( - serialization_alias="@id", + alias="@id", default_factory=lambda: "tst:Test/" + str(uuid4()) ) ld_type: list[str] = Field( - serialization_alias="@type", + alias="@type", default_factory = lambda: [ "tst:Test", ], ) ld_context: dict[str, str | dict] = Field( - serialization_alias="@context", + alias="@context", default_factory = lambda: { "tst": "https://www.github.com/my/repo/", "schema": "http://schema.org/", @@ -67,17 +67,17 @@ class Test2(BaseModel): # JSON-LD fields ld_id: str = Field( - serialization_alias="@id", + alias="@id", default_factory=lambda: "tst:Test2/" + str(uuid4()) ) ld_type: list[str] = Field( - serialization_alias="@type", + alias="@type", default_factory = lambda: [ "tst:Test2", ], ) ld_context: dict[str, str | dict] = Field( - serialization_alias="@context", + alias="@context", default_factory = lambda: { "tst": "https://www.github.com/my/repo/", "schema": "http://schema.org/",