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

use $id in definitions as url for schema downloading

parent a5a10bb8
......@@ -181,22 +181,50 @@
}
}
function map_url(g, download_url) {
var mapped_url = download_url,
hash = mapped_url.hash,
i,
schemas = g.props.schemas,
next_mapped_url;
// simple defence forever loop
for (i = 0; i < Object.keys(schemas).length; i += 1) {
next_mapped_url = g.props.schemas[mapped_url.origin + mapped_url.pathname + mapped_url.search];
if (next_mapped_url === undefined) {
break;
}
mapped_url = next_mapped_url;
if (typeof mapped_url !== "string") {
mapped_url = resolveLocalReference(mapped_url, hash);
break;
}
mapped_url = new URL(mapped_url, g.__path);
if (hash[0] === '#') {
hash = hash.slice(1);
}
if (hash === '/') {
hash = '';
}
hash = mapped_url.hash + hash;
}
return mapped_url;
}
function loadJSONSchema(g, $ref, path) {
var protocol,
url,
download_url,
hash,
mapped_schema,
mapped_url,
queue;
// XXX need use `id` property
if (!path) {
path = "/";
}
url = convertUrlToAbsolute(g, path, decodeURI($ref), window.location);
download_url = url.origin + url.pathname + url.search;
mapped_schema = g.props.schemas[download_url];
if (typeof mapped_schema === "string") {
url = new URL(mapped_schema, g.__path);
mapped_url = map_url(g, url);
if (mapped_url instanceof URL) {
url = mapped_url;
}
protocol = url.protocol;
if (protocol === "http:" || protocol === "https:") {
......@@ -208,27 +236,30 @@
download_url = url.origin + url.pathname + url.search;
hash = url.hash;
url = url.href;
if (typeof mapped_schema === "object") {
queue = RSVP.Queue()
.push(function () {
return mapped_schema;
});
} else if (download_url.startsWith("urn:jio:")) {
if (!(mapped_url instanceof URL)) {
queue = RSVP.Queue()
.push(function () {
return g.downloadJSON(download_url);
return mapped_url;
});
} else {
queue = RSVP.Queue()
.push(function () {
return downloadJSON(download_url);
if (download_url.startsWith("urn:jio:")) {
queue = RSVP.Queue()
.push(function () {
return g.downloadJSON(download_url);
});
} else {
queue = RSVP.Queue()
.push(function () {
return downloadJSON(download_url);
});
}
queue
.push(function (json) {
checkCircular(g, path, url);
return resolveLocalReference(json, hash);
});
}
return queue
.push(function (json) {
checkCircular(g, path, url);
return resolveLocalReference(json, hash);
})
.push(undefined, function (err) {
// XXX it will be great to have ability convert json_pointers(hash)
// in line numbers for pointed to line in rich editors.
......@@ -389,6 +420,24 @@
if (schema.$ref) {
return loadJSONSchema(g, schema.$ref, schema_path);
}
if (schema.definitions) {
var key,
d,
url,
mapped_url;
for (key in schema.definitions) {
if (schema.definitions.hasOwnProperty(key)) {
d = schema.definitions[key];
url = d.$id || d.id;
if (url) {
mapped_url = convertUrlToAbsolute(g, schema_path, '#' + schema_path, window.location);
// XXX /?
mapped_url = mapped_url + 'definitions/' + key;
g.props.schemas[url] = mapped_url;
}
}
}
}
return RSVP.Queue()
.push(function () {
return [{
......
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