test_custom_schema_fields.py — fastapi Source File
Architecture documentation for test_custom_schema_fields.py, a python file in the fastapi codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6745b130_5470_fa85_bd15_d4b15840f1c8["test_custom_schema_fields.py"] 0dda2280_3359_8460_301c_e98c77e78185["typing"] 6745b130_5470_fa85_bd15_d4b15840f1c8 --> 0dda2280_3359_8460_301c_e98c77e78185 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 6745b130_5470_fa85_bd15_d4b15840f1c8 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 6745b130_5470_fa85_bd15_d4b15840f1c8 --> a7c04dee_ee23_5891_b185_47ff6bed036d 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 6745b130_5470_fa85_bd15_d4b15840f1c8 --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style 6745b130_5470_fa85_bd15_d4b15840f1c8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Annotated, Optional
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, WithJsonSchema
app = FastAPI()
class Item(BaseModel):
name: str
description: Annotated[
Optional[str], WithJsonSchema({"type": ["string", "null"]})
] = None
model_config = {
"json_schema_extra": {
"x-something-internal": {"level": 4},
}
}
@app.get("/foo", response_model=Item)
def foo():
return {"name": "Foo item"}
client = TestClient(app)
item_schema = {
"title": "Item",
"required": ["name"],
"type": "object",
"x-something-internal": {
"level": 4,
},
"properties": {
"name": {
"title": "Name",
"type": "string",
},
"description": {
"title": "Description",
"type": ["string", "null"],
},
},
}
def test_custom_response_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json()["components"]["schemas"]["Item"] == item_schema
def test_response():
# For coverage
response = client.get("/foo")
assert response.status_code == 200, response.text
assert response.json() == {"name": "Foo item", "description": None}
Domain
Subdomains
Classes
Dependencies
- __init__.py
- pydantic
- testclient.py
- typing
Source
Frequently Asked Questions
What does test_custom_schema_fields.py do?
test_custom_schema_fields.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_custom_schema_fields.py?
test_custom_schema_fields.py defines 3 function(s): foo, test_custom_response_schema, test_response.
What does test_custom_schema_fields.py depend on?
test_custom_schema_fields.py imports 4 module(s): __init__.py, pydantic, testclient.py, typing.
Where is test_custom_schema_fields.py in the architecture?
test_custom_schema_fields.py is located at tests/test_custom_schema_fields.py (domain: FastAPI, subdomain: Responses, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free