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

remove multiple JSON.parse

parent 6f31e5a6
...@@ -22,11 +22,12 @@ ...@@ -22,11 +22,12 @@
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return jIO.util.ajax({ 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 @@ ...@@ -46,7 +47,6 @@
function resolveReference(partial_schema, schema, base_url) { function resolveReference(partial_schema, schema, base_url) {
var parts, var parts,
external_schema,
ref = partial_schema.$ref; ref = partial_schema.$ref;
if (ref === undefined) { if (ref === undefined) {
...@@ -69,8 +69,7 @@ ...@@ -69,8 +69,7 @@
} }
return getJSON(ref); return getJSON(ref);
}) })
.push(function (json) { .push(function (external_schema) {
external_schema = JSON.parse(json);
parts = ref.split("#"); parts = ref.split("#");
ref = "#" + parts[1]; ref = "#" + parts[1];
return resolveLocalReference(ref, external_schema); return resolveLocalReference(ref, external_schema);
...@@ -190,15 +189,12 @@ ...@@ -190,15 +189,12 @@
return getJSON("slapos_load_meta_schema.json"); return getJSON("slapos_load_meta_schema.json");
} }
function validateJSONSchema(json, base_url) { function validateJSONSchema(schema, base_url) {
return getMetaJSONSchema() return getMetaJSONSchema()
.push(function (meta_schema) { .push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) { if (!tv4.validate(schema, meta_schema)) {
throw new Error("Non valid JSON schema " + json); throw new Error("Non valid JSON schema " + schema);
} }
return JSON.parse(json);
})
.push(function (schema) {
return expandSchema(schema, schema, base_url); return expandSchema(schema, schema, base_url);
}); });
} }
...@@ -219,17 +215,11 @@ ...@@ -219,17 +215,11 @@
}) })
.declareMethod("loadSoftwareJSON", function (url) { .declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url) return getJSON(url);
.push(function (json) {
return JSON.parse(json);
});
}) })
.declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) { .declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) {
return getJSON(schema_url) return getJSON(schema_url)
.push(function (json) {
return JSON.parse(json);
})
.push(function (json_object) { .push(function (json_object) {
var parameter_schema_url, var parameter_schema_url,
st, st,
...@@ -254,9 +244,7 @@ ...@@ -254,9 +244,7 @@
} }
return getJSON(parameter_schema_url) return getJSON(parameter_schema_url)
.push(function (json) { .push(function (schema) {
var schema = JSON.parse(json);
return expandSchema(schema, schema, base_url) return expandSchema(schema, schema, base_url)
.push(function (loaded_json) { .push(function (loaded_json) {
return tv4.validateMultiple(generated_json, loaded_json); return tv4.validateMultiple(generated_json, loaded_json);
...@@ -267,10 +255,9 @@ ...@@ -267,10 +255,9 @@
.declareMethod("validateJSON", function (schema_url, generated_json) { .declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url) return getJSON(schema_url)
.push(function (json) { .push(function (schema) {
var base_url, var base_url,
url_uri = URI(schema_url), url_uri = URI(schema_url);
schema = JSON.parse(json);
base_url = url_uri.path().split("/"); base_url = url_uri.path().split("/");
base_url.pop(); 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