(
*,
field: ModelField | None = None,
response_content: Any,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = True,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
is_coroutine: bool = True,
endpoint_ctx: EndpointContext | None = None,
dump_json: bool = False,
)
| 291 | |
| 292 | |
| 293 | async def serialize_response( |
| 294 | *, |
| 295 | field: ModelField | None = None, |
| 296 | response_content: Any, |
| 297 | include: IncEx | None = None, |
| 298 | exclude: IncEx | None = None, |
| 299 | by_alias: bool = True, |
| 300 | exclude_unset: bool = False, |
| 301 | exclude_defaults: bool = False, |
| 302 | exclude_none: bool = False, |
| 303 | is_coroutine: bool = True, |
| 304 | endpoint_ctx: EndpointContext | None = None, |
| 305 | dump_json: bool = False, |
| 306 | ) -> Any: |
| 307 | if field: |
| 308 | if is_coroutine: |
| 309 | value, errors = field.validate(response_content, {}, loc=("response",)) |
| 310 | else: |
| 311 | value, errors = await run_in_threadpool( |
| 312 | field.validate, response_content, {}, loc=("response",) |
| 313 | ) |
| 314 | if errors: |
| 315 | ctx = endpoint_ctx or EndpointContext() |
| 316 | raise ResponseValidationError( |
| 317 | errors=errors, |
| 318 | body=response_content, |
| 319 | endpoint_ctx=ctx, |
| 320 | ) |
| 321 | serializer = field.serialize_json if dump_json else field.serialize |
| 322 | return serializer( |
| 323 | value, |
| 324 | include=include, |
| 325 | exclude=exclude, |
| 326 | by_alias=by_alias, |
| 327 | exclude_unset=exclude_unset, |
| 328 | exclude_defaults=exclude_defaults, |
| 329 | exclude_none=exclude_none, |
| 330 | ) |
| 331 | |
| 332 | else: |
| 333 | return jsonable_encoder(response_content) |
| 334 | |
| 335 | |
| 336 | async def run_endpoint_function( |
no test coverage detected
searching dependent graphs…