INNER CODE UNIT · Python
_clean_output_file
phillipdupuis/pydantic-to-typescript · pydantic2ts/cli/script.py:202
def _clean_output_file(output_filename: str) -> None:
"""
Clean up the resulting typescript definitions via the following steps:
1. Remove the "_Master_" model.
It exists solely to serve as a namespace for the target models.
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:
lines = f.readlines()
start, end = None, None
for i, line in enumerate(lines):
if line.rstrip("\r\n") == "export interface _Master_ {":
start = i
elif (start is not None) and line.rstrip("\r\n") == "}":
end = i