diff --git a/swh/indexer/metadata_dictionary/cff.py b/swh/indexer/metadata_dictionary/cff.py --- a/swh/indexer/metadata_dictionary/cff.py +++ b/swh/indexer/metadata_dictionary/cff.py @@ -42,16 +42,16 @@ author_data: Dict[str, Optional[Union[str, Dict]]] = { "@type": SCHEMA_URI + "Person" } - if "orcid" in author: + if "orcid" in author and isinstance(author["orcid"], str): author_data["@id"] = author["orcid"] - if "affiliation" in author: + if "affiliation" in author and isinstance(author["affiliation"], str): author_data[SCHEMA_URI + "affiliation"] = { "@type": SCHEMA_URI + "Organization", SCHEMA_URI + "name": author["affiliation"], } - if "family-names" in author: + if "family-names" in author and isinstance(author["family-names"], str): author_data[SCHEMA_URI + "familyName"] = author["family-names"] - if "given-names" in author: + if "given-names" in author and isinstance(author["given-names"], str): author_data[SCHEMA_URI + "givenName"] = author["given-names"] result.append(author_data) diff --git a/swh/indexer/tests/test_metadata.py b/swh/indexer/tests/test_metadata.py --- a/swh/indexer/tests/test_metadata.py +++ b/swh/indexer/tests/test_metadata.py @@ -212,6 +212,55 @@ # then assert expected == result + def test_cff_empty_fields(self): + """ + testing CITATION.cff translation + """ + # given + content = """# YAML 1.2 + authors: + - + affiliation: "Netherlands eScience Center" + family-names: + given-names: Tom + - + affiliation: "Humboldt-Universität zu Berlin" + family-names: Druskat + orcid: + given-names: Stephan + """.encode( + "utf-8" + ) + + expected = { + "@context": "https://doi.org/10.5063/schema/codemeta-2.0", + "type": "SoftwareSourceCode", + "author": [ + { + "type": "Person", + "affiliation": { + "type": "Organization", + "name": "Netherlands eScience Center", + }, + "givenName": "Tom", + }, + { + "type": "Person", + "affiliation": { + "type": "Organization", + "name": "Humboldt-Universität zu Berlin", + }, + "familyName": "Druskat", + "givenName": "Stephan", + }, + ], + } + + # when + result = self.cff_mapping.translate(content) + # then + assert expected == result + def test_compute_metadata_npm(self): """ testing only computation of metadata with hard_mapping_npm