Skip to content

Commit 1e6142a

Browse files
PB-1677: Use <name> instead of properties.<name> for sortby
This is more in line with how the query extension is implemented. For a "query" to the POST /search endpoint the following field values are allowed: - created - updated - title - cf:standard_name - unit So it's not, e.g., "properties.updated" but only "updated". The "sortby" now works the same. The following fields are allowed for sort: - id - collection - datetime - title - created - updated
1 parent 569dd71 commit 1e6142a

7 files changed

Lines changed: 25 additions & 25 deletions

File tree

app/stac_api/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,10 @@ def parse_cache_control_header(cache_control_header):
636636
SORTABLE_FIELDS = {
637637
'id': 'name',
638638
'collection': 'collection__name',
639-
'properties.datetime': 'properties_datetime',
640-
'properties.title': 'properties_title',
641-
'properties.created': 'created',
642-
'properties.updated': 'updated',
639+
'datetime': 'properties_datetime',
640+
'title': 'properties_title',
641+
'created': 'created',
642+
'updated': 'updated',
643643
}
644644

645645

@@ -649,7 +649,7 @@ def parse_sortby_get(sortby_param, sortable_fields):
649649
The sortby parameter is a comma-separated string of fields prefixed with '+'
650650
(ascending, default) or '-' (descending).
651651
652-
Example: "-properties.created,title".
652+
Example: "-created,title".
653653
654654
Args:
655655
sortby_param: string
@@ -695,7 +695,7 @@ def parse_sortby_post(sortby_param, sortable_fields):
695695
The sortby parameter in the request body is a list of objects with a 'field'
696696
and a 'direction' ('asc' or 'desc') property.
697697
698-
Example: [{"field": "properties.created", "direction": "desc"}].
698+
Example: [{"field": "created", "direction": "desc"}].
699699
700700
Args:
701701
sortby_param: list

app/tests/tests_10/test_items_endpoint.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_sortby_properties_datetime(self):
228228

229229
# Test ascending sort
230230
response = self.client.get(
231-
f"/{STAC_BASE_V}/collections/{self.collection.name}/items?sortby=properties.datetime"
231+
f"/{STAC_BASE_V}/collections/{self.collection.name}/items?sortby=datetime"
232232
)
233233

234234
self.assertStatusCode(200, response)
@@ -237,7 +237,7 @@ def test_sortby_properties_datetime(self):
237237

238238
# Test descending sort
239239
response = self.client.get(
240-
f"/{STAC_BASE_V}/collections/{self.collection.name}/items?sortby=-properties.datetime"
240+
f"/{STAC_BASE_V}/collections/{self.collection.name}/items?sortby=-datetime"
241241
)
242242
self.assertStatusCode(200, response)
243243
item_ids = [item['id'] for item in response.json()['features']]
@@ -268,10 +268,10 @@ def test_sortby_multiple_fields(self):
268268
)
269269

270270
# Sort by datetime ascending, then by title descending
271-
response = self.client.get((
272-
f"/{STAC_BASE_V}/collections/{self.collection.name}/items?"
273-
f"sortby=properties.datetime,-properties.title"
274-
))
271+
response = self.client.get(
272+
(f"/{STAC_BASE_V}/collections/{self.collection.name}/items?"
273+
f"sortby=datetime,-title")
274+
)
275275
self.assertStatusCode(200, response)
276276
item_ids = [item['id'] for item in response.json()['features']]
277277
self.assertEqual(

app/tests/tests_10/test_search_endpoint_extensions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ def test_get_sortby_properties_datetime(self):
289289
)
290290

291291
# ascending sort
292-
response = self.client.get(f"{self.path}?sortby=properties.datetime")
292+
response = self.client.get(f"{self.path}?sortby=datetime")
293293
self.assertStatusCode(200, response)
294294
item_ids = [item['id'] for item in response.json()['features']]
295295
self.assertEqual(item_ids, ['item-1', 'item-2', 'item-dt-2', 'item-dt-1', 'item-dt-3'])
296296

297297
# descending sort
298-
response = self.client.get(f"{self.path}?sortby=-properties.datetime")
298+
response = self.client.get(f"{self.path}?sortby=-datetime")
299299
self.assertStatusCode(200, response)
300300
item_ids = [item['id'] for item in response.json()['features']]
301301
self.assertEqual(item_ids, ['item-dt-3', 'item-dt-1', 'item-dt-2', 'item-2', 'item-1'])
@@ -325,7 +325,7 @@ def test_get_sortby_multiple_fields(self):
325325
)
326326

327327
# Sort by datetime ascending, then by title descending
328-
response = self.client.get(f"{self.path}?sortby=properties.datetime,-properties.title")
328+
response = self.client.get(f"{self.path}?sortby=datetime,-title")
329329
self.assertStatusCode(200, response)
330330
item_ids = [item['id'] for item in response.json()['features']]
331331
self.assertEqual(
@@ -378,14 +378,14 @@ def test_post_sortby_properties_datetime(self):
378378
)
379379

380380
# ascending sort
381-
payload = {"sortby": [{"field": "properties.datetime", "direction": "asc"}]}
381+
payload = {"sortby": [{"field": "datetime", "direction": "asc"}]}
382382
response = self.client.post(self.path, data=payload, content_type="application/json")
383383
self.assertStatusCode(200, response)
384384
item_ids = [item['id'] for item in response.json()['features']]
385385
self.assertEqual(item_ids, ['item-1', 'item-2', 'item-dt-2', 'item-dt-1', 'item-dt-3'])
386386

387387
# descending sort
388-
payload = {"sortby": [{"field": "properties.datetime", "direction": "desc"}]}
388+
payload = {"sortby": [{"field": "datetime", "direction": "desc"}]}
389389
response = self.client.post(self.path, data=payload, content_type="application/json")
390390
self.assertStatusCode(200, response)
391391
item_ids = [item['id'] for item in response.json()['features']]
@@ -418,9 +418,9 @@ def test_post_sortby_multiple_fields(self):
418418
# Sort by datetime ascending, then by title descending
419419
payload = {
420420
"sortby": [{
421-
"field": "properties.datetime", "direction": "asc"
421+
"field": "datetime", "direction": "asc"
422422
}, {
423-
"field": "properties.title", "direction": "desc"
423+
"field": "title", "direction": "desc"
424424
}]
425425
}
426426
response = self.client.post(self.path, data=payload, content_type="application/json")

spec/components/parameters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ components:
141141
required: false
142142
schema:
143143
type: string
144-
example: '-properties.created,id'
144+
example: '-created,id'

spec/components/schemas.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ components:
17501750
- asc
17511751
- desc
17521752
example:
1753-
- field: properties.created
1753+
- field: created
17541754
direction: asc
17551755
- field: collection
17561756
direction: desc

spec/static/spec/v1/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ components:
138138
required: false
139139
schema:
140140
type: string
141-
example: '-properties.created,id'
141+
example: '-created,id'
142142
responses:
143143
Collection:
144144
headers:
@@ -1981,7 +1981,7 @@ components:
19811981
- asc
19821982
- desc
19831983
example:
1984-
- field: properties.created
1984+
- field: created
19851985
direction: asc
19861986
- field: collection
19871987
direction: desc

spec/static/spec/v1/openapitransactional.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ components:
138138
required: false
139139
schema:
140140
type: string
141-
example: '-properties.created,id'
141+
example: '-created,id'
142142
uploadId:
143143
name: uploadId
144144
in: path
@@ -2065,7 +2065,7 @@ components:
20652065
- asc
20662066
- desc
20672067
example:
2068-
- field: properties.created
2068+
- field: created
20692069
direction: asc
20702070
- field: collection
20712071
direction: desc

0 commit comments

Comments
 (0)