mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
parent
955ef7101d
commit
b84177c157
|
@ -619,6 +619,7 @@ paths:
|
|||
examples:
|
||||
application/json: OK
|
||||
application/xml: <message> OK </message>
|
||||
text/plain: OK
|
||||
headers:
|
||||
X-Rate-Limit:
|
||||
type: integer
|
||||
|
|
|
@ -20,7 +20,15 @@
|
|||
<div class="action-buttons">
|
||||
<span copy-button [copyText]="xmlSample" class="hint--top-left hint--inversed"> <a>Copy</a> </span>
|
||||
</div>
|
||||
<pre class="xml-sample" [innerHtml]="xmlSample | prism:'xml'"></pre>
|
||||
<pre class="response-sample" [innerHtml]="xmlSample | prism:'xml'"></pre>
|
||||
</div>
|
||||
</tab>
|
||||
<tab tabTitle="text/plain" *ngIf="textSample">
|
||||
<div class="snippet">
|
||||
<div class="action-buttons">
|
||||
<span copy-button [copyText]="xmlSample" class="hint--top-left hint--inversed"> <a>Copy</a> </span>
|
||||
</div>
|
||||
<pre class="response-sample">{{textSample}}</pre>
|
||||
</div>
|
||||
</tab>
|
||||
</tabs>
|
||||
|
|
|
@ -131,7 +131,7 @@ pre {
|
|||
padding-left: 6px;
|
||||
}
|
||||
|
||||
.redoc-json, .xml-sample {
|
||||
.redoc-json, .response-sample {
|
||||
overflow-x: auto;
|
||||
padding: 20px;
|
||||
border-radius: $border-radius*2;
|
||||
|
|
|
@ -6,7 +6,7 @@ import * as OpenAPISampler from 'openapi-sampler';
|
|||
import JsonPointer from '../../utils/JsonPointer';
|
||||
import { BaseComponent, SpecManager } from '../base';
|
||||
import { SchemaNormalizer } from '../../services/schema-normalizer.service';
|
||||
import { getJsonLikeSample, getXmlLikeSample} from '../../utils/helpers';
|
||||
import { getJsonLikeSample, getXmlLikeSample, getTextLikeSample } from '../../utils/helpers';
|
||||
|
||||
@Component({
|
||||
selector: 'schema-sample',
|
||||
|
@ -21,6 +21,7 @@ export class SchemaSample extends BaseComponent implements OnInit {
|
|||
element: any;
|
||||
sample: any;
|
||||
xmlSample: string;
|
||||
textSample: string;
|
||||
enableButtons: boolean = false;
|
||||
|
||||
private _normalizer:SchemaNormalizer;
|
||||
|
@ -51,10 +52,8 @@ export class SchemaSample extends BaseComponent implements OnInit {
|
|||
base.examples = requestExamples;
|
||||
}
|
||||
|
||||
let xmlLikeSample = base.examples && getXmlLikeSample(base.examples);
|
||||
if (xmlLikeSample) {
|
||||
this.xmlSample = xmlLikeSample;
|
||||
}
|
||||
this.xmlSample = base.examples && getXmlLikeSample(base.examples);
|
||||
this.textSample = base.examples && getTextLikeSample(base.examples);
|
||||
|
||||
let jsonLikeSample = base.examples && getJsonLikeSample(base.examples);
|
||||
if (jsonLikeSample) {
|
||||
|
|
|
@ -142,6 +142,10 @@ export function isXmlLike(contentType: string): boolean {
|
|||
return contentType.search(/xml/i) !== -1;
|
||||
}
|
||||
|
||||
export function isTextLike(contentType: string): boolean {
|
||||
return contentType.search(/text\/plain/i) !== -1;
|
||||
}
|
||||
|
||||
export function getJsonLikeSample(samples: Object = {}) {
|
||||
const jsonLikeKeys = Object.keys(samples).filter(isJsonLike);
|
||||
|
||||
|
@ -161,3 +165,14 @@ export function getXmlLikeSample(samples: Object = {}) {
|
|||
|
||||
return samples[xmlLikeKeys[0]];
|
||||
}
|
||||
|
||||
|
||||
export function getTextLikeSample(samples: Object = {}) {
|
||||
const textLikeKeys = Object.keys(samples).filter(isTextLike);
|
||||
|
||||
if (!textLikeKeys.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return samples[textLikeKeys[0]];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user