Skip to content

Commit

Permalink
@GitHK review: field not required
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jul 21, 2023
1 parent d93f5cd commit 2d6a7f3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

from typing import Any

from pydantic import BaseModel, Extra, Field
from pydantic import BaseModel, Extra

from ..utils.change_case import snake_to_camel

NOT_REQUIRED = Field(default=None)


class EmptyModel(BaseModel):
# Used to represent body={}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from ..projects_state import ProjectState
from ..projects_ui import StudyUI
from ..utils.common_validators import empty_str_to_none, none_to_empty_str
from ._base import NOT_REQUIRED, EmptyModel, InputSchema, OutputSchema
from ..utils.pydantic_tools_extension import FieldNotRequired
from ._base import EmptyModel, InputSchema, OutputSchema
from .permalinks import ProjectPermalink


Expand Down Expand Up @@ -65,7 +66,7 @@ class ProjectGet(OutputSchema):
ui: EmptyModel | StudyUI | None
quality: dict[str, Any] = {}
dev: dict | None
permalink: ProjectPermalink = NOT_REQUIRED
permalink: ProjectPermalink = FieldNotRequired()

_empty_description = validator("description", allow_reuse=True, pre=True)(
none_to_empty_str
Expand Down Expand Up @@ -103,15 +104,15 @@ class ProjectReplace(InputSchema):


class ProjectUpdate(InputSchema):
name: str = NOT_REQUIRED
description: str = NOT_REQUIRED
thumbnail: HttpUrlWithCustomMinLength = NOT_REQUIRED
workbench: NodesDict = NOT_REQUIRED
access_rights: dict[GroupIDStr, AccessRights] = NOT_REQUIRED
tags: list[int] = NOT_REQUIRED
classifiers: list[ClassifierID] = NOT_REQUIRED
name: str = FieldNotRequired()
description: str = FieldNotRequired()
thumbnail: HttpUrlWithCustomMinLength = FieldNotRequired()
workbench: NodesDict = FieldNotRequired()
access_rights: dict[GroupIDStr, AccessRights] = FieldNotRequired()
tags: list[int] = FieldNotRequired()
classifiers: list[ClassifierID] = FieldNotRequired()
ui: StudyUI | None = None
quality: dict[str, Any] = NOT_REQUIRED
quality: dict[str, Any] = FieldNotRequired()


__all__: tuple[str, ...] = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from pydantic import Field

from ..utils.serialization import json_dumps, json_loads


class BaseConfig:
json_loads = json_loads
json_dumps = json_dumps


NOT_REQUIRED = Field(default=None)
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
)
from models_library.utils.pydantic_tools_extension import FieldNotRequired
from pydantic import Field, NonNegativeInt, validator
from pydantic.generics import GenericModel

from ._utils_pydantic import NOT_REQUIRED

T = TypeVar("T")

# NOTE: same pagination limits and defaults as web-server
Expand All @@ -46,7 +45,7 @@ class OnePage(GenericModel, Generic[T]):
"""

items: Sequence[T]
total: NonNegativeInt = NOT_REQUIRED
total: NonNegativeInt = FieldNotRequired()

@validator("total", pre=True)
@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from models_library.projects import ProjectID
from models_library.projects_nodes_io import NodeID
from models_library.utils.pydantic_tools_extension import FieldNotRequired
from pydantic import BaseModel, Field

from .._utils_pydantic import NOT_REQUIRED
from .solvers import SolverPort

StudyID: TypeAlias = ProjectID
Expand All @@ -13,8 +13,8 @@
# OUTPUT
class Study(BaseModel): # StudyGet
uid: StudyID
title: str = NOT_REQUIRED
description: str = NOT_REQUIRED
title: str = FieldNotRequired()
description: str = FieldNotRequired()


class StudyPort(SolverPort):
Expand Down

0 comments on commit 2d6a7f3

Please sign in to comment.