mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-30 17:44:07 +03:00
response samples only for responses with samples or schema
This commit is contained in:
parent
823add877b
commit
b07fd26647
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user