Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-schema-faker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fork
json-schema-faker
Commits
e5e578a5
Commit
e5e578a5
authored
5 years ago
by
Alvaro Cabrera Durán
Browse files
Options
Downloads
Patches
Plain Diff
Handle recursion and self-references; fixes #258
parent
58e506ac
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/run.js
+3
-4
3 additions, 4 deletions
src/core/run.js
tests/schema/core/issues/issue-258.json
+0
-1
0 additions, 1 deletion
tests/schema/core/issues/issue-258.json
with
3 additions
and
5 deletions
src/core/run.js
+
3
−
4
View file @
e5e578a5
...
@@ -116,11 +116,10 @@ function resolve(obj, data, values, property) {
...
@@ -116,11 +116,10 @@ function resolve(obj, data, values, property) {
// TODO provide types
// TODO provide types
function
run
(
refs
,
schema
,
container
)
{
function
run
(
refs
,
schema
,
container
)
{
let
depth
=
0
;
try
{
try
{
const
result
=
traverse
(
utils
.
clone
(
schema
),
[],
function
reduce
(
sub
,
parentSchemaPath
)
{
const
result
=
traverse
(
utils
.
clone
(
schema
),
[],
function
reduce
(
sub
,
parentSchemaPath
)
{
// FIXME: handle recursive/self-references, see #258
// also, a depth-limit should be taken into account...
if
(
typeof
sub
.
generate
===
'
function
'
)
{
if
(
typeof
sub
.
generate
===
'
function
'
)
{
return
sub
;
return
sub
;
}
}
...
@@ -135,7 +134,7 @@ function run(refs, schema, container) {
...
@@ -135,7 +134,7 @@ function run(refs, schema, container) {
}
}
if
(
typeof
sub
.
$ref
===
'
string
'
)
{
if
(
typeof
sub
.
$ref
===
'
string
'
)
{
if
(
sub
.
$ref
===
'
#
'
)
{
if
(
sub
.
$ref
===
'
#
'
||
++
depth
>
random
.
number
(
0
,
2
)
)
{
delete
sub
.
$ref
;
delete
sub
.
$ref
;
return
sub
;
return
sub
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/schema/core/issues/issue-258.json
+
0
−
1
View file @
e5e578a5
...
@@ -53,7 +53,6 @@
...
@@ -53,7 +53,6 @@
{
{
"description"
:
"should work as expected"
,
"description"
:
"should work as expected"
,
"schema"
:
"schemas.0"
,
"schema"
:
"schemas.0"
,
"skip"
:
true
,
"valid"
:
true
"valid"
:
true
}
}
]
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment