mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 13:20:19 +03:00
Allow a wided range of text content types
This commit is contained in:
parent
504bdadd78
commit
a9f6b6c69b
|
@ -11,7 +11,7 @@
|
|||
</div>
|
||||
</ng-template>
|
||||
|
||||
<tabs *ngIf="xmlSample; else jsonSnippet">
|
||||
<tabs *ngIf="xmlSample || textSample; else jsonSnippet">
|
||||
<tab tabTitle="JSON" *ngIf="sample">
|
||||
<ng-container *ngTemplateOutlet="jsonSnippet"></ng-container>
|
||||
</tab>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<pre class="response-sample" [innerHtml]="xmlSample | prism:'xml'"></pre>
|
||||
</div>
|
||||
</tab>
|
||||
<tab tabTitle="text/plain" *ngIf="textSample">
|
||||
<tab tabTitle="{{textSampleType}}" *ngIf="textSample">
|
||||
<div class="snippet">
|
||||
<div class="action-buttons">
|
||||
<span copy-button [copyText]="xmlSample" class="hint--top-left hint--inversed"> <a>Copy</a> </span>
|
||||
|
|
|
@ -22,6 +22,7 @@ export class SchemaSample extends BaseComponent implements OnInit {
|
|||
sample: any;
|
||||
xmlSample: string;
|
||||
textSample: string;
|
||||
textSampleType: string;
|
||||
enableButtons: boolean = false;
|
||||
|
||||
private _normalizer:SchemaNormalizer;
|
||||
|
@ -53,7 +54,11 @@ export class SchemaSample extends BaseComponent implements OnInit {
|
|||
}
|
||||
|
||||
this.xmlSample = base.examples && getXmlLikeSample(base.examples);
|
||||
this.textSample = base.examples && getTextLikeSample(base.examples);
|
||||
let textResult = base.examples && getTextLikeSample(base.examples);
|
||||
if( textResult ) {
|
||||
this.textSample = textResult.sample;
|
||||
this.textSampleType = textResult.type;
|
||||
}
|
||||
|
||||
let jsonLikeSample = base.examples && getJsonLikeSample(base.examples);
|
||||
if (jsonLikeSample) {
|
||||
|
|
|
@ -148,7 +148,7 @@ export function isXmlLike(contentType: string): boolean {
|
|||
}
|
||||
|
||||
export function isTextLike(contentType: string): boolean {
|
||||
return contentType.search(/text\/plain/i) !== -1;
|
||||
return contentType.search(/text/i) !== -1;
|
||||
}
|
||||
|
||||
export function getJsonLikeSample(samples: Object = {}) {
|
||||
|
@ -179,5 +179,5 @@ export function getTextLikeSample(samples: Object = {}) {
|
|||
return false;
|
||||
}
|
||||
|
||||
return samples[textLikeKeys[0]];
|
||||
return { type:textLikeKeys[0], sample: samples[textLikeKeys[0]]};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user