Skip to content

Commit 1cced56

Browse files
committed
Generate empty ts file with missing pydantic models
1 parent e8abcba commit 1cced56

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pydantic2ts/cli/script.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ def clean_output_file(output_filename: str) -> None:
101101
with open(output_filename, "r") as f:
102102
lines = f.readlines()
103103

104-
start, end = None, None
105-
for i, line in enumerate(lines):
106-
if line.rstrip("\r\n") == "export interface _Master_ {":
107-
start = i
108-
elif (start is not None) and line.rstrip("\r\n") == "}":
109-
end = i
110-
break
104+
start, end = 0, 0
105+
if len(lines) > 1:
106+
for i, line in enumerate(lines):
107+
if line.rstrip("\r\n") == "export interface _Master_ {":
108+
start = i
109+
elif (start is not None) and line.rstrip("\r\n") == "}":
110+
end = i
111+
break
111112

112113
banner_comment_lines = [
113114
"/* tslint:disable */\n",
@@ -118,7 +119,10 @@ def clean_output_file(output_filename: str) -> None:
118119
"*/\n\n",
119120
]
120121

121-
new_lines = banner_comment_lines + lines[:start] + lines[(end + 1) :]
122+
try:
123+
new_lines = banner_comment_lines + lines[:start] + lines[(end + 1) :]
124+
except TypeError as err:
125+
raise TypeError(f"{err}: output_filename: {output_filename}; {lines}")
122126

123127
with open(output_filename, "w") as f:
124128
f.writelines(new_lines)

0 commit comments

Comments
 (0)