JsonSchema fix issues with subschemas resolving

This commit is contained in:
Roman Hotsiy 2015-11-29 12:04:28 +02:00
parent f964465513
commit 9979fab0ab
2 changed files with 32 additions and 24 deletions

View File

@ -1,5 +1,5 @@
<small *ng-if="errorMessage">{{errorMessage}}</small>
<div class="params-wrap" [ng-class]="{'params-array': _isArray}">
<div class="params-wrap" [ng-class]="{'params-array': isArray}">
<div *ng-for="#prop of data.properties" class="param-wrap">
<div class="param">
<div class="param-name">
@ -14,7 +14,7 @@
</div>
</div>
<div class="param-schema" [ng-class]="{'param-array': prop._isArray}" *ng-if="prop._pointer">
<json-schema pointer="{{prop._pointer}}">
<json-schema pointer="{{prop._pointer}}" [is-array]='prop._isArray'>
</json-schema>
</div>
</div>

View File

@ -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;