Skip to content

Commit 8e88112

Browse files
author
Andrei Neagu
committed
extend models library
1 parent 29f60e0 commit 8e88112

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
from common_library.basic_types import DEFAULT_FACTORY
1313
from common_library.dict_tools import remap_keys
14+
from models_library.projects import ProjectTemplateType, ProjectType
1415
from pydantic import (
1516
BeforeValidator,
1617
ConfigDict,
1718
Field,
1819
HttpUrl,
1920
PlainSerializer,
21+
ValidationInfo,
2022
field_validator,
2123
)
2224
from pydantic.config import JsonDict
@@ -101,6 +103,9 @@ def to_domain_model(self) -> dict[str, Any]:
101103
class ProjectGet(OutputSchema):
102104
uuid: ProjectID
103105

106+
type: ProjectType
107+
template_type: ProjectTemplateType | None
108+
104109
# display
105110
name: str
106111
description: str
@@ -144,12 +149,28 @@ class ProjectGet(OutputSchema):
144149
none_to_empty_str_pre_validator
145150
)
146151

152+
@field_validator("template_type")
153+
@classmethod
154+
def validate_template_type(
155+
cls, v: ProjectTemplateType | None, info: ValidationInfo
156+
) -> ProjectTemplateType | None:
157+
type_value = info.data.get("type")
158+
if type_value == ProjectType.STANDARD and v is not None:
159+
msg = "template_type must be None when type is STANDARD"
160+
raise ValueError(msg)
161+
if type_value == ProjectType.TEMPLATE and v is None:
162+
msg = "template_type must not be None when type is TEMPLATE"
163+
raise ValueError(msg)
164+
return v
165+
147166
@staticmethod
148167
def _update_json_schema_extra(schema: JsonDict) -> None:
149168
schema.update(
150169
examples=[
151170
{
152171
"uuid": "a8b0f384-bd08-4793-ab25-65d5a755f4b6",
172+
"type": "STANDARD",
173+
"template_type": None,
153174
"name": "My Project",
154175
"description": "This is a sample project",
155176
"thumbnail": "https://example.com/thumbnail.png",

packages/models-library/src/models_library/projects.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class ProjectType(str, Enum):
5252
STANDARD = "STANDARD"
5353

5454

55+
class ProjectTemplateType(str, Enum):
56+
TEMPLATE = "TEMPLATE"
57+
TUTORIAL = "TUTORIAL"
58+
HYPERTOOL = "HYPERTOOL"
59+
60+
5561
class BaseProjectModel(BaseModel):
5662
# Description of the project
5763
uuid: Annotated[

packages/pytest-simcore/src/pytest_simcore/simcore_webserver_projects_rest_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def request_desc(self) -> str:
6060
response_body={
6161
"data": {
6262
"uuid": "18f1938c-567d-11ec-b2f3-02420a000010",
63+
"type": "STANDARD",
64+
"template_type": None,
6365
"name": "New Study",
6466
"description": "",
6567
"accessRights": {"2": {"read": True, "write": True, "delete": True}},
@@ -94,6 +96,8 @@ def request_desc(self) -> str:
9496
response_body={
9597
"data": {
9698
"uuid": "18f1938c-567d-11ec-b2f3-02420a000010",
99+
"type": "STANDARD",
100+
"template_type": None,
97101
"name": "New Study",
98102
"description": "",
99103
"thumbnail": "",
@@ -225,6 +229,8 @@ def request_desc(self) -> str:
225229
response_body={
226230
"data": {
227231
"uuid": "18f1938c-567d-11ec-b2f3-02420a000010",
232+
"type": "STANDARD",
233+
"template_type": None,
228234
"name": "New Study",
229235
"description": "",
230236
"thumbnail": "",
@@ -414,6 +420,8 @@ def request_desc(self) -> str:
414420
response_body={
415421
"data": {
416422
"uuid": "18f1938c-567d-11ec-b2f3-02420a000010",
423+
"type": "STANDARD",
424+
"template_type": None,
417425
"name": "New Study",
418426
"description": "",
419427
"thumbnail": "",
@@ -599,6 +607,8 @@ def request_desc(self) -> str:
599607
"data": [
600608
{
601609
"uuid": "18f1938c-567d-11ec-b2f3-02420a000010",
610+
"type": "STANDARD",
611+
"template_type": None,
602612
"name": "New Study",
603613
"description": "",
604614
"thumbnail": "",
@@ -797,6 +807,8 @@ def request_desc(self) -> str:
797807
response_body={
798808
"data": {
799809
"uuid": "4c58409a-d9e4-11ed-9c9e-02420a0b755a",
810+
"type": "STANDARD",
811+
"template_type": None,
800812
"name": "Sleepers",
801813
"description": "5 sleepers interconnected",
802814
"thumbnail": "https://raw.githubusercontent.com/ITISFoundation/osparc-assets/main/assets/TheSoftWatches.jpg",

0 commit comments

Comments
 (0)