Skip to content

Commit

Permalink
change to alias
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jun 14, 2024
1 parent 26181f1 commit 1fafde5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions templates/python-pydantic.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
12 changes: 6 additions & 6 deletions tests/data/expected_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -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/",
Expand Down

0 comments on commit 1fafde5

Please sign in to comment.