Skip to content

Commit

Permalink
feat: support for xml samples in response when there is no schema in …
Browse files Browse the repository at this point in the history
…response

closes #307
  • Loading branch information
RomanHotsiy committed Aug 2, 2017
1 parent 2c89536 commit eb7089b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/components/ResponsesSamples/responses-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
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) {
return (!isNaN(parseFloat(n)) && isFinite(n));
}

function hasExample(response) {
return ((response.examples && getJsonLikeSample(response.examples)) ||
response.schema);
return response.schema || getXmlLikeSample(response.examples) || getJsonLikeSample(response.examples)
}

@Component({
Expand Down
2 changes: 1 addition & 1 deletion lib/components/SchemaSample/schema-sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit eb7089b

Please sign in to comment.