From a6c7b9f694d3f53d38cbdffdb4d775035ae820e0 Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Mon, 9 Dec 2024 23:56:32 +0100 Subject: [PATCH] records-api: add Data Package serializer * Exposes the Data Package serializer under a JSON-LD serialization with the appropriate profile parameter. --- invenio_rdm_records/resources/config.py | 10 +++++++++- .../serializers/test_signposting_serializer.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/invenio_rdm_records/resources/config.py b/invenio_rdm_records/resources/config.py index c34623f4e..501122695 100644 --- a/invenio_rdm_records/resources/config.py +++ b/invenio_rdm_records/resources/config.py @@ -56,6 +56,7 @@ CSVRecordSerializer, DataCite43JSONSerializer, DataCite43XMLSerializer, + DataPackageSerializer, DCATSerializer, DublinCoreXMLSerializer, FAIRSignpostingProfileLvl2Serializer, @@ -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()), @@ -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 ), @@ -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() ), } diff --git a/tests/resources/serializers/test_signposting_serializer.py b/tests/resources/serializers/test_signposting_serializer.py index 67551d342..b6b3b1274 100644 --- a/tests/resources/serializers/test_signposting_serializer.py +++ b/tests/resources/serializers/test_signposting_serializer.py @@ -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", @@ -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",