Commit 9d93d848 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Load specific meta-schemas depending of the serialisation

   On xml serialisation we support a more restrict scope them the whole json schemas and on json-in-xml, despite the fact we could support all, not everything is suitable for form generation.

   The both "meta schemas" are a variation of the draft exclusively for UI rendering purpose.
parent 22c2391f
/*jslint nomen: true, maxlen: 200, indent: 2*/ /*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $, btoa */ /*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $, btoa */
(function (window, rJS, $, RSVP, btoa) { (function (window, rJS, $, RSVP, btoa, URI, tv4) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window);
...@@ -57,12 +57,12 @@ ...@@ -57,12 +57,12 @@
} }
if (ref.substr(0, 1) === "#") { if (ref.substr(0, 1) === "#") {
return RSVP.Queue().push(function () { return new RSVP.Queue().push(function () {
return resolveLocalReference(ref, schema); return resolveLocalReference(ref, schema);
}); });
} }
return RSVP.Queue().push(function () { return new RSVP.Queue().push(function () {
if (URI(ref).protocol() === "") { if (URI(ref).protocol() === "") {
if (base_url !== undefined) { if (base_url !== undefined) {
ref = base_url + "/" + ref; ref = base_url + "/" + ref;
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
expanded_json_schema.properties = {}; expanded_json_schema.properties = {};
} }
return RSVP.Queue().push(function () { return new RSVP.Queue().push(function () {
if (json_schema.$ref) { if (json_schema.$ref) {
return resolveReference( return resolveReference(
json_schema, json_schema,
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
return true; return true;
}).push(function () { }).push(function () {
var property, queue = RSVP.Queue(); var property, queue = new RSVP.Queue();
function wrapperResolveReference(p) { function wrapperResolveReference(p) {
return resolveReference( return resolveReference(
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
}) })
.push(function () { .push(function () {
var zqueue = RSVP.Queue(); var zqueue = new RSVP.Queue();
function wrapperExpandSchema(p) { function wrapperExpandSchema(p) {
return expandSchema( return expandSchema(
...@@ -187,12 +187,18 @@ ...@@ -187,12 +187,18 @@
}); });
} }
function getMetaJSONSchema() { function getMetaJSONSchema(serialisation) {
if (serialisation === "xml") {
return getJSON("slapos_load_meta_schema_xml.json");
}
if (serialisation === "json-in-xml") {
return getJSON("slapos_load_meta_schema_json_in_xml.json");
}
return getJSON("slapos_load_meta_schema.json"); return getJSON("slapos_load_meta_schema.json");
} }
function validateJSONSchema(json, base_url) { function validateJSONSchema(json, base_url, serialisation) {
return getMetaJSONSchema() return getMetaJSONSchema(serialisation)
.push(function (meta_schema) { .push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) { if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json); throw new Error("Non valid JSON schema " + json);
...@@ -205,7 +211,6 @@ ...@@ -205,7 +211,6 @@
} }
gk gk
.declareMethod("getBaseUrl", function (url) { .declareMethod("getBaseUrl", function (url) {
var base_url, url_uri = URI(url); var base_url, url_uri = URI(url);
base_url = url_uri.path().split("/"); base_url = url_uri.path().split("/");
...@@ -213,13 +218,13 @@ ...@@ -213,13 +218,13 @@
base_url = url.split(url_uri.path())[0] + base_url.join("/"); base_url = url.split(url_uri.path())[0] + base_url.join("/");
return base_url; return base_url;
}) })
.declareMethod("loadJSONSchema", function (url) { .declareMethod("loadJSONSchema", function (url, serialisation) {
var gadget = this; var gadget = this;
return getJSON(url) return getJSON(url)
.push(function (json) { .push(function (json) {
return gadget.getBaseUrl(url) return gadget.getBaseUrl(url)
.push(function (base_url) { .push(function (base_url) {
return validateJSONSchema(json, base_url); return validateJSONSchema(json, base_url, serialisation);
}); });
}); });
}) })
...@@ -249,4 +254,4 @@ ...@@ -249,4 +254,4 @@
}); });
}); });
}); });
}(window, rJS, $, RSVP, btoa)); }(window, rJS, $, RSVP, btoa, URI, tv4));
...@@ -553,10 +553,10 @@ ...@@ -553,10 +553,10 @@
return ""; return "";
} }
gk.declareMethod("loadJSONSchema", function (url) { gk.declareMethod("loadJSONSchema", function (url, serialisation) {
return this.getDeclaredGadget('loadschema') return this.getDeclaredGadget('loadschema')
.push(function (gadget) { .push(function (gadget) {
return gadget.loadJSONSchema(url); return gadget.loadJSONSchema(url, serialisation);
}); });
}) })
...@@ -648,10 +648,10 @@ ...@@ -648,10 +648,10 @@
}); });
}) })
.declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter) { .declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter, serialisation) {
var g = this; var g = this;
return g.loadJSONSchema(json_url) return g.loadJSONSchema(json_url, serialisation)
.push(function (json) { .push(function (json) {
var fieldset_list = g.element.querySelectorAll('fieldset'), var fieldset_list = g.element.querySelectorAll('fieldset'),
fieldset = document.createElement("fieldset"); fieldset = document.createElement("fieldset");
...@@ -944,7 +944,8 @@ ...@@ -944,7 +944,8 @@
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url; parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;
} }
return gadget.renderParameterForm(parameter_json_schema_url, return gadget.renderParameterForm(parameter_json_schema_url,
parameter_dict, restricted_parameter); parameter_dict, restricted_parameter,
options.serialisation);
}) })
.push(function () { .push(function () {
var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'), var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'),
......
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>999.21924.60509.42444</string> </value> <value> <string>999.23324.48841.24558</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1649185724.55</float> <float>1649686520.32</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
\ No newline at end of file
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
\ No newline at end of file
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Meta-schema for XML serialisaton schemas",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
},
"customProperties": {
"definitions": {
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "string" ]
}
},
"type": "object",
"properties": {
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/customProperties/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/customProperties/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#/definitions/customProperties" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
\ No newline at end of file
...@@ -209,6 +209,9 @@ web_page_module/rjs_gadget_trial_panel_js ...@@ -209,6 +209,9 @@ web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_gadget_slapos_utils_js web_page_module/rjs_gadget_slapos_utils_js
web_page_module/rjs_leaflet_css web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_tv4_min_js web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs web_site_module/hostingjs
......
...@@ -211,6 +211,9 @@ web_page_module/rjs_gadget_trial_panel_html ...@@ -211,6 +211,9 @@ web_page_module/rjs_gadget_trial_panel_html
web_page_module/rjs_gadget_trial_panel_js web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_leaflet_css web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_tv4_min_js web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs web_site_module/hostingjs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment