Skip to content

Commit 667c00a

Browse files
committed
STAC API: map collection to links
1 parent 0b38f3b commit 667c00a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pycsw/ogc/api/records.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,23 +1214,24 @@ def record2json(record, url, collection, mode='ogcapi-records'):
12141214
if record.metadata_type in ['application/json', 'application/geo+json']:
12151215
rec = json.loads(record.metadata)
12161216
if rec.get('stac_version') is not None and rec['type'] == 'Feature' and mode == 'stac-api':
1217+
collection_ = rec.get('collection', collection)
12171218
LOGGER.debug('Returning native STAC representation')
12181219
rec['links'].extend([{
12191220
'rel': 'self',
12201221
'type': 'application/geo+json',
1221-
'href': f"{url}/collections/{collection}/items/{rec['id']}"
1222+
'href': f"{url}/collections/{collection_}/items/{rec['id']}"
12221223
}, {
12231224
'rel': 'root',
12241225
'type': 'application/json',
12251226
'href': url
12261227
}, {
12271228
'rel': 'parent',
12281229
'type': 'application/json',
1229-
'href': f"{url}/collections/{collection}"
1230+
'href': f"{url}/collections/{collection_}"
12301231
}, {
12311232
'rel': 'collection',
12321233
'type': 'application/json',
1233-
'href': f"{url}/collections/{collection}"
1234+
'href': f"{url}/collections/{collection_}"
12341235
}
12351236
])
12361237

tests/functionaltests/suites/stac_api/test_stac_api_functional.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ def test_items(config):
389389

390390
content = json.loads(api.items({}, cql_json, {})[2])
391391
assert content['numberMatched'] == 1
392+
for feature in content['features']:
393+
for link in feature['links']:
394+
if link['rel'] in ['self', 'parent', 'collection']:
395+
collection_match = f"collections/{cql_json['collections'][0]}"
396+
assert collection_match in link['href']
392397

393398
cql_json = {
394399
'filter-lang': 'cql2-json',

0 commit comments

Comments
 (0)