Skip to content

Commit 30e8a8f

Browse files
remove defaults in openapi schema (#819)
* remove defaults in openapi schema * update openapi example for sort --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent 752b41e commit 30e8a8f

File tree

8 files changed

+79
-49
lines changed

8 files changed

+79
-49
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+
- Remove defaults in OpenAPI schemas
8+
59
### Added
610

711
- add `enable_direct_response` settings to by-pass Pydantic validation and FastAPI serialization for responses

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ 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-
json_schema_extra={
44-
"example": [-175.05, -85.05, 175.05, 85.05],
43+
openapi_examples={
44+
"user-provided": {"value": None},
45+
"Montreal": {"value": "-73.896103,45.364690,-73.413734,45.674283"},
4546
},
4647
)
4748
datetime: Optional[str] = Field(
4849
default=None,
4950
description="""Only return items that have a temporal property that intersects this value.\n
5051
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
51-
json_schema_extra={
52-
"examples": {
53-
"datetime": {"value": "2018-02-12T23:20:50Z"},
54-
"closed-interval": {"value": "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"},
55-
"open-interval-from": {"value": "2018-02-12T00:00:00Z/.."},
56-
"open-interval-to": {"value": "../2018-03-18T12:31:12Z"},
57-
},
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"},
5858
},
5959
)
6060
limit: Optional[Limit] = Field(

stac_fastapi/extensions/stac_fastapi/extensions/core/fields/request.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ def _fields_converter(
4949
Optional[str],
5050
Query(
5151
description="Include or exclude fields from items body.",
52-
json_schema_extra={
53-
"example": "properties.datetime",
52+
openapi_examples={
53+
"user-provided": {"value": None},
54+
"datetime": {"value": "properties.datetime"},
5455
},
5556
),
5657
] = None,

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ class FilterExtensionGetRequest(APIRequest):
2323
description="""A CQL filter expression for filtering items.\n
2424
Supports `CQL-JSON` as defined in https://portal.ogc.org/files/96288\n
2525
Remember to URL encode the CQL-JSON if using GET""",
26-
json_schema_extra={
27-
"example": "id='LC08_L1TP_060247_20180905_20180912_01_T1_L1TP' AND collection='landsat8_l1tp'", # noqa: E501
26+
openapi_examples={
27+
"user-provided": {"value": None},
28+
"landsat8-item": {
29+
"value": "id='LC08_L1TP_060247_20180905_20180912_01_T1_L1TP' AND collection='landsat8_l1tp'" # noqa: E501
30+
},
2831
},
2932
),
3033
] = attr.ib(default=None)
@@ -51,19 +54,25 @@ class FilterExtensionPostRequest(BaseModel):
5154
default=None,
5255
alias="filter",
5356
description="A CQL filter expression for filtering items.",
54-
json_schema_extra={
55-
"example": {
56-
"op": "and",
57-
"args": [
58-
{
59-
"op": "=",
60-
"args": [
61-
{"property": "id"},
62-
"LC08_L1TP_060247_20180905_20180912_01_T1_L1TP",
63-
],
64-
},
65-
{"op": "=", "args": [{"property": "collection"}, "landsat8_l1tp"]},
66-
],
57+
openapi_examples={
58+
"user-provided": {"value": None},
59+
"landsat8-item": {
60+
"value": {
61+
"op": "and",
62+
"args": [
63+
{
64+
"op": "=",
65+
"args": [
66+
{"property": "id"},
67+
"LC08_L1TP_060247_20180905_20180912_01_T1_L1TP",
68+
],
69+
},
70+
{
71+
"op": "=",
72+
"args": [{"property": "collection"}, "landsat8_l1tp"],
73+
},
74+
],
75+
},
6776
},
6877
},
6978
)

stac_fastapi/extensions/stac_fastapi/extensions/core/free_text/request.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ def _ft_converter(
1515
Optional[str],
1616
Query(
1717
description="Parameter to perform free-text queries against STAC metadata",
18-
json_schema_extra={
19-
"example": "ocean,coast",
18+
openapi_examples={
19+
"user-provided": {"value": None},
20+
"Coastal": {"value": "ocean,coast"},
2021
},
2122
),
2223
] = None,
@@ -48,8 +49,9 @@ class FreeTextAdvancedExtensionGetRequest(APIRequest):
4849
Optional[str],
4950
Query(
5051
description="Parameter to perform free-text queries against STAC metadata",
51-
json_schema_extra={
52-
"example": "ocean,coast",
52+
openapi_examples={
53+
"user-provided": {"value": None},
54+
"Coastal": {"value": "ocean,coast"},
5355
},
5456
),
5557
] = attr.ib(default=None)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class QueryExtensionGetRequest(APIRequest):
1818
Optional[str],
1919
Query(
2020
description="Allows additional filtering based on the properties of Item objects", # noqa: E501
21-
json_schema_extra={
22-
"example": '{"eo:cloud_cover": {"gte": 95}}',
21+
openapi_examples={
22+
"user-provided": {"value": None},
23+
"cloudy": {"value": '{"eo:cloud_cover": {"gte": 95}}'},
2324
},
2425
),
2526
] = attr.ib(default=None)
@@ -31,7 +32,8 @@ class QueryExtensionPostRequest(BaseModel):
3132
query: Optional[Dict[str, Dict[str, Any]]] = Field(
3233
None,
3334
description="Allows additional filtering based on the properties of Item objects", # noqa: E501
34-
json_schema_extra={
35-
"example": {"eo:cloud_cover": {"gte": 95}},
35+
openapi_examples={
36+
"user-provided": {"value": None},
37+
"cloudy": {"value": '{"eo:cloud_cover": {"gte": 95}}'},
3638
},
3739
)

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def _sort_converter(
1616
Optional[str],
1717
Query(
1818
description="An array of property names, prefixed by either '+' for ascending or '-' for descending. If no prefix is provided, '+' is assumed.", # noqa: E501
19-
json_schema_extra={
20-
"example": "-gsd,-datetime",
19+
openapi_examples={
20+
"user-provided": {"value": None},
21+
"resolution": {"value": "-gsd"},
22+
"resolution-and-dates": {"value": "-gsd,-datetime"},
2123
},
2224
),
2325
],
@@ -38,12 +40,15 @@ class SortExtensionPostRequest(BaseModel):
3840
sortby: Optional[List[PostSortModel]] = Field(
3941
None,
4042
description="An array of property (field) names, and direction in form of '{'field': '<property_name>', 'direction':'<direction>'}'", # noqa: E501
41-
json_schema_extra={
42-
"example": [
43-
{
44-
"field": "properties.created",
45-
"direction": "asc",
46-
}
47-
],
43+
openapi_examples={
44+
"user-provided": {"value": None},
45+
"creation-time": {
46+
"value": [
47+
{
48+
"field": "properties.created",
49+
"direction": "asc",
50+
}
51+
],
52+
},
4853
},
4954
)

stac_fastapi/types/stac_fastapi/types/search.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def _collection_converter(
4646
Optional[str],
4747
Query(
4848
description="Array of collection Ids to search for items.",
49-
json_schema_extra={
50-
"example": "collection1,collection2",
49+
openapi_examples={
50+
"user-provided": {"value": None},
51+
"single-collection": {"value": "collection1"},
52+
"multi-collections": {"value": "collection1,collection2"},
5153
},
5254
),
5355
] = None,
@@ -60,8 +62,10 @@ def _ids_converter(
6062
Optional[str],
6163
Query(
6264
description="Array of Item ids to return.",
63-
json_schema_extra={
64-
"example": "item1,item2",
65+
openapi_examples={
66+
"user-provided": {"value": None},
67+
"single-item": {"value": "item1"},
68+
"multi-items": {"value": "item1,item2"},
6569
},
6670
),
6771
] = None,
@@ -74,8 +78,9 @@ def _bbox_converter(
7478
Optional[str],
7579
Query(
7680
description="Only return items intersecting this bounding box. Mutually exclusive with **intersects**.", # noqa: E501
77-
json_schema_extra={
78-
"example": "-175.05,-85.05,175.05,85.05",
81+
openapi_examples={
82+
"user-provided": {"value": None},
83+
"Montreal": {"value": "-73.896103,45.364690,-73.413734,45.674283"},
7984
},
8085
),
8186
] = None,
@@ -99,6 +104,7 @@ def _validate_datetime(instance, attribute, value):
99104
description="""Only return items that have a temporal property that intersects this value.\n
100105
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
101106
openapi_examples={
107+
"user-provided": {"value": None},
102108
"datetime": {"value": "2018-02-12T23:20:50Z"},
103109
"closed-interval": {"value": "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"},
104110
"open-interval-from": {"value": "2018-02-12T00:00:00Z/.."},
@@ -162,6 +168,7 @@ class BaseSearchGetRequest(APIRequest, DatetimeMixin):
162168
description="""Only return items intersecting this GeoJSON Geometry. Mutually exclusive with **bbox**. \n
163169
*Remember to URL encode the GeoJSON geometry when using GET request*.""", # noqa: E501
164170
openapi_examples={
171+
"user-provided": {"value": None},
165172
"madrid": {
166173
"value": {
167174
"type": "Feature",

0 commit comments

Comments
 (0)