Commit 5f555486 authored by Boris Kocherov's avatar Boris Kocherov

remove multiple JSON.parse

parent 6f31e5a6
......@@ -22,11 +22,12 @@
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
url: url,
dataType: "json"
})
.then(function (evt) {
return evt.target.responseText;
});
})
.push(function (evt) {
return evt.target.response;
});
}
......@@ -46,7 +47,6 @@
function resolveReference(partial_schema, schema, base_url) {
var parts,
external_schema,
ref = partial_schema.$ref;
if (ref === undefined) {
......@@ -69,8 +69,7 @@
}
return getJSON(ref);
})
.push(function (json) {
external_schema = JSON.parse(json);
.push(function (external_schema) {
parts = ref.split("#");
ref = "#" + parts[1];
return resolveLocalReference(ref, external_schema);
......@@ -190,15 +189,12 @@
return getJSON("slapos_load_meta_schema.json");
}
function validateJSONSchema(json, base_url) {
function validateJSONSchema(schema, base_url) {
return getMetaJSONSchema()
.push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
if (!tv4.validate(schema, meta_schema)) {
throw new Error("Non valid JSON schema " + schema);
}
return JSON.parse(json);
})
.push(function (schema) {
return expandSchema(schema, schema, base_url);
});
}
......@@ -219,23 +215,17 @@
})
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.push(function (json) {
return JSON.parse(json);
});
return getJSON(url);
})
.declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) {
return getJSON(schema_url)
.push(function (json) {
return JSON.parse(json);
})
.push(function (json_object) {
var parameter_schema_url,
st,
base_url,
url_uri = URI(schema_url);
for (st in json_object["software-type"]) {
if (json_object["software-type"].hasOwnProperty(st)) {
if (st === software_type) {
......@@ -243,7 +233,7 @@
}
}
}
if (URI(parameter_schema_url).protocol() === "") {
base_url = url_uri.path().split("/");
base_url.pop();
......@@ -252,25 +242,22 @@
parameter_schema_url = base_url + "/" + parameter_schema_url;
}
}
return getJSON(parameter_schema_url)
.push(function (json) {
var schema = JSON.parse(json);
return getJSON(parameter_schema_url)
.push(function (schema) {
return expandSchema(schema, schema, base_url)
.push(function (loaded_json) {
return tv4.validateMultiple(generated_json, loaded_json);
});
});
});
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.push(function (json) {
.push(function (schema) {
var base_url,
url_uri = URI(schema_url),
schema = JSON.parse(json);
url_uri = URI(schema_url);
base_url = url_uri.path().split("/");
base_url.pop();
......
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