Describe the bug
When a model is generated with a custom header, importing the resulting model module causes the following error:
SyntaxError: from __future__ imports must occur at the beginning of the file
This error occurs because the from __future__
statement must appear near the top of the module (see documentation)
To Reproduce
Generate model via the provided command below using any schema:
Used commandline:
$ datamodel-codegen --input "./openapi.yml" --input-file-type openapi --output ./model.py --output-model-type pydantic_v2.BaseModel --snake-case-field --target-python-version 3.10 --use-schema-description --use-field-description --base-class CustomBaseModel --custom-file-header-path ./custom_pydantic_file_header.py
Expected behavior
Generated module could be imported without any issues.
Version:
Additional context
Consider hoisting the future statement if any custom header option is passed.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too