diff --git a/geojson_pydantic/base.py b/geojson_pydantic/base.py index 61e79fb..718f297 100644 --- a/geojson_pydantic/base.py +++ b/geojson_pydantic/base.py @@ -52,8 +52,10 @@ def validate_bbox(cls, bbox: Optional[BBox]) -> Optional[BBox]: return bbox + # This return is untyped due to a workaround until this issue is resolved: + # https://github.com/tiangolo/fastapi/discussions/10661 @model_serializer(when_used="always", mode="wrap") - def clean_model(self, serializer: Any, info: SerializationInfo) -> Dict[str, Any]: + def clean_model(self, serializer: Any, info: SerializationInfo): # type: ignore [no-untyped-def] """Custom Model serializer to match the GeoJSON specification. Used to remove fields which are optional but cannot be null values. diff --git a/tests/test_geometries.py b/tests/test_geometries.py index e7e2f08..a219dda 100644 --- a/tests/test_geometries.py +++ b/tests/test_geometries.py @@ -339,6 +339,25 @@ def test_parse_geometry_obj_point(): ) +@pytest.mark.parametrize( + "geojson_pydantic_model", + ( + GeometryCollection, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Point, + Polygon, + ), +) +def test_schema_consistency(geojson_pydantic_model): + """Test to check that the schema is the same for validation and serialization""" + assert geojson_pydantic_model.model_json_schema( + mode="validation" + ) == geojson_pydantic_model.model_json_schema(mode="serialization") + + def test_parse_geometry_obj_multi_point(): assert parse_geometry_obj( {"type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]]}