Skip to content

Commit dc08be2

Browse files
committed
catalog
1 parent 0071bf2 commit dc08be2

File tree

2 files changed

+67
-47
lines changed

2 files changed

+67
-47
lines changed
Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from datetime import datetime
22
from typing import Annotated, Any
33

4+
from common_library.basic_types import DEFAULT_FACTORY
45
from models_library.products import ProductName
56
from models_library.services_access import ServiceGroupAccessRights
67
from models_library.services_base import ServiceKeyVersion
78
from models_library.services_metadata_editable import ServiceMetaDataEditable
89
from models_library.services_types import ServiceKey, ServiceVersion
9-
from pydantic import BaseModel, ConfigDict, Field, HttpUrl
10+
from pydantic import AfterValidator, BaseModel, ConfigDict, Field, HttpUrl
11+
from pydantic.config import JsonDict
1012
from pydantic.types import PositiveInt
1113
from simcore_postgres_database.models.services_compatibility import CompatiblePolicyDict
1214

@@ -15,45 +17,55 @@ class ServiceMetaDataAtDB(ServiceKeyVersion, ServiceMetaDataEditable):
1517
# for a partial update all Editable members must be Optional
1618
name: str | None = None
1719
thumbnail: Annotated[str, HttpUrl] | None = None
20+
icon: Annotated[HttpUrl, AfterValidator(str)] | None = None
1821
description: str | None = None
1922

20-
classifiers: Annotated[list[str] | None, Field(default_factory=list)]
23+
classifiers: Annotated[
24+
list[str] | None, Field(default_factory=list)
25+
] = DEFAULT_FACTORY
26+
2127
owner: PositiveInt | None = None
2228

23-
model_config = ConfigDict(
24-
from_attributes=True,
25-
json_schema_extra={
26-
"example": {
27-
"key": "simcore/services/dynamic/sim4life",
28-
"version": "1.0.9",
29-
"owner": 8,
30-
"name": "sim4life",
31-
"description": "s4l web",
32-
"description_ui": 0,
33-
"thumbnail": "http://thumbnailit.org/image",
34-
"version_display": "S4L X",
35-
"created": "2021-01-18 12:46:57.7315",
36-
"modified": "2021-01-19 12:45:00",
37-
"deprecated": "2099-01-19 12:45:00",
38-
"quality": {
39-
"enabled": True,
40-
"tsr_target": {
41-
f"r{n:02d}": {"level": 4, "references": ""}
42-
for n in range(1, 11)
43-
},
44-
"annotations": {
45-
"vandv": "",
46-
"limitations": "",
47-
"certificationLink": "",
48-
"certificationStatus": "Uncertified",
29+
@staticmethod
30+
def _update_json_schema_extra(schema: JsonDict) -> None:
31+
schema.update(
32+
{
33+
"example": {
34+
"key": "simcore/services/dynamic/sim4life",
35+
"version": "1.0.9",
36+
"owner": 8,
37+
"name": "sim4life",
38+
"description": "s4l web",
39+
"description_ui": 0,
40+
"thumbnail": "http://thumbnailit.org/image",
41+
"icon": "http://example.com/icon.png",
42+
"version_display": "S4L X",
43+
"created": "2021-01-18 12:46:57.7315",
44+
"modified": "2021-01-19 12:45:00",
45+
"deprecated": "2099-01-19 12:45:00",
46+
"quality": {
47+
"enabled": True,
48+
"tsr_target": {
49+
f"r{n:02d}": {"level": 4, "references": ""}
50+
for n in range(1, 11)
51+
},
52+
"annotations": {
53+
"vandv": "",
54+
"limitations": "",
55+
"certificationLink": "",
56+
"certificationStatus": "Uncertified",
57+
},
58+
"tsr_current": {
59+
f"r{n:02d}": {"level": 0, "references": ""}
60+
for n in range(1, 11)
61+
},
4962
},
50-
"tsr_current": {
51-
f"r{n:02d}": {"level": 0, "references": ""}
52-
for n in range(1, 11)
53-
},
54-
},
63+
}
5564
}
56-
},
65+
)
66+
67+
model_config = ConfigDict(
68+
from_attributes=True, json_schema_extra=_update_json_schema_extra
5769
)
5870

5971

@@ -73,6 +85,7 @@ class ServiceWithHistoryFromDB(BaseModel):
7385
description: str
7486
description_ui: bool
7587
thumbnail: str | None
88+
icon: str | None
7689
version_display: str | None
7790
# ownership
7891
owner_email: str | None
@@ -97,18 +110,24 @@ class ServiceWithHistoryFromDB(BaseModel):
97110
class ServiceAccessRightsAtDB(ServiceKeyVersion, ServiceGroupAccessRights):
98111
gid: PositiveInt
99112
product_name: ProductName
100-
model_config = ConfigDict(
101-
from_attributes=True,
102-
json_schema_extra={
103-
"example": {
104-
"key": "simcore/services/dynamic/sim4life",
105-
"version": "1.0.9",
106-
"gid": 8,
107-
"execute_access": True,
108-
"write_access": True,
109-
"product_name": "osparc",
110-
"created": "2021-01-18 12:46:57.7315",
111-
"modified": "2021-01-19 12:45:00",
113+
114+
@staticmethod
115+
def _update_json_schema_extra(schema: JsonDict) -> None:
116+
schema.update(
117+
{
118+
"example": {
119+
"key": "simcore/services/dynamic/sim4life",
120+
"version": "1.0.9",
121+
"gid": 8,
122+
"execute_access": True,
123+
"write_access": True,
124+
"product_name": "osparc",
125+
"created": "2021-01-18 12:46:57.7315",
126+
"modified": "2021-01-19 12:45:00",
127+
}
112128
}
113-
},
129+
)
130+
131+
model_config = ConfigDict(
132+
from_attributes=True, json_schema_extra=_update_json_schema_extra
114133
)

services/catalog/src/simcore_service_catalog/services/services_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _db_to_api_model(
4141
version=service_db.version,
4242
name=service_db.name,
4343
thumbnail=HttpUrl(service_db.thumbnail) if service_db.thumbnail else None,
44+
icon=None,
4445
description=service_db.description,
4546
description_ui=service_db.description_ui,
4647
version_display=service_db.version_display,

0 commit comments

Comments
 (0)