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
5a188248
Commit
5a188248
authored
8 years ago
by
Alvaro Cabrera
Browse files
Options
Downloads
Patches
Plain Diff
Resolve given references; fix #294
parent
99ca0097
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
ts/core/run.ts
+11
-2
11 additions, 2 deletions
ts/core/run.ts
ts/index.ts
+2
-2
2 additions, 2 deletions
ts/index.ts
with
13 additions
and
4 deletions
ts/core/run.ts
+
11
−
2
View file @
5a188248
...
@@ -2,12 +2,14 @@ import traverse from './traverse';
...
@@ -2,12 +2,14 @@ import traverse from './traverse';
import
random
from
'
./random
'
;
import
random
from
'
./random
'
;
import
utils
from
'
./utils
'
;
import
utils
from
'
./utils
'
;
import
deref
from
'
deref
'
;
function
isKey
(
prop
:
string
):
boolean
{
function
isKey
(
prop
:
string
):
boolean
{
return
prop
===
'
enum
'
||
prop
===
'
default
'
||
prop
===
'
required
'
||
prop
===
'
definitions
'
;
return
prop
===
'
enum
'
||
prop
===
'
default
'
||
prop
===
'
required
'
||
prop
===
'
definitions
'
;
}
}
// TODO provide types
// TODO provide types
function
run
(
schema
:
JsonSchema
,
container
:
Container
)
{
function
run
(
refs
:
any
,
schema
:
JsonSchema
,
container
:
Container
)
{
try
{
try
{
return
traverse
(
schema
,
[],
function
reduce
(
sub
,
maxReduceDepth
)
{
return
traverse
(
schema
,
[],
function
reduce
(
sub
,
maxReduceDepth
)
{
if
(
typeof
maxReduceDepth
===
'
undefined
'
)
{
if
(
typeof
maxReduceDepth
===
'
undefined
'
)
{
...
@@ -26,8 +28,15 @@ function run(schema: JsonSchema, container: Container) {
...
@@ -26,8 +28,15 @@ function run(schema: JsonSchema, container: Container) {
if
(
typeof
sub
.
$ref
===
'
string
'
)
{
if
(
typeof
sub
.
$ref
===
'
string
'
)
{
if
(
sub
.
$ref
.
indexOf
(
'
#/
'
)
===
-
1
)
{
if
(
sub
.
$ref
.
indexOf
(
'
#/
'
)
===
-
1
)
{
throw
new
Error
(
'
Reference not found:
'
+
sub
.
$ref
);
var
ref
=
deref
.
util
.
findByRef
(
sub
.
$ref
,
refs
);
if
(
!
ref
)
{
throw
new
Error
(
'
Reference not found:
'
+
sub
.
$ref
);
}
return
ref
;
}
}
// just remove the reference
// just remove the reference
delete
sub
.
$ref
;
delete
sub
.
$ref
;
return
sub
;
return
sub
;
...
...
This diff is collapsed.
Click to expand it.
ts/index.ts
+
2
−
2
View file @
5a188248
...
@@ -13,7 +13,7 @@ function getRefs(refs?: any) {
...
@@ -13,7 +13,7 @@ function getRefs(refs?: any) {
var
$refs
=
{};
var
$refs
=
{};
if
(
Array
.
isArray
(
refs
))
{
if
(
Array
.
isArray
(
refs
))
{
refs
.
forEach
(
function
(
schema
)
{
refs
.
map
(
deref
.
util
.
normalizeSchema
).
forEach
(
function
(
schema
)
{
$refs
[
schema
.
id
]
=
schema
;
$refs
[
schema
.
id
]
=
schema
;
});
});
}
else
{
}
else
{
...
@@ -28,7 +28,7 @@ var jsf = function(schema: JsonSchema, refs?: any) {
...
@@ -28,7 +28,7 @@ var jsf = function(schema: JsonSchema, refs?: any) {
var
$refs
=
getRefs
(
refs
);
var
$refs
=
getRefs
(
refs
);
return
run
(
$
(
schema
,
$refs
,
true
),
container
);
return
run
(
$refs
,
$
(
schema
,
$refs
,
true
),
container
);
};
};
jsf
.
resolve
=
<
jsfAPI
>
function
(
schema
:
JsonSchema
,
refs
?:
any
,
cwd
?:
string
)
{
jsf
.
resolve
=
<
jsfAPI
>
function
(
schema
:
JsonSchema
,
refs
?:
any
,
cwd
?:
string
)
{
...
...
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