|
1 | | -from typing import TypeAlias |
| 1 | +from typing import Annotated, TypeAlias |
2 | 2 |
|
3 | | -from pydantic import BaseModel, ByteSize, ConfigDict, Field |
| 3 | +from pydantic import AnyHttpUrl, BaseModel, ByteSize, ConfigDict, Field |
| 4 | +from pydantic.config import JsonDict |
4 | 5 |
|
5 | 6 | from ..resource_tracker import HardwareInfo, PricingInfo |
6 | 7 | from ..services import ServicePortKey |
@@ -38,40 +39,60 @@ def from_transferred_bytes( |
38 | 39 | class DynamicServiceCreate(ServiceDetails): |
39 | 40 | service_resources: ServiceResourcesDict |
40 | 41 |
|
41 | | - product_name: str = Field(..., description="Current product name") |
42 | | - can_save: bool = Field( |
43 | | - ..., description="the service data must be saved when closing" |
44 | | - ) |
45 | | - wallet_info: WalletInfo | None = Field( |
46 | | - default=None, |
47 | | - description="contains information about the wallet used to bill the running service", |
48 | | - ) |
49 | | - pricing_info: PricingInfo | None = Field( |
50 | | - default=None, |
51 | | - description="contains pricing information (ex. pricing plan and unit ids)", |
52 | | - ) |
53 | | - hardware_info: HardwareInfo | None = Field( |
54 | | - default=None, |
55 | | - description="contains harware information (ex. aws_ec2_instances)", |
56 | | - ) |
57 | | - model_config = ConfigDict( |
58 | | - json_schema_extra={ |
59 | | - "example": { |
60 | | - "key": "simcore/services/dynamic/3dviewer", |
61 | | - "version": "2.4.5", |
62 | | - "user_id": 234, |
63 | | - "project_id": "dd1d04d9-d704-4f7e-8f0f-1ca60cc771fe", |
64 | | - "node_uuid": "75c7f3f4-18f9-4678-8610-54a2ade78eaa", |
65 | | - "basepath": "/x/75c7f3f4-18f9-4678-8610-54a2ade78eaa", |
66 | | - "product_name": "osparc", |
67 | | - "can_save": True, |
68 | | - "service_resources": ServiceResourcesDictHelpers.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
69 | | - "wallet_info": WalletInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
70 | | - "pricing_info": PricingInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
71 | | - "hardware_info": HardwareInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
| 42 | + product_name: Annotated[str, Field(..., description="Current product name")] |
| 43 | + product_api_base_url: Annotated[ |
| 44 | + AnyHttpUrl, |
| 45 | + Field( |
| 46 | + ..., |
| 47 | + description="Base url of the product", |
| 48 | + ), |
| 49 | + ] |
| 50 | + can_save: Annotated[ |
| 51 | + bool, Field(..., description="the service data must be saved when closing") |
| 52 | + ] |
| 53 | + wallet_info: Annotated[ |
| 54 | + WalletInfo | None, |
| 55 | + Field( |
| 56 | + default=None, |
| 57 | + description="contains information about the wallet used to bill the running service", |
| 58 | + ), |
| 59 | + ] |
| 60 | + pricing_info: Annotated[ |
| 61 | + PricingInfo | None, |
| 62 | + Field( |
| 63 | + default=None, |
| 64 | + description="contains pricing information (ex. pricing plan and unit ids)", |
| 65 | + ), |
| 66 | + ] |
| 67 | + hardware_info: Annotated[ |
| 68 | + HardwareInfo | None, |
| 69 | + Field( |
| 70 | + default=None, |
| 71 | + description="contains hardware information (ex. aws_ec2_instances)", |
| 72 | + ), |
| 73 | + ] |
| 74 | + |
| 75 | + @staticmethod |
| 76 | + def _update_json_schema_extra(schema: JsonDict) -> None: |
| 77 | + schema.update( |
| 78 | + { |
| 79 | + "example": { |
| 80 | + "key": "simcore/services/dynamic/3dviewer", |
| 81 | + "version": "2.4.5", |
| 82 | + "user_id": 234, |
| 83 | + "project_id": "dd1d04d9-d704-4f7e-8f0f-1ca60cc771fe", |
| 84 | + "node_uuid": "75c7f3f4-18f9-4678-8610-54a2ade78eaa", |
| 85 | + "basepath": "/x/75c7f3f4-18f9-4678-8610-54a2ade78eaa", |
| 86 | + "product_name": "osparc", |
| 87 | + "product_api_base_url": "https://api.local", |
| 88 | + "can_save": True, |
| 89 | + "service_resources": ServiceResourcesDictHelpers.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
| 90 | + "wallet_info": WalletInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
| 91 | + "pricing_info": PricingInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
| 92 | + "hardware_info": HardwareInfo.model_config["json_schema_extra"]["examples"][0], # type: ignore [index] |
| 93 | + } |
72 | 94 | } |
73 | | - } |
74 | | - ) |
| 95 | + ) |
75 | 96 |
|
76 | 97 |
|
77 | 98 | DynamicServiceGet: TypeAlias = RunningDynamicServiceDetails |
|
0 commit comments