|
1 | | -from typing import Annotated, Any, TypeAlias |
| 1 | +from typing import Annotated, TypeAlias |
2 | 2 |
|
3 | 3 | from pydantic import ConfigDict, Field |
4 | 4 | from pydantic.config import JsonDict |
@@ -106,132 +106,131 @@ def _update_json_schema_extra(schema: JsonDict) -> None: |
106 | 106 |
|
107 | 107 | ServiceInputsGetDict: TypeAlias = dict[ServicePortKey, ServiceInputGet] |
108 | 108 | ServiceOutputsGetDict: TypeAlias = dict[ServicePortKey, ServiceOutputGet] |
109 | | - |
110 | | - |
111 | | -_EXAMPLE_FILEPICKER: dict[str, Any] = { |
112 | | - **api_schemas_catalog_services.ServiceGet.model_json_schema()["examples"][1], |
113 | | - "inputs": {}, |
114 | | - "outputs": { |
115 | | - "outFile": { |
116 | | - "displayOrder": 0, |
117 | | - "label": "File", |
118 | | - "description": "Chosen File", |
119 | | - "type": "data:*/*", |
120 | | - "fileToKeyMap": None, |
121 | | - "keyId": "outFile", |
122 | | - } |
123 | | - }, |
124 | | -} |
125 | | - |
126 | | -_EXAMPLE_SLEEPER: dict[str, Any] = { |
127 | | - **api_schemas_catalog_services.ServiceGet.model_json_schema()["examples"][0], |
128 | | - "inputs": { |
129 | | - "input_1": { |
130 | | - "displayOrder": 1, |
131 | | - "label": "File with int number", |
132 | | - "description": "Pick a file containing only one integer", |
133 | | - "type": "data:text/plain", |
134 | | - "fileToKeyMap": {"single_number.txt": "input_1"}, |
135 | | - "keyId": "input_1", |
136 | | - }, |
137 | | - "input_2": { |
138 | | - "unitLong": "second", |
139 | | - "unitShort": "s", |
140 | | - "label": "Sleep interval", |
141 | | - "description": "Choose an amount of time to sleep in range [0:]", |
142 | | - "keyId": "input_2", |
143 | | - "displayOrder": 2, |
144 | | - "type": "ref_contentSchema", |
145 | | - "contentSchema": { |
146 | | - "title": "Sleep interval", |
147 | | - "type": "integer", |
148 | | - "x_unit": "second", |
149 | | - "minimum": 0, |
150 | | - }, |
151 | | - "defaultValue": 2, |
152 | | - }, |
153 | | - "input_3": { |
154 | | - "displayOrder": 3, |
155 | | - "label": "Fail after sleep", |
156 | | - "description": "If set to true will cause service to fail after it sleeps", |
157 | | - "type": "boolean", |
158 | | - "defaultValue": False, |
159 | | - "keyId": "input_3", |
160 | | - }, |
161 | | - "input_4": { |
162 | | - "unitLong": "meter", |
163 | | - "unitShort": "m", |
164 | | - "label": "Distance to bed", |
165 | | - "description": "It will first walk the distance to bed", |
166 | | - "keyId": "input_4", |
167 | | - "displayOrder": 4, |
168 | | - "type": "ref_contentSchema", |
169 | | - "contentSchema": { |
170 | | - "title": "Distance to bed", |
171 | | - "type": "integer", |
172 | | - "x_unit": "meter", |
173 | | - }, |
174 | | - "defaultValue": 0, |
175 | | - }, |
176 | | - "input_5": { |
177 | | - "unitLong": "byte", |
178 | | - "unitShort": "B", |
179 | | - "label": "Dream (or nightmare) of the night", |
180 | | - "description": "Defines the size of the dream that will be generated [0:]", |
181 | | - "keyId": "input_5", |
182 | | - "displayOrder": 5, |
183 | | - "type": "ref_contentSchema", |
184 | | - "contentSchema": { |
185 | | - "title": "Dream of the night", |
186 | | - "type": "integer", |
187 | | - "x_unit": "byte", |
188 | | - "minimum": 0, |
189 | | - }, |
190 | | - "defaultValue": 0, |
191 | | - }, |
192 | | - }, |
193 | | - "outputs": { |
194 | | - "output_1": { |
195 | | - "displayOrder": 1, |
196 | | - "label": "File containing one random integer", |
197 | | - "description": "Integer is generated in range [1-9]", |
198 | | - "type": "data:text/plain", |
199 | | - "fileToKeyMap": {"single_number.txt": "output_1"}, |
200 | | - "keyId": "output_1", |
201 | | - }, |
202 | | - "output_2": { |
203 | | - "unitLong": "second", |
204 | | - "unitShort": "s", |
205 | | - "label": "Random sleep interval", |
206 | | - "description": "Interval is generated in range [1-9]", |
207 | | - "keyId": "output_2", |
208 | | - "displayOrder": 2, |
209 | | - "type": "ref_contentSchema", |
210 | | - "contentSchema": { |
211 | | - "title": "Random sleep interval", |
212 | | - "type": "integer", |
213 | | - "x_unit": "second", |
214 | | - }, |
215 | | - }, |
216 | | - "output_3": { |
217 | | - "displayOrder": 3, |
218 | | - "label": "Dream output", |
219 | | - "description": "Contains some random data representing a dream", |
220 | | - "type": "data:text/plain", |
221 | | - "fileToKeyMap": {"dream.txt": "output_3"}, |
222 | | - "keyId": "output_3", |
223 | | - }, |
224 | | - }, |
225 | | -} |
226 | | - |
227 | | - |
228 | 109 | ServiceResourcesGet: TypeAlias = api_schemas_catalog_services.ServiceResourcesGet |
229 | 110 |
|
230 | 111 |
|
231 | | -class CatalogServiceListItem(api_schemas_catalog_services.ServiceListItem): |
| 112 | +class CatalogLatestServiceGet(api_schemas_catalog_services.LatestServiceGet): |
232 | 113 | inputs: ServiceInputsGetDict # type: ignore[assignment] |
233 | 114 | outputs: ServiceOutputsGetDict # type: ignore[assignment] |
234 | 115 |
|
| 116 | + @staticmethod |
| 117 | + def _update_json_schema_extra(schema: JsonDict) -> None: |
| 118 | + base_example = ( |
| 119 | + api_schemas_catalog_services.LatestServiceGet.model_json_schema()[ |
| 120 | + "examples" |
| 121 | + ][0] |
| 122 | + ) |
| 123 | + |
| 124 | + schema.update( |
| 125 | + { |
| 126 | + "example": { |
| 127 | + **base_example, |
| 128 | + "inputs": { |
| 129 | + "input_1": { |
| 130 | + "displayOrder": 1, |
| 131 | + "label": "File with int number", |
| 132 | + "description": "Pick a file containing only one integer", |
| 133 | + "type": "data:text/plain", |
| 134 | + "fileToKeyMap": {"single_number.txt": "input_1"}, |
| 135 | + "keyId": "input_1", |
| 136 | + }, |
| 137 | + "input_2": { |
| 138 | + "unitLong": "second", |
| 139 | + "unitShort": "s", |
| 140 | + "label": "Sleep interval", |
| 141 | + "description": "Choose an amount of time to sleep in range [0:]", |
| 142 | + "keyId": "input_2", |
| 143 | + "displayOrder": 2, |
| 144 | + "type": "ref_contentSchema", |
| 145 | + "contentSchema": { |
| 146 | + "title": "Sleep interval", |
| 147 | + "type": "integer", |
| 148 | + "x_unit": "second", |
| 149 | + "minimum": 0, |
| 150 | + }, |
| 151 | + "defaultValue": 2, |
| 152 | + }, |
| 153 | + "input_3": { |
| 154 | + "displayOrder": 3, |
| 155 | + "label": "Fail after sleep", |
| 156 | + "description": "If set to true will cause service to fail after it sleeps", |
| 157 | + "type": "boolean", |
| 158 | + "defaultValue": False, |
| 159 | + "keyId": "input_3", |
| 160 | + }, |
| 161 | + "input_4": { |
| 162 | + "unitLong": "meter", |
| 163 | + "unitShort": "m", |
| 164 | + "label": "Distance to bed", |
| 165 | + "description": "It will first walk the distance to bed", |
| 166 | + "keyId": "input_4", |
| 167 | + "displayOrder": 4, |
| 168 | + "type": "ref_contentSchema", |
| 169 | + "contentSchema": { |
| 170 | + "title": "Distance to bed", |
| 171 | + "type": "integer", |
| 172 | + "x_unit": "meter", |
| 173 | + }, |
| 174 | + "defaultValue": 0, |
| 175 | + }, |
| 176 | + "input_5": { |
| 177 | + "unitLong": "byte", |
| 178 | + "unitShort": "B", |
| 179 | + "label": "Dream (or nightmare) of the night", |
| 180 | + "description": "Defines the size of the dream that will be generated [0:]", |
| 181 | + "keyId": "input_5", |
| 182 | + "displayOrder": 5, |
| 183 | + "type": "ref_contentSchema", |
| 184 | + "contentSchema": { |
| 185 | + "title": "Dream of the night", |
| 186 | + "type": "integer", |
| 187 | + "x_unit": "byte", |
| 188 | + "minimum": 0, |
| 189 | + }, |
| 190 | + "defaultValue": 0, |
| 191 | + }, |
| 192 | + }, |
| 193 | + "outputs": { |
| 194 | + "output_1": { |
| 195 | + "displayOrder": 1, |
| 196 | + "label": "File containing one random integer", |
| 197 | + "description": "Integer is generated in range [1-9]", |
| 198 | + "type": "data:text/plain", |
| 199 | + "fileToKeyMap": {"single_number.txt": "output_1"}, |
| 200 | + "keyId": "output_1", |
| 201 | + }, |
| 202 | + "output_2": { |
| 203 | + "unitLong": "second", |
| 204 | + "unitShort": "s", |
| 205 | + "label": "Random sleep interval", |
| 206 | + "description": "Interval is generated in range [1-9]", |
| 207 | + "keyId": "output_2", |
| 208 | + "displayOrder": 2, |
| 209 | + "type": "ref_contentSchema", |
| 210 | + "contentSchema": { |
| 211 | + "title": "Random sleep interval", |
| 212 | + "type": "integer", |
| 213 | + "x_unit": "second", |
| 214 | + }, |
| 215 | + }, |
| 216 | + "output_3": { |
| 217 | + "displayOrder": 3, |
| 218 | + "label": "Dream output", |
| 219 | + "description": "Contains some random data representing a dream", |
| 220 | + "type": "data:text/plain", |
| 221 | + "fileToKeyMap": {"dream.txt": "output_3"}, |
| 222 | + "keyId": "output_3", |
| 223 | + }, |
| 224 | + }, |
| 225 | + } |
| 226 | + } |
| 227 | + ) |
| 228 | + |
| 229 | + model_config = ConfigDict( |
| 230 | + **OutputSchema.model_config, |
| 231 | + json_schema_extra=_update_json_schema_extra, |
| 232 | + ) |
| 233 | + |
235 | 234 |
|
236 | 235 | class CatalogServiceGet(api_schemas_catalog_services.ServiceGetV2): |
237 | 236 | # pylint: disable=too-many-ancestors |
|
0 commit comments