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