mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-16 18:00: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 { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
||||||
import { BaseComponent, SpecManager } from '../base';
|
import { BaseComponent, SpecManager } from '../base';
|
||||||
import JsonPointer from '../../utils/JsonPointer';
|
import JsonPointer from '../../utils/JsonPointer';
|
||||||
import { statusCodeType, getJsonLikeSample } from '../../utils/helpers';
|
import { statusCodeType, getJsonLikeSample, getXmlLikeSample } from '../../utils/helpers';
|
||||||
|
|
||||||
|
|
||||||
function isNumeric(n) {
|
function isNumeric(n) {
|
||||||
|
@ -11,8 +11,7 @@ function isNumeric(n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasExample(response) {
|
function hasExample(response) {
|
||||||
return ((response.examples && getJsonLikeSample(response.examples)) ||
|
return response.schema || getXmlLikeSample(response.examples) || getJsonLikeSample(response.examples)
|
||||||
response.schema);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<tabs *ngIf="xmlSample; else jsonSnippet">
|
<tabs *ngIf="xmlSample; else jsonSnippet">
|
||||||
<tab tabTitle="JSON">
|
<tab tabTitle="JSON" *ngIf="sample">
|
||||||
<ng-container *ngTemplateOutlet="jsonSnippet"></ng-container>
|
<ng-container *ngTemplateOutlet="jsonSnippet"></ng-container>
|
||||||
</tab>
|
</tab>
|
||||||
<tab tabTitle="XML" *ngIf="xmlSample">
|
<tab tabTitle="XML" *ngIf="xmlSample">
|
||||||
|
|
|
@ -142,7 +142,7 @@ export function isXmlLike(contentType: string): boolean {
|
||||||
return contentType.search(/xml/i) !== -1;
|
return contentType.search(/xml/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);
|
||||||
|
|
||||||
if (!jsonLikeKeys.length) {
|
if (!jsonLikeKeys.length) {
|
||||||
|
@ -152,7 +152,7 @@ export function getJsonLikeSample(samples: Object) {
|
||||||
return samples[jsonLikeKeys[0]];
|
return samples[jsonLikeKeys[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getXmlLikeSample(samples: Object) {
|
export function getXmlLikeSample(samples: Object = {}) {
|
||||||
const xmlLikeKeys = Object.keys(samples).filter(isXmlLike);
|
const xmlLikeKeys = Object.keys(samples).filter(isXmlLike);
|
||||||
|
|
||||||
if (!xmlLikeKeys.length) {
|
if (!xmlLikeKeys.length) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user