Create your own custom code formatters for specialized formatting needs.
Pass the module path containing your formatter class:
datamodel-codegen --input {your_input_file} --output {your_output_file} --custom-formatters "{path_to_your_module}.your_module"from datamodel_code_generator.format import CustomCodeFormatter
class CodeFormatter(CustomCodeFormatter):
def apply(self, code: str) -> str:
# Apply your custom formatting here
# For example, add a custom header comment:
header = "# This code was formatted by custom formatter\n"
return header + codedatamodel-codegen --input schema.json --output model.py --custom-formatters "mypackage.your_module"You can pass keyword arguments to your custom formatter using --custom-formatters-kwargs:
datamodel-codegen --input schema.json --output model.py \
--custom-formatters "mypackage.your_module" \
--custom-formatters-kwargs '{"line_length": 100}'- 🖥️ CLI Reference:
--custom-formatters- Detailed CLI option documentation - 🔧 CLI Reference:
--custom-formatters-kwargs- Pass arguments to custom formatters - 🖌️ Formatting - Built-in code formatting with black and isort