Skip to content

Commit

Permalink
Fix media type for queryables endpoints (#421)
Browse files Browse the repository at this point in the history
* Fix media type for queryables endpoints

* Add CHANGELOG entry for #421

Co-authored-by: Jeff Albrecht <geospatialjeff@gmail.com>
  • Loading branch information
duckontheweb and geospatial-jeff authored Jul 28, 2022
1 parent 4f55ba4 commit 1faabd3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Fixed stray `/` before the `#` in several extension conformance class strings ([383](https://github.com/stac-utils/stac-fastapi/pull/383))
* SQLAlchemy backend bulk item insert now works ([#356](https://github.com/stac-utils/stac-fastapi/issues/356))
* PGStac Backend has stricter implementation of Fields Extension syntax ([#397](https://github.com/stac-utils/stac-fastapi/pull/397))
* `/queryables` endpoint now has type `application/schema+json` instead of `application/json` ([#421](https://github.com/stac-utils/stac-fastapi/pull/421))

## [2.3.0]

Expand Down
10 changes: 10 additions & 0 deletions stac_fastapi/api/stac_fastapi/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,20 @@ class GeoJSONResponse(ORJSONResponse):

media_type = "application/geo+json"

class JSONSchemaResponse(ORJSONResponse):
"""JSON with custom, vendor content-type."""

media_type = "application/schema+json"

else:
from starlette.responses import JSONResponse

class GeoJSONResponse(JSONResponse):
"""JSON with custom, vendor content-type."""

media_type = "application/geo+json"

class JSONSchemaResponse(JSONResponse):
"""JSON with custom, vendor content-type."""

media_type = "application/schema+json"
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

import attr
from fastapi import APIRouter, FastAPI
from starlette.responses import JSONResponse, Response

from stac_fastapi.api.models import APIRequest, CollectionUri, EmptyRequest
from starlette.responses import Response

from stac_fastapi.api.models import (
APIRequest,
CollectionUri,
EmptyRequest,
JSONSchemaResponse,
)
from stac_fastapi.api.routes import create_async_endpoint, create_sync_endpoint
from stac_fastapi.types.core import AsyncBaseFiltersClient, BaseFiltersClient
from stac_fastapi.types.extension import ApiExtension
Expand Down Expand Up @@ -71,7 +76,7 @@ class FilterExtension(ApiExtension):
]
)
router: APIRouter = attr.ib(factory=APIRouter)
response_class: Type[Response] = attr.ib(default=JSONResponse)
response_class: Type[Response] = attr.ib(default=JSONSchemaResponse)

def _create_endpoint(
self,
Expand Down
9 changes: 9 additions & 0 deletions stac_fastapi/pgstac/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ async def test_get_search_content_type(app_client):
assert resp.headers["content-type"] == "application/geo+json"


async def test_get_queryables_content_type(app_client, load_test_collection):
resp = await app_client.get("queryables")
assert resp.headers["content-type"] == "application/schema+json"

coll = load_test_collection
resp = await app_client.get(f"collections/{coll.id}/queryables")
assert resp.headers["content-type"] == "application/schema+json"


async def test_api_headers(app_client):
resp = await app_client.get("/api")
assert (
Expand Down

0 comments on commit 1faabd3

Please sign in to comment.