Skip to content

Commit 2268f04

Browse files
committed
Fixed pydantic model as NO_BODY_METHOD args
1 parent 470cbaf commit 2268f04

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

fastopenapi/resolution/resolver.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic import create_model
1010
from pydantic_core import PydanticUndefined
1111

12-
from fastopenapi.core.constants import ParameterSource
12+
from fastopenapi.core.constants import NO_BODY_METHODS, ParameterSource
1313
from fastopenapi.core.dependency_resolver import dependency_resolver
1414
from fastopenapi.core.params import (
1515
BaseParam,
@@ -59,14 +59,15 @@ def _get_signature(cls, endpoint) -> MappingProxyType[str, inspect.Parameter]:
5959
def resolve(cls, endpoint: Callable, request_data: RequestData) -> dict[str, Any]:
6060
"""Resolve all parameters for an endpoint"""
6161
params = cls._get_signature(endpoint)
62+
method = getattr(endpoint, "__route_meta__", {}).get("method")
6263
kwargs = {}
6364

6465
# Resolve dependencies first
6566
kwargs.update(cls._resolve_dependencies(endpoint, request_data))
6667

6768
# Process regular parameters
6869
regular_kwargs, model_fields, model_values = cls._process_parameters(
69-
params, request_data
70+
params, request_data, method=method
7071
)
7172
kwargs.update(regular_kwargs)
7273

@@ -84,14 +85,15 @@ async def resolve_async(
8485
cls, endpoint: Callable, request_data: RequestData
8586
) -> dict[str, Any]:
8687
params = cls._get_signature(endpoint)
88+
method = getattr(endpoint, "__route_meta__", {}).get("method")
8789
kwargs = {}
8890

8991
# Async dependencies
9092
kwargs.update(await cls._resolve_dependencies_async(endpoint, request_data))
9193

9294
# Sync parameters
9395
regular_kwargs, model_fields, model_values = cls._process_parameters(
94-
params, request_data
96+
params, request_data, method=method
9597
)
9698
kwargs.update(regular_kwargs)
9799

@@ -131,6 +133,7 @@ def _process_parameters(
131133
cls,
132134
params: MappingProxyType[str, inspect.Parameter],
133135
request_data: RequestData,
136+
method: str | None = None,
134137
) -> tuple[dict[str, Any], dict[str, tuple], dict[str, Any]]:
135138
"""Process all endpoint parameters"""
136139
regular_kwargs = {}
@@ -144,7 +147,9 @@ def _process_parameters(
144147

145148
# Handle Pydantic models separately (direct validation without wrapper)
146149
if cls._is_pydantic_model(param.annotation):
147-
source = cls._determine_source(name, param, request_data.path_params)
150+
source = cls._determine_source(
151+
name, param, request_data.path_params, method
152+
)
148153
data = (
149154
request_data.body
150155
if source == ParameterSource.BODY
@@ -214,7 +219,10 @@ def _process_single_parameter(
214219

215220
@staticmethod
216221
def _determine_source(
217-
name: str, param: inspect.Parameter, path_params: dict[str, Any]
222+
name: str,
223+
param: inspect.Parameter,
224+
path_params: dict[str, Any],
225+
method: str | None = None,
218226
) -> ParameterSource:
219227
"""Determine where to extract parameter from using param classes"""
220228
# Check Body and its subclasses first (Form, File)
@@ -235,6 +243,8 @@ def _determine_source(
235243
elif name in path_params:
236244
return ParameterSource.PATH
237245
elif ParameterResolver._is_pydantic_model(param.annotation):
246+
if method and method.upper() in NO_BODY_METHODS:
247+
return ParameterSource.QUERY
238248
return ParameterSource.BODY
239249
else:
240250
return ParameterSource.QUERY

0 commit comments

Comments
 (0)