Skip to content

Commit c70b5b1

Browse files
Merge pull request #153 from markus-work/main
Workaround for #150 FastAPI shows no attributes for models.
2 parents affc75a + 02c1f7c commit c70b5b1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

geojson_pydantic/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def validate_bbox(cls, bbox: Optional[BBox]) -> Optional[BBox]:
5252

5353
return bbox
5454

55+
# This return is untyped due to a workaround until this issue is resolved:
56+
# https://github.com/tiangolo/fastapi/discussions/10661
5557
@model_serializer(when_used="always", mode="wrap")
56-
def clean_model(self, serializer: Any, info: SerializationInfo) -> Dict[str, Any]:
58+
def clean_model(self, serializer: Any, info: SerializationInfo): # type: ignore [no-untyped-def]
5759
"""Custom Model serializer to match the GeoJSON specification.
5860
5961
Used to remove fields which are optional but cannot be null values.

tests/test_geometries.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,25 @@ def test_parse_geometry_obj_point():
339339
)
340340

341341

342+
@pytest.mark.parametrize(
343+
"geojson_pydantic_model",
344+
(
345+
GeometryCollection,
346+
LineString,
347+
MultiLineString,
348+
MultiPoint,
349+
MultiPolygon,
350+
Point,
351+
Polygon,
352+
),
353+
)
354+
def test_schema_consistency(geojson_pydantic_model):
355+
"""Test to check that the schema is the same for validation and serialization"""
356+
assert geojson_pydantic_model.model_json_schema(
357+
mode="validation"
358+
) == geojson_pydantic_model.model_json_schema(mode="serialization")
359+
360+
342361
def test_parse_geometry_obj_multi_point():
343362
assert parse_geometry_obj(
344363
{"type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]]}

0 commit comments

Comments
 (0)