Add missing title injecting to Schema

This commit is contained in:
Roman Gotsiy 2015-10-18 12:28:48 +03:00
parent 55d05b3e03
commit afd42a955a

View File

@ -9,11 +9,11 @@ import JSONSchemaView from 'json-schema-view-js/src/index';
import 'json-schema-view-js/dist/style.css!';
import {ElementRef} from 'angular2/angular2';
import {JsonPointer} from '../../utils/JsonPointer';
@RedocComponent({
selector: 'schema',
template: '',
inputs: ['title', 'description']
template: ''
})
export class JsonSchemaView extends BaseComponent {
constructor(schemaMgr, elementRef) {
@ -27,8 +27,11 @@ export class JsonSchemaView extends BaseComponent {
// TODO: doesn't support circular references
if (schema && schema.$ref) {
let resolved = this.schemaMgr.byPointer(schema.$ref);
let baseName = JsonPointer.baseName(schema.$ref);
// if resolved schema doesn't have title use name from ref
resolved.title = resolved.title || baseName;
Object.assign(schema, resolved);
delete schema.$ref;
schema.$ref = null;
}
Object.keys(schema).forEach((key) => {
@ -41,8 +44,6 @@ export class JsonSchemaView extends BaseComponent {
init() {
this.dereference();
this.componentSchema.title = this.componentSchema.title || this.title;
this.componentSchema.description = this.componentSchema.description || this.description;
const formatter = new JSONSchemaView(this.componentSchema, 1);
this.element.appendChild(formatter.render());
}