mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-14 20:30:31 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79dde8008a | ||
|
|
adb017d6ce | ||
|
|
e160cc5fea |
@@ -67,7 +67,6 @@ def get_object_or_404(
|
|||||||
row = result.scalar_one_or_none()
|
row = result.scalar_one_or_none()
|
||||||
if row is None:
|
if row is None:
|
||||||
raise HTTPException(status_code=404, detail="The object does not exist.")
|
raise HTTPException(status_code=404, detail="The object does not exist.")
|
||||||
|
|
||||||
obj_dict = row
|
obj_dict = row
|
||||||
if expunge:
|
if expunge:
|
||||||
await db.expunge(obj_dict)
|
await db.expunge(obj_dict)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
from .response_schema import * #noqa
|
from .response_schema import * #noqa
|
||||||
|
from .schema_optional import * #noqa
|
||||||
|
|||||||
19
creyPY/fastapi/schemas/schema_optional.py
Normal file
19
creyPY/fastapi/schemas/schema_optional.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from typing import Optional, Type, Union, get_args, get_origin, get_type_hints
|
||||||
|
|
||||||
|
from pydantic import BaseModel, create_model
|
||||||
|
|
||||||
|
|
||||||
|
def optional_fields(cls: Type[BaseModel]) -> Type[BaseModel]:
|
||||||
|
fields = {}
|
||||||
|
for name, hint in get_type_hints(cls).items():
|
||||||
|
if name.startswith("_"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if get_origin(hint) is not Union or type(None) not in get_args(hint):
|
||||||
|
hint = Optional[hint]
|
||||||
|
|
||||||
|
fields[name] = (hint, None)
|
||||||
|
|
||||||
|
new_model = create_model(cls.__name__, __base__=cls, **fields)
|
||||||
|
|
||||||
|
return new_model
|
||||||
@@ -1 +1 @@
|
|||||||
stripe==11.6.0 # Stripe
|
stripe==12.0.0 # Stripe
|
||||||
|
|||||||
Reference in New Issue
Block a user