Skip to content

Commit eb7089b

Browse files
committed
feat: support for xml samples in response when there is no schema in response
closes #307
1 parent 2c89536 commit eb7089b

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lib/components/ResponsesSamples/responses-samples.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
44
import { BaseComponent, SpecManager } from '../base';
55
import JsonPointer from '../../utils/JsonPointer';
6-
import { statusCodeType, getJsonLikeSample } from '../../utils/helpers';
6+
import { statusCodeType, getJsonLikeSample, getXmlLikeSample } from '../../utils/helpers';
77

88

99
function isNumeric(n) {
1010
return (!isNaN(parseFloat(n)) && isFinite(n));
1111
}
1212

1313
function hasExample(response) {
14-
return ((response.examples && getJsonLikeSample(response.examples)) ||
15-
response.schema);
14+
return response.schema || getXmlLikeSample(response.examples) || getJsonLikeSample(response.examples)
1615
}
1716

1817
@Component({

lib/components/SchemaSample/schema-sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ng-template>
1313

1414
<tabs *ngIf="xmlSample; else jsonSnippet">
15-
<tab tabTitle="JSON">
15+
<tab tabTitle="JSON" *ngIf="sample">
1616
<ng-container *ngTemplateOutlet="jsonSnippet"></ng-container>
1717
</tab>
1818
<tab tabTitle="XML" *ngIf="xmlSample">

lib/utils/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function isXmlLike(contentType: string): boolean {
142142
return contentType.search(/xml/i) !== -1;
143143
}
144144

145-
export function getJsonLikeSample(samples: Object) {
145+
export function getJsonLikeSample(samples: Object = {}) {
146146
const jsonLikeKeys = Object.keys(samples).filter(isJsonLike);
147147

148148
if (!jsonLikeKeys.length) {
@@ -152,7 +152,7 @@ export function getJsonLikeSample(samples: Object) {
152152
return samples[jsonLikeKeys[0]];
153153
}
154154

155-
export function getXmlLikeSample(samples: Object) {
155+
export function getXmlLikeSample(samples: Object = {}) {
156156
const xmlLikeKeys = Object.keys(samples).filter(isXmlLike);
157157

158158
if (!xmlLikeKeys.length) {

0 commit comments

Comments
 (0)