Skip to content

Commit

Permalink
Add version 2 of the state and view schema definitions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasongrout committed Apr 19, 2017
1 parent 4f7f87f commit 6a9f470
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jupyter-js-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"font-awesome": "^4.5.0",
"jquery": "^3.1.1",
"jquery-ui": "^1.12.1",
"jupyter-widgets-schema": "^0.1.1",
"jupyter-widgets-schema": "^0.2.0",
"lolex": "^1.4.0",
"scriptjs": "^2.5.8",
"semver": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions jupyter-js-widgets/src-embed/embed-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require('../css/widgets.css');

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

// Magic global widget rendering function:
import * as widgets from '../../jupyter-js-widgets/lib/index';
Expand Down
2 changes: 1 addition & 1 deletion jupyter-widgets-schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyter-widgets-schema",
"version": "0.1.1",
"version": "0.2.0",
"description": "Schemas for the Jupyter interactive Widgets",
"main": "index.js",
"scripts": {
Expand Down
64 changes: 64 additions & 0 deletions jupyter-widgets-schema/v2/state.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Jupyter Interactive Widget State JSON schema.",
"type": "object",
"properties" : {
"version_major" : {
"description": "Format version (major)",
"type": "number",
"minimum": 2,
"maximum": 2
},
"version_minor" : {
"description": "Format version (minor)",
"type": "number"
},
"state": {
"description": "Model State for All Widget Models",
"type": "object",
"additionalProperties" : {
"type": "object",
"properties": {
"model_name": {
"description" : "Name of the JavaScript class holding the model implementation",
"type": "string"
},
"model_module": {
"description" : "Name of the JavaScript module holding the model implementation",
"type": "string"
},
"model_module_version": {
"description" : "Semver range for the JavaScript module holding the model implementation",
"type": "string"
},
"state": {
"description" : "Serialized state of the model",
"type": "object"
},
"buffer_paths": {
"description" : "Array of paths in the state for the corresponding buffers",
"type": "array",
"items": {
"description": "A path for a binary buffer value.",
"type": "array",
"items": {
"description": "An object key or array index",
"anyOf": [{"type": "string"}, {"type": "number"}]
}
}
},
"buffers": {
"description" : "Array of base64-encoded binary buffers",
"type": "array",
"items": {
"description": "A base64-encoded binary buffer",
"type": "string"
}
}
},
"required": [ "model_name", "model_module", "state" ]
}
}
},
"required": [ "version_major", "version_minor", "state" ]
}
22 changes: 22 additions & 0 deletions jupyter-widgets-schema/v2/view.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Jupyter Interactive Widget View JSON schema.",
"type": "object",
"properties" : {
"version_major" : {
"description": "Format version (major)",
"type": "number",
"minimum": 2,
"maximum": 2
},
"version_minor" : {
"description": "Format version (minor)",
"type": "number"
},
"model_id": {
"description": "Unique identifier of the widget model to be displayed",
"type": "string"
}
},
"required": [ "model_id" ]
}
2 changes: 1 addition & 1 deletion widgetsnbextension/src/embed_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var embed_widgets = function() {
'drop_defaults': true
}).then(function(state) {
var data = JSON.stringify({
version_major: 1,
version_major: 2,
version_minor: 0,
state: state
}, null, ' ');
Expand Down
2 changes: 1 addition & 1 deletion widgetsnbextension/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ WidgetManager.prototype._init_actions = function() {
}).then(function(state) {
Jupyter.notebook.metadata.widgets = {
'application/vnd.jupyter.widget-state+json' : {
version_major: 1,
version_major: 2,
version_minor: 0,
state: state
}
Expand Down

0 comments on commit 6a9f470

Please sign in to comment.