Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def fair_signposting_tostring(cls, record):
link = f'<{value["href"]}> ; rel="{rel}"'
if "type" in value:
link += f' ; type="{value["type"]}"'
if "profile" in value:
link += f' ; profile="{value["profile"]}"'
links.append(link)
return " , ".join(links)

Expand Down
18 changes: 13 additions & 5 deletions invenio_rdm_records/resources/serializers/signposting/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Northwestern University.
Expand Down Expand Up @@ -69,12 +69,20 @@
# Has to be placed here to prevent circular dependency.
from invenio_rdm_records.resources.config import record_serializers

result = [
{"href": obj["links"]["self"], "type": mimetype}
for mimetype in sorted(record_serializers)
result = []
for mimetype in sorted(record_serializers):
# Remove the linkset serializer, so that the linkset does not link to itself.
if mimetype != "application/linkset+json"
]
if mimetype == "application/linkset+json":
continue
if ";" in mimetype:
media_type, _, params = mimetype.partition(";")
entry = {"href": obj["links"]["self"], "type": media_type.strip()}
params = params.strip()
if params.startswith('profile="') and params.endswith('"'):
entry["profile"] = params[len('profile="'):-1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black needs to appeased here 😁

else:
entry = {"href": obj["links"]["self"], "type": mimetype}
Comment on lines +77 to +84
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract above as method/function for reuse in the serialize_item.

result.append(entry)

return result or missing

Expand Down
10 changes: 6 additions & 4 deletions tests/resources/serializers/test_signposting_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def test_signposting_serializer_full(
},
{
"href": "https://127.0.0.1:5000/api/records/12345-abcde",
"type": 'application/ld+json;profile="https://datapackage.org/profiles/2.0/datapackage.json"',
"type": "application/ld+json",
"profile": "https://datapackage.org/profiles/2.0/datapackage.json",
},
{
"href": "https://127.0.0.1:5000/api/records/12345-abcde",
Expand Down Expand Up @@ -326,7 +327,7 @@ def test_signposting_lvl1_serializer_full_collections_size_ok(
f'<{api_url}> ; rel="describedby" ; type="application/dcat+xml"',
f'<{api_url}> ; rel="describedby" ; type="application/json"',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json"',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json;profile="https://datapackage.org/profiles/2.0/datapackage.json""',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json" ; profile="https://datapackage.org/profiles/2.0/datapackage.json"',
f'<{api_url}> ; rel="describedby" ; type="application/marcxml+xml"',
f'<{api_url}> ; rel="describedby" ; type="application/vnd.citationstyles.csl+json"',
f'<{api_url}> ; rel="describedby" ; type="application/vnd.datacite.datacite+json"',
Expand Down Expand Up @@ -383,7 +384,8 @@ 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;profile="https://datapackage.org/profiles/2.0/datapackage.json"',
"type": "application/ld+json",
"profile": "https://datapackage.org/profiles/2.0/datapackage.json",
},
{
"href": "https://127.0.0.1:5000/api/records/67890-fghij",
Expand Down Expand Up @@ -464,7 +466,7 @@ def test_signposting_lvl1_serializer_minimal(running_app, minimal_record_to_dict
f'<{api_url}> ; rel="describedby" ; type="application/dcat+xml"',
f'<{api_url}> ; rel="describedby" ; type="application/json"',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json"',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json;profile="https://datapackage.org/profiles/2.0/datapackage.json""',
f'<{api_url}> ; rel="describedby" ; type="application/ld+json" ; profile="https://datapackage.org/profiles/2.0/datapackage.json"',
f'<{api_url}> ; rel="describedby" ; type="application/marcxml+xml"',
f'<{api_url}> ; rel="describedby" ; type="application/vnd.citationstyles.csl+json"',
f'<{api_url}> ; rel="describedby" ; type="application/vnd.datacite.datacite+json"',
Expand Down
Loading