From b07fd2664756b88fbb8ccb16a5e58122d4ee2910 Mon Sep 17 00:00:00 2001 From: Roman Gotsiy Date: Thu, 22 Oct 2015 21:31:12 +0300 Subject: [PATCH] response samples only for responses with samples or schema --- .../ResponsesSamples/responses-samples.html | 2 +- .../ResponsesSamples/responses-samples.js | 8 +++++++- lib/components/SchemaSample/schema-sample.html | 3 ++- lib/components/SchemaSample/schema-sample.js | 14 +++++++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/components/ResponsesSamples/responses-samples.html b/lib/components/ResponsesSamples/responses-samples.html index 4c540c7b..c143b6e0 100644 --- a/lib/components/ResponsesSamples/responses-samples.html +++ b/lib/components/ResponsesSamples/responses-samples.html @@ -1,6 +1,6 @@
Responses samples
- + diff --git a/lib/components/ResponsesSamples/responses-samples.js b/lib/components/ResponsesSamples/responses-samples.js index dec82e39..41420127 100644 --- a/lib/components/ResponsesSamples/responses-samples.js +++ b/lib/components/ResponsesSamples/responses-samples.js @@ -10,6 +10,11 @@ function isNumeric(n) { return (!isNaN(parseFloat(n)) && isFinite(n)); } +function hasExample(response) { + return ((response.examples && response.examples['application/json']) || + response.schema); +} + @RedocComponent({ selector: 'responses-samples', templateUrl: './lib/components/ResponsesSamples/responses-samples.html', @@ -38,7 +43,8 @@ export class ResponsesSamples extends BaseComponent { resp.code = respCode; return resp; - }); + }) + .filter(response => hasExample(response)); this.data.responses = responses; } } diff --git a/lib/components/SchemaSample/schema-sample.html b/lib/components/SchemaSample/schema-sample.html index 932df1bf..71a7b47c 100644 --- a/lib/components/SchemaSample/schema-sample.html +++ b/lib/components/SchemaSample/schema-sample.html @@ -1,4 +1,5 @@
-
 Not supported yet (any-of)
+ +
 Sample unavailable 
{{data.sample | json}}
diff --git a/lib/components/SchemaSample/schema-sample.js b/lib/components/SchemaSample/schema-sample.js index 4f02294a..e10bd446 100644 --- a/lib/components/SchemaSample/schema-sample.js +++ b/lib/components/SchemaSample/schema-sample.js @@ -15,12 +15,20 @@ export class SchemaSample extends BaseComponent { init() { this.data = {}; + + // sometimes for some reason this method is called without resolved pointer + // TODO: fix it and remove the following workaround if (!this.componentSchema || !this.pointer) { - console.log(this.pointer); return; } - this.dereference(); - let sample = SchemaSampler.instantiate(this.componentSchema); + 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); + } + this.data.sample = sample; } }