Skip to content

Commit aafe117

Browse files
committed
Added validator for items to check value type
1 parent 0b2a6a8 commit aafe117

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ninja_extra/schemas/response.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from ninja import Schema
55
from ninja.constants import NOT_SET
6+
from pydantic import validator
67
from pydantic.generics import GenericModel
78
from pydantic.main import BaseModel
89
from pydantic.networks import AnyHttpUrl
@@ -86,6 +87,12 @@ class NinjaPaginationResponseSchema(
8687
):
8788
items: List[T]
8889

90+
@validator("items", pre=True)
91+
def validate_items(cls, value: Any) -> Any:
92+
if value and not isinstance(value, list):
93+
return list(value)
94+
return value
95+
8996
NinjaPaginationResponseSchema.__generic_model__ = NinjaPaginationResponseSchema
9097

9198
class IdSchema(GenericModel, Generic[T], Schema):

0 commit comments

Comments
 (0)