Home / File/ test_schema_extra_examples.py — fastapi Source File

test_schema_extra_examples.py — fastapi Source File

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

File python FastAPI Routing 8 imports 3 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  3fe4836c_ae70_fc66_8f09_91aac47b55e8["test_schema_extra_examples.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 01c652c5_d85c_f45e_848e_412c94ea4172
  188b7cd0_ba07_6be7_094a_820e577cc47b["FastAPIDeprecationWarning"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 188b7cd0_ba07_6be7_094a_820e577cc47b
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  3fe4836c_ae70_fc66_8f09_91aac47b55e8 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 3fe4836c_ae70_fc66_8f09_91aac47b55e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Union

import pytest
from fastapi import Body, Cookie, FastAPI, Header, Path, Query
from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, ConfigDict


def create_app():
    app = FastAPI()

    class Item(BaseModel):
        data: str

        model_config = ConfigDict(
            json_schema_extra={"example": {"data": "Data in schema_extra"}}
        )

    @app.post("/schema_extra/")
    def schema_extra(item: Item):
        return item

    with pytest.warns(FastAPIDeprecationWarning):

        @app.post("/example/")
        def example(item: Item = Body(example={"data": "Data in Body example"})):
            return item

    @app.post("/examples/")
    def examples(
        item: Item = Body(
            examples=[
                {"data": "Data in Body examples, example1"},
                {"data": "Data in Body examples, example2"},
            ],
        ),
    ):
        return item

    with pytest.warns(FastAPIDeprecationWarning):

        @app.post("/example_examples/")
        def example_examples(
            item: Item = Body(
                example={"data": "Overridden example"},
                examples=[
                    {"data": "examples example_examples 1"},
                    {"data": "examples example_examples 2"},
                ],
            ),
        ):
            return item

    # TODO: enable these tests once/if Form(embed=False) is supported
    # TODO: In that case, define if File() should support example/examples too
    # @app.post("/form_example")
    # def form_example(firstname: str = Form(example="John")):
    #     return firstname
// ... (800 more lines)

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_schema_extra_examples.py do?
test_schema_extra_examples.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in test_schema_extra_examples.py?
test_schema_extra_examples.py defines 3 function(s): create_app, test_call_api, test_openapi_schema.
What does test_schema_extra_examples.py depend on?
test_schema_extra_examples.py imports 8 module(s): FastAPIDeprecationWarning, __init__.py, exceptions.py, inline_snapshot, pydantic, pytest, testclient.py, typing.
Where is test_schema_extra_examples.py in the architecture?
test_schema_extra_examples.py is located at tests/test_schema_extra_examples.py (domain: FastAPI, subdomain: Routing, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free