Skip to content

Commit

Permalink
full context for collections and items
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pzaborowski committed Jul 5, 2024
1 parent 11b9480 commit f74ae7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pygeoapi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,15 +1281,20 @@ def describe_collections(self, request: Union[APIRequest, Any],
return headers, HTTPStatus.OK, content

if request.format == F_JSONLD:
jsonld = self.fcmld.copy()
if dataset is not None:
jsonld['dataset'] = jsonldify_collection(self, fcm,
request.locale)
if cls.config['metadata']['linked-data']:

Check failure on line 1284 in pygeoapi/api/__init__.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/api/__init__.py#L1284

[F821] undefined name
jsonld = fcm
jsonld["@context"] = self.fcmld.copy()["@context"]
else:
jsonld['dataset'] = [
jsonldify_collection(self, c, request.locale)
for c in fcm.get('collections', [])
]
jsonld = self.fcmld.copy()
if dataset is not None:
jsonld['dataset'] = jsonldify_collection(self, fcm,
request.locale)
else:
jsonld['dataset'] = [
jsonldify_collection(self, c, request.locale)
for c in fcm.get('collections', [])
]

return headers, HTTPStatus.OK, to_json(jsonld, self.pretty_print)

return headers, HTTPStatus.OK, to_json(fcm, self.pretty_print)
Expand Down
9 changes: 9 additions & 0 deletions pygeoapi/linked_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def inner(*args, **kwargs):
}
}
cls.fcmld = fcmld
collections_context = cls.config['metadata']['linked-data'].get('collections-context', {})

Check failure on line 114 in pygeoapi/linked_data.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/linked_data.py#L114

[E501] line too long
fcmld["@context"].append(collections_context)
return func(cls, *args[1:], **kwargs)
return inner

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

direct_context = jsonld.get('direct-context', None)
context = jsonld.get('context', []).copy()
template = jsonld.get('item_template', None)

if direct_context:
return {
'@context': direct_context,
**data
}

defaultVocabulary = {
'schema': 'https://schema.org/',
'type': '@type'
Expand Down

0 comments on commit f74ae7d

Please sign in to comment.