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
1be336de
Commit
1be336de
authored
Aug 30, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merging shemas
parent
306ead65
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
40 deletions
+152
-40
jsonform.gadget.js
jsonform.gadget.js
+152
-40
No files found.
jsonform.gadget.js
View file @
1be336de
...
...
@@ -5,6 +5,12 @@
"
use strict
"
;
var
expandSchema
;
function
arrayIntersect
(
x
,
y
)
{
return
x
.
filter
(
function
(
value
)
{
return
y
.
indexOf
(
value
)
>=
0
;
});
}
function
URLwithJio
(
url
,
base_url
)
{
var
urn_prefix
,
pathname
,
...
...
@@ -309,7 +315,141 @@
});
}
function
allOf
(
g
,
schema_array
,
schema_path
)
{
function
mergeSchemas
(
x
,
y
,
doesntcopy
)
{
if
(
x
===
true
&&
y
===
true
)
{
return
true
;
}
if
(
x
===
false
||
y
===
false
)
{
return
false
;
}
var
key
,
p
;
if
(
x
===
true
)
{
x
=
{};
}
else
if
(
!
doesntcopy
)
{
x
=
JSON
.
parse
(
JSON
.
stringify
(
x
));
}
if
(
y
===
true
)
{
y
=
{};
}
for
(
key
in
y
)
{
if
(
y
.
hasOwnProperty
(
key
))
{
if
(
x
.
hasOwnProperty
(
key
))
{
switch
(
key
)
{
case
"
maxProperties
"
:
case
"
maxLength
"
:
case
"
maxItems
"
:
case
"
maximum
"
:
case
"
exclusiveMaximum
"
:
if
(
y
[
key
]
<
x
[
key
])
{
x
[
key
]
=
y
[
key
];
}
break
;
case
"
minProperties
"
:
case
"
minItems
"
:
case
"
minLength
"
:
case
"
minimum
"
:
case
"
exclusiveMinimum
"
:
if
(
x
[
key
]
<
y
[
key
])
{
x
[
key
]
=
y
[
key
];
}
break
;
case
"
additionalProperties
"
:
case
"
additionalItems
"
:
case
"
contains
"
:
case
"
propertyNames
"
:
mergeSchemas
(
x
[
key
],
y
[
key
],
true
);
break
;
case
"
items
"
:
// XXX items can be array
mergeSchemas
(
x
[
key
],
y
[
key
],
true
);
break
;
case
"
contentEncoding
"
:
case
"
contentMediaType
"
:
if
(
x
[
key
]
!==
y
[
key
])
{
return
false
;
}
break
;
case
"
multipleOf
"
:
x
[
key
]
=
x
[
key
]
*
y
[
key
];
break
;
case
"
type
"
:
if
(
typeof
x
.
type
===
"
string
"
)
{
if
(
typeof
y
.
type
===
"
string
"
)
{
if
(
x
.
type
!==
y
.
type
)
{
return
false
;
}
}
else
if
(
y
.
type
.
indexOf
(
x
.
type
)
===
-
1
)
{
return
false
;
}
}
else
{
if
(
typeof
y
.
type
===
"
string
"
)
{
if
(
x
.
type
.
indexOf
(
y
.
type
)
===
-
1
)
{
return
false
;
}
}
else
{
x
.
type
=
arrayIntersect
(
x
.
type
,
y
.
type
);
if
(
x
.
type
.
length
===
0
)
{
return
false
;
}
}
}
break
;
case
"
properties
"
:
case
"
patternProperties
"
:
for
(
p
in
y
[
key
])
{
if
(
y
[
key
].
hasOwnProperty
(
p
))
{
if
(
x
[
key
].
hasOwnProperty
(
p
))
{
mergeSchemas
(
x
[
key
][
p
],
y
[
key
][
p
],
true
);
}
else
{
x
[
key
][
p
]
=
y
[
key
][
p
];
}
}
}
break
;
case
"
pattern
"
:
// XXX regex string merge
case
"
dependencies
"
:
// XXX find solution how merge
x
[
key
]
=
y
[
key
];
break
;
case
"
required
"
:
for
(
p
=
0
;
p
<
y
.
required
.
length
;
p
+=
1
)
{
if
(
x
.
required
.
indexOf
(
y
.
required
[
p
])
<
0
)
{
x
.
required
.
push
(
y
.
required
[
p
]);
}
}
break
;
case
"
uniqueItems
"
:
x
[
key
]
=
y
[
key
];
break
;
case
"
allOf
"
:
case
"
anyOf
"
:
case
"
$ref
"
:
case
"
id
"
:
case
"
$id
"
:
// XXX
break
;
default
:
// XXX
x
[
key
]
=
y
[
key
];
}
}
else
{
switch
(
key
)
{
case
"
allOf
"
:
case
"
anyOf
"
:
case
"
$ref
"
:
break
;
default
:
x
[
key
]
=
y
[
key
];
}
}
}
}
return
x
;
}
function
allOf
(
g
,
schema_array
,
schema_path
,
base_schema
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
var
i
,
...
...
@@ -323,10 +463,8 @@
var
i
,
x
,
y
,
key
,
next_schema
,
schema
,
schema_item
,
summ_arr
;
for
(
i
=
0
;
i
<
arr
.
length
-
1
;
i
+=
1
)
{
summ_arr
=
[];
...
...
@@ -334,46 +472,20 @@
for
(
y
=
0
;
y
<
arr
[
i
+
1
].
length
;
y
+=
1
)
{
schema
=
arr
[
i
][
x
].
schema
;
next_schema
=
arr
[
i
+
1
][
y
].
schema
;
if
(
schema
===
true
&&
next_schema
===
true
)
{
schema_item
=
{
schema
:
true
,
schema_path
:
arr
[
i
][
x
].
schema_path
};
}
else
if
(
schema
===
false
||
next_schema
===
false
)
{
schema_item
=
{
schema
:
false
,
schema_path
:
arr
[
i
][
x
].
schema_path
};
}
else
{
if
(
schema
===
true
)
{
schema
=
{};
}
if
(
next_schema
===
true
)
{
next_schema
=
{};
}
// copy before change
schema
=
JSON
.
parse
(
JSON
.
stringify
(
schema
));
for
(
key
in
next_schema
)
{
if
(
next_schema
.
hasOwnProperty
(
key
))
{
if
(
schema
.
hasOwnProperty
(
key
))
{
// XXX need use many many rules for merging
schema
[
key
]
=
next_schema
[
key
];
}
else
{
schema
[
key
]
=
next_schema
[
key
];
}
}
}
schema_item
=
{
schema
:
schema
,
schema_path
:
arr
[
i
][
x
].
schema_path
};
}
summ_arr
.
push
(
schema_item
);
schema
=
mergeSchemas
(
schema
,
next_schema
);
summ_arr
.
push
({
schema
:
schema
,
// XXX we loss path arr[i + 1][y].schema_path
schema_path
:
arr
[
i
][
x
].
schema_path
});
}
}
arr
[
i
+
1
]
=
summ_arr
;
}
return
arr
[
arr
.
length
-
1
];
for
(
x
=
0
;
x
<
summ_arr
.
length
;
x
+=
1
)
{
summ_arr
[
x
].
schema
=
mergeSchemas
(
summ_arr
[
x
].
schema
,
base_schema
);
}
return
summ_arr
;
});
}
...
...
@@ -416,7 +528,7 @@
return
anyOf
(
g
,
schema
.
anyOf
,
schema_path
);
}
if
(
schema
.
allOf
!==
undefined
)
{
return
allOf
(
g
,
schema
.
allOf
,
schema_path
);
return
allOf
(
g
,
schema
.
allOf
,
schema_path
,
schema
);
}
if
(
schema
.
$ref
)
{
return
loadJSONSchema
(
g
,
schema
.
$ref
,
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