Skip to content

Commit be4ecec

Browse files
committed
Add sortables and collection search #7
1 parent cebde22 commit be4ecec

File tree

3 files changed

+174
-19
lines changed

3 files changed

+174
-19
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Sortables (e.g. endpoint `GET /sortables`)
13+
- Sort for Collections (i.e. Collection Search)
14+
815
## [v1.0.0] - 2023-09-28
916

1017
### Changed

README.md

+50-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Overview](#overview)
55
- [HTTP GET](#http-get)
66
- [HTTP POST JSON Entity](#http-post-json-entity)
7+
- [Sortables](#sortables)
78

89
## Overview
910

@@ -12,11 +13,13 @@
1213
- **Conformance Classes:**
1314
- **STAC API - Item Search** binding: <https://api.stacspec.org/v1.0.0/item-search#sort>
1415
- **STAC API - Features** binding: <https://api.stacspec.org/v1.0.0/ogcapi-features#sort>
15-
- **Scope:** STAC API - Features, STAC API - Item Search
16+
- **STAC API - Collection Search** binding: <https://api.stacspec.org/v1.0.0-rc.1/collection-search#sort>
17+
- **Scope:** STAC API - Features, STAC API - Item Search, STAC API - Collection Search
1618
- **[Extension Maturity Classification](https://github.com/radiantearth/stac-api-spec/tree/main/README.md#maturity-classification):** Stable
1719
- **Dependencies:**
1820
- [STAC API - Item Search](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/item-search)
19-
- [STAC API - Features](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/item-search)
21+
- [STAC API - Features](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/ogcapi-features)
22+
- [STAC API - Collection Search](https://github.com/stac-api-extensions/collection-search/tree/v1.0.0-rc.1)
2023
- **Owner**: @philvarner
2124

2225
This specification defines a new parameter, `sortby`, that allows the user to define the fields by which
@@ -25,27 +28,24 @@ Only string, numeric, and datetime attributes of Item (`id` and `collection` onl
2528
may be used to sort results.
2629

2730
It is not required that implementations support sorting over all attributes, but
28-
implementations should return a 400 Bad Request status code when attempting to sort over a field name that does
29-
not support sorting.
30-
This specification does not yet require the implementation of an "-ables" endpoint (like CQL2 does for queryables)
31-
that defines the names of the
32-
fields that can be sorted over, so implementations must provide this out-of-band. Implementers may choose to require
33-
fields in Item Properties to be prefixed with `properties.` or not, or support use of both the prefixed and non-prefixed
34-
name, e.g., `properties.datetime` or `datetime`.
35-
36-
Sort behavior may be bound to either or both of
37-
[STAC API - Item Search](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/item-search) (`/search` endpoint) or
38-
[STAC API - Features](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/ogcapi-features)
39-
(`/collections/{collectionId}/items` endpoint) by advertising the relevant conformance class.
31+
implementations should either implement Sortables or just return a 400 Bad Request status code
32+
when attempting to sort over a field name that does not support sorting.
33+
Implementers may choose to require fields in Item Properties to be prefixed with `properties.` or not,
34+
or support use of both the prefixed and non-prefixed name, e.g., `properties.datetime` or `datetime`.
35+
36+
Sort behavior may be bound to any of the following endpoints by advertising the relevant conformance class:
37+
38+
- [STAC API - Item Search](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/item-search)
39+
(`/search` endpoint),
40+
- [STAC API - Features](https://github.com/radiantearth/stac-api-spec/tree/v1.0.0/ogcapi-features)
41+
(`/collections/{collectionId}/items` endpoint)
42+
- [STAC API - Collection Search](https://github.com/stac-api-extensions/collection-search/tree/v1.0.0-rc.1)
43+
(`/collections` endpoint)
4044

4145
Fields may be sorted in ascending or descending order. The syntax between GET requests and POST requests with a JSON
4246
body vary. The `sortby` value is an array, so multiple sort fields can be defined which will be used to sort
4347
the data in the order provided (e.g., first by `datetime`, then by `eo:cloud_cover`).
4448

45-
**NOTE**: *This specification may change, as our goal is to align with OGC API functionality, and sorting is currently being
46-
worked on as part of OGC API - Records, see [this issue](https://github.com/opengeospatial/ogcapi-records/issues/22)
47-
for the latest discussion.*
48-
4949
## HTTP GET
5050

5151
When calling a relevant endpoint using GET, a single parameter `sortby` with a comma-separated list of item field names must
@@ -103,3 +103,35 @@ The syntax for the `sortby` attribute is:
103103
]
104104
}
105105
```
106+
107+
## Sortables
108+
109+
Additional endpoints that provide so called "Sortables" support clients that want to discover the list of resource
110+
properties with their types and constraints that may be used to sort resources.
111+
112+
These Sortables endpoints return lists of properties (or aliases) that can be used in the `sortby` parameter.
113+
It returns a JSON Schema that defines the properties allowed in `sortby`.
114+
The precise definition of this can be found in the
115+
[OGC API - Features - Part 5: Schemas](https://portal.ogc.org/files/108199#rc_sortables).
116+
117+
All Sortables endpoints SHALL be referenced with a link with the link relation type
118+
`http://www.opengis.net/def/rel/ogc/1.0/sortables`.
119+
120+
| Sortables Endpoint | Endpoint linking to the Sortables Endpoint | Conformance class | Applicable `sortby` endpoints |
121+
| ----------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------ | --------------------------------------- |
122+
| `GET /sortables` | `GET /` | `https://api.stacspec.org/v1.0.0/item-search#sortables` | `GET /search` and `POST /search` |
123+
| `GET /collections/{collectionId}/sortables` | `GET /collections/{collectionId}` | `http://www.opengis.net/spec/ogcapi-features-5/1.0/conf/sortables` | `GET /collections/{collectionId}/items` |
124+
| `GET /...` (*Endpoint name to be chosen by implementation*) | `GET /collections` | `https://api.stacspec.org/v1.0.0-rc.1/collection-search#sortables` | `GET /collections/{collectionId}/items` |
125+
126+
An example for a link to the sortables endpoint could be:
127+
128+
```json
129+
{
130+
"href": "https://stac.example/sortables",
131+
"type": "application/schema+json",
132+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/sortables",
133+
"title": "Sortables"
134+
}
135+
```
136+
137+
For an example of a sortables endpoint response, please see the [openapi.yaml](openapi.yaml).

openapi.yaml

+117-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,113 @@ info:
99
license:
1010
name: Apache License 2.0
1111
url: 'http://www.apache.org/licenses/LICENSE-2.0'
12-
paths: {}
12+
tags:
13+
- name: Sort Extension
14+
description: |
15+
An extension to the STAC API that allows sorting of results based on specified properties.
16+
paths:
17+
/sortables:
18+
get:
19+
summary: Sortables
20+
operationId: getSortables
21+
description: |-
22+
This endpoint returns a list of properties (or aliases) that can be used in the `sortby` parameter
23+
for the cross-collection item search (i.e. `GET /search` and `POST /search`).
24+
It returns a JSON Schema that defines the properties allowed in `sortby`.
25+
The precise definition of this can be found in the OGC API - Features - Part 5: Schemas.
26+
tags:
27+
- Sort Extension
28+
responses:
29+
"200":
30+
$ref: "#/components/responses/Sortables"
31+
default:
32+
$ref: "#/components/responses/Error"
33+
/collections/{collectionId}/sortables:
34+
get:
35+
summary: Sortables for Item lists of a specific Collection
36+
operationId: getCollectionForCollection
37+
description: |-
38+
This endpoint returns a list of properties (or aliases) that can be used in the `sortby` parameter
39+
for the item lists of a collection (i.e. `GET /collections/{collectionId}/items`).
40+
It returns a JSON Schema that defines the properties allowed in `sortby`.
41+
The precise definition of this can be found in the OGC API - Features - Part 5: Schemas.
42+
tags:
43+
- Sort Extension
44+
parameters:
45+
- in: path
46+
name: collectionId
47+
schema:
48+
type: string
49+
required: true
50+
description: ID of Collection
51+
responses:
52+
"200":
53+
$ref: "#/components/responses/Sortables"
54+
default:
55+
$ref: "#/components/responses/Error"
1356
components:
57+
responses:
58+
Sortables:
59+
description: A JSON Schema defining the properties allowed in `sortby`.
60+
content:
61+
application/schema+json:
62+
schema:
63+
type: object
64+
properties:
65+
$schema:
66+
type: string
67+
format: uri
68+
enum:
69+
- https://json-schema.org/draft/2020-12/schema
70+
$id:
71+
type: string
72+
format: uri
73+
type:
74+
type: string
75+
enum:
76+
- object
77+
properties:
78+
type: object
79+
additionalProperties:
80+
type: object
81+
required:
82+
- type
83+
properties:
84+
type:
85+
type: string
86+
title:
87+
type: string
88+
description:
89+
type: string
90+
additionalProperties: true
91+
additionalProperties:
92+
description: |-
93+
If `additionalProperties` is not included or has the default value `true`, any property name is valid in a sorting expression on the collection that is evaluated by the server and the property reference SHALL evaluate to `null`, if the property does not exist for a resource.
94+
95+
If `additionalProperties` is set to `false`, property references that are not explicitly declared in the sortables schema SHALL result in a 400 response.
96+
type: boolean
97+
default: true
98+
example:
99+
$schema: https://json-schema.org/draft/2020-12/schema
100+
$id: https://example.com/sortables
101+
title: Sortables
102+
type: object
103+
properties:
104+
id:
105+
type: string
106+
title:
107+
type: string
108+
datetime:
109+
type: string
110+
format: date-time
111+
eo:cloud_cover:
112+
type: number
113+
Error:
114+
description: An error occurred.
115+
content:
116+
application/json:
117+
schema:
118+
$ref: "#/components/schemas/exception"
14119
parameters:
15120
sortby:
16121
name: sortby
@@ -62,3 +167,14 @@ components:
62167
direction: asc
63168
- field: id
64169
direction: desc
170+
exception:
171+
type: object
172+
description: |-
173+
Information about the exception: an error code plus an optional description.
174+
required:
175+
- code
176+
properties:
177+
code:
178+
type: string
179+
description:
180+
type: string

0 commit comments

Comments
 (0)