Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion format
42 changes: 27 additions & 15 deletions generate_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from glob import glob
from pathlib import Path
from tempfile import NamedTemporaryFile

from datamodel_code_generator import InputFileType, generate, DataModelType
from datamodel_code_generator.model import PythonVersion
Expand All @@ -10,18 +11,29 @@
# Ensure output directory exists
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

generate(
input_=SCHEMA_DIR,
input_file_type=InputFileType.JsonSchema,
output=OUTPUT_DIR,
output_model_type=DataModelType.PydanticV2BaseModel,
target_python_version=PythonVersion.PY_312,
allow_extra_fields=False,
disable_timestamp=True,
reuse_model=True,
use_annotated=True,
field_constraints=True,
custom_class_name_generator=lambda x: x.title().replace("Ethdebug/Format/", "").replace("/", "_"),
use_exact_imports=True,

)
# Temporarily rename LICENSE file so it doesn't cause parsing issues
license_path = SCHEMA_DIR / "LICENSE"

with NamedTemporaryFile(delete=False) as tmp_file:
if license_path.exists():
license_path.rename(tmp_file.name)
temp_license_path = Path(tmp_file.name)
try:
generate(
input_=SCHEMA_DIR,
input_file_type=InputFileType.JsonSchema,
output=OUTPUT_DIR,
output_model_type=DataModelType.PydanticV2BaseModel,
target_python_version=PythonVersion.PY_312,
allow_extra_fields=False,
disable_timestamp=True,
reuse_model=True,
use_annotated=True,
field_constraints=True,
custom_class_name_generator=lambda x: x.title().replace("Ethdebug/Format/", "").replace("/", "_"),
use_exact_imports=True
)
finally:
# Restore LICENSE file
if temp_license_path.exists():
temp_license_path.rename(license_path)