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
fbd9424c
Commit
fbd9424c
authored
Sep 05, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add smart detection 'soft circular links'
parent
33371ea6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
12 deletions
+38
-12
jsonform.gadget.js
jsonform.gadget.js
+38
-12
No files found.
jsonform.gadget.js
View file @
fbd9424c
...
@@ -71,19 +71,40 @@
...
@@ -71,19 +71,40 @@
return
target
;
return
target
;
}
}
function
checkCircular
(
g
,
path
,
url
)
{
function
checkCircular
(
urls
,
path
,
url
)
{
var
required_stack
,
var
required_stack
,
idx
,
idx
,
prev_field_path
=
getMaxPathInDict
(
g
.
props
.
schema_required_
urls
,
path
);
prev_field_path
=
getMaxPathInDict
(
urls
,
path
);
required_stack
=
g
.
props
.
schema_required_
urls
[
prev_field_path
]
||
[];
required_stack
=
urls
[
prev_field_path
]
||
[];
idx
=
required_stack
.
indexOf
(
url
);
idx
=
required_stack
.
indexOf
(
url
);
if
(
idx
>=
0
)
{
if
(
idx
>=
0
)
{
if
(
path
===
prev_field_path
&&
idx
===
0
)
{
if
(
path
===
prev_field_path
&&
idx
===
0
)
{
return
;
return
;
}
}
throw
new
Error
(
"
Circular reference detected
"
);
return
true
;
}
// copy and add url as first element
urls
[
path
]
=
[
url
].
concat
(
required_stack
);
}
function
checkHardCircular
(
g
,
path
,
url
)
{
return
checkCircular
(
g
.
props
.
schema_required_urls
,
path
,
url
);
}
function
checkAndMarkSoftCircular
(
g
,
schema_arr
,
path
,
url
)
{
var
ret
=
true
;
// if schema_arr.length > 1 selection rendered in any case
// so we not need checkCircular and have small optimisation
if
(
schema_arr
.
length
===
1
)
{
ret
=
checkCircular
(
g
.
props
.
schema_urls
,
path
,
url
);
schema_arr
[
0
].
circular
=
ret
;
}
if
(
ret
)
{
// if schema_arr.length > 1 selection rendered and loop break
// if circular found selection rendered and loop break
// so we can begin from start
g
.
props
.
schema_urls
[
path
]
=
[];
}
}
g
.
props
.
schema_required_urls
[
path
]
=
[
url
].
concat
(
required_stack
);
}
}
function
convertToRealWorldSchemaPath
(
g
,
path
)
{
function
convertToRealWorldSchemaPath
(
g
,
path
)
{
...
@@ -261,7 +282,9 @@
...
@@ -261,7 +282,9 @@
}
}
queue
queue
.
push
(
function
(
json
)
{
.
push
(
function
(
json
)
{
checkCircular
(
g
,
path
,
url
);
if
(
checkHardCircular
(
g
,
path
,
url
))
{
throw
new
Error
(
"
Circular reference detected
"
);
}
return
resolveLocalReference
(
json
,
hash
);
return
resolveLocalReference
(
json
,
hash
);
});
});
}
}
...
@@ -305,12 +328,7 @@
...
@@ -305,12 +328,7 @@
return
expandSchema
(
g
,
schema_part
,
path
,
$ref
);
return
expandSchema
(
g
,
schema_part
,
path
,
$ref
);
})
})
.
push
(
function
(
schema_arr
)
{
.
push
(
function
(
schema_arr
)
{
// if length array > 1 form rendered on demand already
checkAndMarkSoftCircular
(
g
,
schema_arr
,
path
,
url
);
// so not needed circular detection
if
(
schema_arr
.
length
===
1
)
{
// XXX need smart circular detection in this place
schema_arr
[
0
].
circular
=
true
;
}
return
schema_arr
;
return
schema_arr
;
});
});
}
}
...
@@ -740,11 +758,19 @@
...
@@ -740,11 +758,19 @@
"
http://json-schema.org/draft-07/schema
"
:
"
json-schema/schema7.json
"
,
"
http://json-schema.org/draft-07/schema
"
:
"
json-schema/schema7.json
"
,
"
http://json-schema.org/schema
"
:
"
json-schema/schema7.json
"
"
http://json-schema.org/schema
"
:
"
json-schema/schema7.json
"
};
};
// schema_urls[path] = [
// stack urls
// "url1",
// "url2"
// ]
// used for break soft circular relation of schemas
g
.
props
.
schema_urls
=
{};
// schema_required_urls[path] = [
// schema_required_urls[path] = [
// stack required urls, on every unrequired field stack begining from []
// stack required urls, on every unrequired field stack begining from []
// "url1",
// "url1",
// "url2"
// "url2"
// ]
// ]
// used for break hard circular relation of schemas
g
.
props
.
schema_required_urls
=
{};
g
.
props
.
schema_required_urls
=
{};
// schema_resolve_errors[schema_url] = {
// schema_resolve_errors[schema_url] = {
// schemaPath: local_schema_path,
// schemaPath: local_schema_path,
...
...
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