Skip to content

Commit 92d73e6

Browse files
Pydantic v1/2 compatibility for provider models (geopython#2056)
* Pydantic v1/2 compatibility for provier models cc: @doublebyte1 * Update mvt.py * Update base.py --------- Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>
1 parent 77a69e1 commit 92d73e6

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

pygeoapi/models/provider/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from enum import Enum
3636
from typing import List, Optional
3737

38+
import pydantic
3839
from pydantic import BaseModel
3940

4041

@@ -875,3 +876,10 @@ class TileSetMetadata(BaseModel):
875876
tileMatrixSetURI: Optional[str] = None
876877
# Links to related resources.
877878
links: Optional[List[LinkType]] = None
879+
880+
881+
if pydantic.VERSION.startswith('1'):
882+
def _dump(self, *, exclude_none: bool = False, **kwargs):
883+
return self.dict(exclude_none=exclude_none, **kwargs)
884+
885+
TileSetMetadata.model_dump = _dump

pygeoapi/models/provider/mvt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#
2828
# =================================================================
2929

30+
import pydantic
3031
from pydantic import BaseModel
3132
from typing import List, Optional
3233

@@ -50,3 +51,10 @@ class MVTTilesJson(BaseModel):
5051
attribution: Optional[str] = None
5152
description: Optional[str] = None
5253
vector_layers: Optional[List[VectorLayers]] = None
54+
55+
56+
if pydantic.VERSION.startswith('1'):
57+
def _dump(self, *, exclude_none: bool = False, **kwargs):
58+
return self.dict(exclude_none=exclude_none, **kwargs)
59+
60+
MVTTilesJson.model_dump = _dump

pygeoapi/provider/mvt_elastic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,4 @@ def get_default_metadata(self, dataset, server_url, layer, tileset,
263263

264264
content.links = links
265265

266-
return content.dict(exclude_none=True)
266+
return content.model_dump(exclude_none=True)

pygeoapi/provider/mvt_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,4 @@ def get_default_metadata(self, dataset, server_url, layer, tileset,
259259

260260
content.links = links
261261

262-
return content.dict(exclude_none=True)
262+
return content.model_dump(exclude_none=True)

pygeoapi/provider/wmts_facade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,4 @@ def get_default_metadata(self, dataset, server_url, layer, tileset,
278278

279279
content.links = links
280280

281-
return content.dict(exclude_none=True)
281+
return content.model_dump(exclude_none=True)

0 commit comments

Comments
 (0)