Skip to content

Commit

Permalink
Merge pull request #1105 from effigies/enh/derivatives
Browse files Browse the repository at this point in the history
ENH: Add GeneratedBy and SourceDatasets to dataset_description schema
  • Loading branch information
rwblair authored Nov 4, 2020
2 parents c1ecfba + c34fb79 commit 474ede9
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
50 changes: 50 additions & 0 deletions bids-validator/tests/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
)
})
})
})
49 changes: 48 additions & 1 deletion bids-validator/validators/json/schemas/dataset_description.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/example.json",
"type": "object",
"properties": {
"Name": {
"type": "string"
Expand Down Expand Up @@ -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": {
Expand All @@ -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"]
}
}
}
}

0 comments on commit 474ede9

Please sign in to comment.