Fix fastapi tests

This commit is contained in:
Santiago Martinez 2023-08-09 01:04:40 +01:00
parent 40bcdfecff
commit 972ee56fde
15 changed files with 266 additions and 89 deletions

View File

@ -79,7 +79,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
db_hero = session.get(Hero, hero_id) db_hero = session.get(Hero, hero_id)
if not db_hero: if not db_hero:
raise HTTPException(status_code=404, detail="Hero not found") raise HTTPException(status_code=404, detail="Hero not found")
hero_data = hero.dict(exclude_unset=True) hero_data = hero.model_dump(exclude_unset=True)
for key, value in hero_data.items(): for key, value in hero_data.items():
setattr(db_hero, key, value) setattr(db_hero, key, value)
session.add(db_hero) session.add(db_hero)

View File

@ -236,7 +236,6 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
class_dict: Dict[str, Any], class_dict: Dict[str, Any],
**kwargs: Any, **kwargs: Any,
) -> Any: ) -> Any:
relationships: Dict[str, RelationshipInfo] = {} relationships: Dict[str, RelationshipInfo] = {}
dict_for_pydantic = {} dict_for_pydantic = {}
original_annotations = class_dict.get("__annotations__", {}) original_annotations = class_dict.get("__annotations__", {})
@ -569,7 +568,22 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
validated = super().model_validate( validated = super().model_validate(
obj, strict=strict, from_attributes=from_attributes, context=context obj, strict=strict, from_attributes=from_attributes, context=context
) )
return cls(**{key: value for key, value in validated})
# remove defaults so they don't get validated
data = {}
for key, value in validated:
field = cls.model_fields[key]
if (
hasattr(field, "default")
and field.default is not PydanticUndefined
and value == field.default
):
continue
data[key] = value
return cls(**data)
def _is_field_noneable(field: FieldInfo) -> bool: def _is_field_noneable(field: FieldInfo) -> bool:

View File

@ -35,6 +35,14 @@ class SelectOfScalar(_Select[Tuple[_TSelect]], Generic[_TSelect]):
inherit_cache = True inherit_cache = True
# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select, Generic[_TSelect]):
inherit_cache = True
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from ..main import SQLModel from ..main import SQLModel

View File

@ -1,3 +1,5 @@
from typing import Any
from sqlmodel.default import Default from sqlmodel.default import Default
@ -9,7 +11,7 @@ def test_default_bool() -> None:
df1 = Default(False) df1 = Default(False)
df2 = Default(0) df2 = Default(0)
df3 = Default("") df3 = Default("")
df4: list = Default([]) df4: list[Any] = Default([])
df5 = Default(None) df5 = Default(None)
assert not not dt1 assert not not dt1

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -210,7 +210,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -220,7 +223,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -228,9 +234,18 @@ openapi_schema = {
"title": "HeroUpdate", "title": "HeroUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"secret_name": {"title": "Secret Name", "type": "string"}, "title": "Name",
"age": {"title": "Age", "type": "integer"}, "anyOf": [{"type": "string"}, {"type": "null"}],
},
"secret_name": {
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -241,7 +256,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -261,7 +276,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -142,7 +142,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -152,7 +155,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -164,7 +170,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -184,7 +190,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -5,7 +5,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -81,7 +81,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -92,7 +95,10 @@ openapi_schema = {
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -103,7 +109,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -123,7 +129,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -5,7 +5,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -81,7 +81,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -91,7 +94,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -103,7 +109,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -123,7 +129,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -113,7 +113,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -123,7 +126,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -135,7 +141,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -155,7 +161,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -397,8 +397,14 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"team_id": {"title": "Team Id", "type": "integer"}, "title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -408,8 +414,14 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"team_id": {"title": "Team Id", "type": "integer"}, "title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -420,20 +432,43 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"team_id": {"title": "Team Id", "type": "integer"}, "title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
"team": {"$ref": "#/components/schemas/TeamRead"}, "team": {
"anyOf": [
{"$ref": "#/components/schemas/TeamRead"},
{"type": "null"},
]
},
}, },
}, },
"HeroUpdate": { "HeroUpdate": {
"title": "HeroUpdate", "title": "HeroUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"secret_name": {"title": "Secret Name", "type": "string"}, "title": "Name",
"age": {"title": "Age", "type": "integer"}, "anyOf": [{"type": "string"}, {"type": "null"}],
"team_id": {"title": "Team Id", "type": "integer"}, },
"secret_name": {
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"TeamCreate": { "TeamCreate": {
@ -475,9 +510,18 @@ openapi_schema = {
"title": "TeamUpdate", "title": "TeamUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"id": {"title": "Id", "type": "integer"}, "id": {
"name": {"title": "Name", "type": "string"}, "title": "Id",
"headquarters": {"title": "Headquarters", "type": "string"}, "anyOf": [{"type": "integer"}, {"type": "null"}],
},
"name": {
"title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"headquarters": {
"title": "Headquarters",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -488,7 +532,7 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -74,13 +74,18 @@ openapi_schema = {
}, },
"Hero": { "Hero": {
"title": "Hero", "title": "Hero",
"required": ["name", "secret_name"],
"type": "object", "type": "object",
"properties": { "properties": {
"id": {"title": "Id", "type": "integer"}, "id": {
"title": "Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -91,7 +96,9 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {
"anyOf": [{"type": "string"}, {"type": "integer"}],
},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -111,7 +118,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
response = client.post("/heroes/", json=hero_data) response = client.post("/heroes/", json=hero_data)
data = response.json() data = response.json()

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -210,7 +210,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -220,7 +223,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -228,9 +234,18 @@ openapi_schema = {
"title": "HeroUpdate", "title": "HeroUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"secret_name": {"title": "Secret Name", "type": "string"}, "title": "Name",
"age": {"title": "Age", "type": "integer"}, "anyOf": [{"type": "string"}, {"type": "null"}],
},
"secret_name": {
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -241,7 +256,9 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {
"anyOf": [{"type": "string"}, {"type": "integer"}],
},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -261,7 +278,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -62,13 +62,18 @@ openapi_schema = {
}, },
"Hero": { "Hero": {
"title": "Hero", "title": "Hero",
"required": ["name", "secret_name"],
"type": "object", "type": "object",
"properties": { "properties": {
"id": {"title": "Id", "type": "integer"}, "id": {
"title": "Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -79,7 +84,9 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {
"anyOf": [{"type": "string"}, {"type": "integer"}],
},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -99,7 +106,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -393,8 +393,14 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"team_id": {"title": "Team Id", "type": "integer"}, "title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -404,8 +410,14 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"team_id": {"title": "Team Id", "type": "integer"}, "title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -413,10 +425,22 @@ openapi_schema = {
"title": "HeroUpdate", "title": "HeroUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"secret_name": {"title": "Secret Name", "type": "string"}, "title": "Name",
"age": {"title": "Age", "type": "integer"}, "anyOf": [{"type": "string"}, {"type": "null"}],
"team_id": {"title": "Team Id", "type": "integer"}, },
"secret_name": {
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"team_id": {
"title": "Team Id",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"TeamCreate": { "TeamCreate": {
@ -442,8 +466,14 @@ openapi_schema = {
"title": "TeamUpdate", "title": "TeamUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"headquarters": {"title": "Headquarters", "type": "string"}, "title": "Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"headquarters": {
"title": "Headquarters",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -454,7 +484,9 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {
"anyOf": [{"type": "string"}, {"type": "integer"}],
},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -474,7 +506,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",

View File

@ -3,7 +3,7 @@ from sqlmodel import create_engine
from sqlmodel.pool import StaticPool from sqlmodel.pool import StaticPool
openapi_schema = { openapi_schema = {
"openapi": "3.0.2", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
"/heroes/": { "/heroes/": {
@ -182,7 +182,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"HeroRead": { "HeroRead": {
@ -192,7 +195,10 @@ openapi_schema = {
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"secret_name": {"title": "Secret Name", "type": "string"}, "secret_name": {"title": "Secret Name", "type": "string"},
"age": {"title": "Age", "type": "integer"}, "age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
"id": {"title": "Id", "type": "integer"}, "id": {"title": "Id", "type": "integer"},
}, },
}, },
@ -200,9 +206,18 @@ openapi_schema = {
"title": "HeroUpdate", "title": "HeroUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {
"secret_name": {"title": "Secret Name", "type": "string"}, "title": "Name",
"age": {"title": "Age", "type": "integer"}, "anyOf": [{"type": "string"}, {"type": "null"}],
},
"secret_name": {
"title": "Secret Name",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"age": {
"title": "Age",
"anyOf": [{"type": "integer"}, {"type": "null"}],
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -213,7 +228,9 @@ openapi_schema = {
"loc": { "loc": {
"title": "Location", "title": "Location",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {
"anyOf": [{"type": "string"}, {"type": "integer"}],
},
}, },
"msg": {"title": "Message", "type": "string"}, "msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"}, "type": {"title": "Error Type", "type": "string"},
@ -233,7 +250,6 @@ def test_tutorial(clear_sqlmodel):
) )
with TestClient(mod.app) as client: with TestClient(mod.app) as client:
hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"} hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
hero2_data = { hero2_data = {
"name": "Spider-Boy", "name": "Spider-Boy",