]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
✅ Move OpenAPI tests inline to simplify updating them with Pydantic v2 (#709)
authorSebastián Ramírez <tiangolo@gmail.com>
Sun, 26 Nov 2023 13:57:12 +0000 (14:57 +0100)
committerGitHub <noreply@github.com>
Sun, 26 Nov 2023 13:57:12 +0000 (13:57 +0000)
tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py
tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py

index dc5a3cb8ff6bd39925dbef2699909874d2b134f8..7444f8858da11fda7355cd4f8630b557852794e8 100644 (file)
@@ -4,115 +4,6 @@ from sqlalchemy.engine.reflection import Inspector
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.1.0",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    }
-                },
-            },
-            "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"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        }
-    },
-    "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": ["id", "name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "id": {"title": "Id", "type": "integer"},
-                    "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": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.multiple_models import tutorial001 as mod
@@ -166,7 +57,124 @@ def test_tutorial(clear_sqlmodel):
 
         assert response.status_code == 200, response.text
 
-        assert data == openapi_schema
+        assert data == {
+            "openapi": "3.1.0",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            }
+                        },
+                    },
+                    "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"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                }
+            },
+            "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": ["id", "name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "id": {"title": "Id", "type": "integer"},
+                            "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": {
+                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
+                                },
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
 
     # Test inherited indexes
     insp: Inspector = inspect(mod.engine)
index e3c20404c0bd1f9656bf70e370e3a604310525bd..4a6bb7499e8c28c2ca694c8c747679999500de48 100644 (file)
@@ -4,115 +4,6 @@ from sqlalchemy.engine.reflection import Inspector
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.1.0",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    }
-                },
-            },
-            "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"
-                                }
-                            }
-                        },
-                    },
-                },
-            },
-        }
-    },
-    "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": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.multiple_models import tutorial002 as mod
@@ -166,7 +57,124 @@ def test_tutorial(clear_sqlmodel):
 
         assert response.status_code == 200, response.text
 
-        assert data == openapi_schema
+        assert data == {
+            "openapi": "3.1.0",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            }
+                        },
+                    },
+                    "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"
+                                        }
+                                    }
+                                },
+                            },
+                        },
+                    },
+                }
+            },
+            "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": {
+                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
+                                },
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
 
     # Test inherited indexes
     insp: Inspector = inspect(mod.engine)
index 0a599574d5dba84b13e362df1ebee307a9db872d..5d2327095eaf7fe8d82bf8b33ebf80717e979d3c 100644 (file)
@@ -2,149 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.1.0",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/HeroRead"},
-                                }
-                            }
-                        },
-                    }
-                },
-            },
-            "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": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.read_one import tutorial001 as mod
@@ -185,4 +42,157 @@ def test_tutorial(clear_sqlmodel):
 
         assert response.status_code == 200, response.text
 
-        assert data == openapi_schema
+        assert data == {
+            "openapi": "3.1.0",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/HeroRead"
+                                            },
+                                        }
+                                    }
+                                },
+                            }
+                        },
+                    },
+                    "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": {
+                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
+                                },
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 968fefa8ca6dd2f88b2e430b7b5cab071e8c5bf4..ca8a41845e100f90e8ad202c048a2c41a034adbe 100644 (file)
@@ -2,105 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.1.0",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {
-                                    "title": "Response Read Heroes Heroes  Get",
-                                    "type": "array",
-                                    "items": {"$ref": "#/components/schemas/Hero"},
-                                }
-                            }
-                        },
-                    }
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/Hero"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {
-                            "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Hero"}
-                            }
-                        },
-                    },
-                    "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"},
-                    }
-                },
-            },
-            "Hero": {
-                "title": "Hero",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "id": {"title": "Id", "type": "integer"},
-                    "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": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.response_model import tutorial001 as mod
@@ -134,4 +35,107 @@ def test_tutorial(clear_sqlmodel):
 
         assert response.status_code == 200, response.text
 
-        assert data == openapi_schema
+        assert data == {
+            "openapi": "3.1.0",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {
+                                            "title": "Response Read Heroes Heroes  Get",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "#/components/schemas/Hero"
+                                            },
+                                        }
+                                    }
+                                },
+                            }
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {"$ref": "#/components/schemas/Hero"}
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {
+                                    "application/json": {
+                                        "schema": {"$ref": "#/components/schemas/Hero"}
+                                    }
+                                },
+                            },
+                            "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"
+                                },
+                            }
+                        },
+                    },
+                    "Hero": {
+                        "title": "Hero",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "id": {"title": "Id", "type": "integer"},
+                            "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": {
+                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
+                                },
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }
index 435155d6e93873ff3e1993b9ad70e20c10c877b3..2136ed8a1f309e121055cf3ebaf5bb957a50fc1a 100644 (file)
@@ -2,93 +2,6 @@ from fastapi.testclient import TestClient
 from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
-openapi_schema = {
-    "openapi": "3.1.0",
-    "info": {"title": "FastAPI", "version": "0.1.0"},
-    "paths": {
-        "/heroes/": {
-            "get": {
-                "summary": "Read Heroes",
-                "operationId": "read_heroes_heroes__get",
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    }
-                },
-            },
-            "post": {
-                "summary": "Create Hero",
-                "operationId": "create_hero_heroes__post",
-                "requestBody": {
-                    "content": {
-                        "application/json": {
-                            "schema": {"$ref": "#/components/schemas/Hero"}
-                        }
-                    },
-                    "required": True,
-                },
-                "responses": {
-                    "200": {
-                        "description": "Successful Response",
-                        "content": {"application/json": {"schema": {}}},
-                    },
-                    "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"},
-                    }
-                },
-            },
-            "Hero": {
-                "title": "Hero",
-                "required": ["name", "secret_name"],
-                "type": "object",
-                "properties": {
-                    "id": {"title": "Id", "type": "integer"},
-                    "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": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
-                    },
-                    "msg": {"title": "Message", "type": "string"},
-                    "type": {"title": "Error Type", "type": "string"},
-                },
-            },
-        }
-    },
-}
-
 
 def test_tutorial(clear_sqlmodel):
     from docs_src.tutorial.fastapi.simple_hero_api import tutorial001 as mod
@@ -142,4 +55,93 @@ def test_tutorial(clear_sqlmodel):
 
         assert response.status_code == 200, response.text
 
-        assert data == openapi_schema
+        assert data == {
+            "openapi": "3.1.0",
+            "info": {"title": "FastAPI", "version": "0.1.0"},
+            "paths": {
+                "/heroes/": {
+                    "get": {
+                        "summary": "Read Heroes",
+                        "operationId": "read_heroes_heroes__get",
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            }
+                        },
+                    },
+                    "post": {
+                        "summary": "Create Hero",
+                        "operationId": "create_hero_heroes__post",
+                        "requestBody": {
+                            "content": {
+                                "application/json": {
+                                    "schema": {"$ref": "#/components/schemas/Hero"}
+                                }
+                            },
+                            "required": True,
+                        },
+                        "responses": {
+                            "200": {
+                                "description": "Successful Response",
+                                "content": {"application/json": {"schema": {}}},
+                            },
+                            "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"
+                                },
+                            }
+                        },
+                    },
+                    "Hero": {
+                        "title": "Hero",
+                        "required": ["name", "secret_name"],
+                        "type": "object",
+                        "properties": {
+                            "id": {"title": "Id", "type": "integer"},
+                            "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": {
+                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
+                                },
+                            },
+                            "msg": {"title": "Message", "type": "string"},
+                            "type": {"title": "Error Type", "type": "string"},
+                        },
+                    },
+                }
+            },
+        }