feat: support for xml samples in response when there is no schema in response

closes #307
This commit is contained in:
Roman Hotsiy 2017-08-02 17:14:40 +03:00
parent 2c8953664a
commit eb7089b76c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 5 additions and 6 deletions

View File

@ -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({

View File

@ -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">

View File

@ -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) {