@@ -348,6 +348,14 @@ class FetchSchemaParam(BaseModel):
348348 )
349349 legacy_generator : Optional [bool ] = False
350350 """uses legacy command line for code generation if true"""
351+ offline_pages : Optional [Dict [str , WtPage ]] = None
352+ """pages to be used offline instead of fetching them from the OSW instance"""
353+ result_model_path : Optional [Union [str , pathlib .Path ]] = None
354+ """path to the generated model file, if None,
355+ the default path ./model/entity.py is used"""
356+
357+ class Config :
358+ arbitrary_types_allowed = True
351359
352360 def fetch_schema (self , fetchSchemaParam : FetchSchemaParam = None ) -> None :
353361 """Loads the given schemas from the OSW instance and auto-generates python
@@ -370,6 +378,8 @@ def fetch_schema(self, fetchSchemaParam: FetchSchemaParam = None) -> None:
370378 schema_title = schema_title ,
371379 mode = mode ,
372380 legacy_generator = fetchSchemaParam .legacy_generator ,
381+ offline_pages = fetchSchemaParam .offline_pages ,
382+ result_model_path = fetchSchemaParam .result_model_path ,
373383 )
374384 )
375385 first = False
@@ -396,6 +406,14 @@ class _FetchSchemaParam(BaseModel):
396406 )
397407 legacy_generator : Optional [bool ] = False
398408 """uses legacy command line for code generation if true"""
409+ offline_pages : Optional [Dict [str , WtPage ]] = None
410+ """pages to be used offline instead of fetching them from the OSW instance"""
411+ result_model_path : Optional [Union [str , pathlib .Path ]] = None
412+ """path to the generated model file, if None,
413+ the default path ./model/entity.py is used"""
414+
415+ class Config :
416+ arbitrary_types_allowed = True
399417
400418 def _fetch_schema (self , fetchSchemaParam : _FetchSchemaParam = None ) -> None :
401419 """Loads the given schema from the OSW instance and autogenerates python
@@ -413,11 +431,21 @@ def _fetch_schema(self, fetchSchemaParam: _FetchSchemaParam = None) -> None:
413431 schema_title = fetchSchemaParam .schema_title
414432 root = fetchSchemaParam .root
415433 schema_name = schema_title .split (":" )[- 1 ]
416- page = self .site .get_page (WtSite .GetPageParam (titles = [schema_title ])).pages [0 ]
417- if not page .exists :
418- print (f"Error: Page { schema_title } does not exist" )
419- return
420- # not only in the JsonSchema namespace the schema is located in the main sot
434+ if (
435+ fetchSchemaParam .offline_pages is not None
436+ and schema_title in fetchSchemaParam .offline_pages
437+ ):
438+ print (f"Fetch { schema_title } from offline pages" )
439+ page = fetchSchemaParam .offline_pages [schema_title ]
440+ else :
441+ print (f"Fetch { schema_title } from online pages" )
442+ page = self .site .get_page (WtSite .GetPageParam (titles = [schema_title ])).pages [
443+ 0
444+ ]
445+ if not page .exists :
446+ print (f"Error: Page { schema_title } does not exist" )
447+ return
448+ # not only in the JsonSchema namespace the schema is located in the main slot
421449 # in all other namespaces, the json_schema slot is used
422450 if schema_title .startswith ("JsonSchema:" ):
423451 schema_str = ""
@@ -441,7 +469,6 @@ def _fetch_schema(self, fetchSchemaParam: _FetchSchemaParam = None) -> None:
441469 )
442470 # fix https://github.com/koxudaxi/datamodel-code-generator/issues/1910
443471 )
444- print (f"Fetch { schema_title } " )
445472
446473 jsonpath_expr = parse ("$..dollarref" )
447474 for match in jsonpath_expr .find (schema ):
@@ -462,9 +489,10 @@ def _fetch_schema(self, fetchSchemaParam: _FetchSchemaParam = None) -> None:
462489 if (
463490 ref_schema_title != schema_title
464491 ): # prevent recursion in case of self references
465- self ._fetch_schema (
466- OSW ._FetchSchemaParam (schema_title = ref_schema_title , root = False )
467- ) # resolve references recursive
492+ _param = fetchSchemaParam .copy ()
493+ _param .root = False
494+ _param .schema_title = ref_schema_title
495+ self ._fetch_schema (_param ) # resolve references recursive
468496
469497 model_dir_path = os .path .join (
470498 os .path .dirname (os .path .abspath (__file__ )), "model"
@@ -730,6 +758,11 @@ class LoadEntityParam(BaseModel):
730758 from the jsondata."""
731759 disable_cache : bool = False
732760 """If true, disable the cache for the loading process"""
761+ offline_pages : Optional [Dict [str , WtPage ]] = None
762+ """pages to be used offline instead of fetching them from the OSW instance"""
763+
764+ class Config :
765+ arbitrary_types_allowed = True # allow any class as type
733766
734767 def __init__ (self , ** data ):
735768 super ().__init__ (** data )
@@ -795,7 +828,9 @@ def load_entity(
795828 self .site .enable_cache ()
796829
797830 entities = []
798- pages = self .site .get_page (WtSite .GetPageParam (titles = param .titles )).pages
831+ pages = self .site .get_page (
832+ WtSite .GetPageParam (titles = param .titles , offline_pages = param .offline_pages )
833+ ).pages
799834 for page in pages :
800835 entity = None
801836 schemas = []
@@ -806,7 +841,11 @@ def load_entity(
806841 if jsondata :
807842 for category in jsondata ["type" ]:
808843 schema = (
809- self .site .get_page (WtSite .GetPageParam (titles = [category ]))
844+ self .site .get_page (
845+ WtSite .GetPageParam (
846+ titles = [category ], offline_pages = param .offline_pages
847+ )
848+ )
810849 .pages [0 ]
811850 .get_slot_content ("jsonschema" )
812851 )
@@ -820,7 +859,9 @@ def load_entity(
820859 if param .autofetch_schema :
821860 self .fetch_schema (
822861 OSW .FetchSchemaParam (
823- schema_title = category , mode = "append"
862+ schema_title = category ,
863+ mode = "append" ,
864+ offline_pages = param .offline_pages ,
824865 )
825866 )
826867 if not hasattr (model , cls_name ):
@@ -1586,6 +1627,10 @@ class ExportJsonLdParams(OswBaseModel):
15861627 build_rdf_graph : Optional [bool ] = False
15871628 """If True, the output is a graph."""
15881629 debug : Optional [bool ] = False
1630+ """If True, debug information is printed."""
1631+
1632+ class Config :
1633+ arbitrary_types_allowed = True
15891634
15901635 def __init__ (self , ** data ):
15911636 super ().__init__ (** data )
0 commit comments