Browse Source
- Extract Response subclasses from return type annotations - Include them as additional media types in OpenAPI - Preserve existing streaming (JSONL) behavior - Keep runtime behavior unchanged - Add comprehensive tests for unions, decorator response_class priority, and mixed model/response cases - Update affected OpenAPI snapshotspull/15040/head
7 changed files with 1207 additions and 104 deletions
File diff suppressed because it is too large
@ -1,17 +1,20 @@ |
|||
import importlib |
|||
|
|||
import pytest |
|||
from fastapi.exceptions import FastAPIError |
|||
|
|||
from ...utils import needs_py310 |
|||
|
|||
|
|||
# Previously, unions including `Response` in the return annotation were |
|||
# considered invalid and raised FastAPIError at import time. |
|||
# They are now supported as part of the enhanced return annotation handling. |
|||
# Importing the module should not raise FastAPIError anymore. |
|||
@pytest.mark.parametrize( |
|||
"module_name", |
|||
[ |
|||
pytest.param("tutorial003_04_py310", marks=needs_py310), |
|||
], |
|||
) |
|||
def test_invalid_response_model(module_name: str) -> None: |
|||
with pytest.raises(FastAPIError): |
|||
importlib.import_module(f"docs_src.response_model.{module_name}") |
|||
def test_response_union_with_response_is_valid(module_name: str) -> None: |
|||
module = importlib.import_module(f"docs_src.response_model.{module_name}") |
|||
assert module is not None |
|||
|
|||
Loading…
Reference in new issue