Describe the bug
When generating the example below, the generated models file contains a class with the name Datum, which is not mentioned in the source models.
class Datum(BaseModel):
property_1: UUID | None = Field(
None, description="Unique identifier for the installation."
)
property_2: str | None = Field(None, description="Description of the installation.")
property_3: AwareDatetime | None = Field(
None, description="Timestamp when the installation was created."
)
The Datum class is an exact duplicate of the DataType class. The PaginatedDataTypeList model unexpectedly wraps the Datum model in stead of the DataType model.
To Reproduce
Example schema:
components:
schemas:
Collection-Wrapper:
description: Generic response wrapper containing a collection of items and pagination metadata.
type: object
required:
- data
- pagination
properties:
data:
description: Array of items in the collection.
type: array
items:
type: object
pagination:
description: Pagination metadata for the collection.
$ref: "#/components/schemas/Metadata"
DataType:
type: object
required:
- id
properties:
property_1:
type: string
format: uuid
readOnly: true
description: Unique identifier for the installation.
property_2:
type: string
description: Description of the installation.
property_3:
type: string
format: date-time
readOnly: true
description: Timestamp when the installation was created.
PaginatedDataTypeList:
allOf:
- properties:
data:
type: array
items:
$ref: "#/components/schemas/DataType"
- $ref: "#/components/schemas/Collection-Wrapper"
Metadata:
type: object
required:
- limit
- page
properties:
limit:
type: integer
minimum: 1
maximum: 100
description: Number of data types returned in this response
example: 20
page:
type: integer
minimum: 1
description: The page number to retrieve
example: 2
Used commandline:
Used pyproject.toml for config with following options
[tool.datamodel-codegen]
input = "openapi.yaml"
output = "src/views/models.py"
output-model-type = "pydantic_v2.BaseModel"
input-file-type = "openapi"
formatters = ["ruff-check", "ruff-format"]
use-schema-description = true
use-title-as-name = true
field-constraints = true
snake-case-field = true
use-standard-collections = true
use-union-operator = true
disable-timestamp = true
use-type-alias = true
Expected behavior
The generated PaginatedDataTypeList model should wrap the DataType model, in stead of the Datum model and the Datum model should not be generated.
Version:
- OS: Windows 11 PRO
- Python version: 3.13.11
- datamodel-code-generator version: 0.52.2
Additional context
Generated output
# generated by datamodel-codegen:
# filename: openapi.yaml
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from pydantic import AwareDatetime, BaseModel, Field
if TYPE_CHECKING:
from uuid import UUID
class DataType(BaseModel):
property_1: UUID | None = Field(
None, description="Unique identifier for the installation."
)
property_2: str | None = Field(None, description="Description of the installation.")
property_3: AwareDatetime | None = Field(
None, description="Timestamp when the installation was created."
)
class Datum(BaseModel):
property_1: UUID | None = Field(
None, description="Unique identifier for the installation."
)
property_2: str | None = Field(None, description="Description of the installation.")
property_3: AwareDatetime | None = Field(
None, description="Timestamp when the installation was created."
)
class Metadata(BaseModel):
limit: int = Field(
...,
description="Number of data types returned in this response",
examples=[20],
ge=1,
le=100,
)
page: int = Field(
..., description="The page number to retrieve", examples=[2], ge=1
)
class CollectionWrapper(BaseModel):
"""
Generic response wrapper containing a collection of items and pagination metadata.
"""
data: list[dict[str, Any]] = Field(
..., description="Array of items in the collection."
)
pagination: Metadata = Field(
..., description="Pagination metadata for the collection."
)
class PaginatedDataTypeList(CollectionWrapper):
data: list[Datum] | None = Field(
None, description="Array of items in the collection."
)
Describe the bug
When generating the example below, the generated models file contains a class with the name
Datum, which is not mentioned in the source models.The Datum class is an exact duplicate of the
DataTypeclass. The PaginatedDataTypeList model unexpectedly wraps theDatummodel in stead of theDataTypemodel.To Reproduce
Example schema:
Used commandline:
Used pyproject.toml for config with following options
Expected behavior
The generated
PaginatedDataTypeListmodel should wrap theDataTypemodel, in stead of theDatummodel and theDatummodel should not be generated.Version:
Additional context
Generated output