Describe the bug
A same schema reference used in an allOf block results in a different class name from a schema reference not in an allOf block.
To Reproduce
Example schema:
openapi: 3.0.0
components:
schemas:
ACHClass:
type: string
title: ACHClass
enum:
- ccd
Foo:
type: object
properties:
ach_class:
$ref: '#/components/schemas/ACHClass'
Bar:
type: object
properties:
ach_class:
allOf:
- $ref: '#/components/schemas/ACHClass'
Used commandline:
$ datamodel-codegen --input test_schema.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --target-python-version 3.14 --enum-field-as-literal all
Expected behavior
the output of the above command is
# generated by datamodel-codegen:
# filename: test_schema.yaml
# timestamp: 2026-01-02T15:59:18+00:00
from typing import Literal
from pydantic import BaseModel, Field, RootModel
class ACHClass(RootModel[Literal['ccd']]):
root: Literal['ccd'] = Field(..., title='ACHClass')
class Foo(BaseModel):
ach_class: ACHClass | None = None
class AchClass(RootModel[ACHClass]):
root: ACHClass
class Bar(BaseModel):
ach_class: AchClass | None = None
I did not expect a subclass AchClass.
Version:
- OS: Mac OS 15.7.1
- Python version: 3.14.2
- datamodel-code-generator version: 0.51.0
Additional context
Add any other context about the problem here.
Describe the bug
A same schema reference used in an allOf block results in a different class name from a schema reference not in an allOf block.
To Reproduce
Example schema:
Used commandline:
Expected behavior
the output of the above command is
I did not expect a subclass AchClass.
Version:
Additional context
Add any other context about the problem here.