Skip to content

Commit

Permalink
Merge cffa9e7 into 711b8ca
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson committed Dec 4, 2019
2 parents 711b8ca + cffa9e7 commit 0dd6bc6
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 60 deletions.
37 changes: 37 additions & 0 deletions fixtures/3/broken_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://example.org/iiif/collection/top",
"type": "Collection",
"summary": { "en": [ "Short summary of the Collection" ] },
"requiredStatement": {
"label": { "en": [ "Attribution" ] },
"value": { "en": [ "Provided by Example Organization" ] }
},
"behavior": [ "multi-part" ],
"items": [
{
"id": "https://example.org/iiif/1/manifest",
"type": "Manifest",
"label": { "en": [ "Example Manifest 1" ] },
"thumbnail": [
{
"id": "https://example.org/manifest1/thumbnail.jpg",
"type": "Image",
"format": "image/jpeg"
}
]
},
{
"id": "https://example.org/iiif/2/manifest",
"type": "Manifest",
"label": { "en": [ "Example Manifest 2" ] },
"thumbnail": [
{
"id": "https://example.org/manifest2/thumbnail.jpg",
"type": "Image",
"format": "image/jpeg"
}
]
}
]
}
1 change: 0 additions & 1 deletion fixtures/3/full_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@
"type": "Annotation",
"motivation": "commenting",
"body": {
"id": "https://example.org/iiif/book1/annotationPage/Body/id",
"type": "TextualBody",
"language": "en",
"value": "I love this manifest!"
Expand Down
49 changes: 49 additions & 0 deletions fixtures/3/version2image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://example.org/iiif/book1/manifest",
"type": "Manifest",
"label": { "en": [ "Book 1" ] },
"items": [
{
"id": "https://example.org/iiif/book1/canvas/p1",
"type": "Canvas",
"label": { "none": [ "p. 1" ] },
"height": 1000,
"width": 750,
"items": [
{
"id": "https://example.org/iiif/book1/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://example.org/iiif/book1/annotation/p0001-image",
"type": "Annotation",
"motivation": "painting",
"body": {
"id": "https://example.org/iiif/book1/page1/full/full/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"service": [
{
"@id": "https://example.org/iiif2/image1/identifier",
"@type": "ImageService2",
"profile": "http://iiif.io/api/image/2/level2.json"
}
],
"height": 2000,
"width": 1500
},
"target": "https://example.org/iiif/book1/canvas/p1"
}
]
}
],
"annotations": [
{
"id": "https://example.org/iiif/book1/comments/p1/1",
"type": "AnnotationPage"
}
]
}
]
}
126 changes: 78 additions & 48 deletions schema/iiif_3_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,56 +128,71 @@
"required": ["type", "items"]
},
"resource": {
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"type": {
"oneOf": [
{
"type": "string",
"pattern": "^Image$"
},
{
"type": "string",
"pattern": "^Sound$"
},
{
"type": "string",
"pattern": "^Video$"
"oneOf": [
{
"title": "Annotation bodies MUST have an id and type property.",
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"type": {
"oneOf": [
{
"type": "string",
"pattern": "^Image$"
},
{
"type": "string",
"pattern": "^Sound$"
},
{
"type": "string",
"pattern": "^Video$"
},
{
"type": "string",
"pattern": "^Model$"
},
{
"type": "string",
"pattern": "^Dataset$"
},
{
"type": "string",
"pattern": "^Text$"
} ]
},
{
"type": "string",
"pattern": "^Model$"
"height": {
"type": "integer"
},
{
"type": "string",
"pattern": "^Dataset$"
"width": {
"type": "integer"
},
{
"type": "string",
"pattern": "^Text$"
"duration": {
"$ref": "#/types/duration"
},
{
"language": { "type": "string"},
"service": { "$ref": "#/classes/service" },
"format": { "$ref": "#/types/format" },
"label": {"$ref": "#/types/lngString" }
},
"required": ["id", "type"]
},
{
"title": "Annotation bodies which are TextualBody MUST have an type and value property.",
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"type": {
"type": "string",
"pattern": "^TextualBody$"
}
]
},
"height": {
"type": "integer"
},
"width": {
"type": "integer"
},
"duration": {
"$ref": "#/types/duration"
},
"language": { "type": "string"},
"service": { "$ref": "#/classes/service" },
"format": { "$ref": "#/types/format" },
"label": {"$ref": "#/types/lngString" }
},
"required": ["id","type"]
},
"value": { "type": "string" },
"format": { "$ref": "#/types/format" },
"language": { "type": "string"}
},
"required": ["value", "type"]
}
]
},
"imgSvr": {
"allOf": [
Expand All @@ -194,14 +209,28 @@
"service": {
"type": "array",
"items": {
"allOf": [
{ "$ref": "#/types/class" },
"oneOf": [
{
"allOf": [
{ "$ref": "#/types/class" },
{
"type": "object",
"properties": {
"profile": { "type": "string" },
"service": { "$ref": "#/classes/service" }
}
}
]
},
{
"type": "object",
"properties": {
"@id": { "$ref": "#/types/id" },
"@type": { "type": "string" },
"profile": { "type": "string" },
"service": { "$ref": "#/classes/service" }
}
},
"required": ["@id", "@type"]
}
]
}
Expand Down Expand Up @@ -368,7 +397,8 @@
"$ref": "#/classes/annotationPage"
}
}
}
},
"required": ["id", "type", "label"]
}
]
},
Expand Down
13 changes: 5 additions & 8 deletions schema/schemavalidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ def validate(data, version, url):
detail = ''
if 'title' in err.schema:
detail = err.schema['title']
print (' Test message: {}'.format(detail))
# print (' Test message: {}'.format(detail))
description = ''
if 'description' in err.schema:
description = err.schema['description']
print (' Test description: {}'.format(description))
print('\n Path for error: {}'.format(printPath(err.path, err.message)))
# print (' Test description: {}'.format(description))
#print('\n Path for error: {}'.format(printPath(err.path, err.message)))
context = err.instance
print (json.dumps(err.instance, indent=4))
#print (json.dumps(err.instance, indent=4))
if isinstance(context, dict):
for key in context:
print('****')
print(key)
print('****')
if isinstance(context[key], list):
context[key] = '[ ... ]'
elif isinstance(context[key], dict):
Expand All @@ -71,7 +68,7 @@ def validate(data, version, url):
'context': context

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

# Return:
Expand Down
27 changes: 24 additions & 3 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,40 @@ def test07_check_manifest3(self):
'fixtures/3/full_example.json',
'fixtures/3/choice.json',
'fixtures/3/collection.json',
'fixtures/3/collection_of_collections.json'
'fixtures/3/collection_of_collections.json',
'fixtures/3/version2image.json'
]:
with open(good, 'r') as fh:
data = fh.read()
j = json.loads(v.check_manifest(data, '3.0'))
if j['okay'] != 1:
self.printValidationerror(good, j['errorList'])

self.assertEqual(j['okay'], 1)

for bad_data in ['fixtures/3/broken_simple_image.json',
'fixtures/3/broken_choice.json']:
'fixtures/3/broken_choice.json',
'fixtures/3/broken_collection.json']:
with open(bad_data, 'r') as fh:

data = fh.read()
j = json.loads(v.check_manifest(data, '3.0'))

if j['okay'] == 1:
print ("Expected {} to fail validation but it passed....".format(bad_data))

self.assertEqual(j['okay'], 0)


def printValidationerror(self, filename, errors):
print ('Failed to validate: {}'.format(filename))
errorCount = 1
for err in errors:
print(err['title'])
if 'description' in err:
print (' Test description: {}'.format(err['description']))
print('\n Path for error: {}'.format(err['path']))
print('\n Context: {}'.format(err['context']))
errorCount += 1

if __name__ == '__main__':
unittest.main()

0 comments on commit 0dd6bc6

Please sign in to comment.