1515import rdflib
1616from jsonpath_ng .ext import parse
1717from mwclient .client import Site
18- from pydantic .v1 import BaseModel , PrivateAttr , create_model , validator
18+ from pydantic .v1 import BaseModel , Field , PrivateAttr , create_model , validator
1919from pyld import jsonld
2020
2121import osw .model .entity as model
@@ -93,7 +93,7 @@ def mw_site(self) -> Site:
9393 return self .site .mw_site
9494
9595 @staticmethod
96- def get_osw_id (uuid : uuid ) -> str :
96+ def get_osw_id (uuid : Union [ str , UUID ] ) -> str :
9797 """Generates a OSW-ID based on the given uuid by prefixing "OSW" and removing
9898 all '-' from the uuid-string
9999
@@ -109,7 +109,7 @@ def get_osw_id(uuid: uuid) -> str:
109109 return "OSW" + str (uuid ).replace ("-" , "" )
110110
111111 @staticmethod
112- def get_uuid (osw_id ) -> uuid :
112+ def get_uuid (osw_id : str ) -> UUID :
113113 """Returns the uuid for a given OSW-ID
114114
115115 Parameters
@@ -182,26 +182,19 @@ def sort_list_of_entities_by_class(
182182 return OSW .SortEntitiesResult (by_name = by_name , by_type = by_type )
183183
184184 class SchemaRegistration (BaseModel ):
185- """
186- dataclass param of register_schema()
187-
188- Attributes
189- ----------
190- model_cls:
191- the model class
192- schema_name:
193- the name of the schema
194- schema_bases:
195- list of base schemas (referenced by allOf)
196- """
185+ """dataclass param of register_schema()"""
197186
198187 class Config :
199188 arbitrary_types_allowed = True # allow any class as type
200189
201190 model_cls : Type [OswBaseModel ]
191+ """The model class"""
202192 schema_uuid : str # Optional[str] = model_cls.__uuid__
193+ """The schema uuid"""
203194 schema_name : str # Optional[str] = model_cls.__name__
204- schema_bases : List [str ] = ["Category:Item" ]
195+ """The schema name"""
196+ schema_bases : List [str ] = Field (default = ["Category:Item" ])
197+ """A list of base schemas (referenced by allOf)"""
205198
206199 def register_schema (self , schema_registration : SchemaRegistration ):
207200 """Registers a new or updated schema in OSW by creating the corresponding
@@ -271,25 +264,17 @@ def register_schema(self, schema_registration: SchemaRegistration):
271264 print ("Entity stored at " + page .get_url ())
272265
273266 class SchemaUnregistration (BaseModel ):
274- """
275- dataclass param of register_schema()
276-
277- Attributes
278- ----------
279- model_cls:
280- the model class
281- schema_name:
282- the name of the schema
283- schema_bases:
284- list of base schemas (referenced by allOf)
285- """
267+ """dataclass param of register_schema()"""
286268
287269 class Config :
288270 arbitrary_types_allowed = True # allow any class as type
289271
290272 model_cls : Optional [Type [OswBaseModel ]]
273+ """The model class"""
291274 model_uuid : Optional [str ]
275+ """The model uuid"""
292276 comment : Optional [str ]
277+ """The comment for the deletion, to be left behind"""
293278
294279 def unregister_schema (self , schema_unregistration : SchemaUnregistration ):
295280 """deletes the corresponding category page
@@ -1393,7 +1378,7 @@ class ExportJsonLdParams(OswBaseModel):
13931378 entities : Union [OswBaseModel , List [OswBaseModel ]]
13941379 """The entities to convert to JSON-LD. Can be a single entity or a list of
13951380 entities."""
1396- id_keys : Optional [List [str ]] = ["osw_id" ]
1381+ id_keys : Optional [List [str ]] = Field ( default = ["osw_id" ])
13971382 """The keys to use as @id in the JSON-LD output. If not found in the entity at root
13981383 level, the full page title is used."""
13991384 resolve_context : Optional [bool ] = True
0 commit comments