-
-
Notifications
You must be signed in to change notification settings - Fork 422
Closed
Description
Describe the bug
When using custom base model class, empty models assigned instead of generated with "pass".
This leads to TypeError if there is a model subclassing two empty models.
E TypeError: duplicate base class MyBaseModel
EmptyDummySchema = MyBaseModel
EmptyDummySchema2 = MyBaseModel
class ReferenceOnlyEmptySchemas(EmptyDummySchema, EmptyDummySchema2):
pass
To Reproduce
Example schema:
EmptyDummySchema:
description: Just for reference and test that it'll be removed in merged interface.
type: object
EmptyDummySchema2:
description: Just for reference and test that it'll be removed in merged interface.
type: object
ReferenceOnlyEmptySchemas:
allOf:
- $ref: '#/components/schemas/EmptyDummySchema'
- $ref: '#/components/schemas/EmptyDummySchema2'
Expected behavior
Keep generating empty models as before
class EmptyDummySchema(MyBaseModel):
pass
class EmptyDummySchema2(MyBaseModel):
pass
** Additional context **
This might be related to https://github.com/koxudaxi/datamodel-code-generator/pull/2376/files
I suppose that the template should account for custom base classes, not only BaseModel:
[src/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2]
{% if base_class != "BaseModel" and "," not in base_class and not fields and not config -%}
Metadata
Metadata
Assignees
Labels
No labels