Describe the bug
For some reason, all of my fields are set as nullable, using strict-nullable
dosen't change anything. This migh well be my error, but after spending much time trying endless combinations of settings, I resorted to opening a bug report.
To Reproduce
Example schema:
openapi: 3.0.0
components:
schemas:
ParentCompany:
description: A parent company record
type: object
properties:
id:
type: integer
nullable: true
name:
type: string
Used commandline:
$ datamodel-codegen --input ./src/tvdb/swagger.yml --input-file-type openapi --output ./src/tvdb/generated_models.py --output-model-type pydantic_v2.BaseModel
pyprohect.toml
:
[tool.datamodel-codegen]
field-constraints = true
snake-case-field = true
target-python-version = "3.12"
use-default-kwarg = true
use-exact-imports = true
use-field-description = true
use-union-operator = true
reuse-model = true
output-model-type = "pydantic_v2.BaseModel"
custom-file-header = "# ruff: noqa: D101 # Allow missing docstrings"
field-include-all-keys = true
strict-nullable = false # or true, dosen't change anything
Expected output
# ruff: noqa: D101 # Allow missing docstrings
from __future__ import annotations
from pydantic import BaseModel
class ParentCompany(BaseModel):
id: int | None = None
name: str
Actual output
# ruff: noqa: D101 # Allow missing docstrings
from __future__ import annotations
from pydantic import BaseModel
class ParentCompany(BaseModel):
id: int | None = None
name: str | None = None
Version:
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