diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index 1b237bdf..e4bca2b7 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -1,5 +1,5 @@ {{errorMessage}} -
+
@@ -7,13 +7,13 @@
- {{prop.type}} {{prop.format}} + {{prop._displayType}} {{prop.format}} Required
-
+
diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js index 73dae7a0..6db70904 100644 --- a/lib/components/JsonSchema/json-schema.js +++ b/lib/components/JsonSchema/json-schema.js @@ -25,11 +25,23 @@ export default class JsonSchema extends BaseComponent { let schema = this.componentSchema; this.data = {}; this.data.properties = []; - if (schema.type !== 'object') { + if (schema.type !== 'object' && schema.type !== 'array') { // TODO - this.errorMessage = 'Non-object (array-based) schemas are not implemented yet'; + this.errorMessage = 'Non-object and non-array schemas are not implemented yet'; return; } + + if (schema.type === 'array') { + this._isArray = true; + this.pointer = schema.items._pointer || this.pointer; + schema = schema.items; + } + + if (schema.type === 'object') { + this.pointer = schema._pointer || this.pointer; + } + + if (!schema.properties) return; let props = Object.keys(schema.properties).map(prop => { let propData = schema.properties[prop]; @@ -53,18 +65,19 @@ export default class JsonSchema extends BaseComponent { injectPropData(prop, propData) { propData._name = prop; propData.isRequired = this.requiredMap[prop]; - + propData._displayType = propData.type; if (propData.type === 'array') { let itemType = propData.items.type; if (itemType === 'object') { itemType = propData.items.title || 'object'; - propData._pointer = propData.items._pointer; + propData._pointer = this.pointer + '/properties/' + prop; } - propData.type = `array of ${itemType}`; + propData._displayType= `array of ${itemType}`; + propData._isArray = true; } if (propData.type === 'object') { - propData.type = propData.title || 'object'; + propData._displayType = propData.title || 'object'; } } diff --git a/lib/components/JsonSchema/json-schema.scss b/lib/components/JsonSchema/json-schema.scss index 301b1b42..ccdb1638 100644 --- a/lib/components/JsonSchema/json-schema.scss +++ b/lib/components/JsonSchema/json-schema.scss @@ -122,3 +122,44 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin; .param-schema .param-wrap:first-of-type .param-name:before { display: none !important; } + + +/* styles for array-schema for array */ +$array-marker-font-sz: 12px; +$array-marker-line-height: 1.5; +.params-wrap.params-array:before, .params-wrap.params-array:after { + display: block; + font-weight: bold; + color: #999; + font-size: $array-marker-font-sz; + line-height: $array-marker-line-height; +} + +.params-wrap.params-array:after { + content: "]"; +} + +.params-wrap.params-array:before { + content: "Array ["; +} + +.params-wrap.params-array { + padding-left: $bullet-margin; +} + +.param-schema.param-array:before { + bottom: ($array-marker-font-sz * $array-marker-line-height) / 2; + width: $bullet-margin; + border-left-style: dashed; + border-bottom: $lines-width dashed $tree-lines-color; +} + +.params-wrap.params-array > .param-wrap:first-of-type > .param > .param-name:after { + content: ""; + display: block; + position: absolute; + left: -$lines-width; + top: 0; + border-left: $line-border-erase; + height: ($param-name-height/2) + $cell-padding; +} diff --git a/lib/components/base.js b/lib/components/base.js index e2cae3cf..0bfff831 100644 --- a/lib/components/base.js +++ b/lib/components/base.js @@ -79,7 +79,8 @@ export class BaseComponent { * simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing. * TODO: doesn't support circular references */ - dereference(schema = this.componentSchema) { + dereference(schema = Object.assign({}, this.componentSchema)) { + //schema = Object.assign({}, schema); if (schema && schema.$ref) { let resolved = this.schemaMgr.byPointer(schema.$ref); let baseName = JsonPointer.baseName(schema.$ref); @@ -96,6 +97,7 @@ export class BaseComponent { this.dereference(value); } }); + this.componentSchema = schema; } joinAllOf(schema = this.componentSchema) {