From 35a49a478e306037fd2c4570bca17551462e5188 Mon Sep 17 00:00:00 2001 From: Pedro Crespo <32402063+pcrespov@users.noreply.github.com> Date: Mon, 26 Jun 2023 20:41:35 +0200 Subject: [PATCH] moves model classes of api schemas to models_library --- .../webserver/scripts/openapi_projects_crud.py | 18 +++++++++--------- .../api_schemas_webserver/_base.py | 3 ++- .../api_schemas_webserver/projects.py | 18 +++++++++--------- .../projects_permalink.py | 6 ++++++ .../projects/_crud_create_utils.py | 2 +- .../projects/_crud_read_utils.py | 4 ++-- .../projects/_handlers_crud.py | 14 +++++++------- .../projects/_permalink_api.py | 8 +------- .../isolated/test_projects__rest_schemas.py | 14 +++++++------- 9 files changed, 44 insertions(+), 43 deletions(-) rename services/web/server/src/simcore_service_webserver/rest/schemas_base.py => packages/models-library/src/models_library/api_schemas_webserver/_base.py (96%) rename services/web/server/src/simcore_service_webserver/projects/_rest_schemas.py => packages/models-library/src/models_library/api_schemas_webserver/projects.py (85%) create mode 100644 packages/models-library/src/models_library/api_schemas_webserver/projects_permalink.py diff --git a/api/specs/webserver/scripts/openapi_projects_crud.py b/api/specs/webserver/scripts/openapi_projects_crud.py index 6d009beb40b3..a4071a528aa6 100644 --- a/api/specs/webserver/scripts/openapi_projects_crud.py +++ b/api/specs/webserver/scripts/openapi_projects_crud.py @@ -17,6 +17,15 @@ create_openapi_specs, ) from fastapi import FastAPI, Query, status +from models_library.api_schemas_webserver.projects import ( + ProjectCopyOverride, + ProjectCreateNew, + ProjectGet, + ProjectListItem, + ProjectReplace, + ProjectUpdate, + TaskGet, +) from models_library.generics import Envelope from models_library.projects import ProjectID from models_library.rest_pagination import DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, Page @@ -29,15 +38,6 @@ _ProjectCreateParams, _ProjectListParams, ) -from simcore_service_webserver.projects._rest_schemas import ( - ProjectCopyOverride, - ProjectCreateNew, - ProjectGet, - ProjectListItem, - ProjectReplace, - ProjectUpdate, - TaskGet, -) app = FastAPI(redoc_url=None) diff --git a/services/web/server/src/simcore_service_webserver/rest/schemas_base.py b/packages/models-library/src/models_library/api_schemas_webserver/_base.py similarity index 96% rename from services/web/server/src/simcore_service_webserver/rest/schemas_base.py rename to packages/models-library/src/models_library/api_schemas_webserver/_base.py index f33b983ec867..1f0bfd645167 100644 --- a/services/web/server/src/simcore_service_webserver/rest/schemas_base.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/_base.py @@ -5,9 +5,10 @@ from typing import Any -from models_library.utils.change_case import snake_to_camel from pydantic import BaseModel, Extra +from ..utils.change_case import snake_to_camel + class InputSchema(BaseModel): class Config: # type: ignore[pydantic-alias] diff --git a/services/web/server/src/simcore_service_webserver/projects/_rest_schemas.py b/packages/models-library/src/models_library/api_schemas_webserver/projects.py similarity index 85% rename from services/web/server/src/simcore_service_webserver/projects/_rest_schemas.py rename to packages/models-library/src/models_library/api_schemas_webserver/projects.py index eb1378dd25d6..acea17923d5d 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_rest_schemas.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/projects.py @@ -7,18 +7,18 @@ from typing import Any, Literal, TypeAlias -from models_library.emails import LowerCaseEmailStr -from models_library.projects import ClassifierID, DateTimeStr, NodesDict, ProjectID -from models_library.projects_access import AccessRights, GroupIDStr -from models_library.projects_nodes import HttpUrlWithCustomMinLength -from models_library.projects_state import ProjectState -from models_library.projects_ui import StudyUI -from models_library.utils.common_validators import empty_str_to_none, none_to_empty_str from pydantic import BaseModel, Extra, Field, validator from servicelib.aiohttp.long_running_tasks.server import TaskGet -from ..rest.schemas_base import InputSchema, OutputSchema -from ._permalink_api import ProjectPermalink +from ..emails import LowerCaseEmailStr +from ..projects import ClassifierID, DateTimeStr, NodesDict, ProjectID +from ..projects_access import AccessRights, GroupIDStr +from ..projects_nodes import HttpUrlWithCustomMinLength +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 InputSchema, OutputSchema +from .projects_permalink import ProjectPermalink NOT_REQUIRED = Field(default=None) diff --git a/packages/models-library/src/models_library/api_schemas_webserver/projects_permalink.py b/packages/models-library/src/models_library/api_schemas_webserver/projects_permalink.py new file mode 100644 index 000000000000..f409d9d70df8 --- /dev/null +++ b/packages/models-library/src/models_library/api_schemas_webserver/projects_permalink.py @@ -0,0 +1,6 @@ +from pydantic import BaseModel, HttpUrl + + +class ProjectPermalink(BaseModel): + url: HttpUrl + is_public: bool diff --git a/services/web/server/src/simcore_service_webserver/projects/_crud_create_utils.py b/services/web/server/src/simcore_service_webserver/projects/_crud_create_utils.py index d05ca1ed28ef..ce6caeeb3f44 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_crud_create_utils.py +++ b/services/web/server/src/simcore_service_webserver/projects/_crud_create_utils.py @@ -6,6 +6,7 @@ from aiohttp import web from jsonschema import ValidationError as JsonSchemaValidationError +from models_library.api_schemas_webserver.projects import ProjectGet from models_library.projects import ProjectID from models_library.projects_nodes_io import NodeID, NodeIDStr from models_library.projects_state import ProjectStatus @@ -30,7 +31,6 @@ from ..users.api import get_user_name from . import projects_api from ._permalink_api import update_or_pop_permalink_in_project -from ._rest_schemas import ProjectGet from .db import ProjectDBAPI from .exceptions import ProjectInvalidRightsError, ProjectNotFoundError from .models import ProjectDict diff --git a/services/web/server/src/simcore_service_webserver/projects/_crud_read_utils.py b/services/web/server/src/simcore_service_webserver/projects/_crud_read_utils.py index d53faf00fe1c..0467bf8c955e 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_crud_read_utils.py +++ b/services/web/server/src/simcore_service_webserver/projects/_crud_read_utils.py @@ -7,6 +7,8 @@ from enum import Enum from aiohttp import web +from models_library.api_schemas_webserver._base import OutputSchema +from models_library.api_schemas_webserver.projects import ProjectListItem from models_library.projects import ProjectID from models_library.users import UserID from pydantic import BaseModel, Extra, Field, NonNegativeInt, PositiveInt @@ -14,10 +16,8 @@ from simcore_postgres_database.webserver_models import ProjectType as ProjectTypeDB from ..catalog.client import get_services_for_user_in_product -from ..rest.schemas_base import OutputSchema from . import projects_api from ._permalink_api import update_or_pop_permalink_in_project -from ._rest_schemas import ProjectListItem from .db import ProjectDBAPI from .models import ProjectDict, ProjectTypeAPI diff --git a/services/web/server/src/simcore_service_webserver/projects/_handlers_crud.py b/services/web/server/src/simcore_service_webserver/projects/_handlers_crud.py index 56c668267239..52c1a987c564 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_handlers_crud.py +++ b/services/web/server/src/simcore_service_webserver/projects/_handlers_crud.py @@ -8,6 +8,13 @@ from aiohttp import web from jsonschema import ValidationError as JsonSchemaValidationError +from models_library.api_schemas_webserver.projects import ( + EmptyModel, + ProjectCopyOverride, + ProjectCreateNew, + ProjectGet, + ProjectUpdate, +) from models_library.projects import Project, ProjectID from models_library.projects_state import ProjectLocked from models_library.rest_pagination import DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, Page @@ -42,13 +49,6 @@ from . import _crud_create_utils, _crud_read_utils, projects_api from ._crud_read_utils import OrderDirection, ProjectListFilters, ProjectOrderBy from ._permalink_api import update_or_pop_permalink_in_project -from ._rest_schemas import ( - EmptyModel, - ProjectCopyOverride, - ProjectCreateNew, - ProjectGet, - ProjectUpdate, -) from .db import ProjectDBAPI from .exceptions import ( ProjectDeleteError, diff --git a/services/web/server/src/simcore_service_webserver/projects/_permalink_api.py b/services/web/server/src/simcore_service_webserver/projects/_permalink_api.py index 4af2715ac4f0..7239cabd1368 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_permalink_api.py +++ b/services/web/server/src/simcore_service_webserver/projects/_permalink_api.py @@ -3,8 +3,8 @@ from typing import Any, Callable, Coroutine, cast from aiohttp import web +from models_library.api_schemas_webserver.projects_permalink import ProjectPermalink from models_library.projects import ProjectID -from pydantic import BaseModel, HttpUrl from .exceptions import PermalinkFactoryError, PermalinkNotAllowedError from .models import ProjectDict @@ -12,12 +12,6 @@ _PROJECT_PERMALINK = f"{__name__}" _logger = logging.getLogger(__name__) - -class ProjectPermalink(BaseModel): - url: HttpUrl - is_public: bool - - _CreateLinkCallable = Callable[ [web.Request, ProjectID], Coroutine[Any, Any, ProjectPermalink] ] diff --git a/services/web/server/tests/unit/isolated/test_projects__rest_schemas.py b/services/web/server/tests/unit/isolated/test_projects__rest_schemas.py index f114bf8a932a..b8e4fcbdc477 100644 --- a/services/web/server/tests/unit/isolated/test_projects__rest_schemas.py +++ b/services/web/server/tests/unit/isolated/test_projects__rest_schemas.py @@ -5,6 +5,13 @@ import pytest +from models_library.api_schemas_webserver.projects import ( + ProjectCreateNew, + ProjectGet, + ProjectListItem, + ProjectReplace, + TaskProjectGet, +) from models_library.generics import Envelope from models_library.rest_pagination import Page from pydantic import parse_obj_as @@ -19,13 +26,6 @@ REPLACE_PROJECT_ON_MODIFIED, HttpApiCallCapture, ) -from simcore_service_webserver.projects._rest_schemas import ( - ProjectCreateNew, - ProjectGet, - ProjectListItem, - ProjectReplace, - TaskProjectGet, -) @pytest.mark.parametrize(