Home / File/ test_optional_list.py — fastapi Source File

test_optional_list.py — fastapi Source File

Architecture documentation for test_optional_list.py, a python file in the fastapi codebase. 6 imports, 0 dependents.

File python FastAPI Applications 6 imports 24 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  ab9ca345_fca0_14e6_b530_7d9da4ee783c["test_optional_list.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  ab9ca345_fca0_14e6_b530_7d9da4ee783c --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style ab9ca345_fca0_14e6_b530_7d9da4ee783c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated, Optional

import pytest
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, Field

app = FastAPI()

# =====================================================================================
# Without aliases


@app.get("/optional-list-str")
async def read_optional_list_str(
    p: Annotated[Optional[list[str]], Header()] = None,
):
    return {"p": p}


class HeaderModelOptionalListStr(BaseModel):
    p: Optional[list[str]] = None


@app.get("/model-optional-list-str")
async def read_model_optional_list_str(
    p: Annotated[HeaderModelOptionalListStr, Header()],
):
    return {"p": p.p}


@pytest.mark.parametrize(
    "path",
    ["/optional-list-str", "/model-optional-list-str"],
)
def test_optional_list_str_schema(path: str):
    assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
        [
            {
                "required": False,
                "schema": {
                    "anyOf": [
                        {"items": {"type": "string"}, "type": "array"},
                        {"type": "null"},
                    ],
                    "title": "P",
                },
                "name": "p",
                "in": "header",
            }
        ]
    )


@pytest.mark.parametrize(
    "path",
    ["/optional-list-str", "/model-optional-list-str"],
)
def test_optional_list_str_missing(path: str):
// ... (295 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_optional_list.py do?
test_optional_list.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_optional_list.py?
test_optional_list.py defines 24 function(s): read_model_optional_list_alias, read_model_optional_list_alias_and_validation_alias, read_model_optional_list_str, read_model_optional_list_validation_alias, read_optional_list_alias, read_optional_list_alias_and_validation_alias, read_optional_list_str, read_optional_list_validation_alias, test_optional_list_alias_and_validation_alias_by_alias, test_optional_list_alias_and_validation_alias_by_name, and 14 more.
What does test_optional_list.py depend on?
test_optional_list.py imports 6 module(s): __init__.py, inline_snapshot, pydantic, pytest, testclient.py, typing.
Where is test_optional_list.py in the architecture?
test_optional_list.py is located at tests/test_request_params/test_header/test_optional_list.py (domain: FastAPI, subdomain: Applications, directory: tests/test_request_params/test_header).

Analyze Your Own Codebase

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

Try Supermodel Free