From fd95dbefbc84ec052091acb4d58d62293088c416 Mon Sep 17 00:00:00 2001 From: Johnny Date: Sun, 8 Jun 2025 21:11:04 +0800 Subject: [PATCH] fix: Add 'utf-8' encoding to output .ts open calls to prevent UnicodeDecodeError --- pydantic2ts/cli/script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydantic2ts/cli/script.py b/pydantic2ts/cli/script.py index 76fc9a9..7f04a10 100644 --- a/pydantic2ts/cli/script.py +++ b/pydantic2ts/cli/script.py @@ -208,7 +208,7 @@ def _clean_output_file(output_filename: str) -> None: By rolling them all up into a single model, we can generate a single output file. 2. Add a banner comment with clear instructions for regenerating the typescript definitions. """ - with open(output_filename, "r") as f: + with open(output_filename, "r", encoding="utf-8") as f: lines = f.readlines() start, end = None, None @@ -233,7 +233,7 @@ def _clean_output_file(output_filename: str) -> None: new_lines = banner_comment_lines + lines[:start] + lines[(end + 1) :] - with open(output_filename, "w") as f: + with open(output_filename, "w", encoding="utf-8") as f: f.writelines(new_lines)