diff --git a/iiif_prezi3/helpers/auto_fields.py b/iiif_prezi3/helpers/auto_fields.py index 727f7b8..8860f43 100644 --- a/iiif_prezi3/helpers/auto_fields.py +++ b/iiif_prezi3/helpers/auto_fields.py @@ -181,6 +181,6 @@ def __init__(self): # Set up some obvious defaults ai.register_on_class(AnnotationPage, Class) al.register_on_class(KeyValueString, Class, Reference) -ait.register_on_class(Canvas, Range) +ait.register_on_class(Canvas, Range, AnnotationPage) alst.register_on_class(Class, AnnotationPage, ResourceItem, ServiceItem1, NavPlace, Reference, ProviderItem) allst.register_on_class(HomepageItem) diff --git a/iiif_prezi3/skeleton.py b/iiif_prezi3/skeleton.py index ccc860c..eca87b9 100644 --- a/iiif_prezi3/skeleton.py +++ b/iiif_prezi3/skeleton.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: iiif_3_0.json -# timestamp: 2023-02-17T13:09:25+00:00 +# timestamp: 2023-06-01T15:24:07+00:00 from __future__ import annotations @@ -56,7 +56,7 @@ class ViewingDirection(Base): class Id(Base): - __root__: AnyUrl = Field(..., title='Id must be presesnt and must be a URI') + __root__: AnyUrl = Field(..., title='Id must be present and must be a URI') class LngString(Base): @@ -94,13 +94,33 @@ class Format(Base): __root__: constr(regex=r'^[a-z][a-z]*/.*$') -class AnnoSelectorItem(Base): +class SelectorItem(Base): type: str - t: Optional[Duration] = None + t: Duration -class AnnoSelector(Base): - __root__: Union[AnyUrl, AnnoSelectorItem] +class SelectorItem1(Base): + type: constr(regex=r'^FragmentSelector$') = 'FragmentSelector' + conformsTo: AnyUrl = 'http://www.w3.org/TR/media-frags/' + value: Any + + +class SelectorItem2(Base): + type: constr(regex=r'^SvgSelector$') = 'SvgSelector' + value: Any + + +class SelectorItem3(Base): + type: constr(regex=r'^ImageApiSelector$') = 'ImageApiSelector' + region: Optional[Any] = None + size: Optional[Any] = None + rotation: Optional[Any] = None + quality: Optional[Any] = None + format: Optional[Any] = None + + +class Selector(Base): + __root__: Union[AnyUrl, SelectorItem, SelectorItem1, SelectorItem2, SelectorItem3] class NavPlace(Base): @@ -142,8 +162,8 @@ class SpecificResource(Base): type: constr(regex=r'^SpecificResource$') = 'SpecificResource' format: Optional[Format] = None accessibility: Optional[str] = None - source: Id - selector: Union[AnnoSelector, List[AnnoSelector]] + source: Union[Id, Class] + selector: Union[Selector, List[Selector]] class HomepageItem(Class): @@ -165,6 +185,7 @@ class PartOf(Base): class Item(Class): type: constr(regex=r'^Canvas$') = 'Canvas' + items: List class SeeAlso(Base): @@ -179,18 +200,15 @@ class Model(Base): __root__: Union[Manifest, Collection, AnnotationPage] -class AnnotationPage(Base): - class Config: - extra = Extra.forbid - - context: Optional[Any] = Field(None, alias='@context') +class AnnotationPage(Class): + context: Optional[Union[List[AnyUrl], str]] = Field(None, alias='@context') id: Id type: constr(regex=r'^AnnotationPage$') = 'AnnotationPage' rendering: Optional[External] = None label: Optional[LngString] = None service: Optional[Service] = None thumbnail: Optional[List[Resource]] = None - items: Optional[List[Annotation]] = None + items: List[Annotation] class Collection(Class): @@ -217,7 +235,7 @@ class Collection(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: Optional[List[Union[ManifestRef, CollectionRef, Collection]]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class Manifest(Class): @@ -246,7 +264,7 @@ class Manifest(Class): partOf: Optional[PartOf] = None items: Optional[List[Canvas]] = None structures: Optional[List[Range]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class AccompanyingCanvas(Class): @@ -269,7 +287,7 @@ class AccompanyingCanvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class BodyItem(Choice): @@ -308,7 +326,7 @@ class Canvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class PlaceholderCanvas(Class): @@ -331,7 +349,7 @@ class PlaceholderCanvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class ProviderItem(Class): @@ -352,9 +370,9 @@ class Range(Class): service: Optional[Service] = None placeholderCanvas: Optional[PlaceholderCanvas] = None accompanyingCanvas: Optional[AccompanyingCanvas] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None thumbnail: Optional[List[Resource]] = None - items: List[Union[SpecificResource, Item, Range, CanvasRef, RangeRef]] + items: List[Union[SpecificResource, Item, Range, CanvasRef]] class ResourceItem(Base): @@ -369,7 +387,7 @@ class ResourceItem(Base): format: Optional[Format] = None label: Optional[LngString] = None thumbnail: Optional[List[Resource]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class Resource(Base): @@ -396,29 +414,37 @@ class AnnotationCollection(Class): type: constr(regex=r'^AnnotationCollection$') = 'AnnotationCollection' rendering: Optional[External] = None partOf: Optional[PartOf] = None - next: Optional[AnnotationPage] = None - first: Optional[AnnotationPage] = None - last: Optional[AnnotationPage] = None + next: Optional[AnnotationPageRef] = None + first: Optional[AnnotationPageRef] = None + last: Optional[AnnotationPageRef] = None service: Optional[Service] = None thumbnail: Optional[List[Resource]] = None items: Optional[List[Annotation]] = None class Reference(Base): + class Config: + extra = Extra.allow + id: Id - label: LngString + label: Optional[LngString] = None type: constr( regex=r'^Manifest$|^AnnotationPage$|^Collection$|^AnnotationCollection$|^Canvas$|^Range$' ) thumbnail: Optional[List[Resource]] = None +class AnnotationPageRef(Reference): + type: Optional[constr(regex=r'^AnnotationPage$')] = None + + class CollectionRef(Reference): type: Optional[constr(regex=r'^Collection$')] = None + label: LngString class ManifestRef(Reference): - type: Optional[constr(regex=r'^Manifest$')] = None + type: constr(regex=r'^Manifest$') = 'Manifest' class Config: extra = Extra.allow @@ -446,3 +472,4 @@ class RangeRef(Reference): ResourceItem.update_forward_refs() ServiceItem.update_forward_refs() ServiceItem1.update_forward_refs() +AnnotationCollection.update_forward_refs() diff --git a/utils/modify_skeleton.py b/utils/modify_skeleton.py index 4eeffc9..4546a45 100644 --- a/utils/modify_skeleton.py +++ b/utils/modify_skeleton.py @@ -2,9 +2,16 @@ { "description": "Allow extra properties on ManifestRef", "type": "insert", - "before": "class ManifestRef(Reference):\n type: Optional[constr(regex=r'^Manifest$')] = None\n", + "before": "class ManifestRef(Reference):\n type: constr(regex=r'^Manifest$') = 'Manifest'\n", "after": "\n\nclass CanvasRef(Reference):", "data": "\n class Config:\n extra = Extra.allow\n" + }, + { + "description": "Re-add RangeRef", + "type": "insert", + "before": "class CanvasRef(Reference):\n type: Optional[constr(regex=r'^Canvas$')] = None\n", + "after": "\n\nModel.update_forward_refs()", + "data": "\n\nclass RangeRef(Reference):\n type: Optional[constr(regex=r'^Range$')] = None\n" } ]