remove duplicated code

This commit is contained in:
2026-02-06 07:30:20 -03:00
parent 30b2e1cf44
commit 26bd158c47
43 changed files with 12 additions and 2528 deletions

View File

@@ -0,0 +1,77 @@
"""
Model Generator
Orchestrates model generation from various sources to various formats.
Delegates to loaders for input and generators for output.
"""
from pathlib import Path
from typing import Dict, Type
from .generator import GENERATORS, BaseGenerator
from .loader import ConfigLoader
class ModelGenerator:
"""
Generates typed models from configuration.
This is the main entry point for model generation.
Delegates to format-specific generators.
"""
def __init__(
self,
config: ConfigLoader,
output_path: Path,
output_format: str = "pydantic",
):
"""
Initialize the generator.
Args:
config: Loaded configuration
output_path: Exact path where to write (file or directory depending on format)
output_format: Output format (pydantic, django, prisma, typescript, protobuf)
"""
self.config = config
self.output_path = Path(output_path)
self.output_format = output_format
if output_format not in GENERATORS:
raise ValueError(
f"Unknown output format: {output_format}. "
f"Available: {list(GENERATORS.keys())}"
)
self.generator = GENERATORS[output_format]()
def generate(self) -> Path:
"""
Generate models to the specified output path.
Returns:
Path to the generated file/directory
"""
# Determine output file path
if self.output_path.suffix:
# User specified a file path
output_file = self.output_path
else:
# User specified a directory, add default filename
output_file = (
self.output_path / f"__init__{self.generator.file_extension()}"
)
self.generator.generate(self.config, output_file)
print(f"Generated {self.output_format} models: {output_file}")
return output_file
@classmethod
def available_formats(cls) -> list:
"""Return list of available output formats."""
return list(GENERATORS.keys())
# Re-export for backwards compatibility
WRITERS = GENERATORS