mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-14 04:46:34 +03:00
db7f500ba0
Use Reflect.metadate decorator instead of Class.parameters Add fallback old syntax of flexbox Other minor styling fixes
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
import {ElementRef} from 'angular2/core';
|
|
|
|
import SchemaSampler from 'json-schema-instantiator';
|
|
|
|
import {JsonFormatter} from '../../utils/JsonFormatterPipe';
|
|
import {RedocComponent, BaseComponent, SchemaManager} from '../base';
|
|
|
|
@RedocComponent({
|
|
selector: 'schema-sample',
|
|
templateUrl: './lib/components/SchemaSample/schema-sample.html',
|
|
pipes: [JsonFormatter],
|
|
styleUrls: ['./lib/components/SchemaSample/schema-sample.css']
|
|
})
|
|
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
|
|
export default class SchemaSample extends BaseComponent {
|
|
constructor(schemaMgr, elementRef) {
|
|
super(schemaMgr);
|
|
this.element = elementRef.nativeElement;
|
|
}
|
|
|
|
init() {
|
|
this.data = {};
|
|
|
|
let base = {};
|
|
let sample;
|
|
|
|
// got pointer not directly to the schema but e.g. to response obj
|
|
if (this.componentSchema.schema) {
|
|
base = this.componentSchema;
|
|
this.componentSchema = this.componentSchema.schema;
|
|
}
|
|
|
|
if (base.examples && base.examples['application/json']) {
|
|
sample = base.examples['application/json'];
|
|
} else {
|
|
this.dereference(this.componentSchema);
|
|
sample = SchemaSampler.instantiate(this.componentSchema);
|
|
}
|
|
|
|
this.data.sample = sample;
|
|
|
|
|
|
this.element.addEventListener('click', (event) => {
|
|
var collapsed, target = event.target;
|
|
if (event.target.className === 'collapser') {
|
|
collapsed = target.parentNode.getElementsByClassName('collapsible')[0];
|
|
if (collapsed.parentNode.classList.contains('collapsed')) {
|
|
collapsed.parentNode.classList.remove('collapsed');
|
|
} else {
|
|
collapsed.parentNode.classList.add('collapsed');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|