From 9979fab0ab519c100d9ad77cf6ed81853f37b017 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sun, 29 Nov 2015 12:04:28 +0200 Subject: [PATCH] JsonSchema fix issues with subschemas resolving --- lib/components/JsonSchema/json-schema.html | 4 +- lib/components/JsonSchema/json-schema.js | 52 +++++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index e4bca2b7..60482c45 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -1,5 +1,5 @@ {{errorMessage}} -
+
@@ -14,7 +14,7 @@
- +
diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js index 6db70904..cd6ccdad 100644 --- a/lib/components/JsonSchema/json-schema.js +++ b/lib/components/JsonSchema/json-schema.js @@ -7,7 +7,8 @@ import {ElementRef} from 'angular2/angular2'; selector: 'json-schema', templateUrl: './lib/components/JsonSchema/json-schema.html', styleUrls: ['./lib/components/JsonSchema/json-schema.css'], - directives: [JsonSchema] + directives: [JsonSchema], + inputs: ['isArray'] }) export default class JsonSchema extends BaseComponent { constructor(schemaMgr, elementRef) { @@ -16,31 +17,38 @@ export default class JsonSchema extends BaseComponent { } prepareModel() { + this.data = {}; + this.data.properties = []; + + if (!this.componentSchema) { + // TODO + this.errorMessage = 'Can\'t load component schema'; + console.warn(`${this.errorMessage}: ${this.pointer}`); + return; + } + this.dereference(); - this.joinAllOf(); + let schema = this.componentSchema; + + if (schema.type === 'array') { + this.isArray = true; + schema = schema.items; + } + this.joinAllOf(schema); + + if (schema.type !== 'object') { + // TODO + this.errorMessage = 'Non-object and non-array schemas are not implemented yet'; + console.warn(`${this.errorMessage}: ${schema.type}`); + return; + } + + this.pointer = schema._pointer || this.pointer; + this.requiredMap = {}; if (this.schema.required) { this.schema.required.forEach(prop => this.requiredMap[prop] = true); } - let schema = this.componentSchema; - this.data = {}; - this.data.properties = []; - if (schema.type !== 'object' && schema.type !== 'array') { - // TODO - 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 => { @@ -70,7 +78,7 @@ export default class JsonSchema extends BaseComponent { let itemType = propData.items.type; if (itemType === 'object') { itemType = propData.items.title || 'object'; - propData._pointer = this.pointer + '/properties/' + prop; + propData._pointer = propData.items._pointer || this.pointer + '/properties/' + prop + '/items'; } propData._displayType= `array of ${itemType}`; propData._isArray = true;