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

remove multiple base_url computation

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