mirror of https://github.com/tiangolo/fastapi.git
⬆️ Upgrade compatibility with Pydantic v2.4, new renamed functions and JSON Schema input/output models with default values (#10344)
* 🚚 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
This commit is contained in:
parent
b944b55dfc
commit
bc935e08b6
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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) == {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"}],
|
||||
|
|
|
|||
|
|
@ -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"}],
|
||||
|
|
|
|||
|
|
@ -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"}],
|
||||
|
|
|
|||
|
|
@ -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"}],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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'"},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue