Skip to content

Commit

Permalink
#24: Workaround fastapi/fastapi#684 by setting info in models.
Browse files Browse the repository at this point in the history
  • Loading branch information
grololo06 committed Oct 7, 2021
1 parent a07ea52 commit 6fb8892
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 300 deletions.
230 changes: 165 additions & 65 deletions py/API_models/crud.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions py/API_models/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ExportReq(BaseModel):
"Per A(cquisition) or S(ample) or ''")
out_to_ftp: bool = Field(title="Copy result file to FTP area. Original file is still available.")

class Config:
schema_extra = {"title": "Export request Model"}

class ExportRsp(EMODnetExportRsp):
"""
Expand Down
9 changes: 5 additions & 4 deletions py/API_models/helpers/TypedDictToModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

# noinspection PyPackageRequirements
from pydantic import create_model

from API_models.helpers import PydanticModelT
# noinspection PyPackageRequirements
from pydantic.fields import ModelField

from API_models.helpers import PydanticModelT

# Generify the def with input type
T = TypeVar('T')


def typed_dict_to_model(typed_dict: T, field_infos: Optional[Dict[str, Any]] = None): # TODO -> Type[BaseModel]:
def typed_dict_to_model(typed_dict: T, field_infos: Optional[Dict[str, Any]] = None,
config: Any = None): # TODO -> Type[BaseModel], and type for config:
annotations = {}
for name, field in typed_dict.__annotations__.items():
if field == Optional[str]:
Expand All @@ -32,7 +33,7 @@ def typed_dict_to_model(typed_dict: T, field_infos: Optional[Dict[str, Any]] =
raise Exception("Not managed yet") # pragma:nocover

ret: PydanticModelT = create_model(
typed_dict.__name__, **annotations # type: ignore
typed_dict.__name__, __config__=config, **annotations # type: ignore
)
# Make the model get-able
# noinspection PyTypeHints
Expand Down
6 changes: 6 additions & 0 deletions py/API_models/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ImportReq(BaseModel):
update_mode: str = Field(title="Update data ('Yes'), including classification ('Cla')",
default="")

class Config:
schema_extra = {"title": "Import request Model"}


class ImportRsp(BaseModel):
""" Import response. """
Expand Down Expand Up @@ -84,6 +87,9 @@ class SimpleImportReq(BaseModel):
# default=[v for v in PossibleSimpleImportFields.__members__])
possible_values: List[str] = [v for v in SimpleImportFields.__members__]

class Config:
schema_extra = {"title": "Simple import request Model"}


class SimpleImportRsp(BaseModel):
""" Simple Import, response. """
Expand Down
7 changes: 5 additions & 2 deletions py/API_models/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class LoginReq(BaseModel):
password: str = Field(title="User's password" , default=None, description="User password", example="test!")
username: str = Field(title="User's eamil", default=None, description="User email used during registration", example="[email protected]")
password: str = Field(title="User's password", default=None, description="User password", example="test!")
username: str = Field(title="User's email", default=None, description="User email used during registration",
example="[email protected]")

class Config:
schema_extra = {"title": "Login request Model"}
173 changes: 112 additions & 61 deletions py/API_models/objects.py

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions py/API_models/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,27 @@ class PredictionReq(BaseModel):
"""
Prediction, AKA Auto Classification, request.
"""
project_id: int = Field(title="Project Id", description="The destination project, of which objects will be predicted.")
source_project_ids: List[int] = Field(title="Source project Ids", description="The source projects, objects in them will serve as reference.",
min_items=1)
features: List[str] = Field(title="Features", description="The object features AKA free column, to use in the algorithm. "
"Features must be common to all projects, source ones and destination one",
project_id: int = Field(title="Project Id",
description="The destination project, of which objects will be predicted.")
source_project_ids: List[int] = Field(title="Source project Ids",
description="The source projects, objects in them will serve as reference.",
min_items=1)
features: List[str] = Field(title="Features",
description="The object features AKA free column, to use in the algorithm. "
"Features must be common to all projects, source ones and destination one",
min_items=1)
categories: List[int] = Field(title="Categories", description="In source projects, only objects validated with these categories "
"will be considered.",
categories: List[int] = Field(title="Categories",
description="In source projects, only objects validated with these categories "
"will be considered.",
min_items=1)
use_scn: bool = Field(title="Use scn", description="Use extra features, generated using the image, for improving the prediction.",
use_scn: bool = Field(title="Use scn",
description="Use extra features, generated using the image, for improving the prediction.",
default=False)

class Config:
schema_extra = {
"title": "Prediction Request",
"description": "How to predict, in details.",
"example": {
"project_id": [3426],
"source_project_ids": [1040, 1820],
Expand All @@ -38,7 +45,8 @@ class PredictionRsp(BaseModel):
"""
Prediction response.
"""
errors: List[str] = Field(title="Errors", description="Showstopper problems found while preparing the prediction.",
errors: List[str] = Field(title="Errors",
description="Showstopper problems found while preparing the prediction.",
example=[], default=[])
warnings: List[str] = Field(title="Warnings", description="Problems found while preparing the prediction.",
example=[], default=[])
Expand Down
3 changes: 3 additions & 0 deletions py/API_models/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class SubsetReq(BaseModel):
limit_value: float = Field(title="Limit value", description="Limit value, e.g. 20% or 5 per copepoda or 5% per sample.", example=10.0)
do_images: bool = Field(title="Do images", description="If set, also clone images.", example=True)

class Config:
schema_extra = {"title": "Subset request Model"}


class SubsetRsp(BaseModel):
""" Subset response. """
Expand Down
Loading

0 comments on commit 6fb8892

Please sign in to comment.