Datamodel-code-generator: Pydantic "Field" class not being imported when using the --snake-case-field option

Created on 23 Jan 2021  路  2Comments  路  Source: koxudaxi/datamodel-code-generator

Example:

echo "{\"petName\": \"Lady\"}" | datamodel-codegen \
    --disable-timestamp \
    --field-constraints \
    --snake-case-field \
    --input-file-type json \
    --target-python-version 3.8 \
    --class-name Pet
````

Output:
```python
# generated by datamodel-codegen:
#   filename:  <stdin>

from __future__ import annotations

from pydantic import BaseModel


class Pet(BaseModel):
    pet_name: str = Field(..., alias='petName')

The output should be:

# <...>
from pydantic import BaseModel, Field
# <...>

Version:

  • OS: Debian Buster
  • Python version: 3.8
  • datamodel-code-generator version: 0.6.24
released

Most helpful comment

@koxudaxi thanks a lot for the quick response. I've updated datamodel-code-generator to the latest version (0.6.26) and now this issue seems to be solved. I believe we can close this issue.

All 2 comments

@CarlosDomingues
Thank you for creating this issue.
I have released a fixed version as 0.6.25 馃殌

@koxudaxi thanks a lot for the quick response. I've updated datamodel-code-generator to the latest version (0.6.26) and now this issue seems to be solved. I believe we can close this issue.

Was this page helpful?
0 / 5 - 0 ratings