diff --git a/cypress/integration/persons.js b/cypress/integration/persons.js index b3b68ce..daad8ca 100644 --- a/cypress/integration/persons.js +++ b/cypress/integration/persons.js @@ -1,850 +1,892 @@ /** * Copyright (C) 2020 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ /* * Tests the author/contributor dynamic fieldsets */ "use strict"; describe('Zero author', function() { it('can be exported', function() { cy.get('#name').type('My Test Software'); cy.get('#generateCodemetaV2').click(); cy.get('#errorMessage').should('have.text', ''); 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", }); }); it('can be imported from no list', function() { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "name": "My Test Software", })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '0'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('not.exist'); }); it('can be imported from empty list', function() { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "name": "My Test Software", "author": [], })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '0'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('not.exist'); }); }); describe('One full author', function() { it('can be exported', function() { cy.get('#name').type('My Test Software'); cy.get('#author_nb').should('have.value', '0'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('not.exist'); cy.get('#author_1_givenName').should('not.exist'); cy.get('#author_add').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('exist'); cy.get('#author_2').should('not.exist'); cy.get('#author_1_givenName').should('have.value', ''); cy.get('#author_1_familyName').should('have.value', ''); cy.get('#author_1_email').should('have.value', ''); cy.get('#author_1_id').should('have.value', ''); cy.get('#author_1_affiliation').should('have.value', ''); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_familyName').type('Doe'); cy.get('#author_1_email').type('jdoe@example.org'); cy.get('#author_1_id').type('http://example.org/~jdoe'); cy.get('#author_1_affiliation').type('http://example.org/'); cy.get('#generateCodemetaV2').click(); cy.get('#errorMessage').should('have.text', ''); 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", "author": [ { "type": "Person", "id": "http://example.org/~jdoe", "givenName": "Jane", "familyName": "Doe", "email": "jdoe@example.org", "affiliation": { "type": "Organization", "id": "http://example.org/", } } ], }); }); it('can be imported even if there is also a role-less author', function() { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "@type": "Person", "@id": "http://example.org/~jdoe", "givenName": "Jane", "familyName": "Doe", "email": "jdoe@example.org", "affiliation": { "@type": "Organization", "@id": "http://example.org/", } } ], })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('exist'); cy.get('#author_2').should('not.exist'); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_familyName').should('have.value', 'Doe'); cy.get('#author_1_email').should('have.value', 'jdoe@example.org'); cy.get('#author_1_id').should('have.value', 'http://example.org/~jdoe'); cy.get('#author_1_affiliation').should('have.value', 'http://example.org/'); }); + + it('is imported without its id if it is a blank node', function() { + cy.get('#codemetaText').then((elem) => + elem.text(JSON.stringify({ + "@context": "https://doi.org/10.5063/schema/codemeta-2.0", + "@type": "SoftwareSourceCode", + "name": "My Test Software", + "author": [ + { + "@type": "Person", + "@id": "_:author_1", + "givenName": "Jane", + } + ], + })) + ); + cy.get('#importCodemeta').click(); + + cy.get('#author_1_givenName').should('have.value', 'Jane'); + cy.get('#author_1_id').should('have.value', ''); + }); }); describe('Affiliation id', function() { it('can be exported', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('http://example.org/'); cy.get('#generateCodemetaV2').click(); cy.get('#errorMessage').should('have.text', ''); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane", "affiliation": { "type": "Organization", "id": "http://example.org/", } } ], }); }); it('can be imported', function() { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "@type": "Person", "@id": "http://example.org/~jdoe", "givenName": "Jane", "familyName": "Doe", "email": "jdoe@example.org", "affiliation": { "@type": "Organization", "@id": "http://example.org/", } } ], })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('exist'); cy.get('#author_2').should('not.exist'); cy.get('#author_1_affiliation').should('have.value', 'http://example.org/'); }); }); describe('Affiliation name', function() { it('can be exported', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#generateCodemetaV2').click(); cy.get('#errorMessage').should('have.text', ''); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane", "affiliation": { "type": "Organization", "name": "Example Org", } } ], }); }); it('can be imported', function() { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "@type": "Person", "@id": "http://example.org/~jdoe", "givenName": "Jane", "familyName": "Doe", "email": "jdoe@example.org", "affiliation": { "@type": "Organization", "name": "Example Org", } } ], })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_0').should('not.exist'); cy.get('#author_1').should('exist'); cy.get('#author_2').should('not.exist'); cy.get('#author_1_affiliation').should('have.value', 'Example Org'); }); }); describe('Author order change', function() { it('is a noop with a single author', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#author_1_moveToRight').click(); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_affiliation').should('have.value', 'Example Org'); cy.get('#author_1_moveToLeft').click(); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_affiliation').should('have.value', 'Example Org'); }); it('flips two authors', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#author_2_givenName').type('John'); cy.get('#author_2_familyName').type('Doe'); cy.get('#author_3_givenName').type('Alex'); cy.get('#author_1_moveToRight').click(); cy.get('#author_1_givenName').should('have.value', 'John'); cy.get('#author_1_familyName').should('have.value', 'Doe'); cy.get('#author_1_affiliation').should('have.value', ''); cy.get('#author_2_givenName').should('have.value', 'Jane'); cy.get('#author_2_familyName').should('have.value', ''); cy.get('#author_2_affiliation').should('have.value', 'Example Org'); cy.get('#author_3_givenName').should('have.value', 'Alex'); cy.get('#author_3_familyName').should('have.value', ''); cy.get('#author_3_affiliation').should('have.value', ''); }); it('updates generated Codemeta', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#author_2_givenName').type('John'); cy.get('#author_2_familyName').type('Doe'); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane", "affiliation": { "type": "Organization", "name": "Example Org", } }, { + "id": "_:author_2", "type": "Person", "givenName": "John", "familyName": "Doe", }, ], }); cy.get('#author_1_moveToRight').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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "John", "familyName": "Doe", }, { + "id": "_:author_2", "type": "Person", "givenName": "Jane", "affiliation": { "type": "Organization", "name": "Example Org", } }, ], }); }); it('wraps around to the right', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#author_2_givenName').type('John'); cy.get('#author_2_familyName').type('Doe'); cy.get('#author_3_givenName').type('Alex'); cy.get('#author_1_moveToLeft').click() cy.get('#author_1_givenName').should('have.value', 'Alex'); cy.get('#author_1_familyName').should('have.value', ''); cy.get('#author_1_affiliation').should('have.value', ''); cy.get('#author_2_givenName').should('have.value', 'John'); cy.get('#author_2_familyName').should('have.value', 'Doe'); cy.get('#author_2_affiliation').should('have.value', ''); cy.get('#author_3_givenName').should('have.value', 'Jane'); cy.get('#author_3_familyName').should('have.value', ''); cy.get('#author_3_affiliation').should('have.value', 'Example Org'); }); it('wraps around to the left', function() { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_affiliation').type('Example Org'); cy.get('#author_2_givenName').type('John'); cy.get('#author_2_familyName').type('Doe'); cy.get('#author_3_givenName').type('Alex'); cy.get('#author_3_moveToRight').click() cy.get('#author_1_givenName').should('have.value', 'Alex'); cy.get('#author_1_familyName').should('have.value', ''); cy.get('#author_1_affiliation').should('have.value', ''); cy.get('#author_2_givenName').should('have.value', 'John'); cy.get('#author_2_familyName').should('have.value', 'Doe'); cy.get('#author_2_affiliation').should('have.value', ''); cy.get('#author_3_givenName').should('have.value', 'Jane'); cy.get('#author_3_familyName').should('have.value', ''); cy.get('#author_3_affiliation').should('have.value', 'Example Org'); }); }); describe('One author 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('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_0').type('Developer'); cy.get('#author_1_startDate_0').type('2024-03-04'); cy.get('#author_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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "schema:Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" } ] }); }); it('can have two roles', function () { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_0').type('Developer'); cy.get('#author_1_startDate_0').type('2024-03-04'); cy.get('#author_1_endDate_0').type('2024-04-03'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_1').type('Maintainer'); cy.get('#author_1_startDate_1').type('2024-04-04'); cy.get('#author_1_endDate_1').type('2024-05-05'); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Maintainer", "startDate": "2024-04-04", "endDate": "2024-05-05" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" } ] }); }); it('can be deleted then added again', function () { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_0').type('Developer'); cy.get('#author_1_startDate_0').type('2024-03-04'); cy.get('#author_1_endDate_0').type('2024-04-03'); cy.get('#author_1_role_remove_0').click(); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_1').type('Maintainer'); cy.get('#author_1_startDate_1').type('2024-04-04'); cy.get('#author_1_endDate_1').type('2024-05-05'); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Maintainer", "startDate": "2024-04-04", "endDate": "2024-05-05" } ] }); }); it('can be imported', function () { + cy.get('#codemetaText').then((elem) => + elem.text(JSON.stringify({ + "@context": "https://w3id.org/codemeta/3.0", + "type": "SoftwareSourceCode", + "name": "My Test Software", + "author": [ + { + "id": "_:author_1", + "type": "Person", + "givenName": "Jane" + }, + { + "type": "Role", + "schema:author": "_:author_1", + "roleName": "Developer", + "startDate": "2024-03-04", + "endDate": "2024-04-03" + } + ] + })) + ); + cy.get('#importCodemeta').click(); + + cy.get('#author_nb').should('have.value', '1'); + cy.get('#author_1_givenName').should('have.value', 'Jane'); + cy.get('#author_1_roleName_0').should('have.value', 'Developer'); + cy.get('#author_1_startDate_0').should('have.value', '2024-03-04'); + cy.get('#author_1_endDate_0').should('have.value', '2024-04-03'); + }); + + it('can be imported without an id', function () { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://w3id.org/codemeta/3.0", "type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "type": "Person", "givenName": "Jane" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Jane" }, "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" } ] })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_roleName_0').should('have.value', 'Developer'); cy.get('#author_1_startDate_0').should('have.value', '2024-03-04'); cy.get('#author_1_endDate_0').should('have.value', '2024-04-03'); }); it('can be imported when there is a second one, and they are merged', function () { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://w3id.org/codemeta/3.0", "type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "type": "Person", "givenName": "Jane" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Jane" }, "roleName": "Maintainer", "startDate": "2024-04-04", "endDate": "2024-05-05" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Jane" }, "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" } ] })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '1'); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_roleName_0').should('have.value', 'Maintainer'); cy.get('#author_1_startDate_0').should('have.value', '2024-04-04'); cy.get('#author_1_endDate_0').should('have.value', '2024-05-05'); cy.get('#author_1_roleName_1').should('have.value', 'Developer'); cy.get('#author_1_startDate_1').should('have.value', '2024-03-04'); cy.get('#author_1_endDate_1').should('have.value', '2024-04-03'); }); }); describe('Multiple authors', function () { it('who both have roles can be exported', function () { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_add').click(); cy.get('#author_2_givenName').type('Joe'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_0').type('Developer'); cy.get('#author_1_startDate_0').type('2024-03-04'); cy.get('#author_1_endDate_0').type('2024-04-03'); cy.get('#author_2_role_add').click(); cy.get('#author_2_roleName_0').type('Maintainer'); cy.get('#author_2_startDate_0').type('2024-04-04'); cy.get('#author_2_endDate_0').type('2024-05-05'); 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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" }, { + "id": "_:author_2", "type": "Person", "givenName": "Joe" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Joe" - }, + "schema:author": "_:author_2", "roleName": "Maintainer", "startDate": "2024-04-04", "endDate": "2024-05-05" } ] }); }); it('whose one has a role and the other not can be exported', function () { cy.get('#name').type('My Test Software'); cy.get('#author_add').click(); cy.get('#author_1_givenName').type('Jane'); cy.get('#author_add').click(); cy.get('#author_2_givenName').type('Joe'); cy.get('#author_1_role_add').click(); cy.get('#author_1_roleName_0').type('Developer'); cy.get('#author_1_startDate_0').type('2024-03-04'); cy.get('#author_1_endDate_0').type('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", "author": [ { + "id": "_:author_1", "type": "Person", "givenName": "Jane" }, { "type": "Role", - "schema:author": { - "type": "Person", - "givenName": "Jane" - }, + "schema:author": "_:author_1", "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" }, { + "id": "_:author_2", "type": "Person", "givenName": "Joe" } ] }); }); it('who both have roles can be imported', function () { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://w3id.org/codemeta/3.0", "type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "type": "Person", "givenName": "Jane" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Jane" }, "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" }, { "type": "Person", "givenName": "Joe" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Joe" }, "roleName": "Maintainer", "startDate": "2024-04-04", "endDate": "2024-05-05" } ] })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '2'); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_roleName_0').should('have.value', 'Developer'); cy.get('#author_1_startDate_0').should('have.value', '2024-03-04'); cy.get('#author_1_endDate_0').should('have.value', '2024-04-03'); cy.get('#author_2_givenName').should('have.value', 'Joe'); cy.get('#author_2_roleName_0').should('have.value', 'Maintainer'); cy.get('#author_2_startDate_0').should('have.value', '2024-04-04'); cy.get('#author_2_endDate_0').should('have.value', '2024-05-05'); }); it('whose one has a role and the other not can be imported', function () { cy.get('#codemetaText').then((elem) => elem.text(JSON.stringify({ "@context": "https://w3id.org/codemeta/3.0", "type": "SoftwareSourceCode", "name": "My Test Software", "author": [ { "type": "Person", "givenName": "Jane" }, { "type": "Role", "schema:author": { "type": "Person", "givenName": "Jane" }, "roleName": "Developer", "startDate": "2024-03-04", "endDate": "2024-04-03" }, { "type": "Person", "givenName": "Joe" } ] })) ); cy.get('#importCodemeta').click(); cy.get('#author_nb').should('have.value', '2'); cy.get('#author_1_givenName').should('have.value', 'Jane'); cy.get('#author_1_roleName_0').should('have.value', 'Developer'); cy.get('#author_1_startDate_0').should('have.value', '2024-03-04'); cy.get('#author_1_endDate_0').should('have.value', '2024-04-03'); cy.get('#author_2_givenName').should('have.value', 'Joe'); }); }); diff --git a/js/codemeta_generation.js b/js/codemeta_generation.js index 6dd111d..05c458b 100644 --- a/js/codemeta_generation.js +++ b/js/codemeta_generation.js @@ -1,437 +1,445 @@ /** * Copyright (C) 2019-2020 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ "use strict"; const LOCAL_CONTEXT_PATH = "./data/contexts/codemeta-local.jsonld"; const LOCAL_CONTEXT_URL = "local"; const CODEMETA_CONTEXTS = { "2.0": { path: "./data/contexts/codemeta-2.0.jsonld", url: "https://doi.org/10.5063/schema/codemeta-2.0" }, "3.0": { path: "./data/contexts/codemeta-3.0.jsonld", url: "https://w3id.org/codemeta/3.0" } } const SPDX_PREFIX = 'https://spdx.org/licenses/'; const loadContextData = async () => { const [contextLocal, contextV2, contextV3] = await Promise.all([ fetch(LOCAL_CONTEXT_PATH).then(response => response.json()), fetch(CODEMETA_CONTEXTS["2.0"].path).then(response => response.json()), fetch(CODEMETA_CONTEXTS["3.0"].path).then(response => response.json()) ]); return { [LOCAL_CONTEXT_URL]: contextLocal, [CODEMETA_CONTEXTS["2.0"].url]: contextV2, [CODEMETA_CONTEXTS["3.0"].url]: contextV3 } } const getJsonldCustomLoader = contexts => { return url => { const xhrDocumentLoader = jsonld.documentLoaders.xhr(); if (url in contexts) { return { contextUrl: null, document: contexts[url], documentUrl: url }; } return xhrDocumentLoader(url); } }; const initJsonldLoader = contexts => { jsonld.documentLoader = getJsonldCustomLoader(contexts); }; function emptyToUndefined(v) { if (v == null || v == "") return undefined; else return v; } function getIfSet(query) { return emptyToUndefined(document.querySelector(query).value); } function setIfDefined(query, value) { if (value !== undefined) { document.querySelector(query).value = value; } } function getLicenses() { let selectedLicenses = Array.from(document.getElementById("selected-licenses").children); return selectedLicenses.map(licenseDiv => SPDX_PREFIX + licenseDiv.children[0].innerText); } // Names of codemeta properties with a matching HTML field name const directCodemetaFields = [ 'codeRepository', 'contIntegration', 'dateCreated', 'datePublished', 'dateModified', 'downloadUrl', 'issueTracker', 'name', 'version', 'identifier', 'description', 'applicationCategory', 'releaseNotes', 'funding', 'developmentStatus', 'isSourceCodeOf', 'isPartOf', 'referencePublication' ]; const splittedCodemetaFields = [ ['keywords', ','], ['programmingLanguage', ','], ['runtimePlatform', ','], ['operatingSystem', ','], ['softwareRequirements', '\n'], ['relatedLink', '\n'], ] // Names of codemeta properties with a matching HTML field name, // in a Person object const directPersonCodemetaFields = [ 'givenName', 'familyName', 'email', 'affiliation', ]; const directRoleCodemetaFields = [ 'roleName', 'startDate', 'endDate', ]; const directReviewCodemetaFields = [ 'reviewAspect', 'reviewBody' ]; const crossCodemetaFields = { "contIntegration": ["contIntegration", "continuousIntegration"], // "embargoDate": ["embargoDate", "embargoEndDate"], Not present in the form yet TODO ? }; +function generateBlankNode(customId) { + return `_:${customId}`; +} + function generateShortOrg(fieldName) { var affiliation = getIfSet(fieldName); if (affiliation !== undefined) { if (isUrl(affiliation)) { return { "@type": "Organization", "@id": affiliation, }; } else { return { "@type": "Organization", "name": affiliation, }; } } else { return undefined; } } function generatePerson(idPrefix) { var doc = { "@type": "Person", } - var id = getIfSet(`#${idPrefix}_id`); - if (id !== undefined) { - doc["@id"] = id; - } + const id = getIfSet(`#${idPrefix}_id`); + doc["@id"] = id? id : generateBlankNode(idPrefix); directPersonCodemetaFields.forEach(function (item, index) { doc[item] = getIfSet(`#${idPrefix}_${item}`); }); doc["affiliation"] = generateShortOrg(`#${idPrefix}_affiliation`); return doc; } function generateRole(id) { const doc = { "@type": "Role" }; directRoleCodemetaFields.forEach(function (item, index) { doc[item] = getIfSet(`#${id} .${item}`); }); return doc; } function generateRoles(idPrefix, 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 + role["schema:author"] = getDocumentId(person); // Prefix with "schema:" to prevent it from expanding into a list roles.push(role); }); return roles; } function generatePersons(prefix) { var persons = []; var nbPersons = getNbPersons(prefix); for (let personId = 1; personId <= nbPersons; personId++) { const idPrefix = `${prefix}_${personId}`; const person = generatePerson(idPrefix); persons.push(person); const roles = generateRoles(idPrefix, person); if (roles.length > 0) { persons = persons.concat(roles); } } return persons; } function generateReview() { const doc = { "@type": "Review" }; directReviewCodemetaFields.forEach(function (item, index) { doc[item] = getIfSet(`#${item}`); }); return doc; } async function buildExpandedJson() { var doc = { "@context": LOCAL_CONTEXT_URL, "@type": "SoftwareSourceCode", }; let licenses = getLicenses(); if (licenses.length > 0) { doc["license"] = licenses; } // Generate most fields directCodemetaFields.forEach(function (item, index) { doc[item] = getIfSet('#' + item) }); doc["funder"] = generateShortOrg('#funder', doc["affiliation"]); const review = generateReview(); if (review["reviewAspect"] || review["reviewBody"]) { doc["review"] = generateReview(); } // Generate simple fields parsed simply by splitting splittedCodemetaFields.forEach(function (item, index) { const id = item[0]; const separator = item[1]; const value = getIfSet('#' + id); if (value !== undefined) { doc[id] = value.split(separator).map(trimSpaces); } }); // Generate dynamic fields var authors = generatePersons('author'); if (authors.length > 0) { doc["author"] = authors; } var contributors = generatePersons('contributor'); if (contributors.length > 0) { doc["contributor"] = contributors; } for (const [key, items] of Object.entries(crossCodemetaFields)) { items.forEach(item => { doc[item] = doc[key]; }); } return await jsonld.expand(doc); } // v2.0 is still default version for generation, for now async function generateCodemeta(codemetaVersion = "2.0") { var inputForm = document.querySelector('#inputForm'); var codemetaText, errorHTML; if (inputForm.checkValidity()) { const expanded = await buildExpandedJson(); const compacted = await jsonld.compact(expanded, CODEMETA_CONTEXTS[codemetaVersion].url); codemetaText = JSON.stringify(compacted, null, 4); errorHTML = ""; } else { codemetaText = ""; errorHTML = "invalid input (see error above)"; inputForm.reportValidity(); } document.querySelector('#codemetaText').innerText = codemetaText; setError(errorHTML); // Run validator on the exported value, for extra validation. // If this finds a validation, it means there is a bug in our code (either // generation or validation), and the generation MUST NOT generate an // invalid codemeta file, regardless of user input. if (codemetaText && !validateDocument(JSON.parse(codemetaText))) { alert('Bug detected! The data you wrote is correct; but for some reason, it seems we generated an invalid codemeta.json. Please report this bug at https://github.com/codemeta/codemeta-generator/issues/new and copy-paste the generated codemeta.json file. Thanks!'); } if (codemetaText) { // For restoring the form state on page reload sessionStorage.setItem('codemetaText', codemetaText); } } // Imports a single field (name or @id) from an Organization. function importShortOrg(fieldName, doc) { if (doc !== undefined) { // Use @id if set, else use name setIfDefined(fieldName, doc["name"]); setIfDefined(fieldName, getDocumentId(doc)); } } function importReview(doc) { if (doc !== undefined) { directReviewCodemetaFields.forEach(item => { setIfDefined('#' + item, doc[item]); }); } } function authorsEqual(author1, author2) { - // TODO should test more properties for equality? + const id1 = typeof author1 === "string"? author1 : getDocumentId(author1); + const id2 = typeof author2 === "string"? author2 : getDocumentId(author2); + if (id1 || id2) { + return id1 === id2; + } return author1.givenName === author2.givenName && author1.familyName === author2.familyName && author1.email === author2.email; } function getSingleAuthorsFromRoles(docs) { return docs.filter(doc => getDocumentType(doc) === "Role") .map(doc => doc["schema:author"]) .reduce((authorSet, currentAuthor) => { const foundAuthor = authorSet.find(author => authorsEqual(author, currentAuthor)); if (!foundAuthor) { return authorSet.concat([currentAuthor]); } else { return authorSet; } }, []); } function importRoles(personPrefix, roles) { roles.forEach(role => { const roleId = addRole(`${personPrefix}`); directRoleCodemetaFields.forEach(item => { setIfDefined(`#${personPrefix}_${item}_${roleId}`, role[item]); }); }); } function importPersons(prefix, legend, docs) { if (docs === undefined) { return; } const authors = docs.filter(doc => getDocumentType(doc) === "Person"); const authorsFromRoles = getSingleAuthorsFromRoles(docs); const allAuthorDocs = authors.concat(authorsFromRoles) .reduce((authors, currentAuthor) => { if (!authors.find(author => authorsEqual(author, currentAuthor))) { authors.push(currentAuthor); } return authors; }, []); allAuthorDocs.forEach(function (doc, index) { var personId = addPerson(prefix, legend); - setIfDefined(`#${prefix}_${personId}_id`, getDocumentId(doc)); + if (!isBlankNode(getDocumentId(doc))) { + setIfDefined(`#${prefix}_${personId}_id`, getDocumentId(doc)); + } directPersonCodemetaFields.forEach(function (item, index) { setIfDefined(`#${prefix}_${personId}_${item}`, doc[item]); }); importShortOrg(`#${prefix}_${personId}_affiliation`, doc['affiliation']); const roles = docs.filter(currentDoc => getDocumentType(currentDoc) === "Role") .filter(currentDoc => authorsEqual(currentDoc["schema:author"], doc)); importRoles(`${prefix}_${personId}`, roles); }); } async function importCodemeta() { var inputForm = document.querySelector('#inputForm'); var doc = await parseAndValidateCodemeta(false); resetForm(); if (doc['license'] !== undefined) { if (typeof doc['license'] === 'string') { doc['license'] = [doc['license']]; } doc['license'].forEach(l => { if (l.indexOf(SPDX_PREFIX) !== 0) { return; } let licenseId = l.substring(SPDX_PREFIX.length); insertLicenseElement(licenseId); }); } directCodemetaFields.forEach(function (item, index) { setIfDefined('#' + item, doc[item]); }); importShortOrg('#funder', doc["funder"]); importReview(doc["review"]); // Import simple fields by joining on their separator splittedCodemetaFields.forEach(function (item, index) { const id = item[0]; const separator = item[1]; let value = doc[id]; if (value !== undefined) { if (Array.isArray(value)) { value = value.join(separator); } setIfDefined('#' + id, value); } }); for (const [key, items] of Object.entries(crossCodemetaFields)) { let value = ""; items.forEach(item => { value = doc[item] || value; }); setIfDefined(`#${key}`, value); } importPersons('author', 'Author', doc['author']) importPersons('contributor', 'Contributor', doc['contributor']) } function loadStateFromStorage() { var codemetaText = sessionStorage.getItem('codemetaText') if (codemetaText) { document.querySelector('#codemetaText').innerText = codemetaText; importCodemeta(); } } diff --git a/js/utils.js b/js/utils.js index 8d203cb..a36b621 100644 --- a/js/utils.js +++ b/js/utils.js @@ -1,36 +1,44 @@ /** * Copyright (C) 2019 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ "use strict"; function getNbPersons(prefix) { var nbField = document.querySelector(`#${prefix}_nb`); return parseInt(nbField.value, 10); } function setNbPersons(prefix, nb) { var nbField = document.querySelector(`#${prefix}_nb`); nbField.value = nb; } function setError(msg) { document.querySelector("#errorMessage").innerHTML = msg; } function trimSpaces(s) { return s.replace(/^\s+|\s+$/g, ''); } // From https://stackoverflow.com/a/43467144 function isUrl(s) { try { new URL(s); return true; } catch (e) { return false; } } + +function isBlankNode(s) { + return typeof s === 'string' && s.startsWith("_:"); +} + +function isUrlOrBlankNode(s) { + return isUrl(s) || isBlankNode(s); +} diff --git a/js/validation/primitives.js b/js/validation/primitives.js index 2dc1cd0..debb113 100644 --- a/js/validation/primitives.js +++ b/js/validation/primitives.js @@ -1,146 +1,156 @@ /** * Copyright (C) 2020 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ /* * Validators for native schema.org data types. */ // Validates an URL or an array of URLs function validateUrls(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { if (typeof subdoc != 'string') { if (inList) { setError(`"${fieldName}" must be a list of URLs (or a single URL), but it contains: ${JSON.stringify(subdoc)}`); } else { setError(`"${fieldName}" must be an URL (or a list of URLs), not: ${JSON.stringify(subdoc)}`); } return false; } else { return validateUrl(fieldName, subdoc); } }); } // Validates a single URL function validateUrl(fieldName, doc) { if (!isUrl(doc)) { setError(`Invalid URL in field "${fieldName}": ${JSON.stringify(doc)}`) return false; } else { return true; } } +function validateUrlOrBlankNode(fieldName, doc) { + if (!isUrlOrBlankNode(doc)) { + setError(`Invalid URL or blank node in field "${fieldName}": ${JSON.stringify(doc)}`) + return false; + } + else { + return true; + } +} + // Validates a Text/URL or an array of Texts/URLs function validateTextsOrUrls(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { if (typeof subdoc != 'string') { if (inList) { setError(`"${fieldName}" must be a list of texts/URLs (or a single text/URL), but it contains: ${JSON.stringify(subdoc)}`); } else { setError(`"${fieldName}" must be a text/URL (or a list of texts/URLs), not: ${JSON.stringify(subdoc)}`); } return false; } else { return true; } }); } // Validates a Text or an array of Texts function validateTexts(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { if (typeof subdoc != 'string') { if (inList) { setError(`"${fieldName}" must be a list of texts (or a single text), but it contains: ${JSON.stringify(subdoc)}`); } else { setError(`"${fieldName}" must be a text (or a list of texts), not: ${JSON.stringify(subdoc)}`); } return false; } else { return true; } }); } // Validates a single Text function validateText(fieldName, doc) { if (typeof doc != 'string') { setError(`"${fieldName}" must be text, not ${JSON.stringify(doc)}`); return false; } else { return true; } } // Validates a Number or list of Number function validateNumbers(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { if (typeof subdoc != 'number') { if (inList) { setError(`"${fieldName}" must be an array of numbers (or a single number), but contains: ${JSON.stringify(subdoc)}`); } else { setError(`"${fieldName}" must be a number or an array of numbers, not: ${JSON.stringify(subdoc)}`); } return false; } else { return true; } }); } // Validates a single Text or Number function validateNumberOrText(fieldName, doc) { if (typeof doc == 'string') { return true; } else if (typeof doc == 'number') { return true; } else { setError(`"${fieldName}" must be text or a number, not ${JSON.stringify(doc)}`); return false; } } // Validates a single Boolean function validateBoolean(fieldName, doc) { if (typeof doc != 'boolean') { setError(`"${fieldName}" must be a boolean (ie. "true" or "false"), not ${JSON.stringify(subdoc)}`); return false; } else { return true; } } // Validates a single Date function validateDate(fieldName, doc) { let re = /^\d{4}-\d{2}-\d{2}$/; if (typeof doc != 'string') { setError(`"${fieldName}" must be a date, not ${JSON.stringify(doc)}`); return false; } else if (!doc.match(re)) { setError(`"${fieldName}" must be a date in the format YYYY-MM-DD, not ${JSON.stringify(doc)}`); return false; } else { return true; } } diff --git a/js/validation/things.js b/js/validation/things.js index 13b4b25..63c6732 100644 --- a/js/validation/things.js +++ b/js/validation/things.js @@ -1,346 +1,346 @@ /** * Copyright (C) 2020-2021 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ /* * Validators for codemeta objects derived from http://schema.org/Thing. */ function getDocumentType(doc) { // TODO: check there is at most one. // FIXME: is the last variant allowed? return doc["type"] || doc["@type"] || doc["codemeta:type"] } function getDocumentId(doc) { return doc["id"] || doc["@id"]; } function isCompactTypeEqual(type, compactedType) { // FIXME: are all variants allowed? return (type == `${compactedType}` || type == `schema:${compactedType}` || type == `codemeta:${compactedType}` || type == `http://schema.org/${compactedType}` ); } function isFieldFromOtherVersionToIgnore(fieldName) { return ["codemeta:contIntegration", "codemeta:continuousIntegration", "codemeta:isSourceCodeOf", "schema:roleName", "schema:startDate", "schema:endDate", "schema:review", "schema:reviewAspect", "schema:reviewBody", "schema:releaseNotes"].includes(fieldName); } function noValidation(fieldName, doc) { return true; } // Validates subtypes of Thing, or URIs // // typeFieldValidators is a map: {type => {fieldName => fieldValidator}} function validateThingOrId(parentFieldName, typeFieldValidators, doc) { var acceptedTypesString = Object.keys(typeFieldValidators).join('/'); if (typeof doc == 'string') { - if (!isUrl(doc)) { + if (!isUrlOrBlankNode(doc)) { setError(`"${parentFieldName}" must be an URL or a ${acceptedTypesString} object, not: ${JSON.stringify(doc)}`); return false; } else { return true; } } else if (!Array.isArray(doc) && typeof doc == 'object') { return validateThing(parentFieldName, typeFieldValidators, doc); } else { setError(`"${parentFieldName}" must be a ${acceptedTypesString} object or URI, not ${JSON.stringify(doc)}`); return false; } } // Validates subtypes of Thing // // typeFieldValidators is a map: {type => {fieldName => fieldValidator}} function validateThing(parentFieldName, typeFieldValidators, doc) { // TODO: check there is either id or @id but not both // TODO: check there is either type or @type but not both var acceptedTypesString = Object.keys(typeFieldValidators).join('/'); var documentType = getDocumentType(doc); var id = getDocumentId(doc); - if (id !== undefined && !isUrl(id)) { - setError(`"${fieldName}" has an invalid URI as id: ${JSON.stringify(id)}"`); + if (id !== undefined && !isUrlOrBlankNode(id)) { + setError(`"${parentFieldName}" has an invalid URI as id: ${JSON.stringify(id)}"`); return false; } if (documentType === undefined) { if (id === undefined) { setError(`"${parentFieldName}" must be a (list of) ${acceptedTypesString} object(s) or an URI, but is missing a type/@type.`); return false; } else { // FIXME: we have an @id but no @type, what should we do? return true; } } for (expectedType in typeFieldValidators) { if (isCompactTypeEqual(documentType, expectedType)) { var fieldValidators = typeFieldValidators[expectedType]; return Object.entries(doc).every((entry) => { var fieldName = entry[0]; var subdoc = entry[1]; if (fieldName == "type" || fieldName == "@type") { // Was checked before return true; } else if (isFieldFromOtherVersionToIgnore(fieldName)) { // Do not check fields from other versions FIXME return true; } else { var validator = fieldValidators[fieldName]; if (validator === undefined) { // TODO: find if it's a field that belongs to another type, // and suggest that to the user setError(`Unknown field "${fieldName}" in "${parentFieldName}".`) return false; } else { return validator(fieldName, subdoc); } } }); } } setError(`"${parentFieldName}" type must be a (list of) ${acceptedTypesString} object(s), not ${JSON.stringify(documentType)}`); return false; } // Helper function to validate a field is either X or a list of X. function validateListOrSingle(fieldName, doc, validator) { if (Array.isArray(doc)) { return doc.every((subdoc) => validator(subdoc, true)); } else { return validator(doc, false); } } // Validates a CreativeWork or an array of CreativeWork function validateCreativeWorks(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { return validateCreativeWork(fieldName, subdoc); }); } // Validates a single CreativeWork function validateCreativeWork(fieldName, doc) { return validateThingOrId(fieldName, { "CreativeWork": creativeWorkFieldValidators, "SoftwareSourceCode": softwareFieldValidators, "SoftwareApplication": softwareFieldValidators, }, doc); } // Validates a Person, Organization or an array of these function validateActors(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { return validateActor(fieldName, subdoc); }); } // Validates a Person or an array of Person function validatePersons(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { return validatePerson(fieldName, subdoc); }); } // Validates an Organization or an array of Organization function validateOrganizations(fieldName, doc) { return validateListOrSingle(fieldName, doc, (subdoc, inList) => { return validateOrganization(fieldName, subdoc); }); } // Validates a single Person or Organization function validateActor(fieldName, doc) { return validateThingOrId(fieldName, { "Role": roleFieldValidators, "Person": personFieldValidators, "Organization": organizationFieldValidators, }, doc); } // Validates a single Person object function validatePerson(fieldName, doc) { return validateThingOrId(fieldName, {"Person": personFieldValidators}, doc); } // Validates a single Organization object function validateOrganization(fieldName, doc) { return validateThingOrId(fieldName, {"Organization": organizationFieldValidators}, doc); } function validateReview(fieldName, doc) { return validateThingOrId(fieldName, {"Review": reviewFieldValidators}, doc); } var softwareFieldValidators = { "@id": validateUrl, "id": validateUrl, "codeRepository": validateUrls, "programmingLanguage": noValidation, "runtimePlatform": validateTexts, "targetProduct": noValidation, // TODO: validate SoftwareApplication "applicationCategory": validateTextsOrUrls, "applicationSubCategory": validateTextsOrUrls, "downloadUrl": validateUrls, "fileSize": validateText, // TODO "installUrl": validateUrls, "memoryRequirements": validateTextsOrUrls, "operatingSystem": validateTexts, "permissions": validateTexts, "processorRequirements": validateTexts, "releaseNotes": validateTextsOrUrls, "softwareHelp": validateCreativeWorks, "softwareRequirements": noValidation, // TODO: validate SoftwareSourceCode "softwareVersion": validateText, // TODO? "storageRequirements": validateTextsOrUrls, "supportingData": noValidation, // TODO "author": validateActors, "citation": validateCreativeWorks, // TODO "contributor": validateActors, "copyrightHolder": validateActors, "copyrightYear": validateNumbers, "creator": validateActors, // TODO: still in codemeta 2.0, but removed from master "dateCreated": validateDate, "dateModified": validateDate, "datePublished": validateDate, "editor": validatePersons, "encoding": noValidation, "fileFormat": validateTextsOrUrls, "funder": validateActors, // TODO: may be other types "keywords": validateTexts, "license": validateCreativeWorks, "producer": validateActors, "provider": validateActors, "publisher": validateActors, "sponsor": validateActors, "version": validateNumberOrText, "isAccessibleForFree": validateBoolean, "isSourceCodeOf": validateTextsOrUrls, "isPartOf": validateCreativeWorks, "hasPart": validateCreativeWorks, "position": noValidation, "identifier": noValidation, // TODO "description": validateText, "name": validateText, "sameAs": validateUrls, "url": validateUrls, "relatedLink": validateUrls, "review": validateReview, "softwareSuggestions": noValidation, // TODO: validate SoftwareSourceCode "maintainer": validateActors, "contIntegration": validateUrls, "continuousIntegration": validateUrls, "buildInstructions": validateUrls, "developmentStatus": validateText, // TODO: use only repostatus strings? "embargoDate": validateDate, "embargoEndDate": validateDate, "funding": validateText, "issueTracker": validateUrls, "referencePublication": noValidation, // TODO? "readme": validateUrls, }; var creativeWorkFieldValidators = { "@id": validateUrl, "id": validateUrl, "author": validateActors, "citation": validateCreativeWorks, // TODO "contributor": validateActors, "copyrightHolder": validateActors, "copyrightYear": validateNumbers, "creator": validateActors, // TODO: still in codemeta 2.0, but removed from master "dateCreated": validateDate, "dateModified": validateDate, "datePublished": validateDate, "editor": validatePersons, "encoding": noValidation, "funder": validateActors, // TODO: may be other types "keywords": validateTexts, "license": validateCreativeWorks, "producer": validateActors, "provider": validateActors, "publisher": validateActors, "sponsor": validateActors, "version": validateNumberOrText, "isAccessibleForFree": validateBoolean, "isPartOf": validateCreativeWorks, "hasPart": validateCreativeWorks, "position": noValidation, "identifier": noValidation, // TODO "description": validateText, "name": validateText, "sameAs": validateUrls, "url": validateUrls, }; var roleFieldValidators = { "roleName": validateText, "startDate": validateDate, "endDate": validateDate, "schema:author": validateActor }; var personFieldValidators = { - "@id": validateUrl, - "id": validateUrl, + "@id": validateUrlOrBlankNode, + "id": validateUrlOrBlankNode, "givenName": validateText, "familyName": validateText, "email": validateText, "affiliation": validateOrganizations, "identifier": validateUrls, "name": validateText, // TODO: this is technically valid, but should be allowed here? "url": validateUrls, }; var organizationFieldValidators = { "@id": validateUrl, "id": validateUrl, "email": validateText, "identifier": validateUrls, "name": validateText, "address": validateText, "sponsor": validateActors, "funder": validateActors, // TODO: may be other types "isPartOf": validateOrganizations, "url": validateUrls, // TODO: add more? }; const reviewFieldValidators = { "reviewAspect": validateText, "reviewBody": validateText, }