Debian Codegraph @

tests/test_openapi_model_description_trim_on_formfeed.py

raw
1 from fastapi import FastAPI
2 from fastapi.testclient import TestClient
3 from pydantic import BaseModel
4
5 app = FastAPI()
6
7
8 class MyModel(BaseModel):
9 """
10 A model with a form feed character in the title.
11 \f
12 Text after form feed character.
13 """
14
15
16 @app.get("/foo")
17 def foo(v: MyModel): # pragma: no cover
18 pass
19
20
21 client = TestClient(app)
22
23
24 def test_openapi():
25 response = client.get("/openapi.json")
26 assert response.status_code == 200, response.text
27 openapi_schema = response.json()
28
29 assert openapi_schema["components"]["schemas"]["MyModel"]["description"] == (
30 "A model with a form feed character in the title.\n"
31 )