Proper examples generation: fixes #43

This commit is contained in:
Roman Hotsiy 2016-05-29 20:26:20 +03:00
parent 61d9a42477
commit 4005d8f61b
4 changed files with 13 additions and 4 deletions

View File

@ -2,7 +2,7 @@
import { ElementRef } from '@angular/core'; import { ElementRef } from '@angular/core';
import SchemaSampler from 'json-schema-instantiator'; import * as OpenAPISampler from 'openapi-sampler';
import { RedocComponent, BaseComponent, SchemaManager } from '../base'; import { RedocComponent, BaseComponent, SchemaManager } from '../base';
import { JsonFormatter } from '../../utils/JsonFormatterPipe'; import { JsonFormatter } from '../../utils/JsonFormatterPipe';
@ -36,7 +36,11 @@ export class SchemaSample extends BaseComponent {
sample = base.examples['application/json']; sample = base.examples['application/json'];
} else { } else {
this.dereference(this.componentSchema); this.dereference(this.componentSchema);
sample = SchemaSampler.instantiate(this.componentSchema); try {
sample = OpenAPISampler.sample(this.componentSchema);
} catch(e) {
console.error('@@@@@@@@@@@@@@@@@@@' + e);
}
} }
this.data.sample = sample; this.data.sample = sample;

View File

@ -65,6 +65,7 @@ pre {
} }
.redoc-json { .redoc-json {
overflow-x: auto;
padding: 20px; padding: 20px;
border-radius: $border-radius*2; border-radius: $border-radius*2;
background-color: darken($black, 2%); background-color: darken($black, 2%);

View File

@ -43,9 +43,9 @@
"json": "github:systemjs/plugin-json@^0.1.0", "json": "github:systemjs/plugin-json@^0.1.0",
"json-formatter-js": "npm:json-formatter-js@^0.2.0", "json-formatter-js": "npm:json-formatter-js@^0.2.0",
"json-pointer": "npm:json-pointer@^0.3.0", "json-pointer": "npm:json-pointer@^0.3.0",
"json-schema-instantiator": "npm:json-schema-instantiator@^0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2",
"marked": "npm:marked@^0.3.5", "marked": "npm:marked@^0.3.5",
"openapi-sampler": "npm:openapi-sampler@^0.1.2",
"prismjs": "npm:prismjs@^1.3.0", "prismjs": "npm:prismjs@^1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@^0.1.0", "scrollparent": "npm:scrollparent@^0.1.0",
@ -63,6 +63,10 @@
"overrides": { "overrides": {
"github:Robdel12/DropKick@2.1.7": { "github:Robdel12/DropKick@2.1.7": {
"format": "global" "format": "global"
},
"npm:openapi-sampler@0.1.2": {
"main": "src/openapi-sampler",
"format": "esm"
} }
} }
}, },

View File

@ -53,9 +53,9 @@ System.config({
"json": "github:systemjs/plugin-json@0.1.2", "json": "github:systemjs/plugin-json@0.1.2",
"json-formatter-js": "npm:json-formatter-js@0.2.0", "json-formatter-js": "npm:json-formatter-js@0.2.0",
"json-pointer": "npm:json-pointer@0.3.0", "json-pointer": "npm:json-pointer@0.3.0",
"json-schema-instantiator": "npm:json-schema-instantiator@0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2",
"marked": "npm:marked@0.3.5", "marked": "npm:marked@0.3.5",
"openapi-sampler": "npm:openapi-sampler@0.1.2",
"prismjs": "npm:prismjs@1.3.0", "prismjs": "npm:prismjs@1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@0.1.0", "scrollparent": "npm:scrollparent@0.1.0",