Skip to content

Commit ad04dc9

Browse files
committed
Add version 2 of the state and view schema definitions.
1. We add optional buffer_paths and buffers keys to a model’s state dictionary. 2. We remove the requirement that each schema defines *all* of the properties an object may have, so that we can have backwards-compatible updates by adding optional properties. In other words, removed a number of additionalProperties: false entries in the schema.
1 parent f63da14 commit ad04dc9

File tree

7 files changed

+92
-6
lines changed

7 files changed

+92
-6
lines changed

jupyter-js-widgets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"font-awesome": "^4.5.0",
9797
"jquery": "^3.1.1",
9898
"jquery-ui": "^1.12.1",
99-
"jupyter-widgets-schema": "^0.1.1",
99+
"jupyter-widgets-schema": "^0.2.0",
100100
"lolex": "^1.4.0",
101101
"scriptjs": "^2.5.8",
102102
"semver": "^5.1.0",

jupyter-js-widgets/src-embed/embed-webpack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ require('../css/widgets.css');
1919

2020
// Load json schema validator
2121
var Ajv = require('ajv');
22-
var widget_state_schema = require('jupyter-widgets-schema').v1.state;
23-
var widget_view_schema = require('jupyter-widgets-schema').v1.view;
22+
var widget_state_schema = require('jupyter-widgets-schema').v2.state;
23+
var widget_view_schema = require('jupyter-widgets-schema').v2.view;
2424

2525
// Magic global widget rendering function:
2626
import * as widgets from '../../jupyter-js-widgets/lib/index';

jupyter-widgets-schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyter-widgets-schema",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Schemas for the Jupyter interactive Widgets",
55
"main": "index.js",
66
"scripts": {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "Jupyter Interactive Widget State JSON schema.",
4+
"type": "object",
5+
"properties" : {
6+
"version_major" : {
7+
"description": "Format version (major)",
8+
"type": "number",
9+
"minimum": 2,
10+
"maximum": 2
11+
},
12+
"version_minor" : {
13+
"description": "Format version (minor)",
14+
"type": "number"
15+
},
16+
"state": {
17+
"description": "Model State for All Widget Models",
18+
"type": "object",
19+
"additionalProperties" : {
20+
"type": "object",
21+
"properties": {
22+
"model_name": {
23+
"description" : "Name of the JavaScript class holding the model implementation",
24+
"type": "string"
25+
},
26+
"model_module": {
27+
"description" : "Name of the JavaScript module holding the model implementation",
28+
"type": "string"
29+
},
30+
"model_module_version": {
31+
"description" : "Semver range for the JavaScript module holding the model implementation",
32+
"type": "string"
33+
},
34+
"state": {
35+
"description" : "Serialized state of the model",
36+
"type": "object"
37+
},
38+
"buffer_paths": {
39+
"description" : "Array of paths in the state for the corresponding buffers",
40+
"type": "array",
41+
"items": {
42+
"description": "A path for a binary buffer value.",
43+
"type": "array",
44+
"items": {
45+
"description": "An object key or array index",
46+
"anyOf": [{"type": "string"}, {"type": "number"}]
47+
}
48+
}
49+
},
50+
"buffers": {
51+
"description" : "Array of base64-encoded binary buffers",
52+
"type": "array",
53+
"items": {
54+
"description": "A base64-encoded binary buffer",
55+
"type": "string"
56+
}
57+
}
58+
},
59+
"required": [ "model_name", "model_module", "state" ]
60+
}
61+
}
62+
},
63+
"required": [ "version_major", "version_minor", "state" ]
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "Jupyter Interactive Widget View JSON schema.",
4+
"type": "object",
5+
"properties" : {
6+
"version_major" : {
7+
"description": "Format version (major)",
8+
"type": "number",
9+
"minimum": 2,
10+
"maximum": 2
11+
},
12+
"version_minor" : {
13+
"description": "Format version (minor)",
14+
"type": "number"
15+
},
16+
"model_id": {
17+
"description": "Unique identifier of the widget model to be displayed",
18+
"type": "string"
19+
}
20+
},
21+
"required": [ "model_id" ]
22+
}

widgetsnbextension/src/embed_widgets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var embed_widgets = function() {
1313
'drop_defaults': true
1414
}).then(function(state) {
1515
var data = JSON.stringify({
16-
version_major: 1,
16+
version_major: 2,
1717
version_minor: 0,
1818
state: state
1919
}, null, ' ');

widgetsnbextension/src/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ WidgetManager.prototype._init_actions = function() {
164164
}).then(function(state) {
165165
Jupyter.notebook.metadata.widgets = {
166166
'application/vnd.jupyter.widget-state+json' : {
167-
version_major: 1,
167+
version_major: 2,
168168
version_minor: 0,
169169
state: state
170170
}

0 commit comments

Comments
 (0)