Add support for Pydantic v2 (while keeping support for v1 if v2 is not available), including initial work by AntonDeMeester (#722)

Co-authored-by: Mohamed Farahat <farahats9@yahoo.com>
Co-authored-by: Stefan Borer <stefan.borer@gmail.com>
Co-authored-by: Peter Landry <peter.landry@gmail.com>
Co-authored-by: Anton De Meester <antondemeester+github@gmail.com>
This commit is contained in:
Sebastián Ramírez
2023-12-04 15:42:39 +01:00
committed by GitHub
parent 5b733b348d
commit fa2f178b8a
79 changed files with 2614 additions and 517 deletions

View File

@@ -1,3 +1,4 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool
@@ -263,7 +264,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"HeroRead": {
@@ -273,7 +283,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -281,9 +300,36 @@ def test_tutorial(clear_sqlmodel):
"title": "HeroUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"secret_name": IsDict(
{
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Secret Name", "type": "string"}
),
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"ValidationError": {

View File

@@ -1,3 +1,4 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool
@@ -266,7 +267,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"HeroRead": {
@@ -276,7 +286,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -284,9 +303,36 @@ def test_tutorial(clear_sqlmodel):
"title": "HeroUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"secret_name": IsDict(
{
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Secret Name", "type": "string"}
),
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"ValidationError": {

View File

@@ -1,3 +1,4 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool
@@ -266,7 +267,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"HeroRead": {
@@ -276,7 +286,16 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -284,9 +303,36 @@ def test_tutorial(clear_sqlmodel):
"title": "HeroUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"secret_name": IsDict(
{
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Secret Name", "type": "string"}
),
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
},
},
"ValidationError": {