mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-28 11:33:43 +03:00
Add missing title injecting to Schema
This commit is contained in:
parent
55d05b3e03
commit
afd42a955a
|
@ -9,11 +9,11 @@ import JSONSchemaView from 'json-schema-view-js/src/index';
|
||||||
import 'json-schema-view-js/dist/style.css!';
|
import 'json-schema-view-js/dist/style.css!';
|
||||||
|
|
||||||
import {ElementRef} from 'angular2/angular2';
|
import {ElementRef} from 'angular2/angular2';
|
||||||
|
import {JsonPointer} from '../../utils/JsonPointer';
|
||||||
|
|
||||||
@RedocComponent({
|
@RedocComponent({
|
||||||
selector: 'schema',
|
selector: 'schema',
|
||||||
template: '',
|
template: ''
|
||||||
inputs: ['title', 'description']
|
|
||||||
})
|
})
|
||||||
export class JsonSchemaView extends BaseComponent {
|
export class JsonSchemaView extends BaseComponent {
|
||||||
constructor(schemaMgr, elementRef) {
|
constructor(schemaMgr, elementRef) {
|
||||||
|
@ -27,8 +27,11 @@ export class JsonSchemaView extends BaseComponent {
|
||||||
// TODO: doesn't support circular references
|
// TODO: doesn't support circular references
|
||||||
if (schema && schema.$ref) {
|
if (schema && schema.$ref) {
|
||||||
let resolved = this.schemaMgr.byPointer(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);
|
Object.assign(schema, resolved);
|
||||||
delete schema.$ref;
|
schema.$ref = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(schema).forEach((key) => {
|
Object.keys(schema).forEach((key) => {
|
||||||
|
@ -41,8 +44,6 @@ export class JsonSchemaView extends BaseComponent {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.dereference();
|
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);
|
const formatter = new JSONSchemaView(this.componentSchema, 1);
|
||||||
this.element.appendChild(formatter.render());
|
this.element.appendChild(formatter.render());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user