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
@@ -518,8 +519,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"HeroRead": {
@@ -529,8 +548,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -538,10 +575,46 @@ 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"},
"team_id": {"title": "Team Id", "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"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"TeamCreate": {
@@ -567,8 +640,26 @@ def test_tutorial(clear_sqlmodel):
"title": "TeamUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"headquarters": {"title": "Headquarters", "type": "string"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"headquarters": IsDict(
{
"title": "Headquarters",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Headquarters", "type": "string"}
),
},
},
"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
@@ -521,8 +522,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"HeroRead": {
@@ -532,8 +551,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -541,10 +578,46 @@ 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"},
"team_id": {"title": "Team Id", "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"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"TeamCreate": {
@@ -570,8 +643,26 @@ def test_tutorial(clear_sqlmodel):
"title": "TeamUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"headquarters": {"title": "Headquarters", "type": "string"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"headquarters": IsDict(
{
"title": "Headquarters",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Headquarters", "type": "string"}
),
},
},
"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
@@ -521,8 +522,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"HeroRead": {
@@ -532,8 +551,26 @@ def test_tutorial(clear_sqlmodel):
"properties": {
"name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"team_id": {"title": "Team Id", "type": "integer"},
"age": IsDict(
{
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Age", "type": "integer"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
"id": {"title": "Id", "type": "integer"},
},
},
@@ -541,10 +578,46 @@ 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"},
"team_id": {"title": "Team Id", "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"}
),
"team_id": IsDict(
{
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Team Id", "type": "integer"}
),
},
},
"TeamCreate": {
@@ -570,8 +643,26 @@ def test_tutorial(clear_sqlmodel):
"title": "TeamUpdate",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"headquarters": {"title": "Headquarters", "type": "string"},
"name": IsDict(
{
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Name", "type": "string"}
),
"headquarters": IsDict(
{
"title": "Headquarters",
"anyOf": [{"type": "string"}, {"type": "null"}],
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Headquarters", "type": "string"}
),
},
},
"ValidationError": {