Skip to content

Commit f74ae7d

Browse files
committed
full context for collections and items
default jsonld for collections did not allow for custom context. items were transofrmed to schems. woth this change context can be added for both collection level and items level
1 parent 11b9480 commit f74ae7d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

pygeoapi/api/__init__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,15 +1281,20 @@ def describe_collections(self, request: Union[APIRequest, Any],
12811281
return headers, HTTPStatus.OK, content
12821282

12831283
if request.format == F_JSONLD:
1284-
jsonld = self.fcmld.copy()
1285-
if dataset is not None:
1286-
jsonld['dataset'] = jsonldify_collection(self, fcm,
1287-
request.locale)
1284+
if cls.config['metadata']['linked-data']:
1285+
jsonld = fcm
1286+
jsonld["@context"] = self.fcmld.copy()["@context"]
12881287
else:
1289-
jsonld['dataset'] = [
1290-
jsonldify_collection(self, c, request.locale)
1291-
for c in fcm.get('collections', [])
1292-
]
1288+
jsonld = self.fcmld.copy()
1289+
if dataset is not None:
1290+
jsonld['dataset'] = jsonldify_collection(self, fcm,
1291+
request.locale)
1292+
else:
1293+
jsonld['dataset'] = [
1294+
jsonldify_collection(self, c, request.locale)
1295+
for c in fcm.get('collections', [])
1296+
]
1297+
12931298
return headers, HTTPStatus.OK, to_json(jsonld, self.pretty_print)
12941299

12951300
return headers, HTTPStatus.OK, to_json(fcm, self.pretty_print)

pygeoapi/linked_data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def inner(*args, **kwargs):
111111
}
112112
}
113113
cls.fcmld = fcmld
114+
collections_context = cls.config['metadata']['linked-data'].get('collections-context', {})
115+
fcmld["@context"].append(collections_context)
114116
return func(cls, *args[1:], **kwargs)
115117
return inner
116118

@@ -193,9 +195,16 @@ def geojson2jsonld(cls, data: dict, dataset: str,
193195
jsonld = cls.config['resources'][dataset].get('linked-data', {})
194196
ds_url = f"{cls.get_collections_url()}/{dataset}"
195197

198+
direct_context = jsonld.get('direct-context', None)
196199
context = jsonld.get('context', []).copy()
197200
template = jsonld.get('item_template', None)
198201

202+
if direct_context:
203+
return {
204+
'@context': direct_context,
205+
**data
206+
}
207+
199208
defaultVocabulary = {
200209
'schema': 'https://schema.org/',
201210
'type': '@type'

0 commit comments

Comments
 (0)