Skip to content

Commit b94c52c

Browse files
avoid future deprecation for pydantic.Field and use json_schema_extra instead of openapi_examples (#833)
1 parent 417ea2c commit b94c52c

File tree

5 files changed

+48
-25
lines changed

5 files changed

+48
-25
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- avoid future deprecation for pydantic.Field and use `json_schema_extra` instead of `openapi_examples`
8+
59
## [5.2.0] - 2025-04-18
610

711
### Fixed

stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,32 @@ class BaseCollectionSearchPostRequest(BaseModel):
4040
bbox: Optional[BBox] = Field(
4141
default=None,
4242
description="Only return items intersecting this bounding box. Mutually exclusive with **intersects**.", # noqa: E501
43-
openapi_examples={
44-
"user-provided": {"value": None},
45-
"Montreal": {"value": "-73.896103,45.364690,-73.413734,45.674283"},
43+
json_schema_extra={
44+
"examples": [
45+
# user-provided
46+
None,
47+
# Montreal
48+
"-73.896103,45.364690,-73.413734,45.674283",
49+
],
4650
},
4751
)
4852
datetime: Optional[str] = Field(
4953
default=None,
5054
description="""Only return items that have a temporal property that intersects this value.\n
5155
Either a date-time or an interval, open or closed. Date and time expressions adhere to RFC 3339. Open intervals are expressed using double-dots.""", # noqa: E501
52-
openapi_examples={
53-
"user-provided": {"value": None},
54-
"datetime": {"value": "2018-02-12T23:20:50Z"},
55-
"closed-interval": {"value": "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"},
56-
"open-interval-from": {"value": "2018-02-12T00:00:00Z/.."},
57-
"open-interval-to": {"value": "../2018-03-18T12:31:12Z"},
56+
json_schema_extra={
57+
"examples": [
58+
# user-provided
59+
None,
60+
# single datetime
61+
"2018-02-12T23:20:50Z",
62+
# closed inverval
63+
"2018-02-12T00:00:00Z/2018-03-18T12:31:12Z",
64+
# open interval FROM
65+
"2018-02-12T00:00:00Z/..",
66+
# open interval TO
67+
"../2018-03-18T12:31:12Z",
68+
],
5869
},
5970
)
6071
limit: Optional[Limit] = Field(

stac_fastapi/extensions/stac_fastapi/extensions/core/filter/request.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ class FilterExtensionPostRequest(BaseModel):
5151
"""Filter extension POST request model."""
5252

5353
filter_expr: Optional[Dict[str, Any]] = Field(
54-
default=None,
54+
None,
5555
alias="filter",
5656
description="A CQL filter expression for filtering items.",
57-
openapi_examples={
58-
"user-provided": {"value": None},
59-
"landsat8-item": {
60-
"value": {
57+
json_schema_extra={
58+
"examples": [
59+
# user-provided
60+
None,
61+
# landsat8-item
62+
{
6163
"op": "and",
6264
"args": [
6365
{
@@ -73,16 +75,16 @@ class FilterExtensionPostRequest(BaseModel):
7375
},
7476
],
7577
},
76-
},
78+
],
7779
},
7880
)
7981
filter_crs: Optional[str] = Field(
82+
None,
8083
alias="filter-crs",
81-
default=None,
8284
description="The coordinate reference system (CRS) used by spatial literals in the 'filter' value. Default is `http://www.opengis.net/def/crs/OGC/1.3/CRS84`", # noqa: E501
8385
)
8486
filter_lang: Optional[Literal["cql-json", "cql2-json"]] = Field(
87+
"cql2-json",
8588
alias="filter-lang",
86-
default="cql2-json",
8789
description="The CQL filter encoding that the 'filter' value uses.",
8890
)

stac_fastapi/extensions/stac_fastapi/extensions/core/query/request.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class QueryExtensionPostRequest(BaseModel):
3232
query: Optional[Dict[str, Dict[str, Any]]] = Field(
3333
None,
3434
description="Allows additional filtering based on the properties of Item objects", # noqa: E501
35-
openapi_examples={
36-
"user-provided": {"value": None},
37-
"cloudy": {"value": '{"eo:cloud_cover": {"gte": 95}}'},
35+
json_schema_extra={
36+
"examples": [
37+
# user-provided
38+
None,
39+
# cloudy
40+
'{"eo:cloud_cover": {"gte": 95}}',
41+
],
3842
},
3943
)

stac_fastapi/extensions/stac_fastapi/extensions/core/sort/request.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ class SortExtensionPostRequest(BaseModel):
4040
sortby: Optional[List[PostSortModel]] = Field(
4141
None,
4242
description="An array of property (field) names, and direction in form of '{'field': '<property_name>', 'direction':'<direction>'}'", # noqa: E501
43-
openapi_examples={
44-
"user-provided": {"value": None},
45-
"creation-time": {
46-
"value": [
43+
json_schema_extra={
44+
"examples": [
45+
# user-provided
46+
None,
47+
# creation-time
48+
[
4749
{
4850
"field": "properties.created",
4951
"direction": "asc",
5052
}
5153
],
52-
},
54+
],
5355
},
5456
)

0 commit comments

Comments
 (0)