mirror of https://github.com/tiangolo/fastapi.git
Refine response model inference logic in APIRoute
- Updated the response model inference to handle cases where the model is None or not a subclass of BaseModel or a dataclass. - Enhanced the logic to infer the response model from the endpoint function's source code when necessary, improving schema generation accuracy.
This commit is contained in:
parent
5246f7c3ad
commit
02493746e2
|
|
@ -545,11 +545,16 @@ class APIRoute(routing.Route):
|
|||
response_model = None
|
||||
else:
|
||||
response_model = return_annotation
|
||||
|
||||
if response_model is not None and not lenient_issubclass(response_model, BaseModel):
|
||||
inferred = infer_response_model_from_ast(endpoint)
|
||||
if inferred:
|
||||
response_model = inferred
|
||||
if (
|
||||
response_model is None
|
||||
or (
|
||||
not lenient_issubclass(response_model, BaseModel)
|
||||
and not dataclasses.is_dataclass(response_model)
|
||||
)
|
||||
):
|
||||
inferred = infer_response_model_from_ast(endpoint)
|
||||
if inferred:
|
||||
response_model = inferred
|
||||
|
||||
self.response_model = response_model
|
||||
self.summary = summary
|
||||
|
|
|
|||
Loading…
Reference in New Issue