Coverage for tests/test_duplicate_models_openapi.py: 100%
23 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import FastAPI 1abcde
2from fastapi.testclient import TestClient 1abcde
3from pydantic import BaseModel 1abcde
5app = FastAPI() 1abcde
8class Model(BaseModel): 1abcde
9 pass 1abcde
12class Model2(BaseModel): 1abcde
13 a: Model 1abcde
16class Model3(BaseModel): 1abcde
17 c: Model 1abcde
18 d: Model2 1abcde
21@app.get("/", response_model=Model3) 1abcde
22def f(): 1abcde
23 return {"c": {}, "d": {"a": {}}} 1abcde
26client = TestClient(app) 1abcde
29def test_get_api_route(): 1abcde
30 response = client.get("/") 1abcde
31 assert response.status_code == 200, response.text 1abcde
32 assert response.json() == {"c": {}, "d": {"a": {}}} 1abcde
35def test_openapi_schema(): 1abcde
36 response = client.get("/openapi.json") 1abcde
37 assert response.status_code == 200, response.text 1abcde
38 assert response.json() == { 1abcde
39 "openapi": "3.1.0",
40 "info": {"title": "FastAPI", "version": "0.1.0"},
41 "paths": {
42 "/": {
43 "get": {
44 "summary": "F",
45 "operationId": "f__get",
46 "responses": {
47 "200": {
48 "description": "Successful Response",
49 "content": {
50 "application/json": {
51 "schema": {"$ref": "#/components/schemas/Model3"}
52 }
53 },
54 }
55 },
56 }
57 }
58 },
59 "components": {
60 "schemas": {
61 "Model": {"title": "Model", "type": "object", "properties": {}},
62 "Model2": {
63 "title": "Model2",
64 "required": ["a"],
65 "type": "object",
66 "properties": {"a": {"$ref": "#/components/schemas/Model"}},
67 },
68 "Model3": {
69 "title": "Model3",
70 "required": ["c", "d"],
71 "type": "object",
72 "properties": {
73 "c": {"$ref": "#/components/schemas/Model"},
74 "d": {"$ref": "#/components/schemas/Model2"},
75 },
76 },
77 }
78 },
79 }