mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 01:54:08 +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>
|
<header> Responses samples </header>
|
||||||
<tabs>
|
<tabs>
|
||||||
<tab *ng-for="#response of data.responses" [tab-title]="response.code">
|
<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>
|
</tab>
|
||||||
</tabs>
|
</tabs>
|
||||||
|
|
|
@ -10,6 +10,11 @@ function isNumeric(n) {
|
||||||
return (!isNaN(parseFloat(n)) && isFinite(n));
|
return (!isNaN(parseFloat(n)) && isFinite(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExample(response) {
|
||||||
|
return ((response.examples && response.examples['application/json']) ||
|
||||||
|
response.schema);
|
||||||
|
}
|
||||||
|
|
||||||
@RedocComponent({
|
@RedocComponent({
|
||||||
selector: 'responses-samples',
|
selector: 'responses-samples',
|
||||||
templateUrl: './lib/components/ResponsesSamples/responses-samples.html',
|
templateUrl: './lib/components/ResponsesSamples/responses-samples.html',
|
||||||
|
@ -38,7 +43,8 @@ export class ResponsesSamples extends BaseComponent {
|
||||||
|
|
||||||
resp.code = respCode;
|
resp.code = respCode;
|
||||||
return resp;
|
return resp;
|
||||||
});
|
})
|
||||||
|
.filter(response => hasExample(response));
|
||||||
this.data.responses = responses;
|
this.data.responses = responses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<div class="snippet">
|
<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>
|
<pre>{{data.sample | json}}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,12 +15,20 @@ export class SchemaSample extends BaseComponent {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.data = {};
|
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) {
|
if (!this.componentSchema || !this.pointer) {
|
||||||
console.log(this.pointer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.dereference();
|
let sample;
|
||||||
let sample = SchemaSampler.instantiate(this.componentSchema);
|
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;
|
this.data.sample = sample;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user