Skip to content

Commit f3b64d8

Browse files
committed
refactor example calls
1 parent 1853c29 commit f3b64d8

File tree

3 files changed

+203
-164
lines changed

3 files changed

+203
-164
lines changed

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

Lines changed: 117 additions & 100 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
@@ -23,56 +24,60 @@
2324

2425

2526
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": ""},
27+
@staticmethod
28+
def _update_json_schema_extra(schema: JsonDict) -> None:
29+
schema.update(
30+
{
31+
"example": {
32+
# ServiceAccessRights
33+
"accessRights": {
34+
1: {
35+
"execute_access": False,
36+
"write_access": False,
37+
}, # type: ignore[dict-item]
38+
2: {
39+
"execute_access": True,
40+
"write_access": True,
41+
}, # type: ignore[dict-item]
42+
44: {
43+
"execute_access": False,
44+
"write_access": False,
45+
}, # type: ignore[dict-item]
6146
},
62-
"enabled": True,
63-
"annotations": {
64-
"vandv": "",
65-
"purpose": "",
66-
"standards": "",
67-
"limitations": "",
68-
"documentation": "",
69-
"certificationLink": "",
70-
"certificationStatus": "Uncertified",
47+
# ServiceMetaData = ServiceCommonData +
48+
"name": "My Human Readable Service Name",
49+
"thumbnail": None,
50+
"description": "An interesting service that does something",
51+
"classifiers": ["RRID:SCR_018997", "RRID:SCR_019001"],
52+
"quality": {
53+
"tsr": {
54+
"r01": {"level": 3, "references": ""},
55+
"r02": {"level": 2, "references": ""},
56+
"r03": {"level": 0, "references": ""},
57+
"r04": {"level": 0, "references": ""},
58+
"r05": {"level": 2, "references": ""},
59+
"r06": {"level": 0, "references": ""},
60+
"r07": {"level": 0, "references": ""},
61+
"r08": {"level": 1, "references": ""},
62+
"r09": {"level": 0, "references": ""},
63+
"r10": {"level": 0, "references": ""},
64+
},
65+
"enabled": True,
66+
"annotations": {
67+
"vandv": "",
68+
"purpose": "",
69+
"standards": "",
70+
"limitations": "",
71+
"documentation": "",
72+
"certificationLink": "",
73+
"certificationStatus": "Uncertified",
74+
},
7175
},
72-
},
76+
}
7377
}
74-
}
75-
)
78+
)
79+
80+
model_config = ConfigDict(json_schema_extra=_update_json_schema_extra)
7681

7782

7883
_EXAMPLE_FILEPICKER: dict[str, Any] = {
@@ -209,10 +214,14 @@ class ServiceGet(
209214
description="None when the owner email cannot be found in the database"
210215
)
211216

217+
@staticmethod
218+
def _update_json_schema_extra(schema: JsonDict) -> None:
219+
schema.update({"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]})
220+
212221
model_config = ConfigDict(
213222
extra="ignore",
214223
populate_by_name=True,
215-
json_schema_extra={"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]},
224+
json_schema_extra=_update_json_schema_extra,
216225
)
217226

218227

@@ -254,62 +263,70 @@ class ServiceGetV2(BaseModel):
254263
json_schema_extra={"default": []},
255264
)
256265

266+
@staticmethod
267+
def _update_json_schema_extra(schema: JsonDict) -> None:
268+
schema.update(
269+
{
270+
"examples": [
271+
{
272+
**_EXAMPLE_SLEEPER, # v2.2.1 (latest)
273+
"history": [
274+
{
275+
"version": _EXAMPLE_SLEEPER["version"],
276+
"version_display": "Summer Release",
277+
"released": "2024-07-20T15:00:00",
278+
},
279+
{
280+
"version": "2.0.0",
281+
"compatibility": {
282+
"canUpdateTo": {
283+
"version": _EXAMPLE_SLEEPER["version"]
284+
},
285+
},
286+
},
287+
{"version": "0.9.11"},
288+
{"version": "0.9.10"},
289+
{
290+
"version": "0.9.8",
291+
"compatibility": {
292+
"canUpdateTo": {"version": "0.9.11"},
293+
},
294+
},
295+
{
296+
"version": "0.9.1",
297+
"versionDisplay": "Matterhorn",
298+
"released": "2024-01-20T18:49:17",
299+
"compatibility": {
300+
"can_update_to": {"version": "0.9.11"},
301+
},
302+
},
303+
{
304+
"version": "0.9.0",
305+
"retired": "2024-07-20T15:00:00",
306+
},
307+
{"version": "0.8.0"},
308+
{"version": "0.1.0"},
309+
],
310+
},
311+
{
312+
**_EXAMPLE_FILEPICKER_V2,
313+
"history": [
314+
{
315+
"version": _EXAMPLE_FILEPICKER_V2["version"],
316+
"version_display": "Odei Release",
317+
"released": "2025-03-25T00:00:00",
318+
}
319+
],
320+
},
321+
]
322+
}
323+
)
324+
257325
model_config = ConfigDict(
258326
extra="forbid",
259327
populate_by_name=True,
260328
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-
},
329+
json_schema_extra=_update_json_schema_extra,
313330
)
314331

315332

0 commit comments

Comments
 (0)