Skip to content

Commit

Permalink
Fix property between Role and Person for contributors
Browse files Browse the repository at this point in the history
It should be:

```
{
    "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
    "type": "SoftwareSourceCode",
    "contributor": [
        {
            "type": "schema:Role",
            "schema:contributor": {
                "type": "Person",
                "givenName": "Jane"
            },
        }
    ]
}
```

instead of:

```
{
    "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
    "type": "SoftwareSourceCode",
    "contributor": [
        {
            "type": "schema:Role",
            "schema:contributor": {
                "type": "Person",
                "givenName": "Jane"
            },
        }
    ]
}
```
  • Loading branch information
progval committed Jul 3, 2024
1 parent 28b7936 commit 0864964
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
62 changes: 62 additions & 0 deletions cypress/integration/persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,65 @@ describe('Multiple authors', function () {
cy.get('#author_2_givenName').should('have.value', 'Joe');
});
});

describe('One contributor with a role', function () {
it('can be exported in both codemeta v2.0 and v3.0 versions', function () {
cy.get('#name').type('My Test Software');

cy.get('#contributor_add').click();
cy.get('#contributor_1_givenName').type('Jane');

cy.get('#contributor_1_role_add').click();
cy.get('#contributor_1_roleName_0').type('Developer');
cy.get('#contributor_1_startDate_0').type('2024-03-04');
cy.get('#contributor_1_endDate_0').type('2024-04-03');

cy.get('#generateCodemetaV2').click();
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"contributor": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "schema:Role",
"schema:contributor": {
"type": "Person",
"givenName": "Jane"
},
"schema:roleName": "Developer",
"schema:startDate": "2024-03-04",
"schema:endDate": "2024-04-03"
}
]
});

cy.get('#generateCodemetaV3').click();
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://w3id.org/codemeta/3.0",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"contributor": [
{
"type": "Person",
"givenName": "Jane"
},
{
"type": "Role",
"schema:contributor": {
"type": "Person",
"givenName": "Jane"
},
"roleName": "Developer",
"startDate": "2024-03-04",
"endDate": "2024-04-03"
}
]
});
});
});
16 changes: 8 additions & 8 deletions js/codemeta_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function generatePerson(idPrefix) {
return doc;
}

function generateRole(id) {
function generateRole(id, property) {
const doc = {
"@type": "Role"
};
Expand All @@ -179,26 +179,26 @@ function generateRole(id) {
return doc;
}

function generateRoles(idPrefix, person) {
function generateRoles(idPrefix, property, person) {
const roles = [];
const roleNodes = document.querySelectorAll(`ul[id^=${idPrefix}_role_`);
roleNodes.forEach(roleNode => {
const role = generateRole(roleNode.id);
role["schema:author"] = person; // Prefix with "schema:" to prevent it from expanding into a list
const role = generateRole(roleNode.id, property);
role[`schema:${property}`] = person; // Prefix with "schema:" to prevent it from expanding into a list
roles.push(role);
});
return roles;
}

function generatePersons(prefix) {
function generatePersons(property) {
var persons = [];
var nbPersons = getNbPersons(prefix);
var nbPersons = getNbPersons(property);

for (let personId = 1; personId <= nbPersons; personId++) {
const idPrefix = `${prefix}_${personId}`;
const idPrefix = `${property}_${personId}`;
const person = generatePerson(idPrefix);
persons.push(person);
const roles = generateRoles(idPrefix, person);
const roles = generateRoles(idPrefix, property, person);
if (roles.length > 0) {
persons = persons.concat(roles);
}
Expand Down

0 comments on commit 0864964

Please sign in to comment.