|
4 | 4 | from sqlmodel import create_engine |
5 | 5 | from sqlmodel.pool import StaticPool |
6 | 6 |
|
7 | | -openapi_schema = { |
8 | | - "openapi": "3.1.0", |
9 | | - "info": {"title": "FastAPI", "version": "0.1.0"}, |
10 | | - "paths": { |
11 | | - "/heroes/": { |
12 | | - "get": { |
13 | | - "summary": "Read Heroes", |
14 | | - "operationId": "read_heroes_heroes__get", |
15 | | - "responses": { |
16 | | - "200": { |
17 | | - "description": "Successful Response", |
18 | | - "content": { |
19 | | - "application/json": { |
20 | | - "schema": { |
21 | | - "title": "Response Read Heroes Heroes Get", |
22 | | - "type": "array", |
23 | | - "items": {"$ref": "#/components/schemas/HeroRead"}, |
24 | | - } |
25 | | - } |
26 | | - }, |
27 | | - } |
28 | | - }, |
29 | | - }, |
30 | | - "post": { |
31 | | - "summary": "Create Hero", |
32 | | - "operationId": "create_hero_heroes__post", |
33 | | - "requestBody": { |
34 | | - "content": { |
35 | | - "application/json": { |
36 | | - "schema": {"$ref": "#/components/schemas/HeroCreate"} |
37 | | - } |
38 | | - }, |
39 | | - "required": True, |
40 | | - }, |
41 | | - "responses": { |
42 | | - "200": { |
43 | | - "description": "Successful Response", |
44 | | - "content": { |
45 | | - "application/json": { |
46 | | - "schema": {"$ref": "#/components/schemas/HeroRead"} |
47 | | - } |
48 | | - }, |
49 | | - }, |
50 | | - "422": { |
51 | | - "description": "Validation Error", |
52 | | - "content": { |
53 | | - "application/json": { |
54 | | - "schema": { |
55 | | - "$ref": "#/components/schemas/HTTPValidationError" |
56 | | - } |
57 | | - } |
58 | | - }, |
59 | | - }, |
60 | | - }, |
61 | | - }, |
62 | | - } |
63 | | - }, |
64 | | - "components": { |
65 | | - "schemas": { |
66 | | - "HTTPValidationError": { |
67 | | - "title": "HTTPValidationError", |
68 | | - "type": "object", |
69 | | - "properties": { |
70 | | - "detail": { |
71 | | - "title": "Detail", |
72 | | - "type": "array", |
73 | | - "items": {"$ref": "#/components/schemas/ValidationError"}, |
74 | | - } |
75 | | - }, |
76 | | - }, |
77 | | - "HeroCreate": { |
78 | | - "title": "HeroCreate", |
79 | | - "required": ["name", "secret_name"], |
80 | | - "type": "object", |
81 | | - "properties": { |
82 | | - "name": {"title": "Name", "type": "string"}, |
83 | | - "secret_name": {"title": "Secret Name", "type": "string"}, |
84 | | - "age": {"title": "Age", "type": "integer"}, |
85 | | - }, |
86 | | - }, |
87 | | - "HeroRead": { |
88 | | - "title": "HeroRead", |
89 | | - "required": ["id", "name", "secret_name"], |
90 | | - "type": "object", |
91 | | - "properties": { |
92 | | - "id": {"title": "Id", "type": "integer"}, |
93 | | - "name": {"title": "Name", "type": "string"}, |
94 | | - "secret_name": {"title": "Secret Name", "type": "string"}, |
95 | | - "age": {"title": "Age", "type": "integer"}, |
96 | | - }, |
97 | | - }, |
98 | | - "ValidationError": { |
99 | | - "title": "ValidationError", |
100 | | - "required": ["loc", "msg", "type"], |
101 | | - "type": "object", |
102 | | - "properties": { |
103 | | - "loc": { |
104 | | - "title": "Location", |
105 | | - "type": "array", |
106 | | - "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, |
107 | | - }, |
108 | | - "msg": {"title": "Message", "type": "string"}, |
109 | | - "type": {"title": "Error Type", "type": "string"}, |
110 | | - }, |
111 | | - }, |
112 | | - } |
113 | | - }, |
114 | | -} |
115 | | - |
116 | 7 |
|
117 | 8 | def test_tutorial(clear_sqlmodel): |
118 | 9 | from docs_src.tutorial.fastapi.multiple_models import tutorial001 as mod |
@@ -166,7 +57,124 @@ def test_tutorial(clear_sqlmodel): |
166 | 57 |
|
167 | 58 | assert response.status_code == 200, response.text |
168 | 59 |
|
169 | | - assert data == openapi_schema |
| 60 | + assert data == { |
| 61 | + "openapi": "3.1.0", |
| 62 | + "info": {"title": "FastAPI", "version": "0.1.0"}, |
| 63 | + "paths": { |
| 64 | + "/heroes/": { |
| 65 | + "get": { |
| 66 | + "summary": "Read Heroes", |
| 67 | + "operationId": "read_heroes_heroes__get", |
| 68 | + "responses": { |
| 69 | + "200": { |
| 70 | + "description": "Successful Response", |
| 71 | + "content": { |
| 72 | + "application/json": { |
| 73 | + "schema": { |
| 74 | + "title": "Response Read Heroes Heroes Get", |
| 75 | + "type": "array", |
| 76 | + "items": { |
| 77 | + "$ref": "#/components/schemas/HeroRead" |
| 78 | + }, |
| 79 | + } |
| 80 | + } |
| 81 | + }, |
| 82 | + } |
| 83 | + }, |
| 84 | + }, |
| 85 | + "post": { |
| 86 | + "summary": "Create Hero", |
| 87 | + "operationId": "create_hero_heroes__post", |
| 88 | + "requestBody": { |
| 89 | + "content": { |
| 90 | + "application/json": { |
| 91 | + "schema": { |
| 92 | + "$ref": "#/components/schemas/HeroCreate" |
| 93 | + } |
| 94 | + } |
| 95 | + }, |
| 96 | + "required": True, |
| 97 | + }, |
| 98 | + "responses": { |
| 99 | + "200": { |
| 100 | + "description": "Successful Response", |
| 101 | + "content": { |
| 102 | + "application/json": { |
| 103 | + "schema": { |
| 104 | + "$ref": "#/components/schemas/HeroRead" |
| 105 | + } |
| 106 | + } |
| 107 | + }, |
| 108 | + }, |
| 109 | + "422": { |
| 110 | + "description": "Validation Error", |
| 111 | + "content": { |
| 112 | + "application/json": { |
| 113 | + "schema": { |
| 114 | + "$ref": "#/components/schemas/HTTPValidationError" |
| 115 | + } |
| 116 | + } |
| 117 | + }, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + } |
| 122 | + }, |
| 123 | + "components": { |
| 124 | + "schemas": { |
| 125 | + "HTTPValidationError": { |
| 126 | + "title": "HTTPValidationError", |
| 127 | + "type": "object", |
| 128 | + "properties": { |
| 129 | + "detail": { |
| 130 | + "title": "Detail", |
| 131 | + "type": "array", |
| 132 | + "items": { |
| 133 | + "$ref": "#/components/schemas/ValidationError" |
| 134 | + }, |
| 135 | + } |
| 136 | + }, |
| 137 | + }, |
| 138 | + "HeroCreate": { |
| 139 | + "title": "HeroCreate", |
| 140 | + "required": ["name", "secret_name"], |
| 141 | + "type": "object", |
| 142 | + "properties": { |
| 143 | + "name": {"title": "Name", "type": "string"}, |
| 144 | + "secret_name": {"title": "Secret Name", "type": "string"}, |
| 145 | + "age": {"title": "Age", "type": "integer"}, |
| 146 | + }, |
| 147 | + }, |
| 148 | + "HeroRead": { |
| 149 | + "title": "HeroRead", |
| 150 | + "required": ["id", "name", "secret_name"], |
| 151 | + "type": "object", |
| 152 | + "properties": { |
| 153 | + "id": {"title": "Id", "type": "integer"}, |
| 154 | + "name": {"title": "Name", "type": "string"}, |
| 155 | + "secret_name": {"title": "Secret Name", "type": "string"}, |
| 156 | + "age": {"title": "Age", "type": "integer"}, |
| 157 | + }, |
| 158 | + }, |
| 159 | + "ValidationError": { |
| 160 | + "title": "ValidationError", |
| 161 | + "required": ["loc", "msg", "type"], |
| 162 | + "type": "object", |
| 163 | + "properties": { |
| 164 | + "loc": { |
| 165 | + "title": "Location", |
| 166 | + "type": "array", |
| 167 | + "items": { |
| 168 | + "anyOf": [{"type": "string"}, {"type": "integer"}] |
| 169 | + }, |
| 170 | + }, |
| 171 | + "msg": {"title": "Message", "type": "string"}, |
| 172 | + "type": {"title": "Error Type", "type": "string"}, |
| 173 | + }, |
| 174 | + }, |
| 175 | + } |
| 176 | + }, |
| 177 | + } |
170 | 178 |
|
171 | 179 | # Test inherited indexes |
172 | 180 | insp: Inspector = inspect(mod.engine) |
|
0 commit comments