]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
⬆️ Upgrade compatibility with Pydantic v2.4, new renamed functions and JSON Schema...
authorSebastián Ramírez <tiangolo@gmail.com>
Thu, 28 Sep 2023 04:14:40 +0000 (23:14 -0500)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2023 04:14:40 +0000 (23:14 -0500)
* 🚚 Refactor deprecated import general_plain_validator_function to with_info_plain_validator_function

* 🚚 Rename deprecated FieldValidationInfo to ValidationInfo

* ✅ Update tests with new defaults for JSON Schema for default values

* ♻️ Add Pydantic v1 version of with_info_plain_validator_function

* 👷 Invalidate cache

* ✅ Fix tests for Pydantic v1

* ✅ Tweak tests coverage for older Pydantic v2 versions

19 files changed:
.github/workflows/test.yml
fastapi/_compat.py
fastapi/datastructures.py
fastapi/openapi/models.py
tests/test_compat.py
tests/test_filter_pydantic_sub_model_pv2.py
tests/test_openapi_separate_input_output_schemas.py
tests/test_tutorial/test_body_updates/test_tutorial001.py
tests/test_tutorial/test_body_updates/test_tutorial001_py310.py
tests/test_tutorial/test_body_updates/test_tutorial001_py39.py
tests/test_tutorial/test_dataclasses/test_tutorial003.py
tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py
tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py
tests/test_tutorial/test_path_operation_configurations/test_tutorial005_py310.py
tests/test_tutorial/test_path_operation_configurations/test_tutorial005_py39.py
tests/test_tutorial/test_path_params/test_tutorial005.py
tests/test_tutorial/test_separate_openapi_schemas/test_tutorial001.py
tests/test_tutorial/test_separate_openapi_schemas/test_tutorial001_py310.py
tests/test_tutorial/test_separate_openapi_schemas/test_tutorial001_py39.py

index c9723b25bbace98862f25552edc13fcd5a220cb8..4ebc64a14dde56af3b31dd6ee4635d2ed9b5bee5 100644 (file)
@@ -29,7 +29,7 @@ jobs:
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v05
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v06
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: pip install -r requirements-tests.txt
@@ -62,7 +62,7 @@ jobs:
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v05
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v06
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: pip install -r requirements-tests.txt
index eb55b08f2e6e3b30452eee78cffbbc886b28b355..a4b305d429fdd115fcc91f2b53c22e9c76bb5c39 100644 (file)
@@ -58,9 +58,15 @@ if PYDANTIC_V2:
     from pydantic_core import CoreSchema as CoreSchema
     from pydantic_core import PydanticUndefined, PydanticUndefinedType
     from pydantic_core import Url as Url
-    from pydantic_core.core_schema import (
-        general_plain_validator_function as general_plain_validator_function,
-    )
+
+    try:
+        from pydantic_core.core_schema import (
+            with_info_plain_validator_function as with_info_plain_validator_function,
+        )
+    except ImportError:  # pragma: no cover
+        from pydantic_core.core_schema import (
+            general_plain_validator_function as with_info_plain_validator_function,  # noqa: F401
+        )
 
     Required = PydanticUndefined
     Undefined = PydanticUndefined
@@ -345,7 +351,7 @@ else:
     class PydanticSchemaGenerationError(Exception):  # type: ignore[no-redef]
         pass
 
-    def general_plain_validator_function(  # type: ignore[misc]
+    def with_info_plain_validator_function(  # type: ignore[misc]
         function: Callable[..., Any],
         *,
         ref: Union[str, None] = None,
index 3c96c56c70e1170cb5eaf0296d63daac8deaea7e..b2865cd405496fe6facde82dbf857e5e80901d3f 100644 (file)
@@ -5,7 +5,7 @@ from fastapi._compat import (
     CoreSchema,
     GetJsonSchemaHandler,
     JsonSchemaValue,
-    general_plain_validator_function,
+    with_info_plain_validator_function,
 )
 from starlette.datastructures import URL as URL  # noqa: F401
 from starlette.datastructures import Address as Address  # noqa: F401
@@ -49,7 +49,7 @@ class UploadFile(StarletteUploadFile):
     def __get_pydantic_core_schema__(
         cls, source: Type[Any], handler: Callable[[Any], CoreSchema]
     ) -> CoreSchema:
-        return general_plain_validator_function(cls._validate)
+        return with_info_plain_validator_function(cls._validate)
 
 
 class DefaultPlaceholder:
index 3d982eb9aec98b6ba3bdb370f1271ce461e25031..5f3bdbb2066a612a9d58af46c923f74734079868 100644 (file)
@@ -7,7 +7,7 @@ from fastapi._compat import (
     GetJsonSchemaHandler,
     JsonSchemaValue,
     _model_rebuild,
-    general_plain_validator_function,
+    with_info_plain_validator_function,
 )
 from fastapi.logger import logger
 from pydantic import AnyUrl, BaseModel, Field
@@ -52,7 +52,7 @@ except ImportError:  # pragma: no cover
         def __get_pydantic_core_schema__(
             cls, source: Type[Any], handler: Callable[[Any], CoreSchema]
         ) -> CoreSchema:
-            return general_plain_validator_function(cls._validate)
+            return with_info_plain_validator_function(cls._validate)
 
 
 class Contact(BaseModel):
index 47160ee76fe4928eda32aa6ac903e5cd313e11d8..bf268b860b1dcdee16afe92db9cbc683c0969236 100644 (file)
@@ -24,7 +24,7 @@ def test_model_field_default_required():
 
 
 @needs_pydanticv1
-def test_upload_file_dummy_general_plain_validator_function():
+def test_upload_file_dummy_with_info_plain_validator_function():
     # For coverage
     assert UploadFile.__get_pydantic_core_schema__(str, lambda x: None) == {}
 
index 9f5e6b08fb6670ea65ddd1ef74ab3f95f1eb4dc8..9097d2ce52e01991922c08dc9e2b37e46a578c16 100644 (file)
@@ -12,7 +12,7 @@ from .utils import needs_pydanticv2
 
 @pytest.fixture(name="client")
 def get_client():
-    from pydantic import BaseModel, FieldValidationInfo, field_validator
+    from pydantic import BaseModel, ValidationInfo, field_validator
 
     app = FastAPI()
 
@@ -28,7 +28,7 @@ def get_client():
         foo: ModelB
 
         @field_validator("name")
-        def lower_username(cls, name: str, info: FieldValidationInfo):
+        def lower_username(cls, name: str, info: ValidationInfo):
             if not name.endswith("A"):
                 raise ValueError("name must end in A")
             return name
index 70f4b90d75128b508dbfbc04593f9b4c2917e7fe..aeb85f735b66655787e8347080218a53221c9041 100644 (file)
@@ -4,19 +4,23 @@ from fastapi import FastAPI
 from fastapi.testclient import TestClient
 from pydantic import BaseModel
 
-from .utils import needs_pydanticv2
+from .utils import PYDANTIC_V2, needs_pydanticv2
 
 
 class SubItem(BaseModel):
     subname: str
     sub_description: Optional[str] = None
     tags: List[str] = []
+    if PYDANTIC_V2:
+        model_config = {"json_schema_serialization_defaults_required": True}
 
 
 class Item(BaseModel):
     name: str
     description: Optional[str] = None
     sub: Optional[SubItem] = None
+    if PYDANTIC_V2:
+        model_config = {"json_schema_serialization_defaults_required": True}
 
 
 def get_app_client(separate_input_output_schemas: bool = True) -> TestClient:
index 58587885efdb07748ecb0c30a324c73c0ab1eee1..e586534a071b113b5551c237b428862fdf3ed222 100644 (file)
@@ -52,9 +52,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -86,9 +84,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -116,7 +112,7 @@ def test_openapi_schema(client: TestClient):
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -126,35 +122,9 @@ def test_openapi_schema(client: TestClient):
         },
         "components": {
             "schemas": {
-                "Item-Input": {
-                    "title": "Item",
+                "Item": {
                     "type": "object",
-                    "properties": {
-                        "name": {
-                            "title": "Name",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "description": {
-                            "title": "Description",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "price": {
-                            "title": "Price",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tax": {"title": "Tax", "type": "number", "default": 10.5},
-                        "tags": {
-                            "title": "Tags",
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
-                "Item-Output": {
                     "title": "Item",
-                    "type": "object",
-                    "required": ["name", "description", "price", "tax", "tags"],
                     "properties": {
                         "name": {
                             "anyOf": [{"type": "string"}, {"type": "null"}],
index d8a62502f0a843cdf200fe85306c2c31c8d10e06..6bc969d43a831d68e89956ee23aab93555ae0100 100644 (file)
@@ -55,9 +55,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -89,9 +87,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -119,7 +115,7 @@ def test_openapi_schema(client: TestClient):
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -129,35 +125,9 @@ def test_openapi_schema(client: TestClient):
         },
         "components": {
             "schemas": {
-                "Item-Input": {
-                    "title": "Item",
+                "Item": {
                     "type": "object",
-                    "properties": {
-                        "name": {
-                            "title": "Name",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "description": {
-                            "title": "Description",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "price": {
-                            "title": "Price",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tax": {"title": "Tax", "type": "number", "default": 10.5},
-                        "tags": {
-                            "title": "Tags",
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
-                "Item-Output": {
                     "title": "Item",
-                    "type": "object",
-                    "required": ["name", "description", "price", "tax", "tags"],
                     "properties": {
                         "name": {
                             "anyOf": [{"type": "string"}, {"type": "null"}],
index c604df6ecb7e9223b4d5479048a07b3af312bf5a..a1edb33707fc07ef8de59988bd92e0e5bea1d267 100644 (file)
@@ -55,9 +55,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -89,9 +87,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -119,7 +115,7 @@ def test_openapi_schema(client: TestClient):
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -129,35 +125,9 @@ def test_openapi_schema(client: TestClient):
         },
         "components": {
             "schemas": {
-                "Item-Input": {
-                    "title": "Item",
+                "Item": {
                     "type": "object",
-                    "properties": {
-                        "name": {
-                            "title": "Name",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "description": {
-                            "title": "Description",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "price": {
-                            "title": "Price",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tax": {"title": "Tax", "type": "number", "default": 10.5},
-                        "tags": {
-                            "title": "Tags",
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
-                "Item-Output": {
                     "title": "Item",
-                    "type": "object",
-                    "required": ["name", "description", "price", "tax", "tags"],
                     "properties": {
                         "name": {
                             "anyOf": [{"type": "string"}, {"type": "null"}],
index f2ca858235faf1d37ae02cc0571e6a2b6e38abb1..dd0e36735eecffa5271c9b9d00fbe2b47f0a2459 100644 (file)
@@ -79,9 +79,7 @@ def test_openapi_schema():
                                 "schema": {
                                     "title": "Items",
                                     "type": "array",
-                                    "items": {
-                                        "$ref": "#/components/schemas/Item-Input"
-                                    },
+                                    "items": {"$ref": "#/components/schemas/Item"},
                                 }
                             }
                         },
@@ -136,14 +134,14 @@ def test_openapi_schema():
             "schemas": {
                 "Author": {
                     "title": "Author",
-                    "required": ["name", "items"],
+                    "required": ["name"],
                     "type": "object",
                     "properties": {
                         "name": {"title": "Name", "type": "string"},
                         "items": {
                             "title": "Items",
                             "type": "array",
-                            "items": {"$ref": "#/components/schemas/Item-Output"},
+                            "items": {"$ref": "#/components/schemas/Item"},
                         },
                     },
                 },
@@ -158,27 +156,15 @@ def test_openapi_schema():
                         }
                     },
                 },
-                "Item-Input": {
+                "Item": {
                     "title": "Item",
                     "required": ["name"],
                     "type": "object",
                     "properties": {
                         "name": {"title": "Name", "type": "string"},
                         "description": {
-                            "title": "Description",
                             "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                    },
-                },
-                "Item-Output": {
-                    "title": "Item",
-                    "required": ["name", "description"],
-                    "type": "object",
-                    "properties": {
-                        "name": {"title": "Name", "type": "string"},
-                        "description": {
                             "title": "Description",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
                         },
                     },
                 },
index c5b2fb670b21305c417d0794ed9f465073918aa3..4f69e4646c980bc94a8976bc20e78321f3148575 100644 (file)
@@ -34,9 +34,7 @@ def test_openapi_schema():
                             "description": "Successful Response",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -57,7 +55,7 @@ def test_openapi_schema():
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -67,7 +65,7 @@ def test_openapi_schema():
         },
         "components": {
             "schemas": {
-                "Item-Input": {
+                "Item": {
                     "title": "Item",
                     "required": ["name", "price"],
                     "type": "object",
@@ -91,30 +89,6 @@ def test_openapi_schema():
                         },
                     },
                 },
-                "Item-Output": {
-                    "title": "Item",
-                    "required": ["name", "description", "price", "tax", "tags"],
-                    "type": "object",
-                    "properties": {
-                        "name": {"title": "Name", "type": "string"},
-                        "description": {
-                            "title": "Description",
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                        },
-                        "price": {"title": "Price", "type": "number"},
-                        "tax": {
-                            "title": "Tax",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tags": {
-                            "title": "Tags",
-                            "uniqueItems": True,
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
                 "ValidationError": {
                     "title": "ValidationError",
                     "required": ["loc", "msg", "type"],
index 458923b5a08f87ee8f4c2ccb17636fb88c798850..d3792e701fcbaa76b7dee0289afb9be70eb5c182 100644 (file)
@@ -34,9 +34,7 @@ def test_openapi_schema():
                             "description": "The created item",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -57,7 +55,7 @@ def test_openapi_schema():
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -67,7 +65,7 @@ def test_openapi_schema():
         },
         "components": {
             "schemas": {
-                "Item-Input": {
+                "Item": {
                     "title": "Item",
                     "required": ["name", "price"],
                     "type": "object",
@@ -91,30 +89,6 @@ def test_openapi_schema():
                         },
                     },
                 },
-                "Item-Output": {
-                    "title": "Item",
-                    "required": ["name", "description", "price", "tax", "tags"],
-                    "type": "object",
-                    "properties": {
-                        "name": {"title": "Name", "type": "string"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                        "price": {"title": "Price", "type": "number"},
-                        "tax": {
-                            "title": "Tax",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tags": {
-                            "title": "Tags",
-                            "uniqueItems": True,
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
                 "ValidationError": {
                     "title": "ValidationError",
                     "required": ["loc", "msg", "type"],
index 1fcc5c4e0cba0630a65a3ba4a63c80200e5dbf0f..a68deb3df5784a76e27e5c16d1e3591b40a415c1 100644 (file)
@@ -41,9 +41,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "The created item",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -64,7 +62,7 @@ def test_openapi_schema(client: TestClient):
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -74,7 +72,7 @@ def test_openapi_schema(client: TestClient):
         },
         "components": {
             "schemas": {
-                "Item-Input": {
+                "Item": {
                     "title": "Item",
                     "required": ["name", "price"],
                     "type": "object",
@@ -98,30 +96,6 @@ def test_openapi_schema(client: TestClient):
                         },
                     },
                 },
-                "Item-Output": {
-                    "title": "Item",
-                    "required": ["name", "description", "price", "tax", "tags"],
-                    "type": "object",
-                    "properties": {
-                        "name": {"title": "Name", "type": "string"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                        "price": {"title": "Price", "type": "number"},
-                        "tax": {
-                            "title": "Tax",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tags": {
-                            "title": "Tags",
-                            "uniqueItems": True,
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
                 "ValidationError": {
                     "title": "ValidationError",
                     "required": ["loc", "msg", "type"],
index 470fe032b162458f746289067a92ad6a367e3b61..e17f2592dc73be6c4dbbd4f4a077062a49ab47d0 100644 (file)
@@ -41,9 +41,7 @@ def test_openapi_schema(client: TestClient):
                             "description": "The created item",
                             "content": {
                                 "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/Item-Output"
-                                    }
+                                    "schema": {"$ref": "#/components/schemas/Item"}
                                 }
                             },
                         },
@@ -64,7 +62,7 @@ def test_openapi_schema(client: TestClient):
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -74,7 +72,7 @@ def test_openapi_schema(client: TestClient):
         },
         "components": {
             "schemas": {
-                "Item-Input": {
+                "Item": {
                     "title": "Item",
                     "required": ["name", "price"],
                     "type": "object",
@@ -98,30 +96,6 @@ def test_openapi_schema(client: TestClient):
                         },
                     },
                 },
-                "Item-Output": {
-                    "title": "Item",
-                    "required": ["name", "description", "price", "tax", "tags"],
-                    "type": "object",
-                    "properties": {
-                        "name": {"title": "Name", "type": "string"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                        "price": {"title": "Price", "type": "number"},
-                        "tax": {
-                            "title": "Tax",
-                            "anyOf": [{"type": "number"}, {"type": "null"}],
-                        },
-                        "tags": {
-                            "title": "Tags",
-                            "uniqueItems": True,
-                            "type": "array",
-                            "items": {"type": "string"},
-                            "default": [],
-                        },
-                    },
-                },
                 "ValidationError": {
                     "title": "ValidationError",
                     "required": ["loc", "msg", "type"],
index 90fa6adaf7898900b846598e3bf1334fd253df2d..2e4b0146bee5f58a19853bbd152396cd36c74c3a 100644 (file)
@@ -33,9 +33,9 @@ def test_get_enums_invalid():
                 {
                     "type": "enum",
                     "loc": ["path", "model_name"],
-                    "msg": "Input should be 'alexnet','resnet' or 'lenet'",
+                    "msg": "Input should be 'alexnet', 'resnet' or 'lenet'",
                     "input": "foo",
-                    "ctx": {"expected": "'alexnet','resnet' or 'lenet'"},
+                    "ctx": {"expected": "'alexnet', 'resnet' or 'lenet'"},
                 }
             ]
         }
index 8079c11343c1bb6e6aa351abdf707ea2c91aecf9..cdfae9f8c1b679e0925bcf419c2fc4adf654763d 100644 (file)
@@ -48,9 +48,7 @@ def test_openapi_schema(client: TestClient) -> None:
                             "content": {
                                 "application/json": {
                                     "schema": {
-                                        "items": {
-                                            "$ref": "#/components/schemas/Item-Output"
-                                        },
+                                        "items": {"$ref": "#/components/schemas/Item"},
                                         "type": "array",
                                         "title": "Response Read Items Items  Get",
                                     }
@@ -65,7 +63,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -102,7 +100,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "type": "object",
                     "title": "HTTPValidationError",
                 },
-                "Item-Input": {
+                "Item": {
                     "properties": {
                         "name": {"type": "string", "title": "Name"},
                         "description": {
@@ -114,18 +112,6 @@ def test_openapi_schema(client: TestClient) -> None:
                     "required": ["name"],
                     "title": "Item",
                 },
-                "Item-Output": {
-                    "properties": {
-                        "name": {"type": "string", "title": "Name"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                    },
-                    "type": "object",
-                    "required": ["name", "description"],
-                    "title": "Item",
-                },
                 "ValidationError": {
                     "properties": {
                         "loc": {
index 4fa98ccbefbf89105a32a3f81f5ada015e7b0125..3b22146f634da826c77d803893c9737da87b3065 100644 (file)
@@ -51,9 +51,7 @@ def test_openapi_schema(client: TestClient) -> None:
                             "content": {
                                 "application/json": {
                                     "schema": {
-                                        "items": {
-                                            "$ref": "#/components/schemas/Item-Output"
-                                        },
+                                        "items": {"$ref": "#/components/schemas/Item"},
                                         "type": "array",
                                         "title": "Response Read Items Items  Get",
                                     }
@@ -68,7 +66,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -105,7 +103,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "type": "object",
                     "title": "HTTPValidationError",
                 },
-                "Item-Input": {
+                "Item": {
                     "properties": {
                         "name": {"type": "string", "title": "Name"},
                         "description": {
@@ -117,18 +115,6 @@ def test_openapi_schema(client: TestClient) -> None:
                     "required": ["name"],
                     "title": "Item",
                 },
-                "Item-Output": {
-                    "properties": {
-                        "name": {"type": "string", "title": "Name"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                    },
-                    "type": "object",
-                    "required": ["name", "description"],
-                    "title": "Item",
-                },
                 "ValidationError": {
                     "properties": {
                         "loc": {
index ad36582ed5e011d275738ab669974e2038dab9a4..991abe8113e967fc4bc751b4053c2592b5ee6862 100644 (file)
@@ -51,9 +51,7 @@ def test_openapi_schema(client: TestClient) -> None:
                             "content": {
                                 "application/json": {
                                     "schema": {
-                                        "items": {
-                                            "$ref": "#/components/schemas/Item-Output"
-                                        },
+                                        "items": {"$ref": "#/components/schemas/Item"},
                                         "type": "array",
                                         "title": "Response Read Items Items  Get",
                                     }
@@ -68,7 +66,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "requestBody": {
                         "content": {
                             "application/json": {
-                                "schema": {"$ref": "#/components/schemas/Item-Input"}
+                                "schema": {"$ref": "#/components/schemas/Item"}
                             }
                         },
                         "required": True,
@@ -105,7 +103,7 @@ def test_openapi_schema(client: TestClient) -> None:
                     "type": "object",
                     "title": "HTTPValidationError",
                 },
-                "Item-Input": {
+                "Item": {
                     "properties": {
                         "name": {"type": "string", "title": "Name"},
                         "description": {
@@ -117,18 +115,6 @@ def test_openapi_schema(client: TestClient) -> None:
                     "required": ["name"],
                     "title": "Item",
                 },
-                "Item-Output": {
-                    "properties": {
-                        "name": {"type": "string", "title": "Name"},
-                        "description": {
-                            "anyOf": [{"type": "string"}, {"type": "null"}],
-                            "title": "Description",
-                        },
-                    },
-                    "type": "object",
-                    "required": ["name", "description"],
-                    "title": "Item",
-                },
                 "ValidationError": {
                     "properties": {
                         "loc": {