1717 StrictInt ,
1818 StrictStr ,
1919)
20+ from pydantic .config import JsonDict
2021
2122TaskCancelEventName = "cancel_event_{}"
2223
2324
2425class PortSchema (BaseModel ):
2526 required : bool
2627
28+ @staticmethod
29+ def _update_json_schema_extra (schema : JsonDict ) -> None :
30+ schema .update (
31+ {
32+ "examples" : [
33+ {
34+ "required" : True ,
35+ },
36+ {
37+ "required" : False ,
38+ },
39+ ]
40+ }
41+ )
42+
2743 model_config = ConfigDict (
2844 extra = "forbid" ,
29- json_schema_extra = {
30- "examples" : [
31- {
32- "required" : True ,
33- },
34- {
35- "required" : False ,
36- },
37- ]
38- },
45+ json_schema_extra = _update_json_schema_extra ,
3946 )
4047
4148
4249class FilePortSchema (PortSchema ):
4350 mapping : str | None = None
4451 url : AnyUrl
4552
53+ @staticmethod
54+ def _update_json_schema_extra (schema : JsonDict ) -> None :
55+ schema .update (
56+ {
57+ "examples" : [
58+ {
59+ "mapping" : "some_filename.txt" ,
60+ "url" : "sftp://some_file_url" ,
61+ "required" : True ,
62+ },
63+ {
64+ "required" : False ,
65+ "url" : "s3://another_file_url" ,
66+ },
67+ ]
68+ }
69+ )
70+
4671 model_config = ConfigDict (
47- json_schema_extra = {
48- "examples" : [
49- {
50- "mapping" : "some_filename.txt" ,
51- "url" : "sftp://some_file_url" ,
52- "required" : True ,
53- },
54- {
55- "required" : False ,
56- "url" : "s3://another_file_url" ,
57- },
58- ]
59- }
72+ json_schema_extra = _update_json_schema_extra ,
6073 )
6174
6275
@@ -70,18 +83,27 @@ class FileUrl(BaseModel):
7083 default = None , description = "the file MIME type" , pattern = MIME_TYPE_RE
7184 )
7285
86+ @staticmethod
87+ def _update_json_schema_extra (schema : JsonDict ) -> None :
88+ schema .update (
89+ {
90+ "examples" : [
91+ {
92+ "url" : "https://some_file_url" ,
93+ "file_mime_type" : "application/json" ,
94+ },
95+ {
96+ "url" : "https://some_file_url" ,
97+ "file_mapping" : "some_file_name.txt" ,
98+ "file_mime_type" : "application/json" ,
99+ },
100+ ]
101+ }
102+ )
103+
73104 model_config = ConfigDict (
74105 extra = "forbid" ,
75- json_schema_extra = {
76- "examples" : [
77- {"url" : "https://some_file_url" , "file_mime_type" : "application/json" },
78- {
79- "url" : "https://some_file_url" ,
80- "file_mapping" : "some_file_name.txt" ,
81- "file_mime_type" : "application/json" ,
82- },
83- ]
84- },
106+ json_schema_extra = _update_json_schema_extra ,
85107 )
86108
87109
@@ -99,18 +121,24 @@ class FileUrl(BaseModel):
99121
100122
101123class TaskInputData (DictModel [ServicePortKey , PortValue ]):
124+ @staticmethod
125+ def _update_json_schema_extra (schema : JsonDict ) -> None :
126+ schema .update (
127+ {
128+ "examples" : [
129+ {
130+ "boolean_input" : False ,
131+ "int_input" : - 45 ,
132+ "float_input" : 4564.45 ,
133+ "string_input" : "nobody thinks like a string" ,
134+ "file_input" : {"url" : "s3://thatis_file_url" },
135+ },
136+ ]
137+ }
138+ )
139+
102140 model_config = ConfigDict (
103- json_schema_extra = {
104- "examples" : [
105- {
106- "boolean_input" : False ,
107- "int_input" : - 45 ,
108- "float_input" : 4564.45 ,
109- "string_input" : "nobody thinks like a string" ,
110- "file_input" : {"url" : "s3://thatis_file_url" },
111- },
112- ]
113- }
141+ json_schema_extra = _update_json_schema_extra ,
114142 )
115143
116144
@@ -126,26 +154,32 @@ class TaskOutputDataSchema(DictModel[ServicePortKey, PortSchemaValue]):
126154 # does not work well in that case. For that reason, the schema is
127155 # sent as a json-schema instead of with a dynamically-created model class
128156 #
129- model_config = ConfigDict (
130- json_schema_extra = {
131- "examples" : [
132- {
133- "boolean_output" : {"required" : False },
134- "int_output" : {"required" : True },
135- "float_output" : {"required" : True },
136- "string_output" : {"required" : False },
137- "file_output" : {
138- "required" : True ,
139- "url" : "https://some_file_url" ,
140- "mapping" : "the_output_filename" ,
141- },
142- "optional_file_output" : {
143- "required" : False ,
144- "url" : "s3://one_file_url" ,
157+ @staticmethod
158+ def _update_json_schema_extra (schema : JsonDict ) -> None :
159+ schema .update (
160+ {
161+ "examples" : [
162+ {
163+ "boolean_output" : {"required" : False },
164+ "int_output" : {"required" : True },
165+ "float_output" : {"required" : True },
166+ "string_output" : {"required" : False },
167+ "file_output" : {
168+ "required" : True ,
169+ "url" : "https://some_file_url" ,
170+ "mapping" : "the_output_filename" ,
171+ },
172+ "optional_file_output" : {
173+ "required" : False ,
174+ "url" : "s3://one_file_url" ,
175+ },
145176 },
146- },
147- ]
148- }
177+ ]
178+ }
179+ )
180+
181+ model_config = ConfigDict (
182+ json_schema_extra = _update_json_schema_extra ,
149183 )
150184
151185
@@ -181,16 +215,20 @@ def from_task_output(
181215
182216 return cls .model_validate (data )
183217
184- model_config = ConfigDict (
185- json_schema_extra = {
186- "examples" : [
187- {
188- "boolean_output" : False ,
189- "int_output" : - 45 ,
190- "float_output" : 4564.45 ,
191- "string_output" : "nobody thinks like a string" ,
192- "file_output" : {"url" : "s3://yet_another_file_url" },
193- },
194- ]
195- }
196- )
218+ @staticmethod
219+ def _update_json_schema_extra (schema : JsonDict ) -> None :
220+ schema .update (
221+ {
222+ "examples" : [
223+ {
224+ "boolean_output" : False ,
225+ "int_output" : - 45 ,
226+ "float_output" : 4564.45 ,
227+ "string_output" : "nobody thinks like a string" ,
228+ "file_output" : {"url" : "s3://yet_another_file_url" },
229+ },
230+ ]
231+ }
232+ )
233+
234+ model_config = ConfigDict (json_schema_extra = _update_json_schema_extra )
0 commit comments