Skip to content

Commit 0eca9c2

Browse files
authored
♻️ Refactors catalog's update_service operation (#7181)
1 parent 1853c29 commit 0eca9c2

File tree

18 files changed

+351
-801
lines changed

18 files changed

+351
-801
lines changed

.github/workflows/ci-testing-pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Check openapi specs are up to date
4040
run: |
4141
if ! ./ci/github/helpers/openapi-specs-diff.bash diff \
42-
https://raw.githubusercontent.com/${{ github.event.pull_request.head.repo.full_name }}/${{ github.event.after }} \
42+
https://raw.githubusercontent.com/${{ github.event.pull_request.head.repo.full_name }}/${{ github.event.pull_request.head.sha }} \
4343
.; then \
4444
echo "::error:: OAS are not up to date. Run 'make openapi-specs' to update them"; exit 1; \
4545
fi

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

Lines changed: 66 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from models_library.rpc_pagination import PageRpc
55
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, NonNegativeInt
6+
from pydantic.config import JsonDict
67

78
from ..boot_options import BootOptions
89
from ..emails import LowerCaseEmailStr
@@ -21,60 +22,6 @@
2122
from ..services_types import ServiceKey, ServiceVersion
2223
from ..utils.change_case import snake_to_camel
2324

24-
25-
class ServiceUpdate(ServiceMetaDataEditable, ServiceAccessRights):
26-
model_config = ConfigDict(
27-
json_schema_extra={
28-
"example": {
29-
# ServiceAccessRights
30-
"accessRights": {
31-
1: {
32-
"execute_access": False,
33-
"write_access": False,
34-
}, # type: ignore[dict-item]
35-
2: {
36-
"execute_access": True,
37-
"write_access": True,
38-
}, # type: ignore[dict-item]
39-
44: {
40-
"execute_access": False,
41-
"write_access": False,
42-
}, # type: ignore[dict-item]
43-
},
44-
# ServiceMetaData = ServiceCommonData +
45-
"name": "My Human Readable Service Name",
46-
"thumbnail": None,
47-
"description": "An interesting service that does something",
48-
"classifiers": ["RRID:SCR_018997", "RRID:SCR_019001"],
49-
"quality": {
50-
"tsr": {
51-
"r01": {"level": 3, "references": ""},
52-
"r02": {"level": 2, "references": ""},
53-
"r03": {"level": 0, "references": ""},
54-
"r04": {"level": 0, "references": ""},
55-
"r05": {"level": 2, "references": ""},
56-
"r06": {"level": 0, "references": ""},
57-
"r07": {"level": 0, "references": ""},
58-
"r08": {"level": 1, "references": ""},
59-
"r09": {"level": 0, "references": ""},
60-
"r10": {"level": 0, "references": ""},
61-
},
62-
"enabled": True,
63-
"annotations": {
64-
"vandv": "",
65-
"purpose": "",
66-
"standards": "",
67-
"limitations": "",
68-
"documentation": "",
69-
"certificationLink": "",
70-
"certificationStatus": "Uncertified",
71-
},
72-
},
73-
}
74-
}
75-
)
76-
77-
7825
_EXAMPLE_FILEPICKER: dict[str, Any] = {
7926
"name": "File Picker",
8027
"thumbnail": None,
@@ -209,10 +156,14 @@ class ServiceGet(
209156
description="None when the owner email cannot be found in the database"
210157
)
211158

159+
@staticmethod
160+
def _update_json_schema_extra(schema: JsonDict) -> None:
161+
schema.update({"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]})
162+
212163
model_config = ConfigDict(
213164
extra="ignore",
214165
populate_by_name=True,
215-
json_schema_extra={"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]},
166+
json_schema_extra=_update_json_schema_extra,
216167
)
217168

218169

@@ -254,62 +205,70 @@ class ServiceGetV2(BaseModel):
254205
json_schema_extra={"default": []},
255206
)
256207

208+
@staticmethod
209+
def _update_json_schema_extra(schema: JsonDict) -> None:
210+
schema.update(
211+
{
212+
"examples": [
213+
{
214+
**_EXAMPLE_SLEEPER, # v2.2.1 (latest)
215+
"history": [
216+
{
217+
"version": _EXAMPLE_SLEEPER["version"],
218+
"version_display": "Summer Release",
219+
"released": "2024-07-20T15:00:00",
220+
},
221+
{
222+
"version": "2.0.0",
223+
"compatibility": {
224+
"canUpdateTo": {
225+
"version": _EXAMPLE_SLEEPER["version"]
226+
},
227+
},
228+
},
229+
{"version": "0.9.11"},
230+
{"version": "0.9.10"},
231+
{
232+
"version": "0.9.8",
233+
"compatibility": {
234+
"canUpdateTo": {"version": "0.9.11"},
235+
},
236+
},
237+
{
238+
"version": "0.9.1",
239+
"versionDisplay": "Matterhorn",
240+
"released": "2024-01-20T18:49:17",
241+
"compatibility": {
242+
"can_update_to": {"version": "0.9.11"},
243+
},
244+
},
245+
{
246+
"version": "0.9.0",
247+
"retired": "2024-07-20T15:00:00",
248+
},
249+
{"version": "0.8.0"},
250+
{"version": "0.1.0"},
251+
],
252+
},
253+
{
254+
**_EXAMPLE_FILEPICKER_V2,
255+
"history": [
256+
{
257+
"version": _EXAMPLE_FILEPICKER_V2["version"],
258+
"version_display": "Odei Release",
259+
"released": "2025-03-25T00:00:00",
260+
}
261+
],
262+
},
263+
]
264+
}
265+
)
266+
257267
model_config = ConfigDict(
258268
extra="forbid",
259269
populate_by_name=True,
260270
alias_generator=snake_to_camel,
261-
json_schema_extra={
262-
"examples": [
263-
{
264-
**_EXAMPLE_SLEEPER, # v2.2.1 (latest)
265-
"history": [
266-
{
267-
"version": _EXAMPLE_SLEEPER["version"],
268-
"version_display": "Summer Release",
269-
"released": "2024-07-20T15:00:00",
270-
},
271-
{
272-
"version": "2.0.0",
273-
"compatibility": {
274-
"canUpdateTo": {"version": _EXAMPLE_SLEEPER["version"]},
275-
},
276-
},
277-
{"version": "0.9.11"},
278-
{"version": "0.9.10"},
279-
{
280-
"version": "0.9.8",
281-
"compatibility": {
282-
"canUpdateTo": {"version": "0.9.11"},
283-
},
284-
},
285-
{
286-
"version": "0.9.1",
287-
"versionDisplay": "Matterhorn",
288-
"released": "2024-01-20T18:49:17",
289-
"compatibility": {
290-
"can_update_to": {"version": "0.9.11"},
291-
},
292-
},
293-
{
294-
"version": "0.9.0",
295-
"retired": "2024-07-20T15:00:00",
296-
},
297-
{"version": "0.8.0"},
298-
{"version": "0.1.0"},
299-
],
300-
},
301-
{
302-
**_EXAMPLE_FILEPICKER_V2,
303-
"history": [
304-
{
305-
"version": _EXAMPLE_FILEPICKER_V2["version"],
306-
"version_display": "Odei Release",
307-
"released": "2025-03-25T00:00:00",
308-
}
309-
],
310-
},
311-
]
312-
},
271+
json_schema_extra=_update_json_schema_extra,
313272
)
314273

315274

0 commit comments

Comments
 (0)