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:
dmontagu
2019-11-27 11:32:02 -08:00
committed by Sebastián Ramírez
parent 90a5796b94
commit ab2b86fe2c
66 changed files with 802 additions and 425 deletions

View File

@@ -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():