Skip to content

Commit 2b2069f

Browse files
committed
fix: Update Python writer unit test and snapshots for resourceType change
1 parent 6d70b8e commit 2b2069f

5 files changed

Lines changed: 29 additions & 8 deletions

File tree

test/api/write-generator/__snapshots__/python.test.ts.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`Python Writer Generator generates Patient resource in inMemoryOnly mode
77
88
from __future__ import annotations
99
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
10-
from typing import List as PyList, Literal
10+
from typing import Any, List as PyList, Literal
1111
1212
from fhir_types.hl7_fhir_r4_core.base import (\\
1313
Address, Attachment, BackboneElement, CodeableConcept, ContactPoint, HumanName, Identifier, Period, Reference
@@ -65,6 +65,9 @@ class Patient(DomainResource):
6565
photo: PyList[Attachment] | None = Field(None, alias="photo", serialization_alias="photo")
6666
telecom: PyList[ContactPoint] | None = Field(None, alias="telecom", serialization_alias="telecom")
6767
68+
def model_post_init(self, __context: Any) -> None:
69+
self.__pydantic_fields_set__.add("resource_type")
70+
6871
def to_json(self, indent: int | None = None) -> str:
6972
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
7073

test/api/write-generator/multi-package/__snapshots__/cda.test.ts.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ exports[`CDA Python Generation should generate ClinicalDocument type (promoted l
7676
7777
from __future__ import annotations
7878
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
79-
from typing import List as PyList, Literal
79+
from typing import Any, List as PyList, Literal
8080
8181
8282
@@ -121,6 +121,9 @@ class ClinicalDocument(ANY):
121121
type_id: II | None = Field(None, alias="typeId", serialization_alias="typeId")
122122
version_number: INT | None = Field(None, alias="versionNumber", serialization_alias="versionNumber")
123123
124+
def model_post_init(self, __context: Any) -> None:
125+
self.__pydantic_fields_set__.add("resource_type")
126+
124127
def to_json(self, indent: int | None = None) -> str:
125128
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
126129

test/api/write-generator/multi-package/__snapshots__/local-package.test.ts.snap

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ exports[`Local Package Folder - Multi-Package Generation Python Generation shoul
192192
193193
from __future__ import annotations
194194
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
195-
from typing import List as PyList, Literal
195+
from typing import Any, List as PyList, Literal
196196
197197
from fhir_types.hl7_fhir_r4_core.base import Coding, Identifier, Reference
198198
from fhir_types.hl7_fhir_r4_core.domain_resource import DomainResource
@@ -214,6 +214,9 @@ class ExampleNotebook(DomainResource):
214214
tag: PyList[Coding] | None = Field(None, alias="tag", serialization_alias="tag")
215215
title: str = Field(alias="title", serialization_alias="title")
216216
217+
def model_post_init(self, __context: Any) -> None:
218+
self.__pydantic_fields_set__.add("resource_type")
219+
217220
def to_json(self, indent: int | None = None) -> str:
218221
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
219222
@@ -231,7 +234,7 @@ exports[`Local Package Folder - Multi-Package Generation Python Generation shoul
231234
232235
from __future__ import annotations
233236
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
234-
from typing import List as PyList, Literal
237+
from typing import Any, List as PyList, Literal
235238
236239
from fhir_types.hl7_fhir_r4_core.base import Extension, Narrative
237240
from fhir_types.hl7_fhir_r4_core.resource import Resource
@@ -252,6 +255,9 @@ class DomainResource(Resource):
252255
modifier_extension: PyList[Extension] | None = Field(None, alias="modifierExtension", serialization_alias="modifierExtension")
253256
text: Narrative | None = Field(None, alias="text", serialization_alias="text")
254257
258+
def model_post_init(self, __context: Any) -> None:
259+
self.__pydantic_fields_set__.add("resource_type")
260+
255261
def to_json(self, indent: int | None = None) -> str:
256262
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
257263
@@ -269,7 +275,7 @@ exports[`Local Package Folder - Multi-Package Generation Python Generation shoul
269275
270276
from __future__ import annotations
271277
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
272-
from typing import List as PyList, Literal
278+
from typing import Any, List as PyList, Literal
273279
274280
from fhir_types.hl7_fhir_r4_core.base import (\\
275281
Address, Attachment, BackboneElement, CodeableConcept, ContactPoint, HumanName, Identifier, Period, Reference
@@ -327,6 +333,9 @@ class Patient(DomainResource):
327333
photo: PyList[Attachment] | None = Field(None, alias="photo", serialization_alias="photo")
328334
telecom: PyList[ContactPoint] | None = Field(None, alias="telecom", serialization_alias="telecom")
329335
336+
def model_post_init(self, __context: Any) -> None:
337+
self.__pydantic_fields_set__.add("resource_type")
338+
330339
def to_json(self, indent: int | None = None) -> str:
331340
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
332341

test/api/write-generator/multi-package/__snapshots__/sql-on-fhir.test.ts.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ exports[`SQL-on-FHIR Python Generation should generate ViewDefinition type (prom
8686
8787
from __future__ import annotations
8888
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
89-
from typing import List as PyList, Literal
89+
from typing import Any, List as PyList, Literal
9090
9191
from fhir_types.hl7_fhir_r5_core.base import BackboneElement
9292
from fhir_types.hl7_fhir_r5_core.canonical_resource import CanonicalResource
@@ -162,6 +162,9 @@ class ViewDefinition(CanonicalResource):
162162
select: PyList[ViewDefinitionSelect] = Field(alias="select", serialization_alias="select")
163163
where: PyList[ViewDefinitionWhere] | None = Field(None, alias="where", serialization_alias="where")
164164
165+
def model_post_init(self, __context: Any) -> None:
166+
self.__pydantic_fields_set__.add("resource_type")
167+
165168
def to_json(self, indent: int | None = None) -> str:
166169
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
167170
@@ -179,7 +182,7 @@ exports[`SQL-on-FHIR Python Generation should generate domain_resource for R5 1`
179182
180183
from __future__ import annotations
181184
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
182-
from typing import List as PyList, Literal
185+
from typing import Any, List as PyList, Literal
183186
184187
from fhir_types.hl7_fhir_r5_core.base import Extension, Narrative
185188
from fhir_types.hl7_fhir_r5_core.resource import Resource
@@ -200,6 +203,9 @@ class DomainResource(Resource):
200203
modifier_extension: PyList[Extension] | None = Field(None, alias="modifierExtension", serialization_alias="modifierExtension")
201204
text: Narrative | None = Field(None, alias="text", serialization_alias="text")
202205
206+
def model_post_init(self, __context: Any) -> None:
207+
self.__pydantic_fields_set__.add("resource_type")
208+
203209
def to_json(self, indent: int | None = None) -> str:
204210
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
205211

test/api/write-generator/python.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("Python Writer Generator", async () => {
3434
});
3535
it("generates base.py with TypeVar import and declaration", async () => {
3636
const basePy = result.filesGenerated["generated/hl7_fhir_r4_core/base.py"];
37-
expect(basePy).toContain("from typing import Generic, List as PyList, Literal");
37+
expect(basePy).toContain("from typing import Any, Generic, List as PyList, Literal");
3838
expect(basePy).toContain("from typing_extensions import TypeVar");
3939
expect(basePy).toContain("T = TypeVar('T', bound=str, default=str)");
4040
});

0 commit comments

Comments
 (0)