|
3 | 3 |
|
4 | 4 | from models_library.rpc_pagination import PageRpc |
5 | 5 | from pydantic import BaseModel, ConfigDict, Field, HttpUrl, NonNegativeInt |
| 6 | +from pydantic.config import JsonDict |
6 | 7 |
|
7 | 8 | from ..boot_options import BootOptions |
8 | 9 | from ..emails import LowerCaseEmailStr |
|
23 | 24 |
|
24 | 25 |
|
25 | 26 | 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] |
61 | 46 | }, |
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 | + }, |
71 | 75 | }, |
72 | | - }, |
| 76 | + } |
73 | 77 | } |
74 | | - } |
75 | | - ) |
| 78 | + ) |
| 79 | + |
| 80 | + model_config = ConfigDict(json_schema_extra=_update_json_schema_extra) |
76 | 81 |
|
77 | 82 |
|
78 | 83 | _EXAMPLE_FILEPICKER: dict[str, Any] = { |
@@ -209,10 +214,14 @@ class ServiceGet( |
209 | 214 | description="None when the owner email cannot be found in the database" |
210 | 215 | ) |
211 | 216 |
|
| 217 | + @staticmethod |
| 218 | + def _update_json_schema_extra(schema: JsonDict) -> None: |
| 219 | + schema.update({"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]}) |
| 220 | + |
212 | 221 | model_config = ConfigDict( |
213 | 222 | extra="ignore", |
214 | 223 | populate_by_name=True, |
215 | | - json_schema_extra={"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]}, |
| 224 | + json_schema_extra=_update_json_schema_extra, |
216 | 225 | ) |
217 | 226 |
|
218 | 227 |
|
@@ -254,62 +263,70 @@ class ServiceGetV2(BaseModel): |
254 | 263 | json_schema_extra={"default": []}, |
255 | 264 | ) |
256 | 265 |
|
| 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 | + |
257 | 325 | model_config = ConfigDict( |
258 | 326 | extra="forbid", |
259 | 327 | populate_by_name=True, |
260 | 328 | 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, |
313 | 330 | ) |
314 | 331 |
|
315 | 332 |
|
|
0 commit comments