Commit 61e2a609 authored by Boris Kocherov's avatar Boris Kocherov

remove multiple base_url computation

parent 5f555486
......@@ -12,6 +12,16 @@
}
}
function getBaseUrl(schema_url) {
var base_url,
url_uri = URI(schema_url);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
return base_url;
}
function getJSON(url) {
var protocol = URI(url).protocol();
if (protocol === "http" || protocol === "https") {
......@@ -203,13 +213,7 @@
.declareMethod("loadJSONSchema", function (url) {
return getJSON(url)
.push(function (json) {
var base_url, url_uri;
url_uri = URI(url);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = url.split(url_uri.path())[0] + base_url.join("/");
var base_url = getBaseUrl(url);
return validateJSONSchema(json, base_url);
});
})
......@@ -223,8 +227,7 @@
.push(function (json_object) {
var parameter_schema_url,
st,
base_url,
url_uri = URI(schema_url);
base_url;
for (st in json_object["software-type"]) {
if (json_object["software-type"].hasOwnProperty(st)) {
......@@ -235,9 +238,7 @@
}
if (URI(parameter_schema_url).protocol() === "") {
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
base_url = getBaseUrl(schema_url);
if (base_url !== undefined) {
parameter_schema_url = base_url + "/" + parameter_schema_url;
}
......@@ -256,13 +257,7 @@
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.push(function (schema) {
var base_url,
url_uri = URI(schema_url);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
var base_url = getBaseUrl(schema_url);
return expandSchema(schema, schema, base_url)
.push(function (loaded_schema) {
return tv4.validateMultiple(generated_json, loaded_schema);
......
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