Skip to content

Commit 3bdc8a2

Browse files
committed
cleanup
1 parent 611db31 commit 3bdc8a2

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from typing import Any, TypeAlias
2+
from typing import Annotated, Any, TypeAlias
33

44
from models_library.rpc_pagination import PageRpc
55
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, NonNegativeInt
@@ -24,6 +24,10 @@
2424

2525

2626
class ServiceUpdate(ServiceMetaDataEditable, ServiceAccessRights):
27+
28+
thumbnail: Annotated[str, HttpUrl] | None = None
29+
icon: HttpUrl | None = None
30+
2731
@staticmethod
2832
def _update_json_schema_extra(schema: JsonDict) -> None:
2933
schema.update(

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,39 @@
22
33
"""
44

5+
from typing import Annotated
6+
57
from pydantic import BaseModel, ConfigDict, Field
68

79
from .groups import GroupID
810
from .utils.change_case import snake_to_camel
911

1012

1113
class ServiceGroupAccessRights(BaseModel):
12-
execute_access: bool = Field(
13-
default=False,
14-
description="defines whether the group can execute the service",
15-
)
16-
write_access: bool = Field(
17-
default=False, description="defines whether the group can modify the service"
18-
)
14+
execute_access: Annotated[
15+
bool, Field(description="defines whether the group can execute the service")
16+
] = False
17+
write_access: Annotated[
18+
bool, Field(description="defines whether the group can modify the service")
19+
] = False
1920

2021

2122
class ServiceGroupAccessRightsV2(BaseModel):
2223
execute: bool = False
2324
write: bool = False
2425

2526
model_config = ConfigDict(
26-
alias_generator=snake_to_camel, populate_by_name=True, extra="forbid"
27+
alias_generator=snake_to_camel,
28+
populate_by_name=True,
29+
extra="forbid",
2730
)
2831

2932

3033
class ServiceAccessRights(BaseModel):
31-
access_rights: dict[GroupID, ServiceGroupAccessRights] | None = Field(
32-
None,
33-
alias="accessRights",
34-
description="service access rights per group id",
35-
)
34+
access_rights: Annotated[
35+
dict[GroupID, ServiceGroupAccessRightsV2] | None,
36+
Field(
37+
alias="accessRights",
38+
description="service access rights per group id",
39+
),
40+
] = None

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

Lines changed: 5 additions & 4 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 AfterValidator, ConfigDict, Field, HttpUrl
5+
from common_library.basic_types import DEFAULT_FACTORY
6+
from pydantic import ConfigDict, Field, HttpUrl
67
from pydantic.config import JsonDict
78

89
from .services_base import ServiceBaseDisplay
@@ -20,8 +21,8 @@
2021
class ServiceMetaDataEditable(ServiceBaseDisplay):
2122
# Overrides ServiceBaseDisplay fields to Optional for a partial update
2223
name: str | None # type: ignore[assignment]
23-
thumbnail: Annotated[str, HttpUrl] | None = None
24-
icon: Annotated[HttpUrl, AfterValidator(str)] | None = None
24+
thumbnail: Annotated[str, HttpUrl] | None # type: ignore[assignment]
25+
icon: HttpUrl | None # type: ignore[assignment]
2526
description: str | None # type: ignore[assignment]
2627
description_ui: bool = False
2728
version_display: str | None = None
@@ -37,7 +38,7 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
3738
classifiers: list[str] | None
3839
quality: Annotated[
3940
dict[str, Any], Field(default_factory=dict, json_schema_extra={"default": {}})
40-
]
41+
] = DEFAULT_FACTORY
4142

4243
@staticmethod
4344
def _update_json_schema_extra(schema: JsonDict) -> None:

services/catalog/src/simcore_service_catalog/db/repositories/_services_sql.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def list_latest_services_with_history_stmt(
274274
latest_query.c.description,
275275
latest_query.c.description_ui,
276276
latest_query.c.thumbnail,
277+
latest_query.c.icon,
277278
latest_query.c.version_display,
278279
# ownership
279280
latest_query.c.owner_email,
@@ -313,6 +314,7 @@ def list_latest_services_with_history_stmt(
313314
latest_query.c.description,
314315
latest_query.c.description_ui,
315316
latest_query.c.thumbnail,
317+
latest_query.c.icon,
316318
latest_query.c.version_display,
317319
latest_query.c.classifiers,
318320
latest_query.c.created,

services/catalog/tests/unit/with_dbs/test_api_rest_services__list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ async def test_list_services_with_details(
5656
url = URL("/v0/services").with_query({"user_id": user_id, "details": "true"})
5757

5858
# now fake the director such that it returns half the services
59-
fake_registry_service_data = ServiceMetaDataPublished.model_config[
60-
"json_schema_extra"
61-
]["examples"][0]
59+
fake_registry_service_data = ServiceMetaDataPublished.model_json_schema()[
60+
"examples"
61+
][0]
6262

6363
mocked_director_service_api_base.get("/services", name="list_services").respond(
6464
200,
@@ -262,9 +262,9 @@ async def test_list_services_that_are_deprecated(
262262
assert received_service.deprecated == deprecation_date
263263

264264
# for details, the director must return the same service
265-
fake_registry_service_data = ServiceMetaDataPublished.model_config[
266-
"json_schema_extra"
267-
]["examples"][0]
265+
fake_registry_service_data = ServiceMetaDataPublished.model_json_schema()[
266+
"examples"
267+
][0]
268268
mocked_director_service_api_base.get("/services", name="list_services").respond(
269269
200,
270270
json={

0 commit comments

Comments
 (0)