stac-api-protocol 0.3.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/CHANGELOG.md +20 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/PKG-INFO +1 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/README.md +9 -0
- stac_api_protocol-0.5.0/demo/stac_api_demo/queryables.json +9 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/stac_api_demo/service.py +20 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/explanation/architecture.md +1 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/how-to/deploy-uvicorn.md +3 -2
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/how-to/register-service.md +5 -3
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/reference/api.md +36 -4
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/reference/index.md +1 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/tutorials/first-steps.md +50 -8
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/__about__.py +1 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/main.py +60 -22
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/queryables.json +8 -1
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/stac_service.py +20 -0
- stac_api_protocol-0.5.0/tests/test_demo_service.py +50 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_filter_compliance.py +59 -11
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_routes.py +46 -6
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_stac_service.py +4 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/.gitignore +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/LICENSE +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/README.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/.gitignore +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/download-data.sh +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/examples.sh +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/pyproject.toml +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/stac_api_demo/__init__.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/demo/start.sh +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/diagrams/architecture.svg +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/diagrams/architecture_dark.svg +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/diagrams/src/architecture.puml +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/explanation/index.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/how-to/index.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/how-to/install.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/how-to/use-cli.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/index.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/reference/openapi.html +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/docs/tutorials/index.md +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/pyproject.toml +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/__init__.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/models.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/plugin_loader.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/py.typed +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/conftest.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_bbox_queries.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_models.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_plugin_loader.py +0 -0
- {stac_api_protocol-0.3.0 → stac_api_protocol-0.5.0}/tests/test_search_validation.py +0 -0
|
@@ -23,6 +23,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
23
|
|
|
24
24
|
## [Unreleased]
|
|
25
25
|
|
|
26
|
+
## [0.5.0] - 2026-12-01
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- **Breaking:** `StacApiService.get_queryables` now accepts `collection_id: str | None = None`. Providers must update their method signatures: the global endpoint calls the method without arguments, while collection endpoints pass the collection identifier after checking that the collection exists. Providers can return distinct schemas for each scope.
|
|
31
|
+
- Updated the demo to return scope-specific queryables identifiers and documented global and collection-specific queryables in the service reference and tutorial.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Item, collection-item, and GET/POST search responses now use `application/geo+json`. Queryables retain `application/schema+json`, and metadata and errors retain `application/json`. Shared media-type constants keep response headers and generated OpenAPI declarations consistent.
|
|
36
|
+
|
|
37
|
+
## [0.4.0] - 2026-12-01
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- Queryables JSON Schema definition delegated to `StacApiService` implementations.
|
|
42
|
+
|
|
26
43
|
## [0.3.0] - 2026-11-30
|
|
27
44
|
|
|
28
45
|
### Changed
|
|
@@ -59,7 +76,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
59
76
|
|
|
60
77
|
- Initial project release.
|
|
61
78
|
|
|
62
|
-
[Unreleased]: https://github.com/Terradue/stac-api-protocol/compare/0.
|
|
79
|
+
[Unreleased]: https://github.com/Terradue/stac-api-protocol/compare/0.5.0...HEAD
|
|
80
|
+
[0.5.0]: https://github.com/Terradue/stac-api-protocol/compare/0.4.0...0.5.0
|
|
81
|
+
[0.4.0]: https://github.com/Terradue/stac-api-protocol/compare/0.3.0...0.4.0
|
|
63
82
|
[0.3.0]: https://github.com/Terradue/stac-api-protocol/compare/0.2.0...0.3.0
|
|
64
83
|
[0.2.0]: https://github.com/Terradue/stac-api-protocol/compare/0.1.1...0.2.0
|
|
65
84
|
[0.1.1]: https://github.com/Terradue/stac-api-protocol/compare/0.1.0...0.1.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: stac-api-protocol
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A Python FastAPI HTTP adapter for STAC API Core, Item Search, Features and Collections.
|
|
5
5
|
Project-URL: Documentation, https://terradue.github.io/stac-api-protocol/
|
|
6
6
|
Project-URL: Issues, https://github.com/Terradue/stac-api-protocol/issues
|
|
@@ -56,3 +56,12 @@ JSON-encoded string. `pygeofilter-duckdb` translates the existing search argumen
|
|
|
56
56
|
internally.
|
|
57
57
|
Each query uses its own DuckDB connection. Runtime queries use downloaded local
|
|
58
58
|
files and a preinstalled spatial extension, with no external database server.
|
|
59
|
+
|
|
60
|
+
Since v0.4.0, `GeoParquetService.get_queryables(collection_id=None)` loads a fresh
|
|
61
|
+
document from `stac_api_demo/queryables.json`. With no collection identifier it
|
|
62
|
+
returns catalogue-wide queryables with `$id: /queryables`; with a collection
|
|
63
|
+
identifier it sets `$id` to `/collections/{collectionId}/queryables`, URL-encoding
|
|
64
|
+
the identifier. Both scopes advertise no CQL2 fields (`properties: {}`,
|
|
65
|
+
`additionalProperties: false`) because this demo rejects CQL2 filters. Providers
|
|
66
|
+
with CQL2 support can return different fields for each collection. The adapter
|
|
67
|
+
checks that the collection exists and preserves the returned document unchanged.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
3
|
+
"$id": "/queryables",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"title": "NAIP demo queryables",
|
|
6
|
+
"description": "This demo supports standard Item Search parameters but does not implement CQL2 filtering.",
|
|
7
|
+
"properties": {},
|
|
8
|
+
"additionalProperties": false
|
|
9
|
+
}
|
|
@@ -20,8 +20,10 @@ import json
|
|
|
20
20
|
import os
|
|
21
21
|
from datetime import datetime as DateTime
|
|
22
22
|
from functools import cache
|
|
23
|
+
from importlib.resources import files
|
|
23
24
|
from pathlib import Path
|
|
24
25
|
from typing import TYPE_CHECKING
|
|
26
|
+
from urllib.parse import quote
|
|
25
27
|
|
|
26
28
|
import duckdb
|
|
27
29
|
from pygeofilter import ast, values
|
|
@@ -145,6 +147,24 @@ class GeoParquetService(StacApiService):
|
|
|
145
147
|
)
|
|
146
148
|
}
|
|
147
149
|
|
|
150
|
+
def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
|
|
151
|
+
"""Return a fresh schema advertising no CQL2 fields in this demo.
|
|
152
|
+
|
|
153
|
+
The demo supports standard Item Search parameters but rejects CQL2
|
|
154
|
+
expressions. The schema therefore disallows additional queryables in
|
|
155
|
+
both scopes, with an identifier matching the selected scope.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
collection_id: Collection to describe, or None for catalogue-wide
|
|
159
|
+
queryables. The HTTP adapter checks that the collection exists.
|
|
160
|
+
"""
|
|
161
|
+
schema: dict[str, object] = json.loads(
|
|
162
|
+
files("stac_api_demo").joinpath("queryables.json").read_text("utf-8")
|
|
163
|
+
)
|
|
164
|
+
if collection_id is not None:
|
|
165
|
+
schema["$id"] = f"/collections/{quote(collection_id, safe='')}/queryables"
|
|
166
|
+
return schema
|
|
167
|
+
|
|
148
168
|
def get_collections(self, base_url: str) -> Collections:
|
|
149
169
|
"""Return all static collection descriptions, including metadata-only datasets."""
|
|
150
170
|
return Collections(
|
|
@@ -25,7 +25,7 @@ acts exclusively as the HTTP adapter**.
|
|
|
25
25
|
## The service port
|
|
26
26
|
|
|
27
27
|
`StacApiService`, defined in `src/stac_api_protocol/stac_service.py`, is the boundary
|
|
28
|
-
between the HTTP adapter and an adopter's catalogue application. It is an abstract base class with
|
|
28
|
+
between the HTTP adapter and an adopter's catalogue application. It is an abstract base class with six adopter-defined catalogue operations and
|
|
29
29
|
two final metadata methods. Adopters subclass it and supply a catalogue identifier,
|
|
30
30
|
title, and description. Incomplete subclasses cannot be instantiated.
|
|
31
31
|
|
|
@@ -132,8 +132,9 @@ curl -fsS "$api/openapi.json" > /dev/null
|
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
The landing page's `self` should be `https://api.example.com/stac/`, its `data`
|
|
135
|
-
link should be `https://api.example.com/stac/collections
|
|
136
|
-
|
|
135
|
+
link should be `https://api.example.com/stac/collections`. Since v0.4.0, the
|
|
136
|
+
queryables `$id` is supplied by the provider and is not rewritten by the adapter;
|
|
137
|
+
check it against your provider configuration. Inspect provider-generated
|
|
137
138
|
navigation links too. Open the public `/stac/docs` URL in a browser and check that
|
|
138
139
|
its schema loads.
|
|
139
140
|
|
|
@@ -19,7 +19,7 @@ limitations under the License.
|
|
|
19
19
|
## Implement the port
|
|
20
20
|
|
|
21
21
|
Create a concrete implementation of `StacApiService` from
|
|
22
|
-
`stac_api_protocol.stac_service`. Implement the
|
|
22
|
+
`stac_api_protocol.stac_service`. Implement the six abstract methods in the
|
|
23
23
|
[service contract](../reference/api.md), using your own application and backend
|
|
24
24
|
logic. The [tutorial](../tutorials/first-steps.md) provides a complete minimal
|
|
25
25
|
example.
|
|
@@ -42,8 +42,10 @@ def create_service() -> StacApiService:
|
|
|
42
42
|
|
|
43
43
|
This example uses the base constructor, which requires catalogue identity metadata.
|
|
44
44
|
Adapt construction to your application's configuration and resource lifecycle.
|
|
45
|
-
The inherited landing-page method uses the incoming request; your
|
|
46
|
-
|
|
45
|
+
The inherited landing-page method uses the incoming request; your catalogue operations receive ordinary filter values. Since v0.4.0,
|
|
46
|
+
`get_queryables(collection_id=None)` supplies catalogue-wide queryables, while
|
|
47
|
+
a collection identifier selects the schema for that collection. No request URL
|
|
48
|
+
is passed to this method.
|
|
47
49
|
|
|
48
50
|
## Declare the entry point
|
|
49
51
|
|
|
@@ -18,10 +18,10 @@ limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
Adopters subclass `StacApiService`, defined in
|
|
20
20
|
`src/stac_api_protocol/stac_service.py`. The HTTP adapter invokes its synchronous
|
|
21
|
-
methods with parsed filter values. All
|
|
21
|
+
methods with parsed filter values. All eight operations belong to the same
|
|
22
22
|
registered `item_service` provider.
|
|
23
23
|
|
|
24
|
-
The constructor requires `id`, `title`, and `description`.
|
|
24
|
+
The constructor requires `id`, `title`, and `description`. Six catalogue operations
|
|
25
25
|
are abstract. `get_landing_page()` and `get_conformance_declaration()` are
|
|
26
26
|
final concrete methods and must not be overridden. The landing page uses
|
|
27
27
|
root-relative links. Both responses advertise the bundled STAC and OGC
|
|
@@ -38,8 +38,8 @@ conformance classes, including Filter Extension capabilities since version 0.2.0
|
|
|
38
38
|
| `GET /collections/{collectionId}/items/{featureId}` | `get_feature(collection_id, feature_id)` | `pystac.Item` or `None` |
|
|
39
39
|
| `GET /conformance` | `get_conformance_declaration()` | `ConformanceClasses` |
|
|
40
40
|
| `GET /search`, `POST /search` | `get_item_search(bbox, intersects, datetime, limit, ids, collections, filter)` | `pystac.ItemCollection` or `None` |
|
|
41
|
-
| `GET /queryables` |
|
|
42
|
-
| `GET /collections/{collectionId}/queryables` |
|
|
41
|
+
| `GET /queryables` | `get_queryables()` | JSON Schema (`application/schema+json`) |
|
|
42
|
+
| `GET /collections/{collectionId}/queryables` | `get_queryables(collection_id)` after `describe_collection(collection_id)` | JSON Schema (`application/schema+json`) |
|
|
43
43
|
|
|
44
44
|
`LandingPage`, `Collections`, and `ConformanceClasses` come from
|
|
45
45
|
`stac_api_protocol.models`. Use these existing types rather than creating
|
|
@@ -70,6 +70,38 @@ Providers are responsible for evaluating expressions, combining them with other
|
|
|
70
70
|
search constraints, and fulfilling the advertised conformance classes. Protocol
|
|
71
71
|
support and protocol tests do not certify a backend's filtering behavior.
|
|
72
72
|
|
|
73
|
+
## Provider-defined queryables since v0.4.0
|
|
74
|
+
|
|
75
|
+
**Version 0.4.0 adds the abstract `get_queryables(collection_id: str | None = None) -> dict[str, object]` method.**
|
|
76
|
+
Existing providers must implement this method before they can be instantiated.
|
|
77
|
+
The adapter no longer loads the protocol's bundled `queryables.json`.
|
|
78
|
+
|
|
79
|
+
Return a JSON-serializable JSON Schema document describing the Item fields your
|
|
80
|
+
backend supports in CQL2 expressions. Providers own `$schema`, `$id`, `type`,
|
|
81
|
+
`properties`, and `additionalProperties`. Keep the schema in your provider
|
|
82
|
+
package and load it with `importlib.resources`, as the demo does. Queryable names
|
|
83
|
+
are Item fields such as `id` or `eo:cloud_cover`; request parameters such as
|
|
84
|
+
`filter` and `filter-lang` are not queryable fields.
|
|
85
|
+
|
|
86
|
+
Both `/queryables` and `/collections/{collectionId}/queryables` return the provider's
|
|
87
|
+
document unchanged with media type `application/schema+json`. The global endpoint
|
|
88
|
+
calls `get_queryables()` with the default `collection_id=None` for catalogue-wide
|
|
89
|
+
queryables. The collection endpoint passes its collection identifier to
|
|
90
|
+
`get_queryables(collection_id)`, allowing the provider to return different fields,
|
|
91
|
+
constraints, and metadata for each collection. No request URL is passed.
|
|
92
|
+
The adapter does not rewrite `$id` or validate the returned schema. Configure
|
|
93
|
+
the document's identifier for each scope in the provider.
|
|
94
|
+
For collection requests, the adapter first checks that the collection exists;
|
|
95
|
+
unknown collections return HTTP 404 without calling `get_queryables()`. A provider
|
|
96
|
+
failure returns HTTP 500 with a generic description.
|
|
97
|
+
|
|
98
|
+
The demo implements the method using its own packaged JSON file. Because its
|
|
99
|
+
backend rejects CQL2 expressions, it returns empty `properties` and
|
|
100
|
+
`additionalProperties: false` in both scopes. It sets `$id` to `/queryables` for
|
|
101
|
+
the catalogue or `/collections/{collectionId}/queryables` for a collection,
|
|
102
|
+
URL-encoding the collection identifier. This documents the demo's limitation; it does not
|
|
103
|
+
make the demo fulfill the protocol's advertised CQL2 conformance classes.
|
|
104
|
+
|
|
73
105
|
## Filter and result semantics
|
|
74
106
|
|
|
75
107
|
- `bbox` is a list of numbers or `None`; `ids` and `collections` are lists of strings
|
|
@@ -24,7 +24,7 @@ and HTTP error handling.
|
|
|
24
24
|
|
|
25
25
|
## Integration at a glance
|
|
26
26
|
|
|
27
|
-
1. Subclass `StacApiService` and implement its
|
|
27
|
+
1. Subclass `StacApiService` and implement its six abstract catalogue operations.
|
|
28
28
|
2. Expose a callable factory that returns your service implementation.
|
|
29
29
|
3. Register that factory in your package's `pyproject.toml`:
|
|
30
30
|
|
|
@@ -16,7 +16,7 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
# Build your first service
|
|
18
18
|
|
|
19
|
-
This tutorial builds an empty catalogue provider. It demonstrates the
|
|
19
|
+
This tutorial builds an empty catalogue provider. It demonstrates the six abstract operations of the
|
|
20
20
|
service contract and factory discovery without requiring a database. An empty
|
|
21
21
|
catalogue cannot demonstrate filtering or item retrieval; replace these methods
|
|
22
22
|
with your own application logic when connecting real data.
|
|
@@ -31,7 +31,8 @@ my-catalogue/
|
|
|
31
31
|
└── src/
|
|
32
32
|
└── my_catalogue/
|
|
33
33
|
├── __init__.py
|
|
34
|
-
|
|
34
|
+
├── provider.py
|
|
35
|
+
└── queryables.json
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
Leave `__init__.py` empty. Put the following in `pyproject.toml`:
|
|
@@ -45,7 +46,7 @@ build-backend = "hatchling.build"
|
|
|
45
46
|
name = "my-catalogue"
|
|
46
47
|
version = "0.1.0"
|
|
47
48
|
requires-python = ">=3.11"
|
|
48
|
-
dependencies = ["stac-api-protocol"]
|
|
49
|
+
dependencies = ["stac-api-protocol>=0.4.0"]
|
|
49
50
|
|
|
50
51
|
[project.entry-points."stacapi.service"]
|
|
51
52
|
item_service = "my_catalogue.provider:create_service"
|
|
@@ -62,6 +63,10 @@ to find your factory once this package is installed.
|
|
|
62
63
|
Put this implementation in `src/my_catalogue/provider.py`:
|
|
63
64
|
|
|
64
65
|
```python
|
|
66
|
+
import json
|
|
67
|
+
from importlib.resources import files
|
|
68
|
+
from urllib.parse import quote
|
|
69
|
+
|
|
65
70
|
from geojson import GeometryCollection
|
|
66
71
|
from geojson.geometry import Geometry
|
|
67
72
|
from pystac import Collection, Item, ItemCollection
|
|
@@ -73,36 +78,53 @@ from stac_api_protocol.stac_service import StacApiService
|
|
|
73
78
|
class EmptyCatalogueService(StacApiService):
|
|
74
79
|
"""Expose an empty catalogue to demonstrate the service boundary."""
|
|
75
80
|
|
|
76
|
-
def
|
|
81
|
+
def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
|
|
82
|
+
"""Return the empty schema with an identifier for the selected scope.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
collection_id: Collection to describe, or None for the catalogue.
|
|
86
|
+
"""
|
|
87
|
+
schema: dict[str, object] = json.loads(
|
|
88
|
+
files("my_catalogue").joinpath("queryables.json").read_text("utf-8")
|
|
89
|
+
)
|
|
90
|
+
if collection_id is not None:
|
|
91
|
+
schema["$id"] = f"/collections/{quote(collection_id, safe='')}/queryables"
|
|
92
|
+
return schema
|
|
93
|
+
|
|
94
|
+
def get_collections(self, base_url: str) -> Collections:
|
|
77
95
|
"""Return the catalogue's empty collection listing."""
|
|
78
96
|
return Collections(collections=[], links=[])
|
|
79
97
|
|
|
80
|
-
def describe_collection(self, collection_id: str) -> Collection | None:
|
|
98
|
+
def describe_collection(self, base_url: str, collection_id: str) -> Collection | None:
|
|
81
99
|
"""Report that the requested collection does not exist."""
|
|
82
100
|
return None
|
|
83
101
|
|
|
84
102
|
def get_features(
|
|
85
103
|
self,
|
|
104
|
+
base_url: str,
|
|
86
105
|
collection_id: str,
|
|
87
106
|
limit: int | None,
|
|
88
107
|
bbox: list[float] | None,
|
|
89
108
|
datetime: str | None,
|
|
109
|
+
filter: str | dict[str, object] | bool | None = None,
|
|
90
110
|
) -> ItemCollection | None:
|
|
91
111
|
"""Report that the requested collection does not exist."""
|
|
92
112
|
return None
|
|
93
113
|
|
|
94
|
-
def get_feature(self, collection_id: str, feature_id: str) -> Item | None:
|
|
114
|
+
def get_feature(self, base_url: str, collection_id: str, feature_id: str) -> Item | None:
|
|
95
115
|
"""Report that the requested item does not exist."""
|
|
96
116
|
return None
|
|
97
117
|
|
|
98
118
|
def get_item_search(
|
|
99
119
|
self,
|
|
120
|
+
base_url: str,
|
|
100
121
|
bbox: list[float] | None,
|
|
101
122
|
intersects: Geometry | GeometryCollection | None,
|
|
102
123
|
datetime: str | None,
|
|
103
124
|
limit: int | None,
|
|
104
125
|
ids: list[str] | None,
|
|
105
126
|
collections: list[str] | None,
|
|
127
|
+
filter: str | dict[str, object] | bool | None = None,
|
|
106
128
|
) -> ItemCollection | None:
|
|
107
129
|
"""Return a successful search with no matching items."""
|
|
108
130
|
return ItemCollection([])
|
|
@@ -115,12 +137,32 @@ def create_service() -> StacApiService:
|
|
|
115
137
|
)
|
|
116
138
|
```
|
|
117
139
|
|
|
140
|
+
Create `src/my_catalogue/queryables.json` for the provider-owned queryables API,
|
|
141
|
+
available since v0.4.0:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
146
|
+
"$id": "/queryables",
|
|
147
|
+
"type": "object",
|
|
148
|
+
"properties": {},
|
|
149
|
+
"additionalProperties": false
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
This empty catalogue advertises no queryable fields. Replace the schema with the
|
|
154
|
+
fields your backend supports when adding CQL2 evaluation. The global endpoint
|
|
155
|
+
calls `get_queryables()`; the collection endpoint passes the collection identifier
|
|
156
|
+
after confirming it exists. This example uses the same empty field definitions
|
|
157
|
+
with a scope-specific `$id`. A real provider can select a different schema for
|
|
158
|
+
each collection. The adapter serves the returned document unchanged.
|
|
159
|
+
|
|
118
160
|
The class specializes `StacApiService`; the factory returns it through the port.
|
|
119
161
|
Neither needs to import FastAPI. All HTTP handling remains in the adapter.
|
|
120
162
|
|
|
121
163
|
The base class supplies the final landing-page and conformance methods. It builds
|
|
122
|
-
links from the incoming landing-page request and advertises the
|
|
123
|
-
|
|
164
|
+
links from the incoming landing-page request and advertises the bundled STAC
|
|
165
|
+
and OGC conformance classes. Adopters implement the other six abstract operations
|
|
124
166
|
and must fulfill those advertised capabilities. This empty example demonstrates
|
|
125
167
|
the integration mechanics; it is not a conformance certification.
|
|
126
168
|
|
|
@@ -18,12 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
"""Expose STAC routes backed by the configured service provider."""
|
|
20
20
|
|
|
21
|
-
import json
|
|
22
21
|
import logging
|
|
23
22
|
import math
|
|
24
23
|
import re
|
|
25
24
|
from datetime import datetime as DateTime
|
|
26
|
-
from importlib.resources import files
|
|
27
25
|
from typing import TYPE_CHECKING, Annotated
|
|
28
26
|
from urllib.parse import quote
|
|
29
27
|
|
|
@@ -52,6 +50,10 @@ from .models import Exception as StacException
|
|
|
52
50
|
from .plugin_loader import load_dependency
|
|
53
51
|
from .stac_service import StacApiService
|
|
54
52
|
|
|
53
|
+
JSON_MEDIA_TYPE = "application/json"
|
|
54
|
+
GEOJSON_MEDIA_TYPE = "application/geo+json"
|
|
55
|
+
JSON_SCHEMA_MEDIA_TYPE = "application/schema+json"
|
|
56
|
+
|
|
55
57
|
get_item_service = load_dependency("item_service")
|
|
56
58
|
|
|
57
59
|
|
|
@@ -76,6 +78,7 @@ def _get_url(request: Request) -> str:
|
|
|
76
78
|
async def http_exception_handler(_request: Request, error: StarletteHTTPException) -> JSONResponse:
|
|
77
79
|
"""Return application and framework HTTP errors using the STAC error schema."""
|
|
78
80
|
return JSONResponse(
|
|
81
|
+
media_type=JSON_MEDIA_TYPE,
|
|
79
82
|
status_code=error.status_code,
|
|
80
83
|
headers=error.headers,
|
|
81
84
|
content=StacException(
|
|
@@ -94,6 +97,7 @@ async def validation_exception_handler(
|
|
|
94
97
|
for issue in error.errors()
|
|
95
98
|
)
|
|
96
99
|
return JSONResponse(
|
|
100
|
+
media_type=JSON_MEDIA_TYPE,
|
|
97
101
|
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
|
98
102
|
content=StacException(code="422", description=description).model_dump(mode="json"),
|
|
99
103
|
)
|
|
@@ -104,6 +108,7 @@ async def unexpected_exception_handler(_request: Request, error: Exception) -> J
|
|
|
104
108
|
"""Log unexpected application failures and return a generic STAC error."""
|
|
105
109
|
logging.getLogger(__name__).error("Unhandled application error", exc_info=error)
|
|
106
110
|
return JSONResponse(
|
|
111
|
+
media_type=JSON_MEDIA_TYPE,
|
|
107
112
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
108
113
|
content=StacException(code="500", description="Internal Server Error").model_dump(
|
|
109
114
|
mode="json"
|
|
@@ -187,7 +192,7 @@ def get_landing_page(
|
|
|
187
192
|
raise _server_error(f"An error occurred when looking for the Landing Page: {e}") from e
|
|
188
193
|
|
|
189
194
|
if landing_page:
|
|
190
|
-
return JSONResponse(content=landing_page.to_dict())
|
|
195
|
+
return JSONResponse(content=landing_page.to_dict(), media_type=JSON_MEDIA_TYPE)
|
|
191
196
|
|
|
192
197
|
raise _not_found("Landing Page does not exist in this Catalogue")
|
|
193
198
|
|
|
@@ -201,7 +206,7 @@ def _collection_with_queryables(collection: Collection) -> Collection:
|
|
|
201
206
|
Link(
|
|
202
207
|
relation,
|
|
203
208
|
f"/collections/{quote(collection.id, safe='')}/queryables",
|
|
204
|
-
media_type=
|
|
209
|
+
media_type=JSON_SCHEMA_MEDIA_TYPE,
|
|
205
210
|
)
|
|
206
211
|
)
|
|
207
212
|
return linked_collection
|
|
@@ -251,7 +256,9 @@ def describe_collection(
|
|
|
251
256
|
) from e
|
|
252
257
|
|
|
253
258
|
if collection:
|
|
254
|
-
return JSONResponse(
|
|
259
|
+
return JSONResponse(
|
|
260
|
+
content=_collection_with_queryables(collection).to_dict(), media_type=JSON_MEDIA_TYPE
|
|
261
|
+
)
|
|
255
262
|
|
|
256
263
|
raise _not_found(f"Collection {collection_id} does not exist in this Catalogue")
|
|
257
264
|
|
|
@@ -311,7 +318,12 @@ def _get_filter(
|
|
|
311
318
|
|
|
312
319
|
@app.get(
|
|
313
320
|
"/collections/{collectionId}/items",
|
|
314
|
-
|
|
321
|
+
response_class=Response,
|
|
322
|
+
responses={
|
|
323
|
+
"200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
|
|
324
|
+
"4XX": {"model": StacException},
|
|
325
|
+
"5XX": {"model": StacException},
|
|
326
|
+
},
|
|
315
327
|
tags=["Features"],
|
|
316
328
|
)
|
|
317
329
|
def get_features(
|
|
@@ -346,7 +358,7 @@ def get_features(
|
|
|
346
358
|
) from e
|
|
347
359
|
|
|
348
360
|
if search_result is not None:
|
|
349
|
-
return JSONResponse(content=search_result.to_dict())
|
|
361
|
+
return JSONResponse(content=search_result.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
|
|
350
362
|
|
|
351
363
|
raise _not_found(
|
|
352
364
|
f"Getting Features from Collection {collection_id} with criteria: limit={limit}, bbox={bbox}, datetime={datetime} did not produce any result"
|
|
@@ -355,7 +367,12 @@ def get_features(
|
|
|
355
367
|
|
|
356
368
|
@app.get(
|
|
357
369
|
"/collections/{collectionId}/items/{featureId}",
|
|
358
|
-
|
|
370
|
+
response_class=Response,
|
|
371
|
+
responses={
|
|
372
|
+
"200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
|
|
373
|
+
"4XX": {"model": StacException},
|
|
374
|
+
"5XX": {"model": StacException},
|
|
375
|
+
},
|
|
359
376
|
tags=["Features"],
|
|
360
377
|
)
|
|
361
378
|
def get_feature(
|
|
@@ -375,7 +392,7 @@ def get_feature(
|
|
|
375
392
|
) from e
|
|
376
393
|
|
|
377
394
|
if feature:
|
|
378
|
-
return JSONResponse(content=feature.to_dict())
|
|
395
|
+
return JSONResponse(content=feature.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
|
|
379
396
|
|
|
380
397
|
raise _not_found(
|
|
381
398
|
f"Item {feature_id} does not exist in Collection {collection_id} in this Catalogue"
|
|
@@ -426,7 +443,7 @@ def _item_search(
|
|
|
426
443
|
) from e
|
|
427
444
|
|
|
428
445
|
if search_result is not None:
|
|
429
|
-
return JSONResponse(content=search_result.to_dict())
|
|
446
|
+
return JSONResponse(content=search_result.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
|
|
430
447
|
|
|
431
448
|
raise _not_found(
|
|
432
449
|
f"Searching with criteria: bbox={bbox}, intersects={intersects}, datetime={datetime}, limit={limit}, ids={ids}, collections={collections}, filter={filter} did not produce any result"
|
|
@@ -437,23 +454,29 @@ def _item_search(
|
|
|
437
454
|
"/queryables",
|
|
438
455
|
response_class=Response,
|
|
439
456
|
responses={
|
|
440
|
-
"200": {"content": {
|
|
457
|
+
"200": {"content": {JSON_SCHEMA_MEDIA_TYPE: {}}},
|
|
441
458
|
"default": {"model": StacException},
|
|
442
459
|
},
|
|
443
460
|
tags=["Filter Extension"],
|
|
444
461
|
)
|
|
445
|
-
def get_queryables(
|
|
446
|
-
"""Return the
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
462
|
+
def get_queryables(service: StacApiService = Depends(get_item_service)) -> Response:
|
|
463
|
+
"""Return the provider's queryables schema without modifying its contents.
|
|
464
|
+
|
|
465
|
+
Raises:
|
|
466
|
+
HTTPException: With status 500 if the provider cannot retrieve queryables.
|
|
467
|
+
"""
|
|
468
|
+
try:
|
|
469
|
+
schema = service.get_queryables()
|
|
470
|
+
except Exception as error:
|
|
471
|
+
raise _server_error("Unable to retrieve queryables") from error
|
|
472
|
+
return JSONResponse(content=schema, media_type=JSON_SCHEMA_MEDIA_TYPE)
|
|
450
473
|
|
|
451
474
|
|
|
452
475
|
@app.get(
|
|
453
476
|
"/collections/{collectionId}/queryables",
|
|
454
477
|
response_class=Response,
|
|
455
478
|
responses={
|
|
456
|
-
"200": {"content": {
|
|
479
|
+
"200": {"content": {JSON_SCHEMA_MEDIA_TYPE: {}}},
|
|
457
480
|
"default": {"model": StacException},
|
|
458
481
|
},
|
|
459
482
|
tags=["Filter Extension"],
|
|
@@ -463,11 +486,11 @@ def get_collection_queryables(
|
|
|
463
486
|
collection_id: str = Path(..., alias="collectionId"),
|
|
464
487
|
service: StacApiService = Depends(get_item_service),
|
|
465
488
|
) -> Response:
|
|
466
|
-
"""Return the
|
|
489
|
+
"""Return the provider's queryables schema for the requested collection.
|
|
467
490
|
|
|
468
491
|
Raises:
|
|
469
492
|
HTTPException: With status 404 if the collection does not exist, or
|
|
470
|
-
status 500 if the provider cannot retrieve
|
|
493
|
+
status 500 if the provider cannot retrieve metadata or queryables.
|
|
471
494
|
"""
|
|
472
495
|
try:
|
|
473
496
|
collection = service.describe_collection(_get_url(request), collection_id)
|
|
@@ -475,7 +498,12 @@ def get_collection_queryables(
|
|
|
475
498
|
raise _server_error("Unable to retrieve collection metadata") from error
|
|
476
499
|
if collection is None:
|
|
477
500
|
raise _not_found(f"Collection {collection_id} does not exist in this Catalogue")
|
|
478
|
-
|
|
501
|
+
|
|
502
|
+
try:
|
|
503
|
+
schema = service.get_queryables(collection_id)
|
|
504
|
+
except Exception as error:
|
|
505
|
+
raise _server_error("Unable to retrieve queryables") from error
|
|
506
|
+
return JSONResponse(content=schema, media_type=JSON_SCHEMA_MEDIA_TYPE)
|
|
479
507
|
|
|
480
508
|
|
|
481
509
|
def _parse_intersects(value: str | None) -> GeometryGeoJSON | GeometryCollection | None:
|
|
@@ -502,7 +530,12 @@ def _parse_intersects(value: str | None) -> GeometryGeoJSON | GeometryCollection
|
|
|
502
530
|
|
|
503
531
|
@app.get(
|
|
504
532
|
"/search",
|
|
505
|
-
|
|
533
|
+
response_class=Response,
|
|
534
|
+
responses={
|
|
535
|
+
"200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
|
|
536
|
+
"4XX": {"model": StacException},
|
|
537
|
+
"5XX": {"model": StacException},
|
|
538
|
+
},
|
|
506
539
|
tags=["Item Search"],
|
|
507
540
|
)
|
|
508
541
|
def get_item_search(
|
|
@@ -540,7 +573,12 @@ def get_item_search(
|
|
|
540
573
|
|
|
541
574
|
@app.post(
|
|
542
575
|
"/search",
|
|
543
|
-
|
|
576
|
+
response_class=Response,
|
|
577
|
+
responses={
|
|
578
|
+
"200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
|
|
579
|
+
"4XX": {"model": StacException},
|
|
580
|
+
"5XX": {"model": StacException},
|
|
581
|
+
},
|
|
544
582
|
tags=["Item Search"],
|
|
545
583
|
)
|
|
546
584
|
def post_item_search(
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"$id": "/queryables",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"title": "Queryables for STAC API",
|
|
6
|
-
"description": "Queryable names for the STAC API Item Search filter.",
|
|
6
|
+
"description": "Queryable names for the STAC API Item Search filter, supporting CQL2 JSON (cql2-json) and CQL2 Text (cql2-text) expressions.",
|
|
7
7
|
"properties": {
|
|
8
8
|
"id": {
|
|
9
9
|
"description": "ID",
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
"updated": {
|
|
29
29
|
"description": "Last Update Time",
|
|
30
30
|
"$ref": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/datetime.json#/properties/updated"
|
|
31
|
+
},
|
|
32
|
+
"filter": {
|
|
33
|
+
"description": "The CQL2-(JSON|TEXT) filter.",
|
|
34
|
+
"oneOf": [
|
|
35
|
+
{ "type": "string" },
|
|
36
|
+
{ "$ref": "https://schemas.opengis.net/cql2/1.0/cql2.json" }
|
|
37
|
+
]
|
|
31
38
|
}
|
|
32
39
|
},
|
|
33
40
|
"additionalProperties": true
|
|
@@ -183,3 +183,23 @@ class StacApiService(ABC):
|
|
|
183
183
|
collections: Collection identifiers, or None to search all collections.
|
|
184
184
|
filter: CQL2 expression, or None to omit CQL2 filtering.
|
|
185
185
|
"""
|
|
186
|
+
|
|
187
|
+
@abstractmethod
|
|
188
|
+
def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
|
|
189
|
+
"""Return the JSON Schema describing fields available in CQL2 filters.
|
|
190
|
+
|
|
191
|
+
Available since v0.4.0. Providers own the complete JSON-serializable
|
|
192
|
+
document, including its schema dialect, identifier, property definitions,
|
|
193
|
+
and additional-property policy. The adapter returns the document unchanged
|
|
194
|
+
and does not pass a request URL. For collection requests, the adapter
|
|
195
|
+
verifies that the collection exists before calling this method.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
collection_id: Collection whose queryable fields to describe, or
|
|
199
|
+
None for catalogue-wide queryables. The global endpoint calls
|
|
200
|
+
this method without arguments.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
A queryables JSON Schema document. Its properties describe searchable
|
|
204
|
+
Item fields, rather than search request parameters such as ``filter``.
|
|
205
|
+
"""
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import TYPE_CHECKING
|
|
18
|
+
|
|
19
|
+
import pytest
|
|
20
|
+
from stac_api_demo.service import GeoParquetService
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize(
|
|
27
|
+
("collection_id", "schema_id"),
|
|
28
|
+
[
|
|
29
|
+
(None, "/queryables"),
|
|
30
|
+
("naip", "/collections/naip/queryables"),
|
|
31
|
+
("other collection/id", "/collections/other%20collection%2Fid/queryables"),
|
|
32
|
+
],
|
|
33
|
+
)
|
|
34
|
+
def test_demo_queryables_describes_cql2_limitation_and_returns_fresh_document(
|
|
35
|
+
tmp_path: Path,
|
|
36
|
+
collection_id: str | None,
|
|
37
|
+
schema_id: str,
|
|
38
|
+
) -> None:
|
|
39
|
+
(tmp_path / "naip.parquet").touch()
|
|
40
|
+
(tmp_path / "collections.json").write_text("[]", encoding="utf-8")
|
|
41
|
+
service = GeoParquetService(tmp_path)
|
|
42
|
+
|
|
43
|
+
schema = service.get_queryables(collection_id)
|
|
44
|
+
assert schema["type"] == "object"
|
|
45
|
+
assert schema["properties"] == {}
|
|
46
|
+
assert schema["additionalProperties"] is False
|
|
47
|
+
assert schema["$id"] == schema_id
|
|
48
|
+
schema["properties"] = {"unsupported": {"type": "string"}}
|
|
49
|
+
assert service.get_queryables(collection_id)["properties"] == {}
|
|
50
|
+
assert service.get_queryables()["$id"] == "/queryables"
|
|
@@ -62,6 +62,13 @@ def filter_app(
|
|
|
62
62
|
service.get_item_search.return_value = ItemCollection([])
|
|
63
63
|
service.get_features.return_value = ItemCollection([])
|
|
64
64
|
service.describe_collection.return_value = queryables_collection
|
|
65
|
+
service.get_queryables.return_value = {
|
|
66
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
67
|
+
"$id": "https://provider.example/queryables",
|
|
68
|
+
"type": "object",
|
|
69
|
+
"properties": {"eo:cloud_cover": {"type": "number", "minimum": 0}},
|
|
70
|
+
"additionalProperties": False,
|
|
71
|
+
}
|
|
65
72
|
app.dependency_overrides[api.get_item_service] = lambda: service
|
|
66
73
|
try:
|
|
67
74
|
yield app
|
|
@@ -130,6 +137,28 @@ def test_at_least_one_cql2_encoding_is_advertised(service: Mock) -> None:
|
|
|
130
137
|
)
|
|
131
138
|
|
|
132
139
|
|
|
140
|
+
def test_queryables_selects_provider_document_by_collection(
|
|
141
|
+
filter_app: FastAPI, service: Mock
|
|
142
|
+
) -> None:
|
|
143
|
+
global_schema: dict[str, object] = {"type": "object", "properties": {"id": {"type": "string"}}}
|
|
144
|
+
collection_schema: dict[str, object] = {
|
|
145
|
+
"type": "object",
|
|
146
|
+
"properties": {"eo:cloud_cover": {"type": "number"}},
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
def queryables_for_scope(collection_id: str | None = None) -> dict[str, object]:
|
|
150
|
+
return global_schema if collection_id is None else collection_schema
|
|
151
|
+
|
|
152
|
+
service.get_queryables.side_effect = queryables_for_scope
|
|
153
|
+
for path, expected in (
|
|
154
|
+
("/queryables", global_schema),
|
|
155
|
+
("/collections/sentinel/queryables", collection_schema),
|
|
156
|
+
):
|
|
157
|
+
status, body, _ = asyncio.run(_request(filter_app, "GET", path, {}))
|
|
158
|
+
assert status == HTTPStatus.OK
|
|
159
|
+
assert json.loads(body) == expected
|
|
160
|
+
|
|
161
|
+
|
|
133
162
|
def test_landing_page_advertises_queryables_with_standard_relation(service: Mock) -> None:
|
|
134
163
|
service.id = "catalogue"
|
|
135
164
|
service.title = "Test catalogue"
|
|
@@ -145,18 +174,20 @@ def test_landing_page_advertises_queryables_with_standard_relation(service: Mock
|
|
|
145
174
|
|
|
146
175
|
|
|
147
176
|
@pytest.mark.parametrize("path", ["/queryables", "/collections/sentinel/queryables"])
|
|
148
|
-
def test_global_and_collection_queryables_are_available(
|
|
177
|
+
def test_global_and_collection_queryables_are_available(
|
|
178
|
+
filter_app: FastAPI, service: Mock, path: str
|
|
179
|
+
) -> None:
|
|
149
180
|
status, body, headers = asyncio.run(_request(filter_app, "GET", path, {}))
|
|
150
181
|
assert status == HTTPStatus.OK
|
|
151
182
|
assert headers[b"content-type"].split(b";")[0] == b"application/schema+json"
|
|
152
183
|
schema = json.loads(body)
|
|
153
184
|
assert schema["type"] == "object"
|
|
154
185
|
assert schema["$schema"].startswith("https://json-schema.org/")
|
|
155
|
-
assert
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
186
|
+
assert schema == service.get_queryables.return_value
|
|
187
|
+
if path == "/queryables":
|
|
188
|
+
service.get_queryables.assert_called_once_with()
|
|
189
|
+
else:
|
|
190
|
+
service.get_queryables.assert_called_once_with("sentinel")
|
|
160
191
|
|
|
161
192
|
|
|
162
193
|
@pytest.mark.parametrize("filter_lang", [None, "cql2-json"])
|
|
@@ -392,13 +423,28 @@ def queryables_collection() -> Collection:
|
|
|
392
423
|
|
|
393
424
|
|
|
394
425
|
@pytest.mark.parametrize("path", ["/queryables", "/collections/sentinel/queryables"])
|
|
395
|
-
def
|
|
426
|
+
def test_queryables_preserves_provider_document(
|
|
427
|
+
filter_app: FastAPI, service: Mock, path: str
|
|
428
|
+
) -> None:
|
|
429
|
+
original = json.dumps(service.get_queryables.return_value)
|
|
396
430
|
status, body, _ = asyncio.run(_request(filter_app, "GET", path, {"unused": "value"}))
|
|
397
431
|
assert status == HTTPStatus.OK
|
|
398
|
-
|
|
399
|
-
assert
|
|
400
|
-
|
|
401
|
-
|
|
432
|
+
assert json.loads(body) == json.loads(original)
|
|
433
|
+
assert json.dumps(service.get_queryables.return_value) == original
|
|
434
|
+
if path == "/queryables":
|
|
435
|
+
service.get_queryables.assert_called_once_with()
|
|
436
|
+
else:
|
|
437
|
+
service.get_queryables.assert_called_once_with("sentinel")
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
@pytest.mark.parametrize("path", ["/queryables", "/collections/sentinel/queryables"])
|
|
441
|
+
def test_queryables_provider_failure_returns_server_error(
|
|
442
|
+
filter_app: FastAPI, service: Mock, path: str
|
|
443
|
+
) -> None:
|
|
444
|
+
service.get_queryables.side_effect = RuntimeError("Private provider details")
|
|
445
|
+
status, body, _ = asyncio.run(_request(filter_app, "GET", path, {}))
|
|
446
|
+
assert status == HTTPStatus.INTERNAL_SERVER_ERROR
|
|
447
|
+
assert json.loads(body) == {"code": "500", "description": "Unable to retrieve queryables"}
|
|
402
448
|
|
|
403
449
|
|
|
404
450
|
@pytest.mark.parametrize("path", ["/collections/sentinel", "/collections"])
|
|
@@ -434,6 +480,7 @@ def test_unknown_collection_queryables_returns_not_found(
|
|
|
434
480
|
assert status == HTTPStatus.NOT_FOUND
|
|
435
481
|
assert json.loads(body)["code"] == "404"
|
|
436
482
|
service.describe_collection.assert_called_once_with("http://localhost:8000", "unknown")
|
|
483
|
+
service.get_queryables.assert_not_called()
|
|
437
484
|
|
|
438
485
|
|
|
439
486
|
def test_collection_queryables_provider_failure_returns_server_error(
|
|
@@ -446,6 +493,7 @@ def test_collection_queryables_provider_failure_returns_server_error(
|
|
|
446
493
|
assert status == HTTPStatus.INTERNAL_SERVER_ERROR
|
|
447
494
|
assert json.loads(body)["code"] == "500"
|
|
448
495
|
assert "private details" not in body.decode()
|
|
496
|
+
service.get_queryables.assert_not_called()
|
|
449
497
|
|
|
450
498
|
|
|
451
499
|
def test_queryables_openapi_advertises_schema_media_type(api: ModuleType) -> None:
|
|
@@ -34,22 +34,32 @@ if TYPE_CHECKING:
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
@pytest.mark.parametrize(
|
|
37
|
-
("route", "arguments"),
|
|
37
|
+
("route", "arguments", "media_type"),
|
|
38
38
|
[
|
|
39
|
-
("get_landing_page", ()),
|
|
40
|
-
("get_feature", ("sentinel", "scene")),
|
|
41
|
-
(
|
|
42
|
-
|
|
39
|
+
("get_landing_page", (), "application/json"),
|
|
40
|
+
("get_feature", ("sentinel", "scene"), "application/geo+json"),
|
|
41
|
+
(
|
|
42
|
+
"get_features",
|
|
43
|
+
("sentinel", 20, [1.0, 2.0, 3.0, 4.0], None, None),
|
|
44
|
+
"application/geo+json",
|
|
45
|
+
),
|
|
46
|
+
("get_item_search", (None, None, None, 10, None, None, None), "application/geo+json"),
|
|
43
47
|
],
|
|
44
48
|
)
|
|
45
49
|
def test_routes_serialize_service_results(
|
|
46
|
-
api: ModuleType,
|
|
50
|
+
api: ModuleType,
|
|
51
|
+
service: Mock,
|
|
52
|
+
http_request: Request,
|
|
53
|
+
route: str,
|
|
54
|
+
arguments: tuple[object, ...],
|
|
55
|
+
media_type: str,
|
|
47
56
|
) -> None:
|
|
48
57
|
backend = getattr(service, route)
|
|
49
58
|
payload = {"id": "result", "links": []}
|
|
50
59
|
backend.return_value.to_dict.return_value = payload
|
|
51
60
|
response = getattr(api, route)(http_request, *arguments, service=service)
|
|
52
61
|
assert response.status_code == HTTPStatus.OK
|
|
62
|
+
assert response.headers["content-type"] == media_type
|
|
53
63
|
assert json.loads(response.body) == payload
|
|
54
64
|
backend.assert_called_once_with("https://example.com/stac", *arguments)
|
|
55
65
|
|
|
@@ -122,6 +132,7 @@ def test_empty_item_collection_is_success(
|
|
|
122
132
|
)
|
|
123
133
|
response = getattr(api, route)(http_request, *arguments, service=service)
|
|
124
134
|
assert response.status_code == HTTPStatus.OK
|
|
135
|
+
assert response.headers["content-type"] == "application/geo+json"
|
|
125
136
|
assert json.loads(response.body) == {"type": "FeatureCollection", "features": []}
|
|
126
137
|
|
|
127
138
|
|
|
@@ -150,6 +161,7 @@ def test_post_search_forwards_all_filters(
|
|
|
150
161
|
None,
|
|
151
162
|
)
|
|
152
163
|
assert response.status_code == HTTPStatus.OK
|
|
164
|
+
assert response.headers["content-type"] == "application/geo+json"
|
|
153
165
|
|
|
154
166
|
|
|
155
167
|
def test_post_search_defaults(api: ModuleType, service: Mock, http_request: Request) -> None:
|
|
@@ -172,6 +184,7 @@ def test_http_error_handler_preserves_status_and_headers(api: ModuleType) -> Non
|
|
|
172
184
|
HTTPStatus.UNAUTHORIZED, "Authentication required", {"WWW-Authenticate": "Bearer"}
|
|
173
185
|
)
|
|
174
186
|
response = asyncio.run(api.http_exception_handler(Request({"type": "http"}), error))
|
|
187
|
+
assert response.headers["content-type"] == "application/json"
|
|
175
188
|
assert response.status_code == HTTPStatus.UNAUTHORIZED
|
|
176
189
|
assert response.headers["www-authenticate"] == "Bearer"
|
|
177
190
|
assert json.loads(response.body) == {"code": "401", "description": "Authentication required"}
|
|
@@ -185,6 +198,7 @@ def test_validation_error_handler_formats_locations(api: ModuleType) -> None:
|
|
|
185
198
|
]
|
|
186
199
|
)
|
|
187
200
|
response = asyncio.run(api.validation_exception_handler(Request({"type": "http"}), error))
|
|
201
|
+
assert response.headers["content-type"] == "application/json"
|
|
188
202
|
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
|
|
189
203
|
assert json.loads(response.body) == {
|
|
190
204
|
"code": "422",
|
|
@@ -198,8 +212,34 @@ def test_unexpected_error_is_logged_but_not_exposed(
|
|
|
198
212
|
error = RuntimeError("private backend details")
|
|
199
213
|
with caplog.at_level(logging.ERROR):
|
|
200
214
|
response = asyncio.run(api.unexpected_exception_handler(Request({"type": "http"}), error))
|
|
215
|
+
assert response.headers["content-type"] == "application/json"
|
|
201
216
|
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
|
202
217
|
assert json.loads(response.body) == {"code": "500", "description": "Internal Server Error"}
|
|
203
218
|
assert "Unhandled application error" in caplog.text
|
|
204
219
|
assert caplog.records[-1].exc_info is not None
|
|
205
220
|
assert caplog.records[-1].exc_info[1] is error
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@pytest.mark.parametrize(
|
|
224
|
+
("path", "method", "media_type"),
|
|
225
|
+
[
|
|
226
|
+
("/", "get", "application/json"),
|
|
227
|
+
("/collections", "get", "application/json"),
|
|
228
|
+
("/collections/{collectionId}", "get", "application/json"),
|
|
229
|
+
("/conformance", "get", "application/json"),
|
|
230
|
+
("/collections/{collectionId}/items", "get", "application/geo+json"),
|
|
231
|
+
("/collections/{collectionId}/items/{featureId}", "get", "application/geo+json"),
|
|
232
|
+
("/search", "get", "application/geo+json"),
|
|
233
|
+
("/search", "post", "application/geo+json"),
|
|
234
|
+
("/queryables", "get", "application/schema+json"),
|
|
235
|
+
("/collections/{collectionId}/queryables", "get", "application/schema+json"),
|
|
236
|
+
],
|
|
237
|
+
)
|
|
238
|
+
def test_openapi_declares_response_media_types(
|
|
239
|
+
api: ModuleType, path: str, method: str, media_type: str
|
|
240
|
+
) -> None:
|
|
241
|
+
responses = api.app.openapi()["paths"][path][method]["responses"]
|
|
242
|
+
assert set(responses["200"]["content"]) == {media_type}
|
|
243
|
+
for status_code, response in responses.items():
|
|
244
|
+
if status_code != "200":
|
|
245
|
+
assert set(response["content"]) == {"application/json"}
|
|
@@ -28,6 +28,10 @@ if TYPE_CHECKING:
|
|
|
28
28
|
class EmptyCatalogueService(StacApiService):
|
|
29
29
|
"""Exercise inherited metadata using a concrete empty catalogue."""
|
|
30
30
|
|
|
31
|
+
def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
|
|
32
|
+
"""Return an empty queryables document for this test provider."""
|
|
33
|
+
return {"type": "object", "properties": {}, "additionalProperties": False}
|
|
34
|
+
|
|
31
35
|
def get_collections(self, base_url: str) -> Collections:
|
|
32
36
|
"""Return an empty collection listing."""
|
|
33
37
|
return Collections(collections=[], links=[])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|