From 1e02ed01caa1693c1f6f081b22ed255f624081be Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 11 Jan 2026 10:06:18 -0500 Subject: [PATCH] set f= in next/prev links (#2175) --- pygeoapi/api/itemtypes.py | 9 ++++++++- tests/api/test_itemtypes.py | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pygeoapi/api/itemtypes.py b/pygeoapi/api/itemtypes.py index 0caa8808c..20936f759 100644 --- a/pygeoapi/api/itemtypes.py +++ b/pygeoapi/api/itemtypes.py @@ -616,19 +616,26 @@ def get_collection_items( if offset > 0: prev_link = True + print(request.format) if prev_link: prev = max(0, offset - limit) + url = f'{uri}?offset={prev}{serialized_query_params}' + if request.format is not None: + url = f'{uri}?f={request.format}&offset={prev}{serialized_query_params}' # noqa + content['links'].append( { 'type': 'application/geo+json', 'rel': 'prev', 'title': l10n.translate('Items (prev)', request.locale), - 'href': f'{uri}?offset={prev}{serialized_query_params}' + 'href': url }) if next_link: next_ = offset + limit next_href = f'{uri}?offset={next_}{serialized_query_params}' + if request.format is not None: + next_href = f'{uri}?f={request.format}&offset={next_}{serialized_query_params}' # noqa content['links'].append( { 'type': 'application/geo+json', diff --git a/tests/api/test_itemtypes.py b/tests/api/test_itemtypes.py index e47414190..dd3fb9431 100644 --- a/tests/api/test_itemtypes.py +++ b/tests/api/test_itemtypes.py @@ -285,8 +285,7 @@ def test_get_collection_items(config, api_): assert '/collections/obs/items?f=csv&limit=1&bbox=-180,-90,180,90' \ in links[3]['href'] assert links[3]['rel'] == 'alternate' - assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' \ - in links[4]['href'] + assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' in links[4]['href'] # noqa assert links[4]['rel'] == 'prev' assert '/collections/obs' in links[5]['href'] assert links[4]['rel'] == 'prev'