Skip to content

Commit

Permalink
Merge pull request #153 from markus-work/main
Browse files Browse the repository at this point in the history
Workaround for #150 FastAPI shows no attributes for models.
  • Loading branch information
vincentsarago committed Jan 16, 2024
2 parents affc75a + 02c1f7c commit c70b5b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion geojson_pydantic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]}
Expand Down

0 comments on commit c70b5b1

Please sign in to comment.