diff --git a/bids-validator/tests/json.spec.js b/bids-validator/tests/json.spec.js index 65d66b649..fa60abe69 100644 --- a/bids-validator/tests/json.spec.js +++ b/bids-validator/tests/json.spec.js @@ -496,4 +496,54 @@ describe('JSON', function() { assert(issues.length === 0) }) }) + + it('dataset_description.json should validate with DatasetType "derivative" and GeneratedBy defined', function() { + var jsonObj = { + Name: 'Example Name', + BIDSVersion: '1.4.0', + Authors: ['example author'], + DatasetType: 'derivative', + GeneratedBy: [{ Name: 'Manual' }], + } + jsonDict[dataset_description_file.relativePath] = jsonObj + validate.JSON(dataset_description_file, jsonDict, function(issues) { + assert(issues.length === 0) + }) + }) + + it('dataset_description.json should NOT validate with DatasetType "derivative" and GeneratedBy empty', function() { + var jsonObj = { + Name: 'Example Name', + BIDSVersion: '1.4.0', + Authors: ['example author'], + DatasetType: 'derivative', + GeneratedBy: [], + } + jsonDict[dataset_description_file.relativePath] = jsonObj + validate.JSON(dataset_description_file, jsonDict, function(issues) { + assert(issues.length === 1) + assert( + issues[0].code == 55 && + issues[0].evidence == + '.GeneratedBy should NOT have fewer than 1 items', + ) + }) + }) + + it('dataset_description.json should NOT validate with DatasetType "derivative" and GeneratedBy missing', function() { + var jsonObj = { + Name: 'Example Name', + BIDSVersion: '1.4.0', + Authors: ['example author'], + DatasetType: 'derivative', + } + jsonDict[dataset_description_file.relativePath] = jsonObj + validate.JSON(dataset_description_file, jsonDict, function(issues) { + assert(issues.length === 2) + assert( + issues[0].code == 55 && + issues[0].evidence == " should have required property 'GeneratedBy'", + ) + }) + }) }) diff --git a/bids-validator/validators/json/schemas/dataset_description.json b/bids-validator/validators/json/schemas/dataset_description.json index a849f3137..4847d68f9 100644 --- a/bids-validator/validators/json/schemas/dataset_description.json +++ b/bids-validator/validators/json/schemas/dataset_description.json @@ -1,6 +1,7 @@ { "$schema": "http://json-schema.org/draft-06/schema#", "$id": "http://example.com/example.json", + "type": "object", "properties": { "Name": { "type": "string" @@ -51,6 +52,38 @@ "DatasetDOI": { "type": "string" }, + "GeneratedBy": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "Name": {"type": "string"}, + "Version": {"type": "string"}, + "Description": {"type": "string"}, + "CodeURL": {"type": "string", "format": "uri"}, + "Container": { + "type": "object", + "properties": { + "Type": {"type": "string"}, + "Tag": {"type": "string"}, + "URI": {"type": "string", "format": "uri"} + } + } + } + } + }, + "SourceDatasets": { + "type": "array", + "items": { + "type": "object", + "properties": { + "URL": {"type": "string", "format": "uri"}, + "DOI": {"type": "string"}, + "Version": {"type": "string"} + } + } + }, "Genetics": { "type": "object", "properties": { @@ -70,5 +103,19 @@ } }, "required": ["Name", "BIDSVersion"], - "type": "object" + "allOf": [ + { "$ref": "#/dependency-definitions/if-DatasetType-is-derivative-then-GeneratedBy-is-required" } + ], + "dependency-definitions": { + "if-DatasetType-is-derivative-then-GeneratedBy-is-required": { + "if": { + "type": "object", + "properties": {"DatasetType": {"const": "derivative"}}, + "required": ["DatasetType"] + }, + "then": { + "required": ["GeneratedBy"] + } + } + } }