Skip to content

Commit

Permalink
records-api: add Data Package serializer
Browse files Browse the repository at this point in the history
* Exposes the Data Package serializer under a JSON-LD serialization with
  the appropriate profile parameter.
  • Loading branch information
slint committed Dec 9, 2024
1 parent 5090c80 commit a6c7b9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion invenio_rdm_records/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
CSVRecordSerializer,
DataCite43JSONSerializer,
DataCite43XMLSerializer,
DataPackageSerializer,
DCATSerializer,
DublinCoreXMLSerializer,
FAIRSignpostingProfileLvl2Serializer,
Expand Down Expand Up @@ -84,6 +85,10 @@ def _bibliography_headers(obj_or_list, code, many=False):
return _etag_headers


# Schema.org profiles
DATAPACKAGE_PROFILE = "https://datapackage.org/profiles/2.0/datapackage.json"
ROCRATE_PROFILE = "https://w3id.org/ro/crate/1.1"

record_serializers = {
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers),
"application/ld+json": ResponseHandler(SchemaorgJSONLDSerializer()),
Expand Down Expand Up @@ -123,6 +128,9 @@ def _bibliography_headers(obj_or_list, code, many=False):
"application/vnd.datacite.datacite+xml": ResponseHandler(
DataCite43XMLSerializer(), headers=etag_headers
),
f'application/ld+json;profile="{DATAPACKAGE_PROFILE}"': ResponseHandler(
DataPackageSerializer(), headers=etag_headers
),
"application/x-dc+xml": ResponseHandler(
DublinCoreXMLSerializer(), headers=etag_headers
),
Expand Down Expand Up @@ -251,7 +259,7 @@ class RDMRecordResourceConfig(RecordResourceConfig, ConfiguratorMixin):

request_body_parsers = {
"application/json": RequestBodyParser(JSONDeserializer()),
'application/ld+json;profile="https://w3id.org/ro/crate/1.1"': RequestBodyParser(
f'application/ld+json;profile="{ROCRATE_PROFILE}"': RequestBodyParser(
ROCrateJSONDeserializer()
),
}
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/serializers/test_signposting_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_signposting_serializer_full(running_app, full_record_to_dict):
"href": "https://127.0.0.1:5000/api/records/12345-abcde",
"type": "application/ld+json",
},
{
"href": "https://127.0.0.1:5000/api/records/12345-abcde",
"type": 'application/ld+json;profile="https://datapackage.org/profiles/2.0/datapackage.json"',
},
{
"href": "https://127.0.0.1:5000/api/records/12345-abcde",
"type": "application/linkset+json",
Expand Down Expand Up @@ -146,6 +150,10 @@ def test_signposting_serializer_minimal(running_app, minimal_record_to_dict):
"href": "https://127.0.0.1:5000/api/records/67890-fghij",
"type": "application/ld+json",
},
{
"href": "https://127.0.0.1:5000/api/records/67890-fghij",
"type": 'application/ld+json;profile="https://datapackage.org/profiles/2.0/datapackage.json"',
},
{
"href": "https://127.0.0.1:5000/api/records/67890-fghij",
"type": "application/linkset+json",
Expand Down

0 comments on commit a6c7b9f

Please sign in to comment.