]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
✅ Refactor OpenAPI FastAPI tests to simplify updating them later, this moves things...
authorSebastián Ramírez <tiangolo@gmail.com>
Mon, 23 Oct 2023 15:33:08 +0000 (19:33 +0400)
committerGitHub <noreply@github.com>
Mon, 23 Oct 2023 15:33:08 +0000 (15:33 +0000)
tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py

index 3a445127a3b1285eb7efa3eb60caf07e82db8ab6..8979245dd67858c9512042186ba709d6d010aeee 100644 (file)
@@ -2,255 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Hero",
-                "operationId": "delete_hero_heroes__hero_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Hero",
-                "operationId": "update_hero_heroes__hero_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "HeroUpdate": {
-                "title": "HeroUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.delete import tutorial001 as mod
@@ -284,10 +35,6 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         response = client.get("/heroes/9000")
         assert response.status_code == 404, response.text
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
         data = response.json()
@@ -308,3 +55,273 @@ def test_tutorial(clear_sqlmodel):
 
         response = client.delete("/heroes/9000")
         assert response.status_code == 404, response.text
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Hero",
+                        "operationId": "delete_hero_heroes__hero_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Hero",
+                        "operationId": "update_hero_heroes__hero_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "HeroUpdate": {
+                        "title": "HeroUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 1a38f7aab510bb32413b2f0ecc1c65765730ece8..d7f642a788ea9c9e33fbccc23e34f40a0331fcde 100644 (file)
@@ -2,178 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            }
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.limit_and_offset import tutorial001 as mod
@@ -207,10 +35,6 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         response = client.get("/heroes/9000")
         assert response.status_code == 404, response.text
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
 
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
@@ -236,3 +60,192 @@ def test_tutorial(clear_sqlmodel):
         data = response.json()
         assert len(data) == 1
         assert data[0]["name"] == hero2_data["name"]
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    }
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 125e00179c2268b0795e979c34f5c73b20677dd1..2ea5e8d6443ec278228553bdf1386dbc1d98540c 100644 (file)
@@ -2,502 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HeroReadWithTeam"
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Hero",
-                "operationId": "delete_hero_heroes__hero_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Hero",
-                "operationId": "update_hero_heroes__hero_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/teams/": {
-            "get": {
-                "summary": "Read Teams",
-                "operationId": "read_teams_teams__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Teams Teams  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/TeamRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Team",
-                "operationId": "create_team_teams__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/TeamCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/TeamRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/teams/{team_id}": {
-            "get": {
-                "summary": "Read Team",
-                "operationId": "read_team_teams__team_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/TeamReadWithHeroes"
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Team",
-                "operationId": "delete_team_teams__team_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Team",
-                "operationId": "update_team_teams__team_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/TeamUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/TeamRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "HeroReadWithTeam": {
-                "title": "HeroReadWithTeam",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                    "team": {"$ref": "#/components/schemas/TeamRead"},
-                },
-            },
-            "HeroUpdate": {
-                "title": "HeroUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                },
-            },
-            "TeamCreate": {
-                "title": "TeamCreate",
-                "required": ["name", "headquarters"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                },
-            },
-            "TeamRead": {
-                "title": "TeamRead",
-                "required": ["name", "headquarters", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "TeamReadWithHeroes": {
-                "title": "TeamReadWithHeroes",
-                "required": ["name", "headquarters", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                    "id": {"title": "Id", "type": "integer"},
-                    "heroes": {
-                        "title": "Heroes",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/HeroRead"},
-                        "default": [],
-                    },
-                },
-            },
-            "TeamUpdate": {
-                "title": "TeamUpdate",
-                "type": "object",
-                "properties": {
-                    "id": {"title": "Id", "type": "integer"},
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.relationships import tutorial001 as mod
@@ -508,11 +12,6 @@ def test_tutorial(clear_sqlmodel):
     )
 
     with TestClient(mod.app) as client:
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
-
         team_preventers = {"name": "Preventers", "headquarters": "Sharp Tower"}
         team_z_force = {"name": "Z-Force", "headquarters": "Sister Margaret’s Bar"}
         response = client.post("/teams/", json=team_preventers)
@@ -604,3 +103,532 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         data = response.json()
         assert len(data) == 1
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroReadWithTeam"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Hero",
+                        "operationId": "delete_hero_heroes__hero_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Hero",
+                        "operationId": "update_hero_heroes__hero_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/teams/": {
+                    "get": {
+                        "summary": "Read Teams",
+                        "operationId": "read_teams_teams__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Teams Teams  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/TeamRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Team",
+                        "operationId": "create_team_teams__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/TeamCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/teams/{team_id}": {
+                    "get": {
+                        "summary": "Read Team",
+                        "operationId": "read_team_teams__team_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamReadWithHeroes"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Team",
+                        "operationId": "delete_team_teams__team_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Team",
+                        "operationId": "update_team_teams__team_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/TeamUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "HeroReadWithTeam": {
+                        "title": "HeroReadWithTeam",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                            "team": {"$ref": "#/components/schemas/TeamRead"},
+                        },
+                    },
+                    "HeroUpdate": {
+                        "title": "HeroUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                        },
+                    },
+                    "TeamCreate": {
+                        "title": "TeamCreate",
+                        "required": ["name", "headquarters"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                        },
+                    },
+                    "TeamRead": {
+                        "title": "TeamRead",
+                        "required": ["name", "headquarters", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "TeamReadWithHeroes": {
+                        "title": "TeamReadWithHeroes",
+                        "required": ["name", "headquarters", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                            "id": {"title": "Id", "type": "integer"},
+                            "heroes": {
+                                "title": "Heroes",
+                                "type": "array",
+                                "items": {"$ref": "#/components/schemas/HeroRead"},
+                                "default": [],
+                            },
+                        },
+                    },
+                    "TeamUpdate": {
+                        "title": "TeamUpdate",
+                        "type": "object",
+                        "properties": {
+                            "id": {"title": "Id", "type": "integer"},
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 705146cc5b405dd2c0d692fa423e329a85abe4fb..da87b8e5c03d59b15eda1adace0c60b5f40cf33d 100644 (file)
@@ -2,255 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Hero",
-                "operationId": "delete_hero_heroes__hero_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Hero",
-                "operationId": "update_hero_heroes__hero_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "HeroUpdate": {
-                "title": "HeroUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.session_with_dependency import tutorial001 as mod
@@ -284,10 +35,6 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         response = client.get("/heroes/9000")
         assert response.status_code == 404, response.text
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
         data = response.json()
@@ -308,3 +55,273 @@ def test_tutorial(clear_sqlmodel):
 
         response = client.delete("/heroes/9000")
         assert response.status_code == 404, response.text
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Hero",
+                        "operationId": "delete_hero_heroes__hero_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Hero",
+                        "operationId": "update_hero_heroes__hero_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "HeroUpdate": {
+                        "title": "HeroUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 04a4b0c14dd72de1849b19ebbaca14d7b77e19ac..08be835a171d5aa4b0fcdd80e6eebd1c929441fe 100644 (file)
@@ -2,468 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Hero",
-                "operationId": "delete_hero_heroes__hero_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Hero",
-                "operationId": "update_hero_heroes__hero_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/teams/": {
-            "get": {
-                "summary": "Read Teams",
-                "operationId": "read_teams_teams__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Teams Teams  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/TeamRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Team",
-                "operationId": "create_team_teams__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/TeamCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/TeamRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/teams/{team_id}": {
-            "get": {
-                "summary": "Read Team",
-                "operationId": "read_team_teams__team_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/TeamRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "delete": {
-                "summary": "Delete Team",
-                "operationId": "delete_team_teams__team_id__delete",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Team",
-                "operationId": "update_team_teams__team_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Team Id", "type": "integer"},
-                        "name": "team_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/TeamUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/TeamRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "HeroUpdate": {
-                "title": "HeroUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "team_id": {"title": "Team Id", "type": "integer"},
-                },
-            },
-            "TeamCreate": {
-                "title": "TeamCreate",
-                "required": ["name", "headquarters"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                },
-            },
-            "TeamRead": {
-                "title": "TeamRead",
-                "required": ["name", "headquarters", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "TeamUpdate": {
-                "title": "TeamUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "headquarters": {"title": "Headquarters", "type": "string"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.teams import tutorial001 as mod
@@ -485,10 +23,6 @@ def test_tutorial(clear_sqlmodel):
             "secret_name": "Tommy Sharp",
             "age": 48,
         }
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
         response = client.post("/heroes/", json=hero1_data)
         assert response.status_code == 200, response.text
         response = client.post("/heroes/", json=hero2_data)
@@ -556,3 +90,502 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         data = response.json()
         assert len(data) == 1
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Hero",
+                        "operationId": "delete_hero_heroes__hero_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Hero",
+                        "operationId": "update_hero_heroes__hero_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/teams/": {
+                    "get": {
+                        "summary": "Read Teams",
+                        "operationId": "read_teams_teams__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Teams Teams  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/TeamRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Team",
+                        "operationId": "create_team_teams__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/TeamCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/teams/{team_id}": {
+                    "get": {
+                        "summary": "Read Team",
+                        "operationId": "read_team_teams__team_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "delete": {
+                        "summary": "Delete Team",
+                        "operationId": "delete_team_teams__team_id__delete",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Team",
+                        "operationId": "update_team_teams__team_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Team Id", "type": "integer"},
+                                "name": "team_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/TeamUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/TeamRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "HeroUpdate": {
+                        "title": "HeroUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "team_id": {"title": "Team Id", "type": "integer"},
+                        },
+                    },
+                    "TeamCreate": {
+                        "title": "TeamCreate",
+                        "required": ["name", "headquarters"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                        },
+                    },
+                    "TeamRead": {
+                        "title": "TeamRead",
+                        "required": ["name", "headquarters", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "TeamUpdate": {
+                        "title": "TeamUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "headquarters": {"title": "Headquarters", "type": "string"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index ec75a2f25ddb9f2554c6018d365200d71b0c6f43..7f48780109cd4ecefa0ccffd3639280c81eb2221 100644 (file)
@@ -2,227 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.0.2",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "parameters": [
-                    {
-                        "required": False,
-                        "schema": {"title": "Offset", "type": "integer", "default": 0},
-                        "name": "offset",
-                        "in": "query",
-                    },
-                    {
-                        "required": False,
-                        "schema": {
-                            "title": "Limit",
-                            "type": "integer",
-                            "default": 100,
-                            "lte": 100,
-                        },
-                        "name": "limit",
-                        "in": "query",
-                    },
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroCreate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-        "/heroes/{hero_id}": {
-            "get": {
-                "summary": "Read Hero",
-                "operationId": "read_hero_heroes__hero_id__get",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-            "patch": {
-                "summary": "Update Hero",
-                "operationId": "update_hero_heroes__hero_id__patch",
-                "parameters": [
-                    {
-                        "required": True,
-                        "schema": {"title": "Hero Id", "type": "integer"},
-                        "name": "hero_id",
-                        "in": "path",
-                    }
-                ],
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/HeroUpdate"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/HeroRead"}
-                            }
-                        },
-                    },
-                    "422": {
-                        "description": "Validation Error",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "$ref": "#/components/schemas/HTTPValidationError"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        },
-    },
-    "components": {
-        "schemas": {
-            "HTTPValidationError": {
-                "title": "HTTPValidationError",
-                "type": "object",
-                "properties": {
-                    "detail": {
-                        "title": "Detail",
-                        "type": "array",
-                        "items": {"$ref": "#/components/schemas/ValidationError"},
-                    }
-                },
-            },
-            "HeroCreate": {
-                "title": "HeroCreate",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "HeroRead": {
-                "title": "HeroRead",
-                "required": ["name", "secret_name", "id"],
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                    "id": {"title": "Id", "type": "integer"},
-                },
-            },
-            "HeroUpdate": {
-                "title": "HeroUpdate",
-                "type": "object",
-                "properties": {
-                    "name": {"title": "Name", "type": "string"},
-                    "secret_name": {"title": "Secret Name", "type": "string"},
-                    "age": {"title": "Age", "type": "integer"},
-                },
-            },
-            "ValidationError": {
-                "title": "ValidationError",
-                "required": ["loc", "msg", "type"],
-                "type": "object",
-                "properties": {
-                    "loc": {
-                        "title": "Location",
-                        "type": "array",
-                        "items": {"type": "string"},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.update import tutorial001 as mod
@@ -258,10 +37,6 @@ def test_tutorial(clear_sqlmodel):
         assert response.status_code == 200, response.text
         response = client.get("/heroes/9000")
         assert response.status_code == 404, response.text
-        response = client.get("/openapi.json")
-        data = response.json()
-        assert response.status_code == 200, response.text
-        assert data == openapi_schema
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
         data = response.json()
@@ -287,3 +62,245 @@ def test_tutorial(clear_sqlmodel):
 
         response = client.patch("/heroes/9001", json={"name": "Dragon Cube X"})
         assert response.status_code == 404, response.text
+
+        response = client.get("/openapi.json")
+        data = response.json()
+        assert response.status_code == 200, response.text
+        assert data == {
+            "openapi": "3.0.2",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "parameters": [
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Offset",
+                                    "type": "integer",
+                                    "default": 0,
+                                },
+                                "name": "offset",
+                                "in": "query",
+                            },
+                            {
+                                "required": False,
+                                "schema": {
+                                    "title": "Limit",
+                                    "type": "integer",
+                                    "default": 100,
+                                    "lte": 100,
+                                },
+                                "name": "limit",
+                                "in": "query",
+                            },
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroCreate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+                "/heroes/{hero_id}": {
+                    "get": {
+                        "summary": "Read Hero",
+                        "operationId": "read_hero_heroes__hero_id__get",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                    "patch": {
+                        "summary": "Update Hero",
+                        "operationId": "update_hero_heroes__hero_id__patch",
+                        "parameters": [
+                            {
+                                "required": True,
+                                "schema": {"title": "Hero Id", "type": "integer"},
+                                "name": "hero_id",
+                                "in": "path",
+                            }
+                        ],
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {
+                                        "$ref": "#/components/schemas/HeroUpdate"
+                                    }
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HeroRead"
+                                        }
+                                    }
+                                },
+                            },
+                            "422": {
+                                "description": "Validation Error",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "$ref": "#/components/schemas/HTTPValidationError"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+            "components": {
+                "schemas": {
+                    "HTTPValidationError": {
+                        "title": "HTTPValidationError",
+                        "type": "object",
+                        "properties": {
+                            "detail": {
+                                "title": "Detail",
+                                "type": "array",
+                                "items": {
+                                    "$ref": "#/components/schemas/ValidationError"
+                                },
+                            }
+                        },
+                    },
+                    "HeroCreate": {
+                        "title": "HeroCreate",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "HeroRead": {
+                        "title": "HeroRead",
+                        "required": ["name", "secret_name", "id"],
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                            "id": {"title": "Id", "type": "integer"},
+                        },
+                    },
+                    "HeroUpdate": {
+                        "title": "HeroUpdate",
+                        "type": "object",
+                        "properties": {
+                            "name": {"title": "Name", "type": "string"},
+                            "secret_name": {"title": "Secret Name", "type": "string"},
+                            "age": {"title": "Age", "type": "integer"},
+                        },
+                    },
+                    "ValidationError": {
+                        "title": "ValidationError",
+                        "required": ["loc", "msg", "type"],
+                        "type": "object",
+                        "properties": {
+                            "loc": {
+                                "title": "Location",
+                                "type": "array",
+                                "items": {"type": "string"},
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }