diff --git a/geoservercloud/models/featuretype.py b/geoservercloud/models/featuretype.py index 2b761d4..591a2d6 100644 --- a/geoservercloud/models/featuretype.py +++ b/geoservercloud/models/featuretype.py @@ -41,7 +41,7 @@ def __init__( namespace_name: str | None = None, title: dict[str, str] | str | None = None, abstract: dict[str, str] | str | None = None, - keywords: list[str] | None = [], + keywords: list[str] | None = None, native_bounding_box: dict[str, Any] | None = None, lat_lon_bounding_box: dict[str, Any] | None = None, attributes: list[dict[str, Any]] | None = None, @@ -130,7 +130,6 @@ def from_get_response_payload(cls, content: dict): title=title, abstract=abstract, srs=feature_type["srs"], - keywords=feature_type["keywords"]["string"], attributes=feature_type["attributes"]["attribute"], metadata_links=metadata_links, enabled=feature_type["enabled"], @@ -142,6 +141,7 @@ def from_get_response_payload(cls, content: dict): advertised=feature_type.get("advertised"), native_bounding_box=feature_type.get("nativeBoundingBox"), lat_lon_bounding_box=feature_type.get("latLonBoundingBox"), + keywords=feature_type.get("keywords", {}).get("string"), encode_measures=feature_type.get("encodeMeasures"), forced_decimals=feature_type.get("forcedDecimals"), simple_conversion_enabled=feature_type.get("simpleConversionEnabled"), @@ -194,8 +194,10 @@ def asdict(self) -> dict[str, Any]: def post_payload(self) -> dict[str, Any]: content = self.asdict() - content["attributes"] = {"attribute": self.attributes} - content["keywords"] = {"string": self.keywords} + if self.attributes is not None: + content["attributes"] = {"attribute": self.attributes} + if self.keywords is not None: + content["keywords"] = {"string": self.keywords} return {"featureType": content} def put_payload(self) -> dict[str, Any]: diff --git a/tests/models/test_featuretype.py b/tests/models/test_featuretype.py index 100a112..fde5ed3 100644 --- a/tests/models/test_featuretype.py +++ b/tests/models/test_featuretype.py @@ -252,3 +252,16 @@ def test_featuretype_repr(): expected_repr = json.dumps(feature_type.post_payload(), indent=4) assert repr(feature_type) == expected_repr + + +def test_featuretype_create_no_keyword(): + feature_type = FeatureType( + namespace_name="test_namespace", + workspace_name="test_workspace", + store_name="test_store", + name="test_name", + native_name="test_native_name", + keywords=None, + ) + + assert feature_type.post_payload()["featureType"].get("keywords") is None