Skip to content

Commit

Permalink
Merge 7233f6b into d2429ab
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson committed Dec 11, 2019
2 parents d2429ab + 7233f6b commit a7d1fd2
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 24 deletions.
81 changes: 81 additions & 0 deletions fixtures/3/broken_embedded_annos.json
@@ -0,0 +1,81 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://example.com/broken_embedded_annos.json",
"type": "Manifest",
"label": {
"en": [
"Audio Recording annotation with annotations in Canvas items rather than canvas/annotations"
]
},
"items": [
{
"id": "https://example.com/annos/canvas/1",
"type": "Canvas",
"duration": 107,
"items": [
{
"id": "https://example.com/annos/canvas/1/paintings",
"type": "AnnotationPage",
"items": [
{
"id": "https://example.com/annos/canvas/1/painting/1",
"type": "Annotation",
"motivation": "painting",
"body": {
"id": "https://library.harvard.edu/poetry/audio/listeningbooth/PS3537E915A6x1974/Her_Kind.mp3",
"type": "Sound",
"format": "audio/mp3",
"duration": 107
},
"target": "https://example.com/annos/canvas/1"
}
],
"annotations": [
{
"id": "https://example.com/annos/annotations.json",
"type": "AnnotationPage",
"items": [
{
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "https://example.com/annos/canvas/1/annotation/1",
"type": "Annotation",
"motivation": "commenting",
"body": {
"type": "TextualBody",
"value": "breath",
"format": "text/plain"
},
"target": {
"source": "https://example.com/annos/canvas/1",
"selector": {
"type": "PointSelector",
"t": "27.660653"
}
}
},
{
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "https://example.com/annos/canvas/1/annotation/2",
"type": "Annotation",
"motivation": "commenting",
"body": {
"type": "TextualBody",
"value": "her kind",
"format": "text/plain"
},
"target": {
"source": "https://example.com/annos/canvas/1",
"selector": {
"type": "RangeSelector",
"t": "46.734653,47.875068"
}
}
}
]
}
]
}
]
}
]
}
8 changes: 6 additions & 2 deletions schema/iiif_3_0.json
Expand Up @@ -461,7 +461,9 @@
"properties": {
"type": {
"type": "string",
"pattern": "^Collection"
"pattern": "^Collection",
"title": "Are you validating a collection?",
"description":"If you are validating a manifest, you may get this error if there are errors in the manifest. The validator first validates it as a manifest and if that fails it will try and validate it using the other types."
},
"metadata": { "$ref": "#/classes/metadata" },
"summary": { "$ref": "#/types/lngString" },
Expand Down Expand Up @@ -656,6 +658,7 @@
{
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"type": {
"type": "string",
"pattern": "^AnnotationPage$"
Expand All @@ -666,7 +669,8 @@
"$ref": "#/classes/annotation"
}
}
}
},
"additionalProperties": false
}
]
},
Expand Down
58 changes: 37 additions & 21 deletions schema/schemavalidator.py
Expand Up @@ -41,29 +41,45 @@ def validate(data, version, url):
if errors:
print('Validation Failed')
errorCount = 1
if len(errors) == 1 and 'is not valid under any of the given schemas' in errors[0].message:
errors = errors[0].context
for err in errors:
detail = ''
if 'title' in err.schema:
detail = err.schema['title']
description = ''
if 'description' in err.schema:
detail += err.schema['description']
context = err.instance
#print (json.dumps(err.instance, indent=4))
if isinstance(context, dict):
for key in context:
if isinstance(context[key], list):
context[key] = '[ ... ]'
elif isinstance(context[key], dict):
context[key] = '{ ... }'
errorsJson.append({
'title': 'Error {} of {}.\n Message: {}'.format(errorCount, len(errors), err.message),
'detail': detail,
'description': description,
'path': printPath(err.path, err.message),
'context': context
if 'is not valid under any of the given schemas' in err.message:
subErrorMessages = []
for subErr in err.context:
if 'is not valid under any of the given schemas' not in subErr.message:
subErrorMessages.append(subErr.message)
errorsJson.append({
'title': 'Error {} of {}.\n Message: Failed to process submission due to many errors'.format(errorCount, len(errors)),
'detail': 'This error is likely due to other listed errors. Fix those errors first.',
'description': "{}".format(subErrorMessages),
'path': '',
'context': ''
})

else:
detail = ''
if 'title' in err.schema:
detail = err.schema['title']
description = ''
if 'description' in err.schema:
detail += ' ' + err.schema['description']
context = err.instance
#print (json.dumps(err.instance, indent=4))
if isinstance(context, dict):
for key in context:
if isinstance(context[key], list):
context[key] = '[ ... ]'
elif isinstance(context[key], dict):
context[key] = '{ ... }'
errorsJson.append({
'title': 'Error {} of {}.\n Message: {}'.format(errorCount, len(errors), err.message),
'detail': detail,
'description': description,
'path': printPath(err.path, err.message),
'context': context

})
})
#print (json.dumps(err.instance, indent=4))
errorCount += 1

Expand Down
3 changes: 2 additions & 1 deletion tests/test_validator.py
Expand Up @@ -147,7 +147,8 @@ def test07_check_manifest3(self):

for bad_data in ['fixtures/3/broken_simple_image.json',
'fixtures/3/broken_choice.json',
'fixtures/3/broken_collection.json']:
'fixtures/3/broken_collection.json',
'fixtures/3/broken_embedded_annos.json']:
with open(bad_data, 'r') as fh:
data = fh.read()
j = json.loads(v.check_manifest(data, '3.0'))
Expand Down

0 comments on commit a7d1fd2

Please sign in to comment.