stac-api-protocol 0.4.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.
Files changed (48) hide show
  1. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/CHANGELOG.md +14 -2
  2. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/PKG-INFO +1 -1
  3. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/README.md +8 -4
  4. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/stac_api_demo/service.py +10 -2
  5. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/how-to/register-service.md +3 -1
  6. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/reference/api.md +12 -7
  7. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/tutorials/first-steps.md +14 -4
  8. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/__about__.py +1 -1
  9. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/main.py +49 -15
  10. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/stac_service.py +9 -4
  11. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_demo_service.py +15 -3
  12. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_filter_compliance.py +31 -2
  13. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_routes.py +46 -6
  14. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_stac_service.py +1 -1
  15. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/.gitignore +0 -0
  16. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/LICENSE +0 -0
  17. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/README.md +0 -0
  18. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/.gitignore +0 -0
  19. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/download-data.sh +0 -0
  20. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/examples.sh +0 -0
  21. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/pyproject.toml +0 -0
  22. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/stac_api_demo/__init__.py +0 -0
  23. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/stac_api_demo/queryables.json +0 -0
  24. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/demo/start.sh +0 -0
  25. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/diagrams/architecture.svg +0 -0
  26. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/diagrams/architecture_dark.svg +0 -0
  27. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/diagrams/src/architecture.puml +0 -0
  28. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/explanation/architecture.md +0 -0
  29. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/explanation/index.md +0 -0
  30. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/how-to/deploy-uvicorn.md +0 -0
  31. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/how-to/index.md +0 -0
  32. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/how-to/install.md +0 -0
  33. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/how-to/use-cli.md +0 -0
  34. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/index.md +0 -0
  35. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/reference/index.md +0 -0
  36. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/reference/openapi.html +0 -0
  37. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/docs/tutorials/index.md +0 -0
  38. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/pyproject.toml +0 -0
  39. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/__init__.py +0 -0
  40. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/models.py +0 -0
  41. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/plugin_loader.py +0 -0
  42. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/py.typed +0 -0
  43. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/src/stac_api_protocol/queryables.json +0 -0
  44. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/conftest.py +0 -0
  45. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_bbox_queries.py +0 -0
  46. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_models.py +0 -0
  47. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_plugin_loader.py +0 -0
  48. {stac_api_protocol-0.4.0 → stac_api_protocol-0.5.0}/tests/test_search_validation.py +0 -0
@@ -23,6 +23,17 @@ 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
+
26
37
  ## [0.4.0] - 2026-12-01
27
38
 
28
39
  ### Added
@@ -65,8 +76,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
65
76
 
66
77
  - Initial project release.
67
78
 
68
- [Unreleased]: https://github.com/Terradue/stac-api-protocol/compare/0.3.1...HEAD
69
- [0.3.1]: https://github.com/Terradue/stac-api-protocol/compare/0.3.0...0.3.1
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
70
82
  [0.3.0]: https://github.com/Terradue/stac-api-protocol/compare/0.2.0...0.3.0
71
83
  [0.2.0]: https://github.com/Terradue/stac-api-protocol/compare/0.1.1...0.2.0
72
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.4.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
@@ -57,7 +57,11 @@ 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
59
 
60
- Since v0.4.0, `GeoParquetService.get_queryables()` supplies the document served at
61
- both queryables endpoints from `stac_api_demo/queryables.json`. It advertises no
62
- CQL2 fields (`properties: {}`, `additionalProperties: false`) because this demo
63
- rejects CQL2 filters. The adapter preserves the provider's `$id` and other metadata.
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.
@@ -23,6 +23,7 @@ from functools import cache
23
23
  from importlib.resources import files
24
24
  from pathlib import Path
25
25
  from typing import TYPE_CHECKING
26
+ from urllib.parse import quote
26
27
 
27
28
  import duckdb
28
29
  from pygeofilter import ast, values
@@ -146,15 +147,22 @@ class GeoParquetService(StacApiService):
146
147
  )
147
148
  }
148
149
 
149
- def get_queryables(self) -> dict[str, object]:
150
+ def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
150
151
  """Return a fresh schema advertising no CQL2 fields in this demo.
151
152
 
152
153
  The demo supports standard Item Search parameters but rejects CQL2
153
- expressions. The schema therefore disallows additional queryables.
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.
154
160
  """
155
161
  schema: dict[str, object] = json.loads(
156
162
  files("stac_api_demo").joinpath("queryables.json").read_text("utf-8")
157
163
  )
164
+ if collection_id is not None:
165
+ schema["$id"] = f"/collections/{quote(collection_id, safe='')}/queryables"
158
166
  return schema
159
167
 
160
168
  def get_collections(self, base_url: str) -> Collections:
@@ -43,7 +43,9 @@ def create_service() -> StacApiService:
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
45
  The inherited landing-page method uses the incoming request; your catalogue operations receive ordinary filter values. Since v0.4.0,
46
- `get_queryables()` also supplies the provider-owned schema without request arguments.
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
 
@@ -39,7 +39,7 @@ conformance classes, including Filter Extension capabilities since version 0.2.0
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
41
  | `GET /queryables` | `get_queryables()` | JSON Schema (`application/schema+json`) |
42
- | `GET /collections/{collectionId}/queryables` | `get_queryables()` after `describe_collection(collection_id)` | 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
@@ -72,7 +72,7 @@ support and protocol tests do not certify a backend's filtering behavior.
72
72
 
73
73
  ## Provider-defined queryables since v0.4.0
74
74
 
75
- **Version 0.4.0 adds the abstract `get_queryables() -> dict[str, object]` method.**
75
+ **Version 0.4.0 adds the abstract `get_queryables(collection_id: str | None = None) -> dict[str, object]` method.**
76
76
  Existing providers must implement this method before they can be instantiated.
77
77
  The adapter no longer loads the protocol's bundled `queryables.json`.
78
78
 
@@ -84,17 +84,22 @@ are Item fields such as `id` or `eo:cloud_cover`; request parameters such as
84
84
  `filter` and `filter-lang` are not queryable fields.
85
85
 
86
86
  Both `/queryables` and `/collections/{collectionId}/queryables` return the provider's
87
- document unchanged with media type `application/schema+json`. The method receives
88
- no request URL or collection identifier, so it supplies a shared schema across
89
- collections. The adapter does not rewrite `$id` to match either endpoint or
90
- validate the returned schema. Configure the document's identifier in the provider.
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.
91
94
  For collection requests, the adapter first checks that the collection exists;
92
95
  unknown collections return HTTP 404 without calling `get_queryables()`. A provider
93
96
  failure returns HTTP 500 with a generic description.
94
97
 
95
98
  The demo implements the method using its own packaged JSON file. Because its
96
99
  backend rejects CQL2 expressions, it returns empty `properties` and
97
- `additionalProperties: false`. This documents the demo's limitation; it does not
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
98
103
  make the demo fulfill the protocol's advertised CQL2 conformance classes.
99
104
 
100
105
  ## Filter and result semantics
@@ -65,6 +65,7 @@ Put this implementation in `src/my_catalogue/provider.py`:
65
65
  ```python
66
66
  import json
67
67
  from importlib.resources import files
68
+ from urllib.parse import quote
68
69
 
69
70
  from geojson import GeometryCollection
70
71
  from geojson.geometry import Geometry
@@ -77,11 +78,17 @@ from stac_api_protocol.stac_service import StacApiService
77
78
  class EmptyCatalogueService(StacApiService):
78
79
  """Expose an empty catalogue to demonstrate the service boundary."""
79
80
 
80
- def get_queryables(self) -> dict[str, object]:
81
- """Return the packaged schema for this empty catalogue."""
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
+ """
82
87
  schema: dict[str, object] = json.loads(
83
88
  files("my_catalogue").joinpath("queryables.json").read_text("utf-8")
84
89
  )
90
+ if collection_id is not None:
91
+ schema["$id"] = f"/collections/{quote(collection_id, safe='')}/queryables"
85
92
  return schema
86
93
 
87
94
  def get_collections(self, base_url: str) -> Collections:
@@ -144,8 +151,11 @@ available since v0.4.0:
144
151
  ```
145
152
 
146
153
  This empty catalogue advertises no queryable fields. Replace the schema with the
147
- fields your backend supports when adding CQL2 evaluation. The adapter serves this
148
- document unchanged at both queryables endpoints for existing collections.
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.
149
159
 
150
160
  The class specializes `StacApiService`; the factory returns it through the port.
151
161
  Neither needs to import FastAPI. All HTTP handling remains in the adapter.
@@ -14,4 +14,4 @@
14
14
 
15
15
  """Package metadata for STAC API Protocol."""
16
16
 
17
- __version__ = "0.4.0"
17
+ __version__ = "0.5.0"
@@ -50,6 +50,10 @@ from .models import Exception as StacException
50
50
  from .plugin_loader import load_dependency
51
51
  from .stac_service import StacApiService
52
52
 
53
+ JSON_MEDIA_TYPE = "application/json"
54
+ GEOJSON_MEDIA_TYPE = "application/geo+json"
55
+ JSON_SCHEMA_MEDIA_TYPE = "application/schema+json"
56
+
53
57
  get_item_service = load_dependency("item_service")
54
58
 
55
59
 
@@ -74,6 +78,7 @@ def _get_url(request: Request) -> str:
74
78
  async def http_exception_handler(_request: Request, error: StarletteHTTPException) -> JSONResponse:
75
79
  """Return application and framework HTTP errors using the STAC error schema."""
76
80
  return JSONResponse(
81
+ media_type=JSON_MEDIA_TYPE,
77
82
  status_code=error.status_code,
78
83
  headers=error.headers,
79
84
  content=StacException(
@@ -92,6 +97,7 @@ async def validation_exception_handler(
92
97
  for issue in error.errors()
93
98
  )
94
99
  return JSONResponse(
100
+ media_type=JSON_MEDIA_TYPE,
95
101
  status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
96
102
  content=StacException(code="422", description=description).model_dump(mode="json"),
97
103
  )
@@ -102,6 +108,7 @@ async def unexpected_exception_handler(_request: Request, error: Exception) -> J
102
108
  """Log unexpected application failures and return a generic STAC error."""
103
109
  logging.getLogger(__name__).error("Unhandled application error", exc_info=error)
104
110
  return JSONResponse(
111
+ media_type=JSON_MEDIA_TYPE,
105
112
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
106
113
  content=StacException(code="500", description="Internal Server Error").model_dump(
107
114
  mode="json"
@@ -185,7 +192,7 @@ def get_landing_page(
185
192
  raise _server_error(f"An error occurred when looking for the Landing Page: {e}") from e
186
193
 
187
194
  if landing_page:
188
- return JSONResponse(content=landing_page.to_dict())
195
+ return JSONResponse(content=landing_page.to_dict(), media_type=JSON_MEDIA_TYPE)
189
196
 
190
197
  raise _not_found("Landing Page does not exist in this Catalogue")
191
198
 
@@ -199,7 +206,7 @@ def _collection_with_queryables(collection: Collection) -> Collection:
199
206
  Link(
200
207
  relation,
201
208
  f"/collections/{quote(collection.id, safe='')}/queryables",
202
- media_type="application/schema+json",
209
+ media_type=JSON_SCHEMA_MEDIA_TYPE,
203
210
  )
204
211
  )
205
212
  return linked_collection
@@ -249,7 +256,9 @@ def describe_collection(
249
256
  ) from e
250
257
 
251
258
  if collection:
252
- return JSONResponse(content=_collection_with_queryables(collection).to_dict())
259
+ return JSONResponse(
260
+ content=_collection_with_queryables(collection).to_dict(), media_type=JSON_MEDIA_TYPE
261
+ )
253
262
 
254
263
  raise _not_found(f"Collection {collection_id} does not exist in this Catalogue")
255
264
 
@@ -309,7 +318,12 @@ def _get_filter(
309
318
 
310
319
  @app.get(
311
320
  "/collections/{collectionId}/items",
312
- responses={"4XX": {"model": StacException}, "5XX": {"model": StacException}},
321
+ response_class=Response,
322
+ responses={
323
+ "200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
324
+ "4XX": {"model": StacException},
325
+ "5XX": {"model": StacException},
326
+ },
313
327
  tags=["Features"],
314
328
  )
315
329
  def get_features(
@@ -344,7 +358,7 @@ def get_features(
344
358
  ) from e
345
359
 
346
360
  if search_result is not None:
347
- return JSONResponse(content=search_result.to_dict())
361
+ return JSONResponse(content=search_result.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
348
362
 
349
363
  raise _not_found(
350
364
  f"Getting Features from Collection {collection_id} with criteria: limit={limit}, bbox={bbox}, datetime={datetime} did not produce any result"
@@ -353,7 +367,12 @@ def get_features(
353
367
 
354
368
  @app.get(
355
369
  "/collections/{collectionId}/items/{featureId}",
356
- responses={"4XX": {"model": StacException}, "5XX": {"model": StacException}},
370
+ response_class=Response,
371
+ responses={
372
+ "200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
373
+ "4XX": {"model": StacException},
374
+ "5XX": {"model": StacException},
375
+ },
357
376
  tags=["Features"],
358
377
  )
359
378
  def get_feature(
@@ -373,7 +392,7 @@ def get_feature(
373
392
  ) from e
374
393
 
375
394
  if feature:
376
- return JSONResponse(content=feature.to_dict())
395
+ return JSONResponse(content=feature.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
377
396
 
378
397
  raise _not_found(
379
398
  f"Item {feature_id} does not exist in Collection {collection_id} in this Catalogue"
@@ -424,7 +443,7 @@ def _item_search(
424
443
  ) from e
425
444
 
426
445
  if search_result is not None:
427
- return JSONResponse(content=search_result.to_dict())
446
+ return JSONResponse(content=search_result.to_dict(), media_type=GEOJSON_MEDIA_TYPE)
428
447
 
429
448
  raise _not_found(
430
449
  f"Searching with criteria: bbox={bbox}, intersects={intersects}, datetime={datetime}, limit={limit}, ids={ids}, collections={collections}, filter={filter} did not produce any result"
@@ -435,7 +454,7 @@ def _item_search(
435
454
  "/queryables",
436
455
  response_class=Response,
437
456
  responses={
438
- "200": {"content": {"application/schema+json": {}}},
457
+ "200": {"content": {JSON_SCHEMA_MEDIA_TYPE: {}}},
439
458
  "default": {"model": StacException},
440
459
  },
441
460
  tags=["Filter Extension"],
@@ -450,14 +469,14 @@ def get_queryables(service: StacApiService = Depends(get_item_service)) -> Respo
450
469
  schema = service.get_queryables()
451
470
  except Exception as error:
452
471
  raise _server_error("Unable to retrieve queryables") from error
453
- return JSONResponse(content=schema, media_type="application/schema+json")
472
+ return JSONResponse(content=schema, media_type=JSON_SCHEMA_MEDIA_TYPE)
454
473
 
455
474
 
456
475
  @app.get(
457
476
  "/collections/{collectionId}/queryables",
458
477
  response_class=Response,
459
478
  responses={
460
- "200": {"content": {"application/schema+json": {}}},
479
+ "200": {"content": {JSON_SCHEMA_MEDIA_TYPE: {}}},
461
480
  "default": {"model": StacException},
462
481
  },
463
482
  tags=["Filter Extension"],
@@ -467,7 +486,7 @@ def get_collection_queryables(
467
486
  collection_id: str = Path(..., alias="collectionId"),
468
487
  service: StacApiService = Depends(get_item_service),
469
488
  ) -> Response:
470
- """Return the provider's shared queryables schema for an existing collection.
489
+ """Return the provider's queryables schema for the requested collection.
471
490
 
472
491
  Raises:
473
492
  HTTPException: With status 404 if the collection does not exist, or
@@ -479,7 +498,12 @@ def get_collection_queryables(
479
498
  raise _server_error("Unable to retrieve collection metadata") from error
480
499
  if collection is None:
481
500
  raise _not_found(f"Collection {collection_id} does not exist in this Catalogue")
482
- return get_queryables(service)
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)
483
507
 
484
508
 
485
509
  def _parse_intersects(value: str | None) -> GeometryGeoJSON | GeometryCollection | None:
@@ -506,7 +530,12 @@ def _parse_intersects(value: str | None) -> GeometryGeoJSON | GeometryCollection
506
530
 
507
531
  @app.get(
508
532
  "/search",
509
- responses={"4XX": {"model": StacException}, "5XX": {"model": StacException}},
533
+ response_class=Response,
534
+ responses={
535
+ "200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
536
+ "4XX": {"model": StacException},
537
+ "5XX": {"model": StacException},
538
+ },
510
539
  tags=["Item Search"],
511
540
  )
512
541
  def get_item_search(
@@ -544,7 +573,12 @@ def get_item_search(
544
573
 
545
574
  @app.post(
546
575
  "/search",
547
- responses={"4XX": {"model": StacException}, "5XX": {"model": StacException}},
576
+ response_class=Response,
577
+ responses={
578
+ "200": {"content": {GEOJSON_MEDIA_TYPE: {}}},
579
+ "4XX": {"model": StacException},
580
+ "5XX": {"model": StacException},
581
+ },
548
582
  tags=["Item Search"],
549
583
  )
550
584
  def post_item_search(
@@ -185,14 +185,19 @@ class StacApiService(ABC):
185
185
  """
186
186
 
187
187
  @abstractmethod
188
- def get_queryables(self) -> dict[str, object]:
188
+ def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
189
189
  """Return the JSON Schema describing fields available in CQL2 filters.
190
190
 
191
191
  Available since v0.4.0. Providers own the complete JSON-serializable
192
192
  document, including its schema dialect, identifier, property definitions,
193
- and additional-property policy. The adapter returns it unchanged at both
194
- catalogue and collection queryables endpoints. No collection identifier
195
- or request URL is passed, so the schema must apply across collections.
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.
196
201
 
197
202
  Returns:
198
203
  A queryables JSON Schema document. Its properties describe searchable
@@ -16,23 +16,35 @@ from __future__ import annotations
16
16
 
17
17
  from typing import TYPE_CHECKING
18
18
 
19
+ import pytest
19
20
  from stac_api_demo.service import GeoParquetService
20
21
 
21
22
  if TYPE_CHECKING:
22
23
  from pathlib import Path
23
24
 
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
+ )
25
34
  def test_demo_queryables_describes_cql2_limitation_and_returns_fresh_document(
26
35
  tmp_path: Path,
36
+ collection_id: str | None,
37
+ schema_id: str,
27
38
  ) -> None:
28
39
  (tmp_path / "naip.parquet").touch()
29
40
  (tmp_path / "collections.json").write_text("[]", encoding="utf-8")
30
41
  service = GeoParquetService(tmp_path)
31
42
 
32
- schema = service.get_queryables()
43
+ schema = service.get_queryables(collection_id)
33
44
  assert schema["type"] == "object"
34
45
  assert schema["properties"] == {}
35
46
  assert schema["additionalProperties"] is False
36
- assert schema["$id"] == "/queryables"
47
+ assert schema["$id"] == schema_id
37
48
  schema["properties"] = {"unsupported": {"type": "string"}}
38
- assert service.get_queryables()["properties"] == {}
49
+ assert service.get_queryables(collection_id)["properties"] == {}
50
+ assert service.get_queryables()["$id"] == "/queryables"
@@ -137,6 +137,28 @@ def test_at_least_one_cql2_encoding_is_advertised(service: Mock) -> None:
137
137
  )
138
138
 
139
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
+
140
162
  def test_landing_page_advertises_queryables_with_standard_relation(service: Mock) -> None:
141
163
  service.id = "catalogue"
142
164
  service.title = "Test catalogue"
@@ -162,7 +184,10 @@ def test_global_and_collection_queryables_are_available(
162
184
  assert schema["type"] == "object"
163
185
  assert schema["$schema"].startswith("https://json-schema.org/")
164
186
  assert schema == service.get_queryables.return_value
165
- service.get_queryables.assert_called_once_with()
187
+ if path == "/queryables":
188
+ service.get_queryables.assert_called_once_with()
189
+ else:
190
+ service.get_queryables.assert_called_once_with("sentinel")
166
191
 
167
192
 
168
193
  @pytest.mark.parametrize("filter_lang", [None, "cql2-json"])
@@ -406,7 +431,10 @@ def test_queryables_preserves_provider_document(
406
431
  assert status == HTTPStatus.OK
407
432
  assert json.loads(body) == json.loads(original)
408
433
  assert json.dumps(service.get_queryables.return_value) == original
409
- service.get_queryables.assert_called_once_with()
434
+ if path == "/queryables":
435
+ service.get_queryables.assert_called_once_with()
436
+ else:
437
+ service.get_queryables.assert_called_once_with("sentinel")
410
438
 
411
439
 
412
440
  @pytest.mark.parametrize("path", ["/queryables", "/collections/sentinel/queryables"])
@@ -465,6 +493,7 @@ def test_collection_queryables_provider_failure_returns_server_error(
465
493
  assert status == HTTPStatus.INTERNAL_SERVER_ERROR
466
494
  assert json.loads(body)["code"] == "500"
467
495
  assert "private details" not in body.decode()
496
+ service.get_queryables.assert_not_called()
468
497
 
469
498
 
470
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
- ("get_features", ("sentinel", 20, [1.0, 2.0, 3.0, 4.0], None, None)),
42
- ("get_item_search", (None, None, None, 10, None, None, None)),
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, service: Mock, http_request: Request, route: str, arguments: tuple[object, ...]
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,7 +28,7 @@ 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) -> dict[str, object]:
31
+ def get_queryables(self, collection_id: str | None = None) -> dict[str, object]:
32
32
  """Return an empty queryables document for this test provider."""
33
33
  return {"type": "object", "properties": {}, "additionalProperties": False}
34
34