Home / Function/ test_typeadapter() — fastapi Function Reference

test_typeadapter() — fastapi Function Reference

Architecture documentation for the test_typeadapter() function in test_arbitrary_types.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  891a5008_a4f5_97df_f4a8_dc3f3026f083["test_typeadapter()"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088["test_arbitrary_types.py"]
  891a5008_a4f5_97df_f4a8_dc3f3026f083 -->|defined in| 0a65a3af_f6dc_1275_2ed7_2fa9f4e69088
  style 891a5008_a4f5_97df_f4a8_dc3f3026f083 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_arbitrary_types.py lines 48–89

def test_typeadapter():
    # This test is only to confirm that Pydantic alone is working as expected
    from pydantic import (
        BaseModel,
        ConfigDict,
        PlainSerializer,
        TypeAdapter,
        WithJsonSchema,
    )

    class FakeNumpyArray:
        def __init__(self):
            self.data = [1.0, 2.0, 3.0]

    FakeNumpyArrayPydantic = Annotated[
        FakeNumpyArray,
        WithJsonSchema(TypeAdapter(list[float]).json_schema()),
        PlainSerializer(lambda v: v.data),
    ]

    class MyModel(BaseModel):
        model_config = ConfigDict(arbitrary_types_allowed=True)
        custom_field: FakeNumpyArrayPydantic

    ta = TypeAdapter(MyModel)
    assert ta.dump_python(MyModel(custom_field=FakeNumpyArray())) == {
        "custom_field": [1.0, 2.0, 3.0]
    }
    assert ta.json_schema() == snapshot(
        {
            "properties": {
                "custom_field": {
                    "items": {"type": "number"},
                    "title": "Custom Field",
                    "type": "array",
                }
            },
            "required": ["custom_field"],
            "title": "MyModel",
            "type": "object",
        }
    )

Domain

Subdomains

Frequently Asked Questions

What does test_typeadapter() do?
test_typeadapter() is a function in the fastapi codebase, defined in tests/test_arbitrary_types.py.
Where is test_typeadapter() defined?
test_typeadapter() is defined in tests/test_arbitrary_types.py at line 48.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free