Skip to content

Commit

Permalink
Add DatasetLinks to JSON schema (#1404)
Browse files Browse the repository at this point in the history
* first try

* add functional DatasetLinks schema: any str bigger than len 0 --> uri

* add tests

* fix lint

* use propertyNames feature, instead of not feature

* migrated eeg_matchingpennies from GitHub to GIN

* fix formatting E501

* Update bids-validator/tests/json.spec.js

Co-authored-by: Chris Markiewicz <effigies@gmail.com>

* Update bids-validator/validators/json/schemas/dataset_description.json

* fix tests

Co-authored-by: Chris Markiewicz <effigies@gmail.com>
  • Loading branch information
sappelhoff and effigies authored Jan 20, 2022
1 parent 4d780ec commit 4feb91b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bids-validator/bids_validator/test_bids_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
HOME = os.path.expanduser('~')

TEST_DATA_DICT = {
'eeg_matchingpennies': 'https://github.com/sappelhoff/eeg_matchingpennies'
'eeg_matchingpennies': (
'https://gin.g-node.org/sappelhoff/eeg_matchingpennies'
),
}

EXCLUDE_KEYWORDS = ['git', 'datalad', 'sourcedata', 'bidsignore']
Expand Down
87 changes: 87 additions & 0 deletions bids-validator/tests/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,93 @@ describe('JSON', function() {
relativePath: '/dataset_description.json',
}

it('dataset_description.json should validate DatasetLinks', function() {
var jsonObj = {
Name: 'Example Name',
BIDSVersion: '1.4.0',
DatasetLinks: {
mylink: 'https://www.google.com',
deriv1: 'derivatives/derivative1',
phantoms: 'file:///data/phantoms',
ds000001: 'doi:10.18112/openneuro.ds000001.v1.0.0',
},
}
jsonDict[dataset_description_file.relativePath] = jsonObj
validate.JSON(dataset_description_file, jsonDict, function(issues) {
assert(issues.length === 0)
})
})

it('dataset_description.json should raise on bad keys in DatasetLinks', function() {
var jsonObj = {
Name: 'Example Name',
BIDSVersion: '1.4.0',
DatasetLinks: {
mylink: 'https://www.google.com',
'': 'https://www.yahoo.com',
'mylink!': ':/path',
'my link': ':/another/path',
},
}
jsonDict[dataset_description_file.relativePath] = jsonObj
validate.JSON(dataset_description_file, jsonDict, function(issues) {
assert(issues.length === 6)
assert(
issues[0].evidence ==
'.DatasetLinks should NOT be shorter than 1 characters',
)
assert(issues[1].evidence == ".DatasetLinks property name '' is invalid")
assert(
issues[2].evidence ==
'.DatasetLinks should match pattern "^[a-zA-Z0-9]*$"',
)
assert(
issues[3].evidence ==
".DatasetLinks property name 'mylink!' is invalid",
)
assert(issues[4].evidence == issues[2].evidence)
assert(
issues[5].evidence ==
".DatasetLinks property name 'my link' is invalid",
)
})
})

it('dataset_description.json should raise on non-object value in DatasetLinks', function() {
var jsonObj = {
Name: 'Example Name',
BIDSVersion: '1.4.0',
DatasetLinks: 'https://www.google.com',
}
jsonDict[dataset_description_file.relativePath] = jsonObj
validate.JSON(dataset_description_file, jsonDict, function(issues) {
assert(issues.length === 1)
assert(issues[0].evidence == '.DatasetLinks should be object')
})
})

it('dataset_description.json should raise on invalid values in DatasetLinks', function() {
var jsonObj = {
Name: 'Example Name',
BIDSVersion: '1.4.0',
DatasetLinks: {
mylink1: 'https://www.google.com',
mylink2: 1,
'': 'https://www.yahoo.com',
},
}
jsonDict[dataset_description_file.relativePath] = jsonObj
validate.JSON(dataset_description_file, jsonDict, function(issues) {
assert(issues.length === 3)
assert(
issues[0].evidence ==
'.DatasetLinks should NOT be shorter than 1 characters',
)
assert(issues[1].evidence == ".DatasetLinks property name '' is invalid")
assert(issues[2].evidence == ".DatasetLinks['mylink2'] should be string")
})
})

it('dataset_description.json should validate with enum of DatasetType', function() {
var jsonObj = {
Name: 'Example Name',
Expand Down
13 changes: 13 additions & 0 deletions bids-validator/validators/json/schemas/dataset_description.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
"DatasetDOI": {
"type": "string"
},
"DatasetLinks": {
"type": "object",
"properties": { },
"propertyNames": {
"type": "string",
"minLength": 1,
"pattern": "^[a-zA-Z0-9]*$"
},
"additionalProperties": {
"type": "string",
"format": "uri-reference"
}
},
"GeneratedBy": {
"type": "array",
"minItems": 1,
Expand Down

0 comments on commit 4feb91b

Please sign in to comment.