Skip to content

Commit ffd59db

Browse files
committed
Return 422 instead of 500 when JSON array is sent for a single Pydantic model parameter
1 parent 190c9ee commit ffd59db

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fastopenapi/resolution/resolver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,16 @@ def _is_pydantic_model(annotation) -> bool:
443443

444444
@staticmethod
445445
def _resolve_pydantic_model(
446-
model_class: type[BaseModel], data: dict[str, Any], param_name: str
446+
model_class: type[BaseModel], data: dict[str, Any] | list, param_name: str
447447
) -> BaseModel:
448448
"""Create Pydantic model instance from data"""
449449
try:
450+
if isinstance(data, list):
451+
raise ValidationError(
452+
f"Validation error for parameter '{param_name}'",
453+
"Expected JSON object, got array",
454+
)
455+
450456
if not data:
451457
data = {}
452458

0 commit comments

Comments
 (0)