@@ -244,7 +244,7 @@ async def all_collections(
244244
245245 next_link : Optional [dict [str , Any ]] = None
246246 prev_link : Optional [dict [str , Any ]] = None
247- first_link : dict [str , Any ] = { "body" : { "limit" : limit , "offset" : 0 }}
247+ first_link : Optional [ dict [str , Any ]] = None
248248
249249 # get provider filter
250250 provider = None
@@ -285,19 +285,8 @@ async def all_collections(
285285 ).intersection (bbox_geom )
286286 ]
287287
288- limit = limit if limit is not None else 10
289- offset = offset if offset is not None else 0
290-
291- paged_collections = collections [offset : offset + limit ]
292-
293288 total = len (collections )
294289
295- if offset + limit < total :
296- next_link = {"body" : {"limit" : limit , "offset" : offset + limit }}
297-
298- if offset > 0 :
299- prev_link = {"body" : {"limit" : limit , "offset" : max (0 , offset - limit )}}
300-
301290 links = [
302291 {
303292 "rel" : Relations .root ,
@@ -306,6 +295,21 @@ async def all_collections(
306295 "title" : get_settings ().stac_fastapi_title ,
307296 },
308297 ]
298+
299+ if self .extension_is_enabled ("OffsetPaginationExtension" ):
300+ limit = limit if limit is not None else 10
301+ offset = offset if offset is not None else 0
302+
303+ collections = collections [offset : offset + limit ]
304+
305+ if offset + limit < total :
306+ next_link = {"body" : {"limit" : limit , "offset" : offset + limit }}
307+
308+ if offset > 0 :
309+ prev_link = {"body" : {"limit" : limit , "offset" : max (0 , offset - limit )}}
310+
311+ first_link = {"body" : {"limit" : limit , "offset" : 0 }}
312+
309313 extension_names = [type (ext ).__name__ for ext in self .extensions ]
310314
311315 paging_links = CollectionSearchPagingLinks (
@@ -315,10 +319,10 @@ async def all_collections(
315319 links .extend (paging_links )
316320
317321 return Collections (
318- collections = paged_collections or [] ,
322+ collections = collections ,
319323 links = links ,
320324 numberMatched = total ,
321- numberReturned = len (paged_collections ),
325+ numberReturned = len (collections ),
322326 )
323327
324328 async def get_collection (self , collection_id : str , request : Request , ** kwargs : Any ) -> Collection :
0 commit comments