response samples only for responses with samples or schema

This commit is contained in:
Roman Gotsiy 2015-10-22 21:31:12 +03:00
parent 823add877b
commit b07fd26647
4 changed files with 21 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<header> Responses samples </header>
<tabs>
<tab *ng-for="#response of data.responses" [tab-title]="response.code">
<schema-sample pointer="{{response.pointer}}/schema"><schema-sample>
<schema-sample [pointer]="response.pointer"><schema-sample>
</tab>
</tabs>

View File

@ -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;
}
}

View File

@ -1,4 +1,5 @@
<div class="snippet">
<pre *ng-if="!data.sample"> Not supported yet (any-of)</pre>
<!-- in case sample is not available for some reason -->
<pre *ng-if="!data.sample"> Sample unavailable </pre>
<pre>{{data.sample | json}}</pre>
</div>

View File

@ -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;
}
}