mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
feat: support for xml samples in response when there is no schema in response
closes #307
This commit is contained in:
parent
2c8953664a
commit
eb7089b76c
|
@ -3,7 +3,7 @@
|
|||
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
||||
import { BaseComponent, SpecManager } from '../base';
|
||||
import JsonPointer from '../../utils/JsonPointer';
|
||||
import { statusCodeType, getJsonLikeSample } from '../../utils/helpers';
|
||||
import { statusCodeType, getJsonLikeSample, getXmlLikeSample } from '../../utils/helpers';
|
||||
|
||||
|
||||
function isNumeric(n) {
|
||||
|
@ -11,8 +11,7 @@ function isNumeric(n) {
|
|||
}
|
||||
|
||||
function hasExample(response) {
|
||||
return ((response.examples && getJsonLikeSample(response.examples)) ||
|
||||
response.schema);
|
||||
return response.schema || getXmlLikeSample(response.examples) || getJsonLikeSample(response.examples)
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</ng-template>
|
||||
|
||||
<tabs *ngIf="xmlSample; else jsonSnippet">
|
||||
<tab tabTitle="JSON">
|
||||
<tab tabTitle="JSON" *ngIf="sample">
|
||||
<ng-container *ngTemplateOutlet="jsonSnippet"></ng-container>
|
||||
</tab>
|
||||
<tab tabTitle="XML" *ngIf="xmlSample">
|
||||
|
|
|
@ -142,7 +142,7 @@ export function isXmlLike(contentType: string): boolean {
|
|||
return contentType.search(/xml/i) !== -1;
|
||||
}
|
||||
|
||||
export function getJsonLikeSample(samples: Object) {
|
||||
export function getJsonLikeSample(samples: Object = {}) {
|
||||
const jsonLikeKeys = Object.keys(samples).filter(isJsonLike);
|
||||
|
||||
if (!jsonLikeKeys.length) {
|
||||
|
@ -152,7 +152,7 @@ export function getJsonLikeSample(samples: Object) {
|
|||
return samples[jsonLikeKeys[0]];
|
||||
}
|
||||
|
||||
export function getXmlLikeSample(samples: Object) {
|
||||
export function getXmlLikeSample(samples: Object = {}) {
|
||||
const xmlLikeKeys = Object.keys(samples).filter(isXmlLike);
|
||||
|
||||
if (!xmlLikeKeys.length) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user