2015-10-21 17:24:04 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import {RedocComponent, BaseComponent} from '../base';
|
|
|
|
|
|
|
|
import SchemaSampler from 'json-schema-instantiator';
|
|
|
|
|
|
|
|
@RedocComponent({
|
|
|
|
selector: 'schema-sample',
|
|
|
|
templateUrl: './lib/components/SchemaSample/schema-sample.html'
|
|
|
|
})
|
|
|
|
export class SchemaSample extends BaseComponent {
|
|
|
|
constructor(schemaMgr) {
|
|
|
|
super(schemaMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.data = {};
|
2015-10-22 21:31:12 +03:00
|
|
|
|
|
|
|
// sometimes for some reason this method is called without resolved pointer
|
|
|
|
// TODO: fix it and remove the following workaround
|
2015-10-21 17:24:04 +03:00
|
|
|
if (!this.componentSchema || !this.pointer) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-22 21:31:12 +03:00
|
|
|
let sample;
|
|
|
|
if (this.componentSchema.examples && this.componentSchema.examples['application/json']) {
|
|
|
|
sample = this.componentSchema.examples['application/json'];
|
|
|
|
} else {
|
|
|
|
this.dereference(this.componentSchema.schema);
|
|
|
|
sample = SchemaSampler.instantiate(this.componentSchema.schema);
|
|
|
|
}
|
|
|
|
|
2015-10-21 17:24:04 +03:00
|
|
|
this.data.sample = sample;
|
|
|
|
}
|
|
|
|
}
|