Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,19 +1834,23 @@ def _get_inherited_field_type( # noqa: PLR0912
except Exception: # pragma: no cover # noqa: BLE001, S112
continue

result: DataType | None = None
if parent_schema.properties:
prop_schema = parent_schema.properties.get(prop_name)
if isinstance(prop_schema, JsonSchemaObject):
result = self._build_lightweight_type(prop_schema)
if result is not None:
return result
# In case of a missing type, continue searching up the inheritance chain
if result is not None and not (result.type == ANY or self._is_list_with_any_item_type(result)):
return result

parent_result: DataType | None = None
if parent_schema.allOf:
grandparent_refs = [self.model_resolver.add_ref(item.ref) for item in parent_schema.allOf if item.ref]
if grandparent_refs:
result = self._get_inherited_field_type(prop_name, grandparent_refs, visited)
if result is not None:
return result
parent_result = self._get_inherited_field_type(prop_name, grandparent_refs, visited)
if parent_result is not None:
return parent_result
return result

return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from pydantic import BaseModel


class Thing(BaseModel):
class Entity(BaseModel):
type_list: list[str] | None = None


class Thing(Entity):
type: str | None = 'playground:Thing'
type_list: list[str] | None = ['playground:Thing']

Expand Down
13 changes: 11 additions & 2 deletions tests/data/openapi/allof_partial_override_array_items.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
openapi: "3.0.0"
components:
schemas:
Entity:
type: object
properties:
type_list:
type: array
items:
type: string
Thing:
allOf:
- $ref: "#/components/schemas/Entity"
type: object
properties:
type:
Expand All @@ -12,7 +21,7 @@ components:
default:
- playground:Thing
items:
type: string
title: A type entry (default playground:Thing)
Person:
allOf:
- $ref: "#/components/schemas/Thing"
Expand All @@ -24,4 +33,4 @@ components:
default:
- playground:Person
items:
title: A type entry
title: A type entry (default playground:Person)
Loading