Skip to content

Commit c572c6d

Browse files
authored
Add DataBlockResponse model to sanitize blocks_obj in API (#1310)
1 parent 0850aff commit c572c6d

File tree

6 files changed

+306
-9
lines changed

6 files changed

+306
-9
lines changed

pydatalab/schemas/cell.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"blocks_obj": {
77
"title": "Blocks Obj",
88
"default": {},
9-
"type": "object"
9+
"type": "object",
10+
"additionalProperties": {
11+
"$ref": "#/definitions/DataBlockResponse"
12+
}
1013
},
1114
"display_order": {
1215
"title": "Display Order",
@@ -171,6 +174,63 @@
171174
"item_id"
172175
],
173176
"definitions": {
177+
"DataBlockResponse": {
178+
"title": "DataBlockResponse",
179+
"description": "A generic response model for a block, i.e., what is stored in `self.data`\nin the corresponding DataBlock class.",
180+
"type": "object",
181+
"properties": {
182+
"blocktype": {
183+
"title": "Blocktype",
184+
"type": "string"
185+
},
186+
"block_id": {
187+
"title": "Block Id",
188+
"type": "string"
189+
},
190+
"item_id": {
191+
"title": "Item Id",
192+
"type": "string"
193+
},
194+
"collection_id": {
195+
"title": "Collection Id",
196+
"type": "string"
197+
},
198+
"title": {
199+
"title": "Title",
200+
"type": "string"
201+
},
202+
"freeform_comment": {
203+
"title": "Freeform Comment",
204+
"type": "string"
205+
},
206+
"file_id": {
207+
"title": "File Id",
208+
"type": "string"
209+
},
210+
"file_ids": {
211+
"title": "File Ids",
212+
"type": "array",
213+
"items": {
214+
"type": "string"
215+
}
216+
},
217+
"b64_encoded_image": {
218+
"title": "B64 Encoded Image",
219+
"type": "object",
220+
"additionalProperties": {
221+
"type": "string"
222+
}
223+
},
224+
"bokeh_plot_data": {
225+
"title": "Bokeh Plot Data",
226+
"type": "string"
227+
}
228+
},
229+
"required": [
230+
"blocktype",
231+
"block_id"
232+
]
233+
},
174234
"RelationshipType": {
175235
"title": "RelationshipType",
176236
"description": "An enumeration of the possible types of relationship between two entries.\n\n```mermaid\nclassDiagram\nclass entryC\nentryC --|> entryA: parent\nentryC ..|> entryD\nentryA <..> entryD: sibling\nentryA --|> entryB : child\n```",
@@ -356,7 +416,10 @@
356416
"blocks_obj": {
357417
"title": "Blocks Obj",
358418
"default": {},
359-
"type": "object"
419+
"type": "object",
420+
"additionalProperties": {
421+
"$ref": "#/definitions/DataBlockResponse"
422+
}
360423
},
361424
"display_order": {
362425
"title": "Display Order",

pydatalab/schemas/equipment.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"blocks_obj": {
77
"title": "Blocks Obj",
88
"default": {},
9-
"type": "object"
9+
"type": "object",
10+
"additionalProperties": {
11+
"$ref": "#/definitions/DataBlockResponse"
12+
}
1013
},
1114
"display_order": {
1215
"title": "Display Order",
@@ -135,6 +138,63 @@
135138
"item_id"
136139
],
137140
"definitions": {
141+
"DataBlockResponse": {
142+
"title": "DataBlockResponse",
143+
"description": "A generic response model for a block, i.e., what is stored in `self.data`\nin the corresponding DataBlock class.",
144+
"type": "object",
145+
"properties": {
146+
"blocktype": {
147+
"title": "Blocktype",
148+
"type": "string"
149+
},
150+
"block_id": {
151+
"title": "Block Id",
152+
"type": "string"
153+
},
154+
"item_id": {
155+
"title": "Item Id",
156+
"type": "string"
157+
},
158+
"collection_id": {
159+
"title": "Collection Id",
160+
"type": "string"
161+
},
162+
"title": {
163+
"title": "Title",
164+
"type": "string"
165+
},
166+
"freeform_comment": {
167+
"title": "Freeform Comment",
168+
"type": "string"
169+
},
170+
"file_id": {
171+
"title": "File Id",
172+
"type": "string"
173+
},
174+
"file_ids": {
175+
"title": "File Ids",
176+
"type": "array",
177+
"items": {
178+
"type": "string"
179+
}
180+
},
181+
"b64_encoded_image": {
182+
"title": "B64 Encoded Image",
183+
"type": "object",
184+
"additionalProperties": {
185+
"type": "string"
186+
}
187+
},
188+
"bokeh_plot_data": {
189+
"title": "Bokeh Plot Data",
190+
"type": "string"
191+
}
192+
},
193+
"required": [
194+
"blocktype",
195+
"block_id"
196+
]
197+
},
138198
"RelationshipType": {
139199
"title": "RelationshipType",
140200
"description": "An enumeration of the possible types of relationship between two entries.\n\n```mermaid\nclassDiagram\nclass entryC\nentryC --|> entryA: parent\nentryC ..|> entryD\nentryA <..> entryD: sibling\nentryA --|> entryB : child\n```",
@@ -320,7 +380,10 @@
320380
"blocks_obj": {
321381
"title": "Blocks Obj",
322382
"default": {},
323-
"type": "object"
383+
"type": "object",
384+
"additionalProperties": {
385+
"$ref": "#/definitions/DataBlockResponse"
386+
}
324387
},
325388
"display_order": {
326389
"title": "Display Order",

pydatalab/schemas/sample.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"blocks_obj": {
1919
"title": "Blocks Obj",
2020
"default": {},
21-
"type": "object"
21+
"type": "object",
22+
"additionalProperties": {
23+
"$ref": "#/definitions/DataBlockResponse"
24+
}
2225
},
2326
"display_order": {
2427
"title": "Display Order",
@@ -224,6 +227,63 @@
224227
"quantity"
225228
]
226229
},
230+
"DataBlockResponse": {
231+
"title": "DataBlockResponse",
232+
"description": "A generic response model for a block, i.e., what is stored in `self.data`\nin the corresponding DataBlock class.",
233+
"type": "object",
234+
"properties": {
235+
"blocktype": {
236+
"title": "Blocktype",
237+
"type": "string"
238+
},
239+
"block_id": {
240+
"title": "Block Id",
241+
"type": "string"
242+
},
243+
"item_id": {
244+
"title": "Item Id",
245+
"type": "string"
246+
},
247+
"collection_id": {
248+
"title": "Collection Id",
249+
"type": "string"
250+
},
251+
"title": {
252+
"title": "Title",
253+
"type": "string"
254+
},
255+
"freeform_comment": {
256+
"title": "Freeform Comment",
257+
"type": "string"
258+
},
259+
"file_id": {
260+
"title": "File Id",
261+
"type": "string"
262+
},
263+
"file_ids": {
264+
"title": "File Ids",
265+
"type": "array",
266+
"items": {
267+
"type": "string"
268+
}
269+
},
270+
"b64_encoded_image": {
271+
"title": "B64 Encoded Image",
272+
"type": "object",
273+
"additionalProperties": {
274+
"type": "string"
275+
}
276+
},
277+
"bokeh_plot_data": {
278+
"title": "Bokeh Plot Data",
279+
"type": "string"
280+
}
281+
},
282+
"required": [
283+
"blocktype",
284+
"block_id"
285+
]
286+
},
227287
"RelationshipType": {
228288
"title": "RelationshipType",
229289
"description": "An enumeration of the possible types of relationship between two entries.\n\n```mermaid\nclassDiagram\nclass entryC\nentryC --|> entryA: parent\nentryC ..|> entryD\nentryA <..> entryD: sibling\nentryA --|> entryB : child\n```",
@@ -409,7 +469,10 @@
409469
"blocks_obj": {
410470
"title": "Blocks Obj",
411471
"default": {},
412-
"type": "object"
472+
"type": "object",
473+
"additionalProperties": {
474+
"$ref": "#/definitions/DataBlockResponse"
475+
}
413476
},
414477
"display_order": {
415478
"title": "Display Order",

pydatalab/schemas/startingmaterial.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"blocks_obj": {
1919
"title": "Blocks Obj",
2020
"default": {},
21-
"type": "object"
21+
"type": "object",
22+
"additionalProperties": {
23+
"$ref": "#/definitions/DataBlockResponse"
24+
}
2225
},
2326
"display_order": {
2427
"title": "Display Order",
@@ -277,6 +280,63 @@
277280
"quantity"
278281
]
279282
},
283+
"DataBlockResponse": {
284+
"title": "DataBlockResponse",
285+
"description": "A generic response model for a block, i.e., what is stored in `self.data`\nin the corresponding DataBlock class.",
286+
"type": "object",
287+
"properties": {
288+
"blocktype": {
289+
"title": "Blocktype",
290+
"type": "string"
291+
},
292+
"block_id": {
293+
"title": "Block Id",
294+
"type": "string"
295+
},
296+
"item_id": {
297+
"title": "Item Id",
298+
"type": "string"
299+
},
300+
"collection_id": {
301+
"title": "Collection Id",
302+
"type": "string"
303+
},
304+
"title": {
305+
"title": "Title",
306+
"type": "string"
307+
},
308+
"freeform_comment": {
309+
"title": "Freeform Comment",
310+
"type": "string"
311+
},
312+
"file_id": {
313+
"title": "File Id",
314+
"type": "string"
315+
},
316+
"file_ids": {
317+
"title": "File Ids",
318+
"type": "array",
319+
"items": {
320+
"type": "string"
321+
}
322+
},
323+
"b64_encoded_image": {
324+
"title": "B64 Encoded Image",
325+
"type": "object",
326+
"additionalProperties": {
327+
"type": "string"
328+
}
329+
},
330+
"bokeh_plot_data": {
331+
"title": "Bokeh Plot Data",
332+
"type": "string"
333+
}
334+
},
335+
"required": [
336+
"blocktype",
337+
"block_id"
338+
]
339+
},
280340
"RelationshipType": {
281341
"title": "RelationshipType",
282342
"description": "An enumeration of the possible types of relationship between two entries.\n\n```mermaid\nclassDiagram\nclass entryC\nentryC --|> entryA: parent\nentryC ..|> entryD\nentryA <..> entryD: sibling\nentryA --|> entryB : child\n```",
@@ -462,7 +522,10 @@
462522
"blocks_obj": {
463523
"title": "Blocks Obj",
464524
"default": {},
465-
"type": "object"
525+
"type": "object",
526+
"additionalProperties": {
527+
"$ref": "#/definitions/DataBlockResponse"
528+
}
466529
},
467530
"display_order": {
468531
"title": "Display Order",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pydantic import BaseModel
2+
3+
from pydatalab.models.utils import JSON_ENCODERS, PyObjectId
4+
5+
6+
class DataBlockResponse(BaseModel):
7+
"""A generic response model for a block, i.e., what is stored in `self.data`
8+
in the corresponding DataBlock class.
9+
"""
10+
11+
blocktype: str
12+
"""The type of the block."""
13+
14+
block_id: str
15+
"""A shorthand random ID for the block."""
16+
17+
item_id: str | None = None
18+
"""The item that the block is attached to, if any."""
19+
20+
collection_id: str | None = None
21+
"""The collection that the block is attached to, if any."""
22+
23+
title: str | None = None
24+
"""The title of the block, if any."""
25+
26+
freeform_comment: str | None = None
27+
"""A freeform comment for the block, if any."""
28+
29+
file_id: PyObjectId | None = None
30+
"""The ID of the file associated with the block, if any."""
31+
32+
file_ids: list[PyObjectId] | None = None
33+
"""A list of file IDs associated with the block, if any."""
34+
35+
b64_encoded_image: dict[PyObjectId, str] | None = None
36+
"""Any base64-encoded image data associated with the block, keyed by file_id, if any."""
37+
38+
bokeh_plot_data: str | None = None
39+
"""A JSON-encoded string containing the Bokeh plot data, if any."""
40+
41+
class Config:
42+
allow_population_by_field_name = True
43+
json_encoders = JSON_ENCODERS
44+
extra = "allow"

0 commit comments

Comments
 (0)