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 29f932f commit 476a2d9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
62 changes: 62 additions & 0 deletions cypress/integration/persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,65 @@ describe('Contributors', function () {
cy.get('#contributor_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"
}
]
});
});
});
12 changes: 6 additions & 6 deletions js/codemeta_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,26 @@ function generateRole(id) {
return doc;
}

function generateRoles(idPrefix, person) {
function generateRoles(property, idPrefix, person) {
const roles = [];
const roleNodes = document.querySelectorAll(`ul[id^=${idPrefix}_role_`);
roleNodes.forEach(roleNode => {
const role = generateRole(roleNode.id);
role["schema:author"] = getDocumentId(person); // Prefix with "schema:" to prevent it from expanding into a list
role[`schema:${property}`] = getDocumentId(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(property, idPrefix, person);
if (roles.length > 0) {
persons = persons.concat(roles);
}
Expand Down

0 comments on commit 476a2d9

Please sign in to comment.