Skip to content

Commit 0071bf2

Browse files
committed
models library
1 parent 4e2916c commit 0071bf2

File tree

3 files changed

+84
-65
lines changed

3 files changed

+84
-65
lines changed

packages/models-library/src/models_library/api_schemas_catalog/services.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
129129
"thumbnail": None,
130130
"description": "A service which awaits for time to pass, two times.",
131131
"description_ui": True,
132+
"icon": "https://cdn-icons-png.flaticon.com/512/25/25231.png",
132133
"classifiers": [],
133134
"quality": {},
134135
"accessRights": {"1": {"execute": True, "write": False}},
@@ -231,6 +232,7 @@ class ServiceGetV2(BaseModel):
231232

232233
name: str
233234
thumbnail: HttpUrl | None = None
235+
icon: HttpUrl | None = None
234236
description: str
235237

236238
description_ui: bool = False
@@ -341,6 +343,7 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
341343
class ServiceUpdateV2(BaseModel):
342344
name: str | None = None
343345
thumbnail: HttpUrl | None = None
346+
icon: HttpUrl | None = None
344347

345348
description: str | None = None
346349
description_ui: bool = False

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

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,56 @@ class ServiceKeyVersion(BaseModel):
1616
description="distinctive name for the node based on the docker registry path",
1717
),
1818
]
19-
version: ServiceVersion = Field(
20-
...,
21-
description="service version number",
22-
)
19+
version: Annotated[
20+
ServiceVersion,
21+
Field(
22+
description="service version number",
23+
),
24+
]
2325

2426
model_config = ConfigDict(frozen=True)
2527

2628

2729
class ServiceBaseDisplay(BaseModel):
28-
name: str = Field(
29-
...,
30-
description="Display name: short, human readable name for the node",
31-
examples=["Fast Counter"],
32-
)
33-
thumbnail: Annotated[str, HttpUrl] | None = Field(
34-
None,
35-
description="url to the thumbnail",
36-
examples=[
37-
"https://user-images.githubusercontent.com/32800795/61083844-ff48fb00-a42c-11e9-8e63-fa2d709c8baf.png"
38-
],
39-
validate_default=True,
40-
)
41-
description: str = Field(
42-
...,
43-
description="human readable description of the purpose of the node",
44-
examples=[
45-
"Our best node type",
46-
"The mother of all nodes, makes your numbers shine!",
47-
],
48-
)
49-
description_ui: bool = Field(
50-
default=False,
51-
description="A flag to enable the `description` to be presented as a single web page (=true) or in another structured format (default=false).",
52-
)
53-
54-
version_display: str | None = Field(
55-
None,
56-
description="A user-friendly or marketing name for the release."
57-
" This can be used to reference the release in a more readable and recognizable format, such as 'Matterhorn Release,' 'Spring Update,' or 'Holiday Edition.'"
58-
" This name is not used for version comparison but is useful for communication and documentation purposes.",
59-
)
30+
name: Annotated[
31+
str,
32+
Field(
33+
description="Display name: short, human readable name for the node",
34+
examples=["Fast Counter"],
35+
),
36+
]
37+
thumbnail: Annotated[
38+
str | None,
39+
Field(
40+
description="URL to the service thumbnail",
41+
validate_default=True,
42+
),
43+
] = None
44+
icon: Annotated[HttpUrl | None, Field(description="URL to the service icon")] = None
45+
description: Annotated[
46+
str,
47+
Field(
48+
description="human readable description of the purpose of the node",
49+
examples=[
50+
"Our best node type",
51+
"The mother of all nodes, makes your numbers shine!",
52+
],
53+
),
54+
]
55+
description_ui: Annotated[
56+
bool,
57+
Field(
58+
description="A flag to enable the `description` to be presented as a single web page (=true) or in another structured format (default=false)."
59+
),
60+
] = False
61+
version_display: Annotated[
62+
str | None,
63+
Field(
64+
description="A user-friendly or marketing name for the release."
65+
"This can be used to reference the release in a more readable and recognizable format, such as 'Matterhorn Release,' 'Spring Update,' or 'Holiday Edition.' "
66+
"This name is not used for version comparison but is useful for communication and documentation purposes."
67+
),
68+
] = None
6069

6170
_empty_is_none = field_validator("thumbnail", mode="before")(
6271
empty_str_to_none_pre_validator

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

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from datetime import datetime
33
from typing import Annotated, Any
44

5-
from pydantic import ConfigDict, Field, HttpUrl
5+
from pydantic import AfterValidator, ConfigDict, Field, HttpUrl
6+
from pydantic.config import JsonDict
67

78
from .services_base import ServiceBaseDisplay
89
from .services_constants import LATEST_INTEGRATION_VERSION
@@ -19,7 +20,8 @@
1920
class ServiceMetaDataEditable(ServiceBaseDisplay):
2021
# Overrides ServiceBaseDisplay fields to Optional for a partial update
2122
name: str | None # type: ignore[assignment]
22-
thumbnail: Annotated[str, HttpUrl] | None
23+
thumbnail: Annotated[str, HttpUrl] | None = None
24+
icon: Annotated[HttpUrl, AfterValidator(str)] | None = None
2325
description: str | None # type: ignore[assignment]
2426
description_ui: bool = False
2527
version_display: str | None = None
@@ -37,32 +39,37 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
3739
dict[str, Any], Field(default_factory=dict, json_schema_extra={"default": {}})
3840
]
3941

40-
model_config = ConfigDict(
41-
json_schema_extra={
42-
"example": {
43-
"key": "simcore/services/dynamic/sim4life",
44-
"version": "1.0.9",
45-
"name": "sim4life",
46-
"description": "s4l web",
47-
"thumbnail": "https://thumbnailit.org/image",
48-
"quality": {
49-
"enabled": True,
50-
"tsr_target": {
51-
f"r{n:02d}": {"level": 4, "references": ""}
52-
for n in range(1, 11)
42+
@staticmethod
43+
def _update_json_schema_extra(schema: JsonDict) -> None:
44+
schema.update(
45+
{
46+
"example": {
47+
"key": "simcore/services/dynamic/sim4life",
48+
"version": "1.0.9",
49+
"name": "sim4life",
50+
"description": "s4l web",
51+
"thumbnail": "https://thumbnailit.org/image",
52+
"icon": "https://cdn-icons-png.flaticon.com/512/25/25231.png",
53+
"quality": {
54+
"enabled": True,
55+
"tsr_target": {
56+
f"r{n:02d}": {"level": 4, "references": ""}
57+
for n in range(1, 11)
58+
},
59+
"annotations": {
60+
"vandv": "",
61+
"limitations": "",
62+
"certificationLink": "",
63+
"certificationStatus": "Uncertified",
64+
},
65+
"tsr_current": {
66+
f"r{n:02d}": {"level": 0, "references": ""}
67+
for n in range(1, 11)
68+
},
5369
},
54-
"annotations": {
55-
"vandv": "",
56-
"limitations": "",
57-
"certificationLink": "",
58-
"certificationStatus": "Uncertified",
59-
},
60-
"tsr_current": {
61-
f"r{n:02d}": {"level": 0, "references": ""}
62-
for n in range(1, 11)
63-
},
64-
},
65-
"classifiers": [],
70+
"classifiers": [],
71+
}
6672
}
67-
}
68-
)
73+
)
74+
75+
model_config = ConfigDict(json_schema_extra=_update_json_schema_extra)

0 commit comments

Comments
 (0)