mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 21:39:22 -04:00
✨ Add support for Pydantic v1 and above 🎉 (#646)
* Make compatible with pydantic v1 * Remove unused import * Remove unused ignores * Update pydantic version * Fix minor formatting issue * ⏪ Revert removing iterate_in_threadpool * ✨ Add backwards compatibility with Pydantic 0.32.2 with deprecation warnings * ✅ Update tests to not break when using Pydantic < 1.0.0 * 📝 Update docs for Pydantic version 1.0.0 * 📌 Update Pydantic range version to support from 0.32.2 * 🎨 Format test imports * ✨ Add support for Pydantic < 1.2 for populate_validators * ✨ Add backwards compatibility for Pydantic < 1.2.0 with required fields * 📌 Relax requirement for Pydantic to < 2.0.0 🎉 🚀 * 💚 Update pragma coverage for older Pydantic versions
This commit is contained in:
committed by
Sebastián Ramírez
parent
90a5796b94
commit
ab2b86fe2c
@@ -3,7 +3,13 @@ from enum import Enum
|
||||
|
||||
import pytest
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from pydantic import BaseModel, Schema, ValidationError
|
||||
from pydantic import BaseModel, ValidationError
|
||||
|
||||
try:
|
||||
from pydantic import Field
|
||||
except ImportError: # pragma: nocover
|
||||
# TODO: remove when removing support for Pydantic < 1.0.0
|
||||
from pydantic import Schema as Field
|
||||
|
||||
|
||||
class Person:
|
||||
@@ -60,7 +66,7 @@ class ModelWithConfig(BaseModel):
|
||||
|
||||
|
||||
class ModelWithAlias(BaseModel):
|
||||
foo: str = Schema(..., alias="Foo")
|
||||
foo: str = Field(..., alias="Foo")
|
||||
|
||||
|
||||
def test_encode_class():
|
||||
|
||||
Reference in New Issue
Block a user