-
Notifications
You must be signed in to change notification settings - Fork 1
feat(spp_api_v2_gis): promote to Beta with validation and exception fixes #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| ### 19.0.2.0.1 | ||
|
|
||
| - Promoted to Beta | ||
| - fix(schemas): Add GeoJSON geometry validation for spatial queries and geofences | ||
| - fix(routers): Use proper exception chaining (from e) for better debugging | ||
| - feat: Add SPP module icon | ||
|
|
||
| ### 19.0.2.0.0 | ||
|
|
||
| - Initial migration to OpenSPP2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,36 @@ | |
|
|
||
| from typing import Literal | ||
|
|
||
| from pydantic import BaseModel, Field | ||
| from pydantic import BaseModel, Field, field_validator | ||
|
|
||
| _VALID_GEOMETRY_TYPES = {"Polygon", "MultiPolygon"} | ||
|
|
||
|
|
||
| def _validate_geojson_geometry(v): | ||
| """Validate that a dict is a valid GeoJSON geometry (Polygon or MultiPolygon).""" | ||
| if not isinstance(v, dict): | ||
| raise ValueError("geometry must be a JSON object") | ||
| geo_type = v.get("type") | ||
| if not geo_type: | ||
| raise ValueError("geometry must have a 'type' field") | ||
| if geo_type not in _VALID_GEOMETRY_TYPES: | ||
| raise ValueError(f"geometry type must be one of {_VALID_GEOMETRY_TYPES}, got '{geo_type}'") | ||
| coords = v.get("coordinates") | ||
| if not coords or not isinstance(coords, list): | ||
| raise ValueError("geometry must have a non-empty 'coordinates' array") | ||
|
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validation for the |
||
| return v | ||
|
|
||
|
|
||
| class SpatialQueryRequest(BaseModel): | ||
| """Request for spatial query.""" | ||
|
|
||
| geometry: dict = Field(..., description="Query geometry as GeoJSON (Polygon or MultiPolygon)") | ||
|
|
||
| @field_validator("geometry") | ||
| @classmethod | ||
| def check_geometry(cls, v): | ||
| return _validate_geojson_geometry(v) | ||
|
|
||
| filters: dict | None = Field(default=None, description="Additional filters for registrants") | ||
| variables: list[str] | None = Field( | ||
| default=None, | ||
|
|
@@ -50,6 +73,11 @@ class GeometryItem(BaseModel): | |
| id: str = Field(..., description="Unique identifier for this geometry (e.g., feature ID)") | ||
| geometry: dict = Field(..., description="GeoJSON geometry (Polygon or MultiPolygon)") | ||
|
|
||
| @field_validator("geometry") | ||
| @classmethod | ||
| def check_geometry(cls, v): | ||
| return _validate_geojson_geometry(v) | ||
|
|
||
|
|
||
| class BatchSpatialQueryRequest(BaseModel): | ||
| """Request for batch spatial query across multiple geometries.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message for invalid geometry types uses the default string representation of a Python set, which can look a bit unpolished (e.g., {'Polygon', 'MultiPolygon'}). It's better to format it as a sorted, comma-separated string for better readability.