@@ -338,6 +338,7 @@ def fetch_schema(self, fetchSchemaParam: FetchSchemaParam = None) -> None:
338338 --use-title-as-name \
339339 --use-schema-description \
340340 --use-field-description \
341+ --encoding utf-8 \
341342 "
342343 )
343344 # see https://koxudaxi.github.io/datamodel-code-generator/
@@ -354,7 +355,7 @@ def fetch_schema(self, fetchSchemaParam: FetchSchemaParam = None) -> None:
354355 # idealy solved by custom templates in the future: https://github.com/koxudaxi/datamodel-code-generator/issues/860
355356
356357 content = ""
357- with open (temp_model_path , "r" ) as f :
358+ with open (temp_model_path , "r" , encoding = "utf-8" ) as f :
358359 content = f .read ()
359360 os .remove (temp_model_path )
360361
@@ -402,12 +403,12 @@ def fetch_schema(self, fetchSchemaParam: FetchSchemaParam = None) -> None:
402403 r"UUID = Field(default_factory=uuid4" ,
403404 content ,
404405 ) # enable default value for uuid
405- with open (result_model_path , "w" ) as f :
406+ with open (result_model_path , "w" , encoding = "utf-8" ) as f :
406407 f .write (content )
407408
408409 if fetchSchemaParam .mode == "append" :
409410 org_content = ""
410- with open (result_model_path , "r" ) as f :
411+ with open (result_model_path , "r" , encoding = "utf-8" ) as f :
411412 org_content = f .read ()
412413
413414 pattern = re .compile (
@@ -428,7 +429,7 @@ def fetch_schema(self, fetchSchemaParam: FetchSchemaParam = None) -> None:
428429 r"(from __future__ import annotations)" , "" , content , 1
429430 ) # remove import statement
430431 # print(content)
431- with open (result_model_path , "a" ) as f :
432+ with open (result_model_path , "a" , encoding = "utf-8" ) as f :
432433 f .write (content )
433434
434435 importlib .reload (model ) # reload the updated module
0 commit comments