mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-06 13:00:34 +03:00
Moved dereference to base class
This commit is contained in:
parent
c3efcf6756
commit
5e207b343c
|
@ -9,7 +9,6 @@ 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',
|
||||
|
@ -21,27 +20,6 @@ export class JsonSchemaView extends BaseComponent {
|
|||
this.element = elementRef.nativeElement;
|
||||
}
|
||||
|
||||
dereference(schema = this.componentSchema) {
|
||||
// simple in-place schema dereferencing. Schema is already bundled so no need in
|
||||
// global dereferencing.
|
||||
// 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);
|
||||
schema.$ref = null;
|
||||
}
|
||||
|
||||
Object.keys(schema).forEach((key) => {
|
||||
let value = schema[key];
|
||||
if (value && typeof value === 'object') {
|
||||
this.dereference(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init() {
|
||||
this.dereference();
|
||||
const formatter = new JSONSchemaView(this.componentSchema, 1);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import {Component, View, OnInit, CORE_DIRECTIVES} from 'angular2/angular2';
|
||||
import {SchemaManager} from '../utils/SchemaManager';
|
||||
import {JsonPointerEscapePipe} from '../utils/pipes';
|
||||
import {JsonPointer} from '../utils/JsonPointer';
|
||||
|
||||
// common inputs for all components
|
||||
let commonInputs = ['pointer']; // json pointer to the schema chunk
|
||||
|
@ -74,6 +75,28 @@ export class BaseComponent {
|
|||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
Object.keys(schema).forEach((key) => {
|
||||
let value = schema[key];
|
||||
if (value && typeof value === 'object') {
|
||||
this.dereference(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to prepare model based on component schema
|
||||
* @abstract
|
||||
|
|
Loading…
Reference in New Issue
Block a user