Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
rjs_json_form
Commits
5ec49b94
Commit
5ec49b94
authored
Aug 18, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use $id in definitions as url for schema downloading
parent
a5a10bb8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
19 deletions
+68
-19
jsonform.gadget.js
jsonform.gadget.js
+68
-19
No files found.
jsonform.gadget.js
View file @
5ec49b94
...
...
@@ -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,12 +236,13 @@
download_url
=
url
.
origin
+
url
.
pathname
+
url
.
search
;
hash
=
url
.
hash
;
url
=
url
.
href
;
if
(
typeof
mapped_schema
===
"
object
"
)
{
if
(
!
(
mapped_url
instanceof
URL
)
)
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
mapped_
schema
;
return
mapped_
url
;
});
}
else
if
(
download_url
.
startsWith
(
"
urn:jio:
"
))
{
}
else
{
if
(
download_url
.
startsWith
(
"
urn:jio:
"
))
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
g
.
downloadJSON
(
download_url
);
...
...
@@ -224,11 +253,13 @@
return
downloadJSON
(
download_url
);
});
}
return
queue
queue
.
push
(
function
(
json
)
{
checkCircular
(
g
,
path
,
url
);
return
resolveLocalReference
(
json
,
hash
);
})
});
}
return
queue
.
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
[{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment