stac-utils / stac-fastapi

STAC API implementation with FastAPI.
https://stac-utils.github.io/stac-fastapi/
MIT License
226 stars 99 forks source link

remove FieldsExtension dependency in `stac-fastapi.api` #709

Closed vincentsarago closed 4 days ago

vincentsarago commented 3 weeks ago

in πŸ‘‡ https://github.com/stac-utils/stac-fastapi/blob/51a756d904e4bab245da4a525e961d64bcbf1321/stac_fastapi/api/stac_fastapi/api/app.py#L255-L263

We check if the FieldsExtension extension is part of the allowed extension, and then remove output model validation if present (because when using fields, the output Item can be an invalid STAC Item).

This works OK, but brings multiple issues:

IMO, this is an implementation issue that stac-fastapi.api shouldn't take care.

At the implementation level should could be dealt like:

class BadCoreClient(BaseCoreClient):
    def post_search(
        self, search_request: BaseSearchPostRequest, **kwargs
    ) -> stac.ItemCollection:

        search_results = ...

        if getattr("fields", search_request):
            return GeoJSONResponse(search_results)

        return stac.ItemCollection(**search_results)

    def get_search(
        self,
        collections: Optional[List[str]] = None,
        ids: Optional[List[str]] = None,
        bbox: Optional[List[NumType]] = None,
        intersects: Optional[str] = None,
        datetime: Optional[Union[str, datetime]] = None,
        limit: Optional[int] = 10,
        **kwargs,
    ) -> stac.ItemCollection:

        search_results = ...

        if kwargs.get("fields"):
            return GeoJSONResponse(search_results)

        return stac.ItemCollection(**search_results)

☝️ This pseudo code show that when a fields parameter is passed we should return the search_results directly by returning a Response object, which won't be validated by fastAPI

jonhealy1 commented 2 weeks ago

@vincentsarago How should we move ahead with this?

vincentsarago commented 2 weeks ago

@jonhealy1 it's a big breaking change IMO, and we should wait for 4.0 for this kind of change.

vincentsarago commented 1 week ago

I think I changed my mind and we should ship this in 3.0 πŸ™ˆ