Skip to content

Commit

Permalink
handle array of objects, array of nested objects
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 18, 2018
1 parent 9d7808d commit 7596dc9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 39,8 @@ window.twbschema = (function () {
var rowBorderClass = ''
for (var field in props) {
if (props.hasOwnProperty(field)) {
// path for nested objects if any
var childDotNotation = dotNotation field
// new field ID for HTML elements
var id = 'schema-field-' counter
counter
Expand Down Expand Up @@ -151,7 153,8 @@ window.twbschema = (function () {
// render current object doc reference
// recursive call
// pass dot notation param
objectContent = gen(prop, dotNotation field '.')
childDotNotation = '.'
objectContent = gen(prop, childDotNotation)
addSpec('Min properties', prop.minProperties)
addSpec('Max properties', prop.maxProperties)
break
Expand All @@ -160,6 163,15 @@ window.twbschema = (function () {
// also shows array element type
type = type '[' prop.items.type ']'
typeLink()
switch (prop.items.type) {
case 'object':
// array of nested objects
// recursive call
// pass dot notation param with [] indicating array
childDotNotation = '[].'
objectContent = gen(prop.items, childDotNotation)
break
}
addSpec('Min elements', prop.minItems)
addSpec('Max elements', prop.maxItems)
break
Expand Down Expand Up @@ -191,7 203,7 @@ window.twbschema = (function () {
'<div class="pb-3 px-3' rowBgClass '">'
'<a class="small" data-toggle="collapse" href="#' id '" '
'aria-expanded="false" aria-controls="' id '">'
'Close<samp> ' dotNotation field '.*</samp>'
'Close<samp> ' childDotNotation '*</samp>'
'</a>'
'</div>'
'</div>'
Expand Down

0 comments on commit 7596dc9

Please sign in to comment.